‎2007 Jun 15 4:37 PM
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.
‎2007 Jun 15 4:39 PM
Use SY-TABIX instead of SY-INDEX when you are in a internal table loop.
‎2007 Jun 15 4:41 PM
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.
‎2007 Jun 15 4:40 PM
remove the sy-index..
I hope this will work
modify gt_tab from gs_tab .
‎2007 Jun 15 4:40 PM
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
‎2007 Jun 15 4:41 PM
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.
‎2007 Jun 15 4:43 PM
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.