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

Update statement

Former Member
0 Likes
767

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
728

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.

5 REPLIES 5
Read only

Former Member
0 Likes
729

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.

Read only

0 Likes
728

thanks

Read only

Former Member
0 Likes
728

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

Read only

Former Member
0 Likes
728

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 here

from 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

Read only

Former Member
0 Likes
728

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