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

Updating customized database table in BAPI

Former Member
0 Likes
2,266

Hi All ,

I ' ve created a customized BAPI.The requirement for this BAPI is to update a z-table.

For this,I had used INSERT & UPDATE command (along with COMMIT & ROLLBACK stmt ) in the BAPI.

Please see the below coding & let me know whether it is right..to use the below coding to update a z_table in the BAPI.

FUNCTION z_bapi_submit.

*Adding new lines into ztable

INSERT z_table FROM TABLE internal_table.

IF sy-subrc = 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK.

ENDIF.

*Modifying the existing lines in ztable

UPDATE z_table FROM TABLE internal_table.

IF sy-subrc = 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK.

ENDIF.

ENDFUNCTION.

Can I use COMMIT & ROLLBACK stmts in the BAPI as above ?

Regards,

Varalakshmi.

6 REPLIES 6
Read only

Former Member
0 Likes
1,393

Hi varalakshmi,

1. Can I use COMMIT & ROLLBACK stmts in the BAPI as above ?

If we use, it will work.

2. BUT

3. Since it is a BAPI,

it should not use any commit work

(as per sap guidelines,

bcos, then it will defeat the purpose

of LUW)

4. COMMIT WORK / ROLLBACK

will be done by the

program, which is calling the bapi.

5. This bapi should only return,

the errors, in an internal table.

*----


6. Instead of using INSERT or UPDATE,

we can just use MODIFY

like this

modify DBTAB from ITAB.

<b>

(Modify will automatically take care

of INSERT/UPDATE based upon

the primary key combination of field values,

found / not found in database table,

as compared to work area)</b>

regards,

amit m.

Read only

0 Likes
1,393

Hi Amit ,

Thanks for your reply.

I got valuable input from you.

Thanks,

Varalakshmi.

Read only

former_member195698
Active Contributor
0 Likes
1,393

1) BAPI's should not have any commit/rollback statement. The Commit/Rollback should be performed in the calling program.

2) Instead of using INSERT/UPDATE use MODIFY statement

3) Instead of Calling INSERT/UPDATE directly in the BAPI call Functional Module (type update, In update task), which will have the required database update statement.

Read only

0 Likes
1,393

Hi Abhishek ,

Thanks for your valuable input .

Can you give me the Function module name that

is used to update the database table in update task ?

Thanks,

Varalakshmi.

Read only

0 Likes
1,393

Hi again,

1. Can you give me the Function module name that

is used to update the database table in update task

Update TASK is

a concept (way of calling any FM).

2. In your case such concept is not required.

3. For making any FM, update task,

we just have to click on the radiobutton

( in se37)

in attributes TAB of the FM.

The radio button is : Update Module.

regards,

amit m.

Read only

0 Likes
1,393

Hi Amit,

I'm now using the MODIFY stmt in the BAPI to update the z-table.

Can I use the below coding..

function z_submit.

modify z_table FROM TABLE internal_table.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ENDIF.

Endfunction.

Can I use the 'BAPI_TRANSACTION_COMMIT' & 'BAPI_TRANSACTION_ROLLBACK' in the BAPI itself

OR

modify z_table FROM TABLE internal_table.

IF sy-subrc ne 0.

populate the RETURN table

ENDIF.

And leave the 'BAPI_TRANSACTION_COMMIT' & 'BAPI_TRANSACTION_ROLLBACK' to be called in the calling program ?

Regards,

Varalakshmi.