‎2008 Sep 01 7:57 AM
Hi all,
In my program I am Writing an loop statement for table ITAB1 and in that loop i am writing
two(2) Read statements for ITAB2 and ITAB3.
Now i Need to append all the data in the tables ITAB1,ITAB2,ITAB3 to ITAB.
How can i write this Append Statement
Can i Append all the data in the three tables at a time or do i need to append one by one
Thanks
Ajay
‎2008 Sep 01 8:03 AM
hi
yes u can
let the work area for this tables are
wa_itab1
wa_itab2
wa_itab3
now
loop at itab1 into wa_itab1.
ur frist read statement and u get thai record in wa_itab2.
then
ur second read statement and u get thai record in wa_itab3.
now
append wa_itab1 to itab.
append wa_itab2 to itab.
append wa_itab3 to itab.
endloop.
‎2008 Sep 01 8:01 AM
Hi,
If the type of the Internal table ITAB1,ITAB2,ITAB3 to ITAB are same then you can directly appen those to final internal table.
The statement is
APPEND ITAB1 to ITAB.
HERE ITAB1 is the workarea of the ITAB1 intearnal table.
same for rest of the internal tables.
Check this link for details-
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb36c8358411d1829f0000e829fbfe/content.htm
Regards,
Sujit
‎2008 Sep 01 8:02 AM
Hi,
Loop at itab1
itab-filed = itab1-field
Read itab2.
if sy-subrac = 0.
itab-field = itab2-field.
endif.
Read itab3.
if sy-subrc = 0.
itab-field = itab3-field.
endif.
APPEND itab.
endloop.
thanks,
‎2008 Sep 01 8:02 AM
‎2008 Sep 01 8:03 AM
Hi Ajay,
Try using this :
Appending Several Lines
You can append internal tables to index tables using the following statement:
APPEND LINES OF <itab1> TO <itab2>.This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
When you append an index table to another index table, you can specify the lines to be appended as follows:
APPEND LINES OF <itab1> [FROM <n1>] [TO <n 2>] TO <itab2>.<n 1 > and <n 2 > specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX contains the index of the last line appended. When you append several lines to a sorted table, you must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
Regards,
Swapna.
‎2008 Sep 01 8:03 AM
hi
yes u can
let the work area for this tables are
wa_itab1
wa_itab2
wa_itab3
now
loop at itab1 into wa_itab1.
ur frist read statement and u get thai record in wa_itab2.
then
ur second read statement and u get thai record in wa_itab3.
now
append wa_itab1 to itab.
append wa_itab2 to itab.
append wa_itab3 to itab.
endloop.
‎2008 Sep 01 8:04 AM
Hello,
Here is one way.Assuming that ITAB1, ITAB2,ITAB3 and ITAB has similar Structures.
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 to ITAB.
READ TABLE ITAB2 with key F1 = ITAB1-F1 Bin Srch.
IF SY-SUBRC EQ 0.
MOVE-CORRESPONDING ITAB2 to ITAB.
ENDIF.
READ TABLE ITAB3 with key F1 = ITAB1-F1 Bin Srch.
IF SY-SUBRC EQ 0.
MOVE-CORRESPONDING ITAB3 to ITAB.
ENDIF.
APPEND ITAB.
ENDLOOP.
Hope it helps.
Thanks and Regards,
Venkat Phani Prasad Konduri
‎2008 Sep 01 8:06 AM
hi,
check this sample code.
Form final_table.
loop at it_bsis.
CLEAR IT_bkpf.
READ TABLE IT_bkpf WITH KEY bukrs = IT_bsis-bukrs
belnr = it_bsis-belnr
gjahr = it_bsis-gjahr.
IF SY-SUBRC = 0.
it_final-xblnr = it_bkpf-xblnr.
it_final-bukrs = it_bkpf-bukrs.
it_final-monat = it_bkpf-monat.
it_final-gjahr = it_bkpf-gjahr.
ENDIF.
CLEAR IT_bseg.
READ TABLE IT_bseg WITH KEY bukrs = IT_bkpf-bukrs
belnr = it_bkpf-belnr
gjahr = it_bkpf-gjahr
hkont = it_bsis-hkont
buzei = it_bsis-buzei.
IF SY-SUBRC = 0.
IT_FINAL-belnr = IT_bseg-belnr.
it_final-prctr = it_bseg-prctr.
IT_FINAL-gsber = IT_bseg-gsber.
it_final-bschl = it_bseg-bschl.
it_final-maber = it_bseg-maber.
ENDIF.
CLEAR IT_KNA1.
READ TABLE IT_KNA1 WITH KEY KUNNR = IT_acct-KndnR.
IF SY-SUBRC = 0.
IT_FINAL-KUNNR = IT_KNA1-KUNNR.
IT_FINAL-name1 = IT_KNA1-name1.
IT_FINAL-stras = IT_KNA1-stras.
IT_FINAL-ort01 = IT_KNA1-ort01.
ENDIF.
APPEND IT_FINAL.
CLEAR IT_FINAL.
endloop.
endform.
‎2008 Sep 01 8:06 AM
Loop at itab1.
move-corresponding itab1 to itab.
read itab2.
move-corresponding itab2 to itab.
read itab3.
move-corresponding itab3 to itab.
append itab.
endloop.
Regards
Sathar
‎2008 Sep 01 8:28 AM
Hi,
itab = itab1.
append itab.
itab = itab2.
append itab.
itab = itab3.
append itab.
i hope this will help you.
Regards,
Harish
‎2008 Sep 01 8:37 AM
Hi Ajay,
Do it like this:
Loop at ITAB1 into WA1.
Read table ITAB2 into WA2 with key field eq WA1-field.
Read table ITAB3 into WA3 with key field eq WA1-field.
WA-field1 = WA1-field.
WA-field2 = WA2-field.
WA-field3 = WA3-field.
Append WA to ITAB.
Endloop.With luck,
Pritam.