Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Internal Table Concept

former_member532868
Participant
0 Kudos

HI

I have 3 internal tables with same structures.

First Internal table i am fetching some data.

i am moving First Internal table (IT_Table1) data into table IT_Table_final like as below

IT_table_final[] = IT_table1[].

After that i am using Second Table IT_Table2.

i need to append data to IT_Table_final using IT_table2 data with out using loop.

Can you please guide me how can i append data to IT_table_final using IT_table2 in all records at a time.

Regards,

Hari

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos
APPEND LINES OF IT_Table2 TO IT_Table_final
4 REPLIES 4

SuhaSaha
Advisor
Advisor
0 Kudos
APPEND LINES OF IT_Table2 TO IT_Table_final

Former Member
0 Kudos

use

CLEAR IT_Table_final.

IF IT_Table1 Is not initial.

APPEND LINES OF IT_Table1 TO IT_Table_final

ENDIF.

IF IT_Table2 Is not initial.

APPEND LINES OF IT_Table2 TO IT_Table_final

ENDIF.

Former Member
0 Kudos

Hi Hari,

You may use the below code if both the tables are having the same structure.


APPEND LINES OF IT_Table2 TO IT_Table_final.

Thanks,

Ranjith

Former Member
0 Kudos

Hi Hari,

I have tried the same scenario that you have mentioned. You can use APPEND statement to append all records from IT_table2 to IT_table_final. But you need to specify the no. of records. For this you can use DESCRIBE TABLE...LINES statement.

When I tried without specifying the no. of lines, I saw that only few lines of IT_table2 were appended. So I suggest you to use


APPEND LINES OF IT_TABLE2 FROM 1 TO N TO IT_TABLE_FINAL.

*---- where N = no. of records in IT_TABLE2------*

For your convenience, I am adding the code that I used.


REPORT  ZREP_SA_002.

TYPES: BEGIN OF TY_KNA1,
       KUNNR TYPE KUNNR,
       LAND1 TYPE LAND1_GP,
       END OF TY_KNA1.

DATA: IT_TABLE1 TYPE STANDARD TABLE OF TY_KNA1 WITH HEADER LINE,
      IT_TABLE2 TYPE STANDARD TABLE OF TY_KNA1 WITH HEADER LINE,
      IT_TABLE_FINAL TYPE STANDARD TABLE OF TY_KNA1 WITH HEADER LINE,
      WA3 LIKE LINE OF IT_TABLE_FINAL,
      LINE TYPE I.

START-OF-SELECTION.

SELECT KUNNR
       LAND1
FROM KNA1
INTO CORRESPONDING FIELDS OF TABLE IT_TABLE1
WHERE KUNNR BETWEEN '0001000000' AND '0001000010'.

IF SY-SUBRC EQ 0.
IT_TABLE_FINAL[] = IT_TABLE1[].
ENDIF.

SELECT KUNNR
       LAND1
FROM KNA1
INTO CORRESPONDING FIELDS OF TABLE IT_TABLE2
WHERE KUNNR BETWEEN '0001000010' AND '0001000020'.

DESCRIBE TABLE IT_TABLE2 LINES LINE.

IF SY-SUBRC EQ 0.
APPEND LINES OF IT_TABLE2 FROM 1 TO LINE TO IT_TABLE_FINAL .
ENDIF.

You can further sort the IT_TABLE_FINAL, and delete adjacent duplicates, for better performance. However, this is optional.


SORT IT_TABLE_FINAL BY KUNNR.
DELETE ADJACENT DUPLICATES FROM IT_TABLE_FINAL.

Hope this helps you,

Best Regards,

Smruthi