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

one problem

abdulazeez12
Active Contributor
0 Likes
712

hii all-

i have the following code:

here gt_tab is table without header line and gs_tab is structure.

loop at gt_tab into gs_tab.

if p_chk = 'X'.

gs_tab-fld1 = 'asdf'.

gs_tab-fld2 = 'cvbn'.

modify gt_tab from gs_tab index sy-index.

else.

read table gt_other with key fld = gs_tab-fld binary search.

if sy-subrc eq 0.

modify gt_tab from gs_tab index sy-tabix.

else.

delete gt_tab index sy-tabix.

endif.

endif.

can anyone tell me what to use to modify and delete in such cases as above? iam getting dump in the above case. it says index is zero and not found.

Tx

endloop.

6 REPLIES 6
Read only

Former Member
0 Likes
691

Use SY-TABIX instead of SY-INDEX when you are in a internal table loop.

Read only

0 Likes
691

Declare a variable of type SY-TABIX and move the value of SY-TABIX to this variable as soon as you enter the loop and use this variable when modifying the table.

Read only

Former Member
0 Likes
691

remove the sy-index..

I hope this will work

modify gt_tab from gs_tab .

Read only

Former Member
0 Likes
691

Hello,

Change the code like this.


data: l_tabix like sy-tabix.

loop at gt_tab into gs_tab.
l_tabix EQ sy-tabix.
if p_chk = 'X'.
gs_tab-fld1 = 'asdf'.
gs_tab-fld2 = 'cvbn'.
modify gt_tab from gs_tab index l_tabix.
else.
read table gt_other with key fld = gs_tab-fld binary search.
if sy-subrc eq 0.
modify gt_tab from gs_tab index l_tabix..
else.
delete gt_tab index l_tabix..
endif.
endif.

regards,

Vasanth

Read only

Former Member
0 Likes
691

hi shakir ,

change the delete statement to this

<b>delete gt_tab from gs_tab index sy-tabix.</b>

<b>when using workares no need to use index sy-tabix, try this. internal table will be modified from workarea.</b>

loop at gt_tab into gs_tab.

if p_chk = 'X'.

gs_tab-fld1 = 'asdf'.

gs_tab-fld2 = 'cvbn'.

<b>modify gt_tab from gs_tab.</b>

else.

read table gt_other with key fld = gs_tab-fld binary search.

if sy-subrc eq 0.

<b>modify gt_tab from gs_tab .</b>

else.

<b>delete gt_tab from gs_tab.</b>

endif.

endif.

Read only

Former Member
0 Likes
691

loop at gt_tab into gs_tab.

if p_chk = 'X'.

gs_tab-fld1 = 'asdf'.

gs_tab-fld2 = 'cvbn'.

<b>modify gt_tab from gs_tab index sy-TABIX.</b>else.

read table gt_other with key fld = gs_tab-fld binary search.

if sy-subrc eq 0.

modify gt_tab from gs_tab index sy-tabix.

else.

delete gt_tab index sy-tabix. " Do not use delete command within loop and endloop

endif.

endif.