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: 

How to Insert a Row in Itab

Former Member
0 Kudos

Dear All

I have two internal tables itab1 and itab2 in itab 1 i have single record with respect to date and pernr in itab2 i have multiple record with respect to date and pernr. now i want that i modify the 1st record of itab 1 and add the 1st record of itab2 into itab1 and the rest of the records of itab2 may be append below of the record for example

itab1

date pernr name

01.01.2009 69 Ammir

01.02.2009 69 Ammir

01.03.2009 69 Ammir

itab2

date pernr Amount

01.02.2009 69 50,000

01.02.2009 69 40,000

01.02.2009 69 30,000

through this example i can explain that i have to post all these amounts in itab1 infront of date 01.02.2009

kindly help me

regards

Ammad

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Try this

LOOP AT ITAB2.
READ TABLE ITAB1 WITH KEY DATE = ITAB2-DATE PERNR = ITAB2-PERNR.
IF SY_SUBRC EQ 0.
L_TABIX = SY-TABIX
CLEAR COUNT.
LOOP AT  ITAB2 WHERE DATE = ITAB2-DATE AND  PERNR = ITAB2-PERNR.
L_TABIX = L_TABIX + 1.
COUNT = COUNT + 1.
IF COUNT EQ 1.
 MODIFY ITAB1.
ELSE.
" move the data to itab1 work area
INSERT using INDEX L_TABIX in Itab1.   or Append the record in the ITAB1 and later you can sort the ITAB1 by PERNR and DATE
ENDIF.
ENDLOOP.
ENDIF.

ENDLOOP.

Edited by: Avinash Kodarapu on Jul 20, 2009 6:22 PM

3 REPLIES 3

Former Member
0 Kudos

Hi Zaman,

You can try the following code.

Loop at itab2.

At new amount.

loop at itab1where date = itab1-date pernr = itab1-pernr.

if itab1-amount is initial.

itab1-amount = itab2-amount.

modify itab1.

clear itab1-amount.

endif.

endloop.

endat.

endloop.

Regards,

vik

Edited by: vikred on Jul 20, 2009 2:50 PM

Former Member
0 Kudos

Hi,

Try this

LOOP AT ITAB2.
READ TABLE ITAB1 WITH KEY DATE = ITAB2-DATE PERNR = ITAB2-PERNR.
IF SY_SUBRC EQ 0.
L_TABIX = SY-TABIX
CLEAR COUNT.
LOOP AT  ITAB2 WHERE DATE = ITAB2-DATE AND  PERNR = ITAB2-PERNR.
L_TABIX = L_TABIX + 1.
COUNT = COUNT + 1.
IF COUNT EQ 1.
 MODIFY ITAB1.
ELSE.
" move the data to itab1 work area
INSERT using INDEX L_TABIX in Itab1.   or Append the record in the ITAB1 and later you can sort the ITAB1 by PERNR and DATE
ENDIF.
ENDLOOP.
ENDIF.

ENDLOOP.

Edited by: Avinash Kodarapu on Jul 20, 2009 6:22 PM

Former Member
0 Kudos

Hi ,

If your internal table do not have many fields then you can open it in debug mode and

insert a record . Try.