‎2010 Jan 07 10:43 AM
Hello ,
I have question about update statement . I have to update DB table from internal table . The fields in DB table are of the same type like fields in It. I am looping in internal table and conditions for update are satisfied , but after when I check DB table in SE16 the fields remains the same like before - no update was done. I am not sure where the error is . I am suspecting commit work statement is not on right palce , i change it but the result is the same.
Please advice .
Krsto
loop at scantbl.
if zdocktostock-gruser is not initial and
zdocktostock-rplant NE scantbl-werks.
update zdocktostock set mandt = scantbl-mandt
zzcartag = scantbl-zzcartag
zzpaltag = scantbl-zzpaltag
zzshiptag = scantbl-zzshiptag
dplant = scantbl-werks
dlgort = scantbl-lgort
ddate = sy-datum
dtime = sy-uzeit
duser = sy-uname.
endif.
COMMIT WORK.
endloop.
‎2010 Jan 07 10:46 AM
Hi Krsto,
You have used UPDATE statement but you have not specified any WHERE condition i.e. which particular record to update based upon matching key fields.
In your code, all records of the table are getting updated, repeatedly in the loop.
Please also use a WHERE condition (as a suffix to UPDATE) to specifiy the unique record (s) to get updated, based upon key fields.
Hope this helps.
Regards,
Amit Mittal.
‎2010 Jan 07 10:46 AM
Hi Krsto,
You have used UPDATE statement but you have not specified any WHERE condition i.e. which particular record to update based upon matching key fields.
In your code, all records of the table are getting updated, repeatedly in the loop.
Please also use a WHERE condition (as a suffix to UPDATE) to specifiy the unique record (s) to get updated, based upon key fields.
Hope this helps.
Regards,
Amit Mittal.
‎2010 Jan 07 10:52 AM
‎2010 Jan 07 10:50 AM
Hi Krsto,
Also use where condition along with Update statement
UPDATE (table)
SET (set_expr) " exisitng
WHERE (condition). " add the condition for which record you want update..
if sy-subrc = 0.
COMMIT WORK.
endif.
Nag
‎2010 Jan 07 10:56 AM
Hi
I doubt whether the IF condition is being satisfied or not..
if zdocktostock-gruser is not initial and
zdocktostock-rplant NE scantbl-werks. " IF condition is ok or not herefrom where you are getting the value of zdocktostock-gruser zdocktostock-rplant (is it having any value)
Put Break Point at Update statement and check whether it is getting executed or not..
update zdocktostock set mandt = scantbl-mandt
zzcartag = scantbl-zzcartag
zzpaltag = scantbl-zzpaltag
zzshiptag = scantbl-zzshiptag
dplant = scantbl-werks
dlgort = scantbl-lgort
ddate = sy-datum
dtime = sy-uzeit
duser = sy-uname.endif.Try to Put Where condition in UPDATE as well
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya
‎2010 Jan 07 10:57 AM
please check the code below how update works
The best way to update database for number of records is through internal table
DATA : WA_SCARR TYPE scarr,
IT_SCARR TYPE STANDARD TABLE OF SCARR.
START-OF-SELECTION.
SELECT * INTO
TABLE IT_SCARR
FROM SCARR.
WA_SCARR-CARRID = 'AE'.
WA_SCARR-CARRNAME = 'JAPAN AIRLINES'.
WA_SCARR-CURRCODE = 'JAR'.
WA_SCARR-URL = 'WWW.JAPAN.COM'.
APPEND WA_SCARR TO IT_SCARR.
WA_SCARR-CARRID = 'AC'.
WA_SCARR-CARRNAME = 'CARGO AIRLINES'.
WA_SCARR-CURRCODE = 'CUR'.
WA_SCARR-URL = 'WWW.CARGO.COM'.
APPEND WA_SCARR TO IT_SCARR.
WA_SCARR-CARRID = 'AH'.
WA_SCARR-CARRNAME = 'HAMARA AIRLINES'.
WA_SCARR-CURRCODE = 'HAM'.
WA_SCARR-URL = 'WWW.HAMARA.COM'.
APPEND WA_SCARR TO IT_SCARR.
UPDATE SCARR FROM TABLE IT_SCARR.
IF SY-SUBRC = 0.
WRITE :/ 'UPDATED SUCCESSFULLY'.
ELSE.
WRITE :/ 'UPDATE FAILED'.
ENDIF.
Please let me know if you need further information
Regards
Satish Boguda