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

BAPI for rollback

Former Member
0 Likes
4,684

Hi Experts,

Is there a BAPI that can rollback a transaction or an update that was created when the transaction find an error ?

Example: When a program finds an error during the transaction, all the successful transactions must not be updated.

1 0001     Successful

2 0002     Successful

3 0003     Successful

4 0004     Error

5 0005     Successful

But if  all infotypes are successful the program must update.

1 0001     Successful

2 0002     Successful

3 0003     Successful

4 0004     Successful

5 0005     Successful

The program right now, saves all infotypes with successful status.

12 REPLIES 12
Read only

ThomasZloch
Active Contributor
0 Likes
3,376

Steps 1 through 5 is your logical unit of work (LUW), so you would only do a commit work (BAPI_TRANSACTION_COMMIT) in case of all five being successfull, and a rollback (BAPI_TRANSACTION_ROLLBACK) if at least one ended in error.

This looks pretty standard, the key is that there is no commit work within the single steps, otherwise you cannot rollback later on.

Thomas

Read only

0 Likes
3,376

Hi Thomas,

Im using  HRHAP_DOCUMENT_CREATE every single line. Is it possible for it not to commit every single step ?

Read only

0 Likes
3,376

You can add simulation check using FM HRHAP_BC_DOCUMENT.

for eg.

* For Simulation

Loop

if FM HRHAP_BC_DOCUMENT returns errors

create log table.

endif.

endloop.

* No errors then create

if log table is empty.

loop

call FM HRHAP_DOCUMENT_CREATE

endloop.

endif.

Read only

0 Likes
3,376

Hi,

fm HRHAP_DOCUMENT_CREATE has an import parameter VTASK.

All option for VTASK can be seen in the values of domain HR_VTASK.

Value 'B' looks quite interesting for buffer update, maybe this one is the right. Maybe you have to call an additional fm to put the buffer updates to database after all updates.

Regards,

Klaus

Read only

former_member196651
Contributor
0 Likes
3,376

Hi Jepoy,

Please use BAPI_TRANSACTION_ROLLBACK.

Regards,

Abijith

Read only

Former Member
0 Likes
3,376

Hi Jepoy ,

I think we have a export parameter S_RETURN which will return the provide us the returning value, so depending upon the S_RETURN-MSGTY you can write a conditional statement that if S_RETURN-MSGTY is 'S' then call BAPI  "COMMIT WORK" else ROLL_BACK.

Thanks & Regards,

Seshadri.

Read only

0 Likes
3,376

Hi seshadri rajendra nath,

Thanks for the reply.

If I do this even though I have an status = 'E' it will update all status with 'S'. My requirement is not to update anything if I find an error/status = 'E'.

Read only

0 Likes
3,376

Hi Jepoy,

After calling the FM , write

IF MSGTYP = 'S'

Use COMMIT WORK FM.

else.

clear the contents

Use ROLL BACK FM.

endif.

I think  above logic may be useful.

Seshadri.

Read only

0 Likes
3,376

The FM will commit even though you don't use the commit FM.

CALL FUNCTION 'HRHAP_DOCUMENT_CREATE'

       EXPORTING

         PLAN_VERSION                   = c_plvar

         T_HEADER_APPRAISER             = it_appraiser

         T_HEADER_APPRAISEE             = it_appraisee

         T_HEADER_OTHERS                = it_header_others "lt_hap_t_header_others

         S_HEADER_TEXTS                 = wa_header_text

         S_HEADER_DATES                 = wa_header_dates

         S_HEADER_STATUS                = wa_header_status

         S_HEADER_DISPLAY               = wa_header_display

         T_BODY_COLUMNS                 = it_body_columns

         T_BODY_ELEMENTS                = it_body_elements

         T_BODY_CELLS                   = it_body_cells

         S_DOC_PROCESSING               = wa_hap_s_doc_processing

         VTASK                          = 'D'

      IMPORTING

        S_RETURN                        = wa_return_message

       CHANGING

         S_APPRAISAL_ID                 = wa_hap_s_appraisal_id

         T_HEADER_PART_APPRAISERS       = it_hap_t_header_part

         T_BODY_CELL_NOTES              = it_hap_t_body_cell_notes

         T_STATUS_NOTES                 = it_hap_t_status_note

Read only

Former Member
0 Likes
3,376

Hi, that's work of SAP-LUW. You need to bundle all your sub-calls to one FM and call this FM in update task, probably you will use local update (set update task local). During the update, commits are omitted, but any rollback stops&rollback all the steps of the update process. See LUW realted SAP ABAP help.

Br

Bohuslav

Read only

krishna_k19
Contributor
0 Likes
3,376

Hi Jepoy,

     All success and error log will be stores in RETURN table , so filter error one(message type E) if it exits then use BAPI ROLLBACK , if not then commit those work.

Regards,

Krishna

Read only

Former Member
0 Likes
3,376

Please replace MSTYP as S_RETURN-MSGTYP.