cancel
Showing results for 
Search instead for 
Did you mean: 

Commit and rollback

Former Member
0 Kudos

Hello Friends,

I have one confusion!

Actually I am calling a few BAPI's to do some task, e.g, creating a SAP BP using a BAPI 'BAPI_BUPA_CREATE_FROM_DATA'. Now after creating a new SAP BP, I commit the newly created SAP Business Partner using the BAPI 'BAPI_TRANSACTION_COMMIT'.

I have a question, is it possible that after creating a SAP BP and before commiting the newly created data, I can use this check !

if sy-subrc eq 0.

and if this check is true the I only commit the new created SAP BP other wise roll back !!?

Need some suggestion upon this !

also pls do mention what is the BAPI to do rollback !

and rollback only be done when sy-subrc eq 4. or ??

Many thanks for your suggestions!

Marek

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Alternatively, after the call you can check

if businesspartner is initial.

*-- not successful, then read the return table for reason

else.

*-- successful

endif.

Former Member
0 Kudos

Hi Marek,

In most of the BAPIs a success is determined by whether a value is returned via the importing parameter of the call. In your case, if the 'Business Partner' parameter has a value other than the initial value, then you can assume your call is successful. In the return table itself, it may be as a message of type 'I'.

Former Member
0 Kudos

hi Srinivas,

Thanks for the reply!

but I am surprised, in case of succeful, there is no TYPE . not even I ?

but when i give incomplete or wronge input then it gives me E ?

I need to make sure, that the BAPI executed successfuly befoer doing commit, and then I have to call another bapi, and if the second bapi fails, then the first bapi also rollback ??

what is the good approach in this senario ?? what do u suggest ?

Marek

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I would have assumed that it would have given you at least a success message. Since it doesn't, you have to assume that an empty "return" table means that the transaction has completed successfully.

Regards,

Rich Heilman

Former Member
0 Kudos

hi Rich

so in that case what would be the check, e.g

Data t TYPE String.

MOVE wa_return_table-TYPE TO t.

IF t = ' '.

Write 'succesful'.

comit...

Else

Write 'Unseusul'.

rollback...

or ?? I dont get this how to put check, incase succesful, inorder to comit the BAPI , `?

may be I am going in too depth ?? or

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I would say something like this........

if BAPIRET2[] is initial.

  • then successful

else.

read table BAPIRET2 with key TYPE = 'E'.

if sy-subrc = 0.

  • not successful.

endif.

endif.

Regards,

Rich Heilman

Former Member
0 Kudos

Normally all the BAPIs will give the messages back in the RETURN tables parameter. You need to read this internal table to see if there are any messages out there with message type 'E' or 'A'. If there are, then you have errors, otherwise your BAPI worked ok. If you use sy-subrc <> 0 after the BAPI call, it will not be correct.

BAPI to do rollback BAPI_TRANSACTION_ROLLBACK.

Message was edited by: Srinivas Adavi

Former Member
0 Kudos

Hi Srinivas,

Might be it would be great, if you would like to mention why not if sy-subrc <> o is not suitable in this senario ??

Many thanks for your kind reply!

Marek

Former Member
0 Kudos

Hello Marek,

In case of a normal Function Module, when an exception is raised within the Function Module, it sets the sy-subrc value to the corresponding value as defined in the calling program.

Example :


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  EXPORTING
    RETFIELD               =
  TABLES
    VALUE_TAB              =
 EXCEPTIONS
   PARAMETER_ERROR        = 1
   NO_VALUES_FOUND        = 2
   OTHERS                 = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

In the above example, the sy-subrc value will be set according to the exception that has been raised in the function module.

Now if we come to RFC Function Modules, the FM can be executed remotely - i.e., in a different <i>system</i>. The value of sy-subrc cannot be checked here, because it is a <i>system variable</i>. It's value is specific only in a particular system. In case of a remote call, the other system cannot set the system variable in the calling system. It has to explicitly pass a variable in one of its exporting parameters.

Please note that a BAPI is also a RFC Function Module, and hence cannot set the SY-SUBRC value.

Just to get things a little more straight, go to the ABAP Editor and use the PATTERN option for a Function Module. try to get the skeletal code for

1. Any normal Function Module.

2. Any RFC Function Module

3. Any BAPI.

I think what you see will drive home the point. If you have further doubts, you are welcome.

Regards,

Anand Mandalika.

Former Member
0 Kudos

hi Anand,

Thanks for your kind reply,

I got the concept which u give here regarding RFC and sy-subrc. Now the thing is that, when ever I BAPI is being called, it returns a return-table, which contains the TYPE and msgs, okey, ?

If the BAPI executed unsuccesuflly, then the TYPE contains 'E' or some error msgs is provided!

But when the BAPI is successfuly, it actually shows TYPE = s ? but in my case when the BAPI is succesful, it does not print any thing, Here is my code!

CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'

EXPORTING

partnercategory = '1'

centraldataperson = persondata

centraldata = person

IMPORTING

businesspartner = businesspartner

TABLES

return = returntable.

LOOP AT returntable INTO wa_returntable.

write wa_returntable-TYPE.

write wa_returntable-MESSAG.

ENDLOOP.

Any suggestions why its so !

PS: it working fine when I provide wronge parameter i.e it shows ms TYPE = 'E', but not when I provid the correct parameter, it does not print any TYPE ?

Marek

Former Member
0 Kudos

Hey,

Any one has any suggestion or any idea ?

Many thanks!

Marek