‎2008 Feb 22 12:42 PM
hi,
i want to insert one itab values into another itab.for ex:i have values in itab1 like this
kunnr amount
10 1000
10 1030
10 1200
20 345
20 346
30 345
30 345
40 234
in itab2
10 1010
10 1020
20 349
30 305
30 325
i want to insert itab2 values at the end of each kunnr in itab1 like this
10 1000
10 1030
10 1200
10 1010
10 1020
20 345
20 346
20 349
30 345
30 345
30 305
30 325
i wrote the code like this
DATA : INDEX TYPE I,
NO_OF_DAYS TYPE P,
GL TYPE SY-TABIX,
XL TYPE SY-TABIX,
VL TYPE SY-TABIX,
V_LINES TYPE I,
V_ADD TYPE I,
COUNTER TYPE I.
V_ADD = 1.
LOOP AT IT_BSID INTO W_BSID from V_ADD .
WA_BSID = W_BSID.
AT END OF KUNNR.
IF SPLGL NE SPACE.
VL = SY-TABIX.
GL = SY-TABIX + 1.
LOOP AT IT_BSID3 INTO W_BSID3 where kunnr = wa_bsid-kunnr.
MOVE-CORRESPONDING W_BSID3 TO W_BSID.
IF VL < V_LINES.
INSERT W_BSID INTO IT_BSID INDEX GL.
ELSEIF VL = V_LINES.
APPEND W_BSID TO IT_BSID .
ENDIF.
GL = GL + 1.
XL = SY-TABIX.
endloop.
ENDIF.
endat.
IF XL NE 0.
V_ADD = 1 + XL.
ELSE.
V_ADD = SY-TABIX + 1.
ENDIF.
CLEAR : INDEX,GL, VL.
ENDLOOP.
please give solution.
Thanks
k srinivas
‎2008 Feb 22 12:50 PM
Take another internal table to insert the same ...
Loop at itab1.
itab3 = itab1.
append itab3.
clear itab3.
at end of kunnr.
loop at itab2 where kunnr = itab1-kunnr.
itab3 = itab2.
append itab3.
clear itab3.
endloop.
endat.
endloop.
‎2008 Feb 22 12:50 PM
Take another internal table to insert the same ...
Loop at itab1.
itab3 = itab1.
append itab3.
clear itab3.
at end of kunnr.
loop at itab2 where kunnr = itab1-kunnr.
itab3 = itab2.
append itab3.
clear itab3.
endloop.
endat.
endloop.
‎2008 Feb 22 12:50 PM
Hi Srinivas,
Declare another internal table itab3 which holds final results.
data: lv_index type sy-index.
sort itab1 by kunnr.
sort itab2 by kunnr.
loop at itab1.
lv_index = sy-index.
itab3 = itab1.
append itab3.
at end of kunnr.
loop at itab2 where kunnr = itab1-kunnr.
itab3 = itab2.
append itab3.
endloop.
endat.
endloop.
At last you will have expected results in itab3.
Regards,
Yellappa.
Edited by: yellappa m on Feb 22, 2008 6:21 PM
‎2008 Feb 22 12:57 PM
‎2008 Feb 22 1:03 PM
Hi,
U can do as below...
DATA : BEGIN OF itab1 OCCURS 0,
fld1 TYPE char2,
fld2 TYPE char5,
END OF itab1,
itab2 LIKE itab1 OCCURS 0 WITH HEADER LINE.
itab1-fld1 = 10.
itab1-fld2 = 100.
APPEND itab1.
itab1-fld1 = 20.
itab1-fld2 = 100.
APPEND itab1.
itab1-fld1 = 30.
itab1-fld2 = 100.
APPEND itab1.
itab1-fld1 = 40.
itab1-fld2 = 100.
APPEND itab1.
itab1-fld1 = 50.
itab1-fld2 = 100.
APPEND itab1.
itab2-fld1 = 10.
itab2-fld2 = 200.
APPEND itab2.
itab2-fld1 = 20.
itab2-fld2 = 200.
APPEND itab2.
itab2-fld1 = 30.
itab2-fld2 = 200.
APPEND itab2.
itab2-fld1 = 40.
itab2-fld2 = 200.
APPEND itab2.
itab2-fld1 = 50.
itab2-fld2 = 200.
APPEND itab2.
WRITE 'ITAB1 values'.
WRITE /.
LOOP AT itab1.
WRITE: / itab1-fld1,itab1-fld2.
ENDLOOP.
WRITE /.
WRITE /'ITAB2 values'.
WRITE /.
LOOP AT itab2.
WRITE: / itab2-fld1,itab2-fld2.
ENDLOOP.
LOOP AT itab1.
itab2-fld1 = itab1-fld1.
itab2-fld2 = itab1-fld2.
APPEND itab2.
ENDLOOP.
SORT itab2 BY fld1 fld2.
WRITE /.
WRITE /'ITAB2 values after appending'.
WRITE /.
LOOP AT itab2.
WRITE: / itab2-fld1,itab2-fld2.
ENDLOOP.Cheers,
jose.