2008 Aug 05 7:53 AM
Hi All,
My final internal table contains 1000 and these final entries should update in standard table for example mara table.
when i use update command as follows.
update <std table> from table <int table>
if sy-subrc - 0.
commit work.
else.
rollback work.
endif.
in debugmode i saw it is showing sy-subrc as 4.
when i use modify instead of update it is working fine. but according my logic i have to use update command only because it has to update existing records only. any body can tell me how to fix this issue.
Thanks,
Maheedhar
2008 Aug 05 7:56 AM
Hi ,
Use Modify Statement only whenever you want to insert records in std table . In ABAP Modify and Update statements has different meaning read help on modify you will understand.
Thanks
Sudharshan
2008 Aug 05 7:56 AM
i´d try to update them within a loop.
Loop at itab into wa.
update mara from wa.
endloop.
there you could as well use a where-statement if needed.
2008 Aug 05 7:57 AM
i´d try to update them within a loop.
Loop at itab into wa.
update mara from wa.
endloop.
there you could as well use a where-statement if needed.
sry for double post, wasnt intended
Edited by: Florian Kemmer on Aug 5, 2008 8:57 AM
2008 Aug 05 7:57 AM
Hi!
You have to LOOP AT your internal table and update the lines after each other...
Or you can simply remove the following from your code:
*if sy-subrc - 0.
*commit work.
*else.
*rollback work.
*endif.
It is not needed, because after the end of the program run, an automatic COMMIT WORK will be triggered.
Regards
Tamá
2008 Aug 05 7:58 AM
perhaps the line does not exist in the database table so it can't modify it.
2008 Aug 05 7:59 AM
2008 Aug 05 8:00 AM
Hi,
Try using this way if possible :
IF NOT g_t_outtab[] IS INITIAL.
DATA: l_error(2) TYPE c.
CLEAR l_error.
LOOP AT g_t_outtab INTO g_wa_outtab WHERE update EQ 'X'.
UPDATE zo9_user_status
SET sub_date = sy-datum
sub_time = sy-uzeit
status = g_wa_outtab-status
WHERE representative = g_wa_outtab-representative AND
selection_id = g_wa_outtab-selection_id AND
sub_date = g_wa_outtab-sub_date AND
sub_time = g_wa_outtab-sub_time AND
superior = g_wa_outtab-superior.
IF sy-subrc EQ 0.
COMMIT WORK.
l_error = 'X1'.
ELSE.
l_error = 'X2'.
CLEAR l_error.
ROLLBACK WORK.
ENDIF.
CLEAR g_wa_outtab.
ENDLOOP.
Hope this helps you.
thanx,
dhanashri.
2008 Aug 05 8:01 AM
create like below
Loop at <int table> into <wa_data>
update <std table> from <wa_data>
if sy-subrc - 0.
commit work.
else.
rollback work.
endif.
endloop.
rgds
rajesh
2008 Aug 05 8:01 AM
Hi
Here is the below code how to use an update query.
LOOP AT LT_MARA_MARC.
UPDATE marc
SET wzeit = pa_wzeit
WHERE matnr = LT_MARA_MARC-MATNR AND
werks = LT_MARA_MARC-WERKS.
ENDLOOP.
2008 Aug 05 8:03 AM
In UPDATE the record will only be updated if key is same that is it will over write the old record and if key is not same it will not be updated and sy-subrc will be 4, while in modify record will be updated if key is same or else if key is not same it will be inserted as new record, that is sy-subrc will always be 0.
so if sy-subrc is 4 than all the 1000 records does not exists in the table,
With luck,
Pritam.
2008 Aug 05 8:03 AM
Mahadhar,
update <std table> from table <int table>
if sy-subrc - 0.
commit work.
else.
rollback work.
endif.
How <int table> is decleared?
and make sure wether perticuler line exist or not for which you are getting sy-subrc = 4?
Amit.
2008 Aug 05 8:09 AM
Hi Amit,
Please see below code...
REPORT zmaheedhar.
TABLES :catsdb, ptex2000.
DATA :it_data LIKE ptex2000 OCCURS 0 WITH HEADER LINE.
DATA : it_final LIKE ptex2000 OCCURS 0 WITH HEADER LINE. "maheed
DATA :it_data1 LIKE it_data OCCURS 0 WITH HEADER LINE.
DATA:it_pa2001 LIKE pa2001 OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_pernr FOR ptex2000-pernr .
PARAMETER :p_date LIKE sy-datum DEFAULT sy-datum.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
SELECT * FROM pa2001 INTO TABLE it_pa2001
WHERE pernr IN s_pernr
AND begda GT p_date.
SORT it_pa2001 BY pernr begda ASCENDING.
SELECT * FROM ptex2000 INTO TABLE it_data
FOR ALL ENTRIES IN it_pa2001
WHERE pernr = it_pa2001-pernr AND
begda = it_pa2001-begda.
SORT it_data BY pernr begda ASCENDING.
LOOP AT it_data.
**
ENDLOOP.
**
WRITE 😕 'hello'.
" -- maheedhar - start
LOOP AT it_pa2001.
READ TABLE it_data WITH KEY pernr = it_pa2001-pernr "INDEX 1.
begda = it_pa2001-begda." BINARY SEARCH.
IF sy-subrc = 0.
"-- Fetch all the entries to final table.
MOVE: it_data-pernr to it_final-pernr,
it_data-uname2 TO it_final-uname2,
it_data-datum2 TO it_final-datum2,
it_data-uzeit2 TO it_final-uzeit2,
it_data-pgmid2 TO it_final-pgmid2,
it_data-statu2 TO it_final-statu2,
it_data-uname3 TO it_final-uname3,
it_data-datum3 TO it_final-datum3,
it_data-uzeit3 TO it_final-uzeit3,
it_data-pgmid3 TO it_final-pgmid3,
it_data-statu3 TO it_final-statu3,
it_data-uname4 TO it_final-uname4,
it_data-datum4 TO it_final-datum4,
it_data-uzeit4 TO it_final-uzeit4,
it_data-pgmid4 TO it_final-pgmid4.
APPEND it_final.
CLEAR it_final.
ENDIF.
ENDLOOP.
IF NOT it_final[] IS INITIAL.
UPDATE ptex2000 FROM TABLE it_final[]
set
MODIFY ptex2000 FROM TABLE it_final[].
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
2008 Aug 05 8:15 AM
maheedhar,
Just slightly Modify your code:
LOOP AT it_pa2001.
READ TABLE it_data WITH KEY pernr = it_pa2001-pernr "INDEX 1.
begda = it_pa2001-begda." BINARY SEARCH.
IF sy-subrc = 0.
"-- Fetch all the entries to final table.
MOVE: it_data-pernr to it_final-pernr,
it_data-uname2 TO it_final-uname2,
it_data-datum2 TO it_final-datum2,
it_data-uzeit2 TO it_final-uzeit2,
it_data-pgmid2 TO it_final-pgmid2,
it_data-statu2 TO it_final-statu2,
it_data-uname3 TO it_final-uname3,
it_data-datum3 TO it_final-datum3,
it_data-uzeit3 TO it_final-uzeit3,
it_data-pgmid3 TO it_final-pgmid3,
it_data-statu3 TO it_final-statu3,
it_data-uname4 TO it_final-uname4,
it_data-datum4 TO it_final-datum4,
it_data-uzeit4 TO it_final-uzeit4,
it_data-pgmid4 TO it_final-pgmid4.
APPEND it_final.
UPDATE ptex2000 FROM TABLE it_final[] "should be in loop.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.CLEAR it_final.
ENDIF.
ENDLOOP.
2008 Aug 05 8:18 AM
Hi Amit,
Actual problem is need to updates those entires after the loop only as per the requirement..
Can you please suggest me how to fix this.
2008 Aug 05 12:26 PM
2008 Aug 05 8:18 AM
Hi,
Sy-subrc being 4 after update means:
"At least one line was not able to be changed".
The statement UPDATE sets sy-dbcnt to the number of changed lines.
So what u r doing is right. Dont use loop.
Instead check sy-dbcnt after UPDATE.
If its more than 0, then it means u have updated some records.
Records which are not in database are just ignored.
Regards
Meenakshi
2008 Aug 05 12:48 PM
Hi,
In UPDATE the record will only be updated if key is same that is it will over write the old record and if key is not same it will not be updated and sy-subrc will be 4, while in modify record will be updated if key is same or else if key is not same it will be inserted as new record, that is sy-subrc will always be 0.
Please check that.
Thanks & Regards,
Mani
2008 Aug 06 8:05 AM
Hi,
After doing Update , sy-dbcnt returns how many records were actually updated.
So check sy-dbcnt value instead of sy-subrc.
sy-subrc will be 4 even when one record failed.
See help on Update statement. It will definitely help.
Regards
Meenakshi