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: 

problem in Modify in loop

Former Member
0 Kudos

Hi all,

Is it possible to modify a internal table in some other internal table's Loop.

In a loop of ITAB , i am moving some fields to IT_FINAL , and trying to Modify IT_FINAL , but it showing dump, so is it possible to modify or append some internal table in some other internal table's Loop , pls suggest some solution.

Thanks in advance,

Regards,

Vivek

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Yes you can modify but you need mention the index as addition.

E.g : MODIFY itab INDEX index1.

So increment a counter in loop & use it in modify statement

9 REPLIES 9

Former Member
0 Kudos

Yes you can modify but you need mention the index as addition.

E.g : MODIFY itab INDEX index1.

So increment a counter in loop & use it in modify statement

Former Member
0 Kudos

Yes - you heve to specify the proper position in the itab (SY-TABIX).

Rob

Former Member
0 Kudos

Can u explain by some example , how to give index or sy-tabix value

rodrigo_paisante3
Active Contributor
0 Kudos

Hi, try this

DATA: BEGIN OF ti_scustom OCCURS 0.

INCLUDE STRUCTURE scustom.

DATA: END OF ti_scustom.

DATA: ti2 LIKE TABLE OF ti_scustom WITH HEADER LINE.

SELECT * FROM scustom INTO TABLE ti_scustom.

ti2[] = ti_scustom[].

LOOP AT ti_scustom.

IF sy-tabix = 2.

ti2-name = 'Paisante'.

MODIFY ti2 index sy-tabix.

ENDIF.

ENDLOOP.

READ TABLE ti2 with key id = 2.

WRITE ti2.

Regards

Former Member
0 Kudos

<b>data : v_tabix liek sy-tabix.</b>

loop at itab1.

<b>v_tabix = sy-tabix.</b>

loop at itab2 where field1 eq itab1-field1.

move-corresponding itab2 to itab1.

<b>modify itab1 index v_tabix.</b>

endloop.

endloop.

Former Member
0 Kudos

Hi,

You need to use index addition if you want to modify an internal table during its LOOP operations.

Use sy-tabix if you want to modify the current record of an internal table.

Reward points if the answer is helpful.

Regards,

Mukul

former_member219399
Active Participant
0 Kudos

Hi,

Can you please paste your code here?

How you are accessing it_final?

are you readig It_final using a key from itab? if so store that index in a field idx and modify it_final with this idx.

ie.

read table it_final with key *****.

if sy-subrc = 0.

idx = sy-tabix.

it_final-field1 = itab-field1.

modify it_final index idx from it_final transporting field1.

endif.

the other approach is modify table it_final from is_final. "where is_final is workarea

with regards,

Vamsi

Former Member
0 Kudos

Vivek,

1.Check the data type of source and target fields.Bath should same type.

2. put below logic.

LOOP AT ITAB.

it_final-field1 = itab-field1.

modify it_final index idx from it_final transporting field1.

ENDLOOP.

Don't forget to reward if useful...

dev_parbutteea
Active Contributor
0 Kudos

Hi,

you can also use the following:

loop at itab1 into wa_tab1.

move wa_tab1-field1 to lwa_results_final-msgtxt.

move wa_tab1-field2 to lwa_results_final-msgid.

move wa_tab1-field3 to lwa_results_final-msgno.

modify li_results_final from lwa_results_final

transporting msgtxt msgid msgno

where ordkey = 'testvariable'.

endloop.

Regards,

Sooness