Yesterday, one member asked the below question. It was no doubt an interview question from one of the largest IT Company in the world.
Question: How to write the entries of first and second table to third table without SORT statement?
No SORT statement should be there in the solution.
The moment this question was floated, there was a debate among the members asking what is the business requirement? Why can we not use SORT?
Then the member who asked this question revealed it is one of the interview question from one the Big Multi National IT Companies.
Then the next debate started that we should not ask such questions in interview. But one of the member defended saying that SORTing Algorithms are asked by interviewers to eliminate at the very first stage of the selection process.
Ok, leaving behind the debate, whether such interview questions actually test the programming skill or not, everyone agreed to find a solution.
We received 2 approaches with working code snippet.
Solution 1 – Provided by Sercan Küçükdemirci
Team SAPYard validated the output. It is as per the requirement. Thank you Sercan!! You may connect with Sercan at LinkedIn.
Solution 2 – Provided by Stephan Koester
gtyt_interger_sortedTYPESORTED TABLE OFiwithNON-UNIQUE KEYtable_line.
Check the output.
Just the INSERT statement did the Magic!! Amazing solution.
Also Read:My First Program in S/4HANA
Every developer think differently. And there can be different ways to achieve the same solution. Solution to this question is a perfect example.
Our SAP Technical Group is just an example of how we can collaborate and learn every day. No question is too silly to ask. Ask, Answer, Propose, Depend, Share and Learn is the motto of our SAP Group.
This is the exact code snippet and output shared by Stephan. All of us can keep this for our quick reference for new ABAP syntax and usage.
Solution 3 – Provided by Stephan Koester
Stephan provided yet another solution without using INSERT statement. Check the below snippet.
gtyt_interger_sortedTYPESORTED TABLE OFiWITHNON-UNIQUE KEYtable_line.
* Starting with NW7.51 It is possible to prevent duplicate entries using DISCARDING DUPLICATES
He has used the new BASE key word. BASE is a functional operand position in which a database convertible to the target type can be specified. BASE is use to specify a start value base for the new structure of internal table.
You can read more about keyword BASE in SAP ABAPDOCU
Also, we can use DISCARDING DUPLICATES keywords for handling duplicate rows in component operator CORRESPONDING. Check more about DISCARDING DUPLICATES in ABAP Help.
Would you like to share some weird Interview Questions you faced? Anything.. Technical or Non-Technical.
Join our Telegram SAP Technical Discuss Group. You need to install Telegram App first.
Check HANA-ABAP Tutorials
- ABAP on SAP HANA. Part I. First Program in ABAP HANA
- ABAP on SAP HANA. Part II. ADT Eclipse and HANA Studio
- ABAP on SAP HANA. Part III. Debugging in ADT
- CDS Part 1. Core Data Services – Introduction
- CDS Part 2. Core Data Services – Deep Dive
- ABAP on SAP HANA. Part VI. New Age Open SQL ABAP 740
- ABAP on SAP HANA. Part VII. SQL Script and SAP HANA Stored Procedure
- ABAP on SAP HANA. Part VIII. ADBC – ABAP DataBase Connectivity
- ABAP on SAP HANA. Part IX. AMDP – ABAP Managed Database Procedure
- ABAP on SAP HANA. Part X. AMDP with SELECT OPTIONS
- ABAP on SAP HANA. Part XI. Are Native SQL and Open SQL Competitors?
- ABAP on SAP HANA. Part XII. Open SQL, CDS or AMDP, which Code to Data Technique to use?
- ABAP on SAP HANA. Part XIII. Sample Functional Specification of HANA Project
- ABAP on SAP HANA: Part XIV. HANA Ready, HANA-tization & HANA Plus
- CDS Part 3. Expose CDS Views as OData Service through Annotation
- ABAP on SAP HANA: Part XVI. HANAtization
- ABAP on SAP HANA: Part XVII. ATC – ABAP Test Cockpit Setup & Exemption Process
- SAP ABAP on HANA: Part XVIII. SALV IDA (Integrated Data Access)
- ABAP for SAP HANA. Part XIX. Sample Technical Specification of HANA Project
- ABAP for SAP HANA. Part XX. ALV Report On SAP HANA – Opportunities And Challenges
- 4 Useful Tips on ABAP and ABAP on HANA
- Associations in HANA – A Conceptual Approach
- CDS Part 5. ABAP CDS Views With Authorization
- ABAP for SAP HANA. Part XXII. How to Consume Native HANA Views Using ADBC?
- CDS Part 6. Basic Expressions & Operations Available for CDS View – I
- 115 ABAP for SAP HANA Interview Questions & Answers
- CDS Part 7. Basic Expressions & Operations Available for CDS View – II
- CDS Part 8. Usage of Built-In Functions in CDS – I
- CDS Part 9. Usage of Built-In Functions in CDS – II
- CDS Part 10. Usage of Built-In Functions in CDS – III
- CDS Part 11. How to Consume CDS View in Smart Business Service KPI Fiori Apps?
- CDS Part 12. Useful 6 CDS Related Tools in ADT
- CDS Part 13. Key Definition in CDS Views
- CDS Part 14. ABAP Annotations for Translatable Texts in CDS Views
- CDS Part 15. Associations in CDS Views – I
- ABAP for SAP HANA – Part 23. How to Access Database Schema Dynamically Using AMDP?
- Video Course – New Features and Syntaxes in SAP ABAP 7.40+ with Exercises
- CDS Part 16. Usage of Built-In Functions in CDS – IV
- ‘ABAP for SAP HANA’ Points to Remember
- Limitations of Open SQL Compared to SQL Script in HANA
- CDS Part 17. How to Overcome GUID Mismatch Linking Problem in ABAP CDS?
- Curious Case of ATC – Priority 2 – Low Performance Operations on Internal Tables
- ABAP for SAP HANA – Part 24. Custom Report Using AMDP