‎2009 Oct 15 4:12 PM
Hi ,
Currently in my code i have a update statement inside the loop. i want to move it out side. My criteria is to modify any number of records. I don't this MODIFY statement will be correct.
LOOP AT t_zvei.
UPDATE zxxvei SET
ardoc = t_zvei-ardoc
where
mjahr = t_zvei-mjahr
monat = t_zvei-monat.
if sy-subrc eq 0.
commit work.
endloop.
endloop.
the problem with MODIFY is that it gives sy-subrc eq 0 only if all records are modified . But i want to commit even if any record is changed.
I want to change only few columns comparing the key ffileds.
Please help
‎2009 Oct 16 4:13 AM
Hi,
<li> Try like below which suggests that bring database table data into internal table and make changes to that internal table and update the same to the database.
Thanks
Venkat.O
REPORT ztest.
DATA: BEGIN OF it_data OCCURS 0,
bukrs TYPE t001-bukrs,
rcomp TYPE t001-rcomp,
END OF it_data.
DATA:it_t001 TYPE STANDARD TABLE OF t001 WITH HEADER LINE.
START-OF-SELECTION.
"Select required records from database table
SELECT * FROM t001 INTO TABLE it_t001.
SORT it_t001."It is sorted based on key fields.
"Get your own data
"Loop your internal table which has data to update database table.
LOOP AT it_data.
READ TABLE it_t001 WITH KEY bukrs = it_data-bukrs.
IF sy-subrc EQ 0.
it_t001-rcomp = 'XYZ Pte ltd'.
MODIFY it_t001 INDEX sy-tabix TRANSPORTING rcomp.
CLEAR it_t001.
ENDIF.
ENDLOOP.
"Modify database table at a time using internal table
MODIFY t001 FROM TABLE it_t001.
IF sy-subrc EQ 0.
WRITE 'All lines were inserted or changed.'.
ELSE.
WRITE 'At least one line could not be processed'.
ENDIF.
‎2009 Oct 16 4:13 AM
Hi,
<li> Try like below which suggests that bring database table data into internal table and make changes to that internal table and update the same to the database.
Thanks
Venkat.O
REPORT ztest.
DATA: BEGIN OF it_data OCCURS 0,
bukrs TYPE t001-bukrs,
rcomp TYPE t001-rcomp,
END OF it_data.
DATA:it_t001 TYPE STANDARD TABLE OF t001 WITH HEADER LINE.
START-OF-SELECTION.
"Select required records from database table
SELECT * FROM t001 INTO TABLE it_t001.
SORT it_t001."It is sorted based on key fields.
"Get your own data
"Loop your internal table which has data to update database table.
LOOP AT it_data.
READ TABLE it_t001 WITH KEY bukrs = it_data-bukrs.
IF sy-subrc EQ 0.
it_t001-rcomp = 'XYZ Pte ltd'.
MODIFY it_t001 INDEX sy-tabix TRANSPORTING rcomp.
CLEAR it_t001.
ENDIF.
ENDLOOP.
"Modify database table at a time using internal table
MODIFY t001 FROM TABLE it_t001.
IF sy-subrc EQ 0.
WRITE 'All lines were inserted or changed.'.
ELSE.
WRITE 'At least one line could not be processed'.
ENDIF.
‎2009 Oct 16 4:25 AM
Venkat,
No where it_data is getting filled before the loop.So,do you think that it will loop the it_data internal table even when there is no data in it ?
K.Kiran.
‎2009 Oct 16 4:41 AM
My dear friend Kiran, You can see the comment written Before LOOP statment "Get your own data Thanks Venkat.O
‎2009 Oct 16 4:59 AM
Venkat,
Ok,didn't checked that.No Offences meant.
Happy Diwali
K.Kiran.
‎2009 Oct 22 7:18 AM
No friends ... I have not all data for the DB table to be modified. I have only few fields that needs to be modified depending upon some criteria.
‎2010 Feb 10 6:34 AM