‎2008 May 07 10:53 AM
My Dear FRNDS,
I am very new to ABAP. And I have read the documentation for function modules but i am not that clear to practice them.So I would be very happy if u people share a little bit of ur experience with me.
Please provide me some examples of all the use cases in function modules and specially exception handling.
Frnds, i am going to work with bapis so i feel practicing function module will give me a edge.
and please tell me after calling a BAPI FM why we have to perform 'BAPI_TRANSACTION_COMMIT' and 'BAPI_TRANSACTION_ROLLBACK'.
.Ur efforts will be greatly rewarded.
thx,
reshali
‎2008 May 07 11:02 AM
Most of the FMs have a return parameter, that specify that the FM call is successful or not. IF it is successful then call 'BAPI_TRANSACTION_COMMIT' to have a database commit or if it is not successful then revart the changes that are already done in database by 'BAPI_TRANSACTION_ROLLBACK' FM.
Now, both this FM calls generally behave like a normal database COMMIT or ROLLBACK. Only difference is that by BAPI you can update the database of a remort system so you need to commit/rollback in that syste. that is why we use 'BAPI_TRANSACTION_COMMIT' or 'BAPI_TRANSACTION_ROLLBACK' instead of normal commit/rollback.
Example:
CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE'
EXPORTING
key = la_key
testrun = l_testrun
generaldata = la_generaldata
generaldatax = la_generaldatax
inventory = la_inventory
inventoryx = la_inventoryx
postinginformation = la_postinginformation
postinginformationx = la_postinginformationx
timedependentdata = la_timedependentdata
timedependentdatax = la_timedependentdatax
allocations = la_allocations
allocationsx = la_allocationsx
origin = la_origin
originx = la_originx
IMPORTING
assetcreated = la_assetcreated
TABLES
depreciationareas = li_depreciationareas
depreciationareasx = li_depreciationareasx
cumulatedvalues = li_cumulatedvalues
postedvalues = li_postedvalues
transactions = li_transactions
return = i_return.
IF NOT i_return[] IS INITIAL.
CLEAR: wa_return,
wa_error_file,
l_message.
LOOP AT i_return INTO wa_return.
IF wa_return-type = 'S'.
wa_error_file-type = wa_return-type.
g_no_load = g_no_load + 1.
IF l_testrun <> 'X'.
CONCATENATE text-009 la_assetcreated-asset
INTO l_message.
CLEAR: la_assetcreated.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ELSE.
l_message = text-064.
ENDIF.
EXIT.
ELSE.
IF l_message IS INITIAL.
CONCATENATE l_message wa_return-message INTO l_message.
ELSE.
CONCATENATE l_message wa_return-message INTO l_message SEPARATED BY ','.
ENDIF.
ENDIF.
‎2008 May 07 11:02 AM
Most of the FMs have a return parameter, that specify that the FM call is successful or not. IF it is successful then call 'BAPI_TRANSACTION_COMMIT' to have a database commit or if it is not successful then revart the changes that are already done in database by 'BAPI_TRANSACTION_ROLLBACK' FM.
Now, both this FM calls generally behave like a normal database COMMIT or ROLLBACK. Only difference is that by BAPI you can update the database of a remort system so you need to commit/rollback in that syste. that is why we use 'BAPI_TRANSACTION_COMMIT' or 'BAPI_TRANSACTION_ROLLBACK' instead of normal commit/rollback.
Example:
CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE'
EXPORTING
key = la_key
testrun = l_testrun
generaldata = la_generaldata
generaldatax = la_generaldatax
inventory = la_inventory
inventoryx = la_inventoryx
postinginformation = la_postinginformation
postinginformationx = la_postinginformationx
timedependentdata = la_timedependentdata
timedependentdatax = la_timedependentdatax
allocations = la_allocations
allocationsx = la_allocationsx
origin = la_origin
originx = la_originx
IMPORTING
assetcreated = la_assetcreated
TABLES
depreciationareas = li_depreciationareas
depreciationareasx = li_depreciationareasx
cumulatedvalues = li_cumulatedvalues
postedvalues = li_postedvalues
transactions = li_transactions
return = i_return.
IF NOT i_return[] IS INITIAL.
CLEAR: wa_return,
wa_error_file,
l_message.
LOOP AT i_return INTO wa_return.
IF wa_return-type = 'S'.
wa_error_file-type = wa_return-type.
g_no_load = g_no_load + 1.
IF l_testrun <> 'X'.
CONCATENATE text-009 la_assetcreated-asset
INTO l_message.
CLEAR: la_assetcreated.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ELSE.
l_message = text-064.
ENDIF.
EXIT.
ELSE.
IF l_message IS INITIAL.
CONCATENATE l_message wa_return-message INTO l_message.
ELSE.
CONCATENATE l_message wa_return-message INTO l_message SEPARATED BY ','.
ENDIF.
ENDIF.
‎2008 May 07 11:04 AM
hai abhishek..
thx for the reply....
its fine...but why dont u help me in dealing with function modules..
thx,
reshali
‎2008 May 07 11:11 AM
I have already given a example above. Another simple example is as follows:
REPORT Z34332_BDC .
data: i_MATNRSELECTION type table of BAPIMATRAM,
wa_MATNRSELECTION like line of i_MATNRSELECTION,
i_MATNRLIST type table of BAPIMATLST,
wa_MATNRLIST like line of i_MATNRLIST,
i_return type table of BAPIRET2.
wa_MATNRSELECTION-MATNR_LOW = '000000000000000001'.
wa_MATNRSELECTION-MATNR_HIGH = '000000000000000055'.
wa_MATNRSELECTION-SIGN = 'I'.
wa_MATNRSELECTION-OPTION = 'BT'.
append wa_MATNRSELECTION to i_MATNRSELECTION.
clear : wa_MATNRSELECTION.
CALL FUNCTION 'BAPI_MATERIAL_GETLIST'
TABLES
MATNRSELECTION = i_MATNRSELECTION
MATNRLIST = i_MATNRLIST
RETURN = i_return
.
clear: wa_MATNRSELECTION.
write: /'Material'.
loop at i_MATNRLIST into wa_MATNRLIST.
write: / wa_MATNRLIST-MATERIAL.
clear: wa_MATNRLIST.
endloop.
What type of help u need in functional module?
‎2008 May 07 11:12 AM
Hi,
Please check this sample codes.
DATA: BAPI_Z05DOGI_DELIVERY LIKE BAPIOBDLVHDRCON-DELIV_NUMB ,
BAPI_Z05DOGI_HEADER_DATA LIKE BAPIOBDLVHDRCON OCCURS 0 WITH HEADER LINE ,
BAPI_Z05DOGI_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCON OCCURS 0 WITH HEADER LINE,
BAPI_Z05DOGI_ITEM_DATA LIKE BAPIOBDLVITEMCON OCCURS 0 WITH HEADER LINE,
BAPI_Z05DOGI_ITEM_CONTROL LIKE BAPIOBDLVITEMCTRLCON OCCURS 0 WITH HEADER LINE ,
BAPI_Z05DOGI_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE .
CLEAR: BAPI_Z05DOGI_DELIVERY , BAPI_Z05DOGI_HEADER_DATA , BAPI_Z05DOGI_HEADER_CONTROL , BAPI_Z05DOGI_ITEM_DATA ,BAPI_Z05DOGI_ITEM_CONTROL , BAPI_Z05DOGI_RETURN .
REFRESH: BAPI_Z05DOGI_HEADER_DATA , BAPI_Z05DOGI_HEADER_CONTROL , BAPI_Z05DOGI_ITEM_DATA , BAPI_Z05DOGI_ITEM_CONTROL , BAPI_Z05DOGI_RETURN .
BAPI_Z05DOGI_DELIVERY = ZMM_WB1-ISSUE .
BAPI_Z05DOGI_HEADER_DATA-DELIV_NUMB = ZMM_WB1-ISSUE.
APPEND BAPI_Z05DOGI_HEADER_DATA.
BAPI_Z05DOGI_HEADER_CONTROL-DELIV_NUMB = ZMM_WB1-ISSUE.
BAPI_Z05DOGI_HEADER_CONTROL-POST_GI_FLG = 'X'.
APPEND BAPI_Z05DOGI_HEADER_CONTROL.
BAPI_Z05DOGI_ITEM_DATA-DELIV_NUMB = ZMM_WB1-ISSUE.
BAPI_Z05DOGI_ITEM_DATA-DELIV_ITEM = 10.
BAPI_Z05DOGI_ITEM_DATA-DLV_QTY = LFIMGGIA.
BAPI_Z05DOGI_ITEM_DATA-SALES_UNIT = XTAB-MEINS.
BAPI_Z05DOGI_ITEM_DATA-DLV_QTY_IMUNIT = LFIMGGIA.
BAPI_Z05DOGI_ITEM_DATA-FACT_UNIT_NOM = UMVKZLIPS.
BAPI_Z05DOGI_ITEM_DATA-FACT_UNIT_DENOM = UMVKNLIPS.
APPEND BAPI_Z05DOGI_ITEM_DATA.
BAPI_Z05DOGI_ITEM_CONTROL-DELIV_NUMB = ZMM_WB1-ISSUE.
BAPI_Z05DOGI_ITEM_CONTROL-DELIV_ITEM = 10.
BAPI_Z05DOGI_ITEM_CONTROL-CHG_DELQTY = 'X'.
APPEND BAPI_Z05DOGI_ITEM_CONTROL.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
EXPORTING
DELIVERY = BAPI_Z05DOGI_DELIVERY
HEADER_DATA = BAPI_Z05DOGI_HEADER_DATA
HEADER_CONTROL = BAPI_Z05DOGI_HEADER_CONTROL
TABLES
ITEM_DATA = BAPI_Z05DOGI_ITEM_DATA
ITEM_CONTROL = BAPI_Z05DOGI_ITEM_CONTROL
RETURN = BAPI_Z05DOGI_RETURN.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = BAPI_Z05DOGI_RETURN.
Go thru this link
http://www.planetsap.com/LIST_ALL_BAPIs.htm
BAPI_TRANSACTION_COMMIT
Execute external Commit when using BAPIs
This method executes a COMMIT WORK command. It is required for
transactions developed externally to the R/3 System that change data in
the R/3 System via BAPI calls.
When you call BAPIs in your program that change data in the R/3 System,
afterwards you must call this method to write the changes to the
database.
COMMIT WORK
The statement COMMIT WORK completes the current SAP LUW and opens a new one, storing all change requests for the currenta SAP LUW in the process
there are some FM that we use for creating trasaction . for example FM : that use for creating production order . if you execut the FM , the system will not create any data in the system so you need to excute the FM : BAPI_TRANSACTION_COMMIT to commit that creating the production order .
in case of commit work, that is a syntax in abap program . if you use this syntax after you insert ,update or delete table in the sap ,system will do it immediately otherwise the system will do it after execution is complete.
ROLLBACK WORK.
for confirming or undoing database updates. COMMIT WORK always concludes a database LUW and starts a new one. ROLLBACK WORK always undoes all changes back to the start of the database LUW.
Regards,
Raj.