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: 

SQL Transactions_ABAP

Former Member
0 Kudos

Hi.

I am updating fields from a Z table with SQL sentences. I am updating each field with an update sentence.

I do not know how to put all these sentences in a single transaction, so that all fields could be updated at the same time or if an error occur all the sentences could be rollbacked.

Does anybody know how to do that in an ABAP code?

Thanks.

Diana.

5 REPLIES 5

matt
Active Contributor
0 Kudos

Go to the ABAP editor. Enter "MODIFY" or "INSERT" or "UPDATE". And get the cursor on either one, and press F1 (help). This will give you a description of the syntax and how to use it.

matt

former_member156446
Active Contributor
0 Kudos

Modify will update the Z table based on primary key... try that..

modify Ztable from Itab. all unique primary keys will get updated into the Ztable.

Former Member
0 Kudos

Hi Diana,

SAP provides something called Bundling Techniques for database updates from within one transaction that spans more than one screen. There is an implicit database commit with every screen change. But to do the database updates in one logical unit of work (LUW, commit all or rollback all) SAP recommends to use the bundling for updates. There are bascially two ways to achieve it:

1. using FORM subroutine with the keyword ON COMMIT;

2. using a Update Function Module.

Both of these actually update the databse when the program execution hits the statement COMMIT WORK.

So you can write all update statements in a FORM subroutine and call it using the ON COMMIT addition like:

PERFORM <formname> ON COMMIT.

...

...some more code here...

...

COMMIT WORK.

The limitation with this method is that you can NOT pass any parameters to the FORM subroutine. You have to work with the global variables.

Alternatively, create a FM and set the radiobutton 'Update Module' with 'Start immed.' radiobutton selected on the Attributes tab. Then put all your update statements in the FM source code. Here you can pass the parameters, if you wish, to update the database fromt the parameters.

For more info, see the help doc at the following link:

Link:[Update techniques|http://help.sap.com/saphelp_47x200/helpdata/en/41/7af4cba79e11d1950f0000e82de14a/content.htm]

Link:[ABAP Prograaming|http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm]

Then go to ABAP Database Access -> Programming Database Updates -> Update Techniques

There are some other related topics that you can refer to.

0 Kudos

Hi Sanjeev.

Your answer has been very useful. But I have the problem that with the PERFORM form ON COMMIT I can not pass any parameters like you said to me.

I am developing a BAPI, wich is a function module, and the parameters that I am using in the SQL sentences are passed by the BAPI interface. I tried to make forms but these are located out of the Module Function (BAPI), so I can´t have the parameter´s value in the forms. Neither as global parameters.

I am trying to understand the second option you gave to me but I can´t.

"Alternatively, create a FM and set the radiobutton 'Update Module' with 'Start immed.' radiobutton selected on the Attributes tab. Then put all your update statements in the FM source code. Here you can pass the parameters, if you wish, to update the database fromt the parameters."

Do you think I have any other option?

Thanks for your help.

Diana.

0 Kudos

Hi Diana,

You may create a update FM (as described earlier) with the parameter interface same as the BAPI's parameter interface. When you call this FM, all the parameters for the BAPI will be passed to your FM and inside the FM code call the BAPI by passing all the parameters from the interface. The call to your FM will be like:

CALL FUNCTION <your_FM> IN UPDATE TASK

EXPORTING

P1 = EX_P1

P2 = EX_P2

......

....."BAPI parameters

.....

EXCEPTIONS

.

This is the only option I can think of.

Hope this helps.

Thanks

Sanjeev