Application Development and Automation 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: 
Read only

inserting one itab values into another

Former Member
0 Likes
538

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
516

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.

4 REPLIES 4
Read only

Former Member
0 Likes
517

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.

Read only

Former Member
0 Likes
516

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

Read only

Former Member
0 Likes
516

HI

Edited by: Sriram Ponna on Feb 22, 2008 6:34 PM

Read only

Former Member
0 Likes
516

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.