Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9760

Re: How to join two internal table rows in alternative manner into one internal table?

$
0
0

Hi Soubhik,

I have added two additional columns for each internal table.

 

Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)

Row_Count  - It represents the Row Count Number, increase the row count value 1 by one..

 

ITAB1:

 

Header 1Header 2Header 3Table_CountRow_Count
abc11
def12
ghi13

 

ITAB2:

 

Header 1Header 2Header 3Table_CountRow_Count
12321
45622
78923

 

Create the Final Internal table as same as the ITAB1/ITAB2 structure.

 

"Data Declarations

DATA: IT_FINAL LIKE TABLE OF ITAB1.          "Final Internal Table

 

FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1,     "TAB1

                               <FS_TAB2> TYPE TY_TAB2.     "TAB2

 

"Assign the values for the additional two column for ITAB1

LOOP AT ITAB1 ASSIGNING <FS_TAB1>.

     <FS_TAB1>-TABLE_COUNT = 1.             "Table value same for all row

     <FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value

ENDLOOP.

 

"Assign the values for the additional two column for ITAB2

LOOP AT ITAB2 ASSIGNING <FS_TAB2>.    

     <FS_TAB2>-TABLE_COUNT = 2.                  "Table value same for all row

     <FS_TAB2>-ROW_COUNT = SY-TABIX.      "Index value

ENDLOOP.

 

"Copy the First Internal Table 'ITAB1' to Final Table

IT_FINAL[] = ITAB1[].

 

"Copy the Second Internal Table 'ITAB2' to Final Table

APPEND IT

LOOP AT ITAB2 INTO WA_TAB2.

APPEND WA_TAB2 TO IT_FINAL.

ENDLOOP.

 

"Sort the Internal Table based on TABLE_COUNT & ROW_COUNT

SORT IT_FINAL BY  ROW_COUNT TABLE_COUNT.

 

After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.

 

Regards

 

Rajkumar Narasimman


Viewing all articles
Browse latest Browse all 9760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>