Question: How to write the entries of first and second table to third table without SORT statement?
No SORT proclamation ought to be there in the arrangement.
The moment this question was raised, there was a discussion among the participants regarding the business requirement. They pondered, “Why might we not use the SORTing Algorithm – Interview Question as a standard solution?” This led to an exploration of the context and efficiency of sorting methods in various scenarios.
Then the part who posed this inquiry uncovered it is one of the inquiry question from one the Huge Worldwide IT Organizations.
Then the following discussion began that we shouldn’t pose such inquiries in interview. However, one of the part protected saying that Arranging Calculations are approached by questioners to wipe out at the absolute first phase of the choice interaction.
Alright, abandoning the discussion, regardless of whether such inquiries questions really test the programming expertise, everybody consented to track down an answer.
We got 2 methodologies with working code piece.
Solution 1
TYPES: tt_int TYPE TABLE OF i WITH EMPTY KEY.
DATA(it_one) = VALUE tt_int( ( 1 ) ( 9 ) ( 12 ) ( 16 ) ).
DATA(it_two) = VALUE tt_int( ( 4 ) ( 10 ) ( 15 ) ( 20 ) ).
DATA:it_three TYPE tt_int.
APPEND LINES OF it_one TO it_three.
APPEND LINES OF it_two TO it_three.
DATA(lv_len) = lines( it_three ).
DATA(i) = 1.
WHILE i < lv_len.
DATA(lv_min) = it_three[ i ].
DATA(j) = i + 1.
WHILE j < lv_len + 1 .
IF it_three[ j ] < lv_min.
DATA(lv_temp) = lv_min.
lv_min = it_three[ j ].
it_three[ j ] = lv_temp.
ENDIF.
j = j + 1.
ENDWHILE.
it_three[ i ] = lv_min.
i = i + 1.
ENDWHILE.
Solution 2
TYPES:
gtyt_interger TYPE TABLE OF i WITH EMPTY KEY,
gtyt_interger_sorted TYPE SORTED TABLE OF i with NON-UNIQUE KEY table_line.
DATA(lt_table1) = VALUE gtyt_interger( ( 1 ) ( 9 ) ( 12 ) ( 16 ) ).
DATA(lt_table2) = VALUE gtyt_interger( ( 4 ) ( 10 ) ( 15 ) ( 20 ) ).
DATA(lt_table3) = CORRESPONDING gtyt_interger_sorted( lt_table1 ).
INSERT LINES OF lt_table2 INTO TABLE lt_table3.
Check the output.
Simply the Supplement explanation did the Wizardry!! Astounding arrangement.
Each engineer think in an unexpected way. What’s more, there can be various ways of accomplishing a similar arrangement. Answer for this question is an ideal model.
Our SAP Specialized Gathering is only an illustration of how we can team up and become familiar with each day. No inquiry is too senseless to even think about presenting. Ask, Reply, Propose, Depend, Offer and Learn is the adage of our SAP Gathering.
This is the specific code bit and result shared by Stephan. We all can save this for our fast reference for new ABAP linguistic structure and utilization.
Solution 3
He gave one more arrangement without utilizing Addition proclamation. Check the beneath piece.
TYPES:
gtyt_interger TYPE TABLE OF i WITH EMPTY KEY,
gtyt_interger_sorted TYPE SORTED TABLE OF i WITH NON-UNIQUE KEY table_line.
DATA(lt_table1) = VALUE gtyt_interger( ( 1 ) ( 9 ) ( 12 ) ( 16 ) ).
DATA(lt_table2) = VALUE gtyt_interger( ( 4 ) ( 10 ) ( 15 ) ( 20 ) ).
DATA(lt_table3) = CORRESPONDING gtyt_interger_sorted( BASE ( lt_table1 ) lt_table2 ).
* Starting with NW7.51 It is possible to prevent duplicate entries using DISCARDING DUPLICATES
* https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/index.htm
cl_demo_output=>write_data( value = lt_table1 name = 'First Table' ).
cl_demo_output=>write_data( value = lt_table2 name = 'Second Table' ).
cl_demo_output=>write_data( value = lt_table3 name = 'Third Table' ).
cl_demo_output=>display( ).
He has utilized the new BASE watchword. BASE is a useful operand position in which a data set convertible to the objective sort can be determined. BASE is use to determine a beginning worth base for the new construction of inside table.
You can peruse more about watchword BASE in SAP ABAPDOCU
Additionally, we can utilize Disposing of Copies watchwords for dealing with copy lines in part administrator Relating. Check more about Disposing of Copies in ABAP Help.
YOU MAY LIKE THIS
Best Practices for SAP Cloud Platform Development: A Comprehensive Guide