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

commit work sets sy-subrc 0

UmaArjunan
Active Participant
0 Likes
3,721

I

Commit work sets sy-subrc always to zero.

In this case how can we know if commit work fails.

Please provide more details and efficient usage of commit statements in a report

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,289

Hi,

Use the following code.

if sy-subrc eq 0.

commit work and wait.

else.

raise error message.

endif.

Regards,

Navee.

12 REPLIES 12
Read only

Former Member
0 Likes
2,289

hi check this..

may the insert or modify or update fails but not commit work...i think there is no fail case in the commit work.

Read only

Former Member
0 Likes
2,289

Hi,

commit work is used mainly in case of database changes...

if in the report at certain point you want to make chages to databasethen you can use commit work....to update changes to your database.....

mot of the times in bapis you have to use expicit commit work for database changes....

check this link.

http://www.abapprogramming.net/2008/05/sap-abap-syntax-for-commit.html

Read only

Former Member
0 Likes
2,289

Hi,

Use this code IN SUITABLE POSITION IN YOUR CODE.

IF SY-SUBRC NE 0

   MESSAGE.................

ENDIF.

Regards,

Anirban

Read only

Former Member
0 Likes
2,289

use

COMMIT WORK AND WAIT.

it will set sy-subrc = 0 if update is successfull otherwise

sy-subrc NE 0.

With luck,

Pritam.

Read only

Former Member
0 Likes
2,289

Hi,

Check this link:

Regards

Adil

Read only

Former Member
0 Likes
2,289

hiii

use FM

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*     EXPORTING
*       WAIT          = WAIT
*     IMPORTING
*       RETURN        = RETURN

it will give you message and if sy-subrc NE 0 then will give you error with message

regards

twinkal

Read only

Former Member
0 Likes
2,289

see the Implemetation of

BAPI_TRANSACTION_COMMIT, how they handled the commit work.

In this case how can we know if commit work fails.

From SAP help

sy-subrc Meaning

0 You have specified the AND WAIT addition, and the updating of the update function modules was successful.

4 You have specified the AND WAIT addition, and the updating of the update function modules was not successful.

Read only

Former Member
0 Likes
2,290

Hi,

Use the following code.

if sy-subrc eq 0.

commit work and wait.

else.

raise error message.

endif.

Regards,

Navee.

Read only

Former Member
0 Likes
2,289

Hi,

Usage of commit statements is as follows:

COMMIT WORK.

Addition

u2026 AND WAIT

Effect

Executes a database commit and thus closes a logical processing unit or Logical Unit of Work ( LUW ) (see also Transaction processing ). This means that

  • all database changes are made irrevocable and cannot be reversed with ROLLBACK WORK and

  • all database locks are released.

COMMIT WORK also

  • calls the subroutines specified by PERFORM u2026 ON COMMIT ,

  • executes asynchronously any update requests (see CALL FUNCTION u2026 IN UPDATE TASK ) specified in these subroutines or started just before,

  • processes the function modules specified in CALL FUNCTION u2026 IN BACKGROUND TASK ,

  • cancels all existing locks (see SAP locking concept ) if no update requests exist,

  • closes all open database cursors (see OPEN CURSOR ) and

  • resets the time slice counter to 0.

COMMIT WORK belongs to the Open SQL command set.

Return code value

The SY-SUBRC is set to 0.

Notes

All subroutines called with PERFORM u2026 ON COMMIT are processed in the LUW concluded by the COMMIT WORK command. All V1 update requests specified in CALL FUNCTION u2026 IN UPDATE TASK are also executed in one LUW . When all V1 update requests have been successfully concluded, the V2 update requests (u201Dupdate with start delayedu201D) are processed, each in one LUW . Parallel to this, the function modules specified in CALL FUNCTION u2026 IN BACKGROUND TASK are each executed in one LUW per destination.

COMMIT WORK commands processed within CALL DIALOG processing

- execute a database commit (see above),

- close all open database cursors,

- reset the time slice counter and

- call the function modules specified by CALL FUNCTION IN

BACKGROUND TASK in the CALL DIALOG processing.

However, subroutines and function modules called with PERFORM u2026 ON COMMIT or CALL FUNCTION u2026 IN UPDATE TASK in the CALL DIALOG processing are not executed in the calling transaction until a COMMIT WORK occurs.

Since COMMIT WORK closes all open database cursors, any attempt to continue a SELECT loop after a COMMIT WORK results in a runtime error. For the same reason, a FETCH after a COMMIT WORK on the now closed cursors also produces a runtime error. You must therefore ensure that any open cursors are no longer used after the COMMIT WORK .

With batch input and CALL TRANSACTION u2026 USING , COMMIT WORK successfully concludes the processing.

Addition

u2026 AND WAIT

Effect

The addition u2026 AND WAIT makes the program wait until the type V1 updates have been completed.

The return code value is set as follows:

SY-SUBRC = 0 The update was successfully performed.

SY-SUBRC <> 0 The update could not be successfully performed.

Note

Runtime errors

  • COMMIT_IN_PERFORM_ON_COMMIT : COMMIT WORK is not allowed in a FORM callled with PERFORM u2026 ON COMMIT .

  • COMMIT_IN_POSTING : COMMIT WORK is not allowed in the update task.

Hope it will help you.

Feel free to ask any doubt.

Regards

Aparna

Read only

Former Member
0 Likes
2,289

really wonder what all replies you get for some quesiton without a thought..

Commit is generally used after INSERT , MODIFY . Update commands.

It makes sense to check the sy-subrc after these statements

not after commit.

ex:

Insert <> from ....

if sy-subrc eq 0.

......

endif.

commit work.

Br,

Vijay.

Read only

Former Member
0 Likes
2,289

Hi,

Use COMMIT WORK and WAIT

The addition ... AND WAIT makes the program wait for the type V1 update (update with immediate start) to be executed.

The Return Code is set as follows:

SY-SUBRC = 0:

The update was performed successfully.

SY-SUBRC <> 0:

The update was not performed successfully.

Best of luck,

Bhumika

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,289

Use the AND WAIT OPTION, so sy-subrc will be set to non-zero value if any error or abend occurs.

(Look at old one doc [Updates in the R/3 System (BC-CST-UP)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCSTUP/BCCSTUP_PT.pdf] always useful)

Regards