‎2006 Sep 04 2:31 PM
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.
‎2006 Sep 04 2:46 PM
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.
‎2006 Sep 05 5:57 AM
Hi Amit ,
Thanks for your reply.
I got valuable input from you.
Thanks,
Varalakshmi.
‎2006 Sep 04 5:22 PM
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.
‎2006 Sep 05 6:02 AM
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.
‎2006 Sep 05 6:32 AM
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.
‎2006 Sep 05 8:03 AM
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.