To get copa document number returned by “BAPI_COPAACTUALS_POSTCOSTDATA” posting
While posting COPA document by BAPI “BAPI_COPAACTUALS_POSTCOSTDATA” , this BAPI
does not return successful records with generated copa document number.
But in case system need to capture generated copa doc number there is workaround with
implicit enhancement withing bapi as described in doc,
About the Domain
SAP ABAP/FICO module can use this document. This will help them to get generated COPA
document number which is posted by BAPI_COPAACTUALS_POSTCOSTDATA.
The step that needs to be followed is as below.
It’s divided mainly into 2 section .
A. custom program
Create a Custom Program like ZCOPA_UPDATE .
Please follow steps given below for this program.
- Export BAPI_Call indicator from your program to memory id
This indicator will make sure enhancement will be trigger only in case bapi will be called for custom program
gv_call_copa_bapi_indicator = ‘Y’ .
EXPORT gv_call_copa_bapi_indicator TO MEMORY ID ‘ZCOPA_UPD_BAPI1’.
- Call Bapi to post data
*To post Copa document
CALL FUNCTION ‘BAPI_COPAACTUALS_POSTCOSTDATA’
operatingconcern = ip_operatingconcern
testrun = ip_testrun
inputdata = lt_bapi_copa_data
fieldlist = lt_bapi_copa_field
return = lt_return.
- IF lt_return IS INITIAL ,means copa doc posted ,then only read copa document number .
In case there is any record in return with message type E or A it means there is an error while generating copa doc , so do not import doc numner from ID ‘ZCOPA_UPD_BAPI’
- CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
- Importing copa document number from enhancement only if lt_return is initial
or have S,I,W message type.because doc number can be populated in error cases also as this enhancement from where exporting memory
ID ‘ZCOPA_UPD_BAPI’ is before actual posting , so always check return table (is initial or have S,I,W message type only)
IMPORT gv_memid_copadoc FROM MEMORY ID ‘ZCOPA_UPD_BAPI’ .
So gv_memid_copadoc will have copa document number which is generated.
Create a implicit enhancement like ZCOPA_ENH_UPDATE .
Please follow steps given below for this enhancement.
- Create implicit enhancement in FM “RKE_SERVE_ACT_DOC_NUMBER “ in the end of function.
Which will be used during BAPI posting as this FM function to get next available document number for COPA posting , But actual posting will happen after this FM .
So at this stage we will be able to get COPA doc number which will be generated later on and confirm if there is no error in return table of BAPI .
As Actual copa posting perform is refreshing inputdata table , and not returning success message we need to use this way .
- Import BAPI called by Custom Program indicator to make sure enhancement will be triggered only if BAPI call from custom program
IMPORT gv_call_copa_bapi_indicator FROM MEMORY ID ‘ZCOPA_UPD_BAPI1’ .
if gv_call_copa_bapi_indicator EQ ‘Y’ .
then only create following steps
- Define field-symbol with genric type as line item table which contain copa records is genric type and define workarea with field Belnr.
*As line item table type genric , so get doc no using field symbol
ASSIGN LINE_ITEM_TAB to <fs_copadoc>.
*As field symbol type any defined work area with belnr which contain copa doc no
MOVE-CORRESPONDING <fs_copadoc> to lw_line_item .
- Get copa document number in variable
GV_MEMID_COPADOC = lw_line_item–belnr .
- And Export Copa Doc number to memory id.
EXPORT GV_MEMID_COPADOC to memory id ‘ZCOPA_UPD_BAPI’.
Copa document number will be retrieved successfully from BAPI.
This code could be used to get copa document number generated through BAPI psoting .