Application Development 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: 

PERFORM ON COMMIT

Former Member
0 Kudos
387

Hi Friends,

I am using

perform insert_header on commit level 1

perform insert_item on commit level 2.

commit work and wait

form insert_header.

INSERT zheader_table.

endform.

form insert_item.

INSERT zitem_table.

endform.

After the header records gets successfully gets created , for some reason if item records insertion fails i need to rollback the header records also

please give some suggestions

I had checked with SY_SUBRC check also before COMMIT WORK AND WAIT , but that value of SY_SUBRC check is not getting recognized

Edited by: Chandrasekhar Jagarlamudi on Jun 2, 2009 8:38 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos
155

Hi,

Try this way..

perform insert_header Changing g_subrc .
if g_subrc EQ 0.
    perform insert_item Changing g_subrc .
    if g_subrc EQ 0.
        commit work and wait
     ELSE.
        ROLLBACK WORK.
     ENDIF.
ENDIF.
commit work and wait

form insert_header Changing g_subrc .
INSERT zheader_table.
g_subrc = sy-subrc.
endform.
form insert_item Changing g_subrc .
INSERT zitem_table.
g_subrc = sy-subrc
endform.

11 REPLIES 11

Former Member
0 Kudos
156

Hi,

Try this way..

perform insert_header Changing g_subrc .
if g_subrc EQ 0.
    perform insert_item Changing g_subrc .
    if g_subrc EQ 0.
        commit work and wait
     ELSE.
        ROLLBACK WORK.
     ENDIF.
ENDIF.
commit work and wait

form insert_header Changing g_subrc .
INSERT zheader_table.
g_subrc = sy-subrc.
endform.
form insert_item Changing g_subrc .
INSERT zitem_table.
g_subrc = sy-subrc
endform.

0 Kudos
155

Thanks Avinash,

In this if the Insert zitem_table fails , we are using ROLLBACK WORK , will it rollback the header details also ? i tried that and we it did not rollback header details

We have to define them as single LUW

0 Kudos
155

HI,

If zitem_table fails it will rollback header details also...there was small mistake in my previous thread i forgaot to comment the Commit work and wait before form statement.

perform insert_header Changing g_subrc .
if g_subrc EQ 0.
    perform insert_item Changing g_subrc .
    if g_subrc EQ 0.
        commit work and wait
     ELSE.
         ROLLBACK WORK.
     ENDIF.
ELSE.
    ROLLBACK WORK.
ENDIF.
 
form insert_header Changing g_subrc .
INSERT zheader_table.
g_subrc = sy-subrc.
endform.
form insert_item Changing g_subrc .
INSERT zitem_table.
g_subrc = sy-subrc
endform.

0 Kudos
155

Thanks Avinash,

I had tried with this, header details are not rolledback

I had tried to insert a new record in header and then an existing record in item table,

So in this case as INSERT Item will fail , header insertion also should be rolledback

Please let me know if i am missing anything


PERFORM header CHANGING v_subrc.
  IF v_subrc = 0.
    PERFORM item CHANGING v_subrc.
    IF v_subrc = 0.
      COMMIT WORK AND WAIT.
    ELSE.
      ROLLBACK WORK.
    ENDIF.
  ELSE.
    ROLLBACK WORK.
  ENDIF.


FORM header CHANGING v_subrc.
  zheader_1-matnr = '1111'.
  INSERT zheader_1.
  v_subrc = sy-subrc.

ENDFORM.                    "header

FORM item CHANGING v_subrc.
  zitem_1-matnr = '000012345'.
  zitem_1-maktx = 'Matnr 1'.
  v_subrc = sy-subrc.

ENDFORM.   

Edited by: Chandrasekhar Jagarlamudi on Jun 2, 2009 2:24 PM

0 Kudos
155

Hi,

FORM item CHANGING v_subrc.
  zitem_1-matnr = '000012345'.
  zitem_1-maktx = 'Matnr 1'.
  INSERT zitem_1.              " Missing this line
  v_subrc = sy-subrc.
 
ENDFORM.

0 Kudos
155

Thanks Avinash, it worked , forgot that insert

Former Member
0 Kudos
155

Hi,

After the 'INSERT' statement check the sy-subrc value. If it not equal to 0, then exit the process.

cheers

gaurav

former_member222860
Active Contributor
0 Kudos
155

Try with this logic:

perform insert_header on commit level 1

form insert_header.
INSERT zheader_table.

if sy-subrc = 0.
  perform insert_item on commit level 2.

  commit work.
else.
  rollback work.
endif.
endform.

Mahesh

0 Kudos
155

Thanks Mahesh, I will try this out and let you know

ThomasZloch
Active Contributor
0 Kudos
155

What's up with your issue here, solved?

Please don't start duplicate threads on the same topics.

Thomas

0 Kudos
155

Thomas,

let me know if you have a solution for this??

Thanks

Chandra