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 & Rollback with Eg!

Former Member
0 Likes
1,503

Hi Friends!

Can any one explain with example where to use commit & rollback

Looking for your help

Rahul.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,443

you have one custom table

data : i_itab like ztest occurs 0 with header line.

start-of-selection.

assume that you have data in internal table

commit work.

modify ztest from table i_itab.

other program :

data : i_itab like ztest occurs 0 with header line.

start-of-selection.

assume that you have data in internal table

rollback work.

modify ztest from table i_itab.

see the results in database table on each step

16 REPLIES 16
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,443

COMMIT and ROLLBACK are closely related to LUW(Logical Unit of Work). What this means is that all tables are updated successfully or none at all. This helps with data consistancy and integrity. Here is some light reading on the subject.

http://help.sap.com/saphelp_nw70/helpdata/en/41/7af4bfa79e11d1950f0000e82de14a/frameset.htm

Regards,

Rich Heilman

Read only

ferry_lianto
Active Contributor
0 Likes
1,443

Hi,

Please check this Uwe's reply from other thread with sample code.

BAPIs are indeed a good example to explain the use of commit work and rollback. BAPIs are RFC-enabled function modules that allow us to access SAP business objects (e.g. materials) from outside.

In case of failure BAPIs do not raise any exceptions but usually return the collected messages in a TABLES parameter RETURN (of line type BAPIRET2).

After calling a BAPI you have to evaluate the returned messages:


DATA:
  lt_return    TYPE BAPIRETTAB (table type of BAPIRET2).
 
 
  CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' 
    EXPORTING
       ...
    IMPORTING
      ...
    TABLES
     ...
       return = lt_return.
 
  LOOP AT lt_return TRANSPORTING NO FIELDS
                 WHERE ( type CA 'AEX' ).  " (A)bort, (E)rror, X=dump
    EXIT.
  ENDLOOP.
  IF ( syst-subrc = 0 ).
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
 
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING  
        wait = 'X'.  " synchronous
  ENDIF.

Please note that BAPIs may or may not return a Success message (type='S') in case of success. An empty RETURN messages indicates a successful BAPI call.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,444

you have one custom table

data : i_itab like ztest occurs 0 with header line.

start-of-selection.

assume that you have data in internal table

commit work.

modify ztest from table i_itab.

other program :

data : i_itab like ztest occurs 0 with header line.

start-of-selection.

assume that you have data in internal table

rollback work.

modify ztest from table i_itab.

see the results in database table on each step

Read only

0 Likes
1,443

Hi Seshu!

Pls tell me the output of the above program its sounds intresting

Read only

0 Likes
1,443

Hi Rahul,

comments are in bold

you have one custom table

data : i_itab like ztest occurs 0 with header line.

start-of-selection.

assume that you have data in internal table

commit work. " <b>When you use commit work ,it will update the data sucessfully</b>modify ztest from table i_itab.

other program :

data : i_itab like ztest occurs 0 with header line.

start-of-selection.

assume that you have data in internal table

rollback work. " <b>It will not update the data even you use modify command because rollback.</b>modify ztest from table i_itab.

see the results in database table on each step

Read only

0 Likes
1,443

Seshu!

Thank u very much

I have one more doubt can u tell me commit and rollback can be used in bdc if yes, can u pls tell me a eg where to use it.

Rahul.

Read only

0 Likes
1,443

Seshu!

Thank u very much

I have one more doubt can u tell me commit and rollback can be used in bdc if yes, can u pls tell me a eg where to use it.

Rahul.

Read only

0 Likes
1,443

commit and rollback - should not use in BDC

in call transaction - there is option ( if you use UPDATE 'S' ) then this will work as commit.

Read only

0 Likes
1,443

No, there is no chance to use COMMIT or ROLLBACK when doing BDC call transaction. The reason is that the CALL TRANSACTION does an implicit COMMIT WORK at the completion of the statement.

Regards,

Rich Heilman

Read only

0 Likes
1,443

Then where it it is used apart from BAPI's

Read only

0 Likes
1,443

use BAPI_TRANSACTION_COMITT Function module

Read only

0 Likes
1,443

Hi Seshu!

It is onley used in bapi's thats all apart from that where it is used

Read only

0 Likes
1,443

We do not use commit work in bapi,we use FM BAPI_transaction_committ after bapi fm .

Read only

0 Likes
1,443

Ok Thats Right!

We use FM in BAPI Thats right i want to know commit & Roll back where it is used

Pls Reply Friend

Rahul.

Read only

0 Likes
1,443

Hello Rahul,

We will not use comitt work in BAPI or BDC,

some times we have direct updation to custom tables,then we use comitt work or roll back.

in the selection-screen we have

option like test mode ,update mode.

when the user choose test mode we will not update database ( Here we use Roll back) and also when ever we have error updating one table and

again we are updating one more table ( In this case if first table updates then need to update second table,otherwise should not update

when the user choose update mode we will update database table ( here we use committ work )

Read only

0 Likes
1,443

Hi Seshu!

Thank u very much i am clear with the concept.

Regards

Rahul.