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

table modification problem

Former Member
0 Likes
332

Hi,

I have one problem.

Suppose I have two delivery doc no & delivery item. Now i m getting the delivery quantity from lips table based on delivery doc no & delivery item.

Now i have to modify my same table having field delivery qty.

sample coding.

data: begin of ty_str,

del_doc like vbfa-vbeln,

del_item like vbfa-posnn,

lfimg like lips-lfimg,

end of ty_str.

data: gt_str like table of ty_str,

gs_str like line of gt_str.

*consider my records r in gt_str.

loop at gt_str into gs_str.

select single lfimg from lips into lv_lfimg where vbeln = gs_str-del_doc

and posnr = gs_str-del_item.

*now i wanted to modify the field lfimg in table gt_str based on del_doc & del_item.

endloop.

Any body will pls suggest me the solution.

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
304

Hello Neha

Simply modify your itab like this:

loop at gt_str into gs_str.
select single lfimg from lips into lv_lfimg 
  where vbeln = gs_str-del_doc
  and posnr   = gs_str-del_item.

*now i wanted to modify the field lfimg in table gt_str based on del_doc & del_item.
  IF ( syst-subrc = 0 ).
    gs_str-lfimg = lv_lfimg.
    MODIFY gt_str FROM gs_str.
  ENDIF.
endloop.

I would suggest the following simplification:

loop at gt_str into gs_str.
select single lfimg from lips into gs_str-lifmg     " lv_lfimg 
  where vbeln = gs_str-del_doc
  and posnr   = gs_str-del_item.

*now i wanted to modify the field lfimg in table gt_str based on del_doc & del_item.
  IF ( syst-subrc = 0 ).
    MODIFY gt_str FROM gs_str.
  ENDIF.
endloop.

Furthermore, if you have many records in gt_str then you should replace the SELECT SINGLE with an array fetch:

DATA:
  gt_tmp    TYPE TABLE of ty_str,
  gs_tmp   TYPE ty_str.

IF ( gt_str IS NOT INITIAL ).
  SELECT * FROM lips INTO CORRESPONDING FIELDS OF TABLE gt_tmp
    FOR ALL ENTRIES IN gt_str
    WHERE vbeln = gs_str-del_doc
    AND      posnr = gs_str-del_item.
ENDIF.

SORT gt_tmp BY vbeln posnr.  " for BINARY SEARCH

loop at gt_str into gs_str.
  READ gt_tmp INTO gs_tmp
    WITH KEY vbeln = gs_str-del_doc
                     posnr = gs_str-del_item
    BINARY SEARCH.

*now i wanted to modify the field lfimg in table gt_str based on del_doc & del_item.
  IF ( syst-subrc = 0 ).
    MODIFY gt_str FROM gs_tmp.    " gs_str.
  ENDIF.
endloop.

Regards

Uwe

Read only

Former Member
0 Likes
304

hi,

1) select the fields outside the loop.

2) Then loop into the itab into work area and modify the itab using

3) MODIFY ITAB TRANSPORTING < key fields in table >.

This modify statement would help.