To get copa document number returned by “BAPI_COPAACTUALS_POSTCOSTDATA” posting
Abstract
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.
Steps involved
The step that needs to be followed is as below.
It’s divided mainly into 2 section .
A. custom program
B. Enhancement
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’
EXPORTING
operatingconcern = ip_operatingconcern
testrun = ip_testrun
TABLES
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’.
Output
Copa document number will be retrieved successfully from BAPI.
Conclusion
This code could be used to get copa document number generated through BAPI psoting .
Hi Vijay,
Thanks for sharing this information. I am working on a similar requirement and now I am able to retrieve document number into my program. 🙂
However, as you might be aware, this usage of EXPORT/IMPORT is obsolete at present.
What best alternative/change do you suggest in the above code to avoid using an obsolete concept?
Thanks in advance.
Barkha
After searching through few posts in SCN,
I came across the following modifications one can make to avoid usage of obsolete method:
IMPORT gv_memid_copadoc = gv_memid_copadoc FROM MEMORY ID 'ZCOPA_UPD_BAPI'.
EXPORT gv_memid_copadoc = gv_memid_copadoc TO MEMORY ID 'ZCOPA_UPD_BAPI'.
Similarly, for other IMPORT/EXPORT pair.
Feel free to correct me if I am wrong anywhere.
Thanks,
Barkha
Hi Vijay,
good solution, but it's only working if you post exactly 1 Document per BAPI call? I call this BAPI from a Excel VBA Funktion with many lines. I look for a solution to get the number of each line item back, may it's possible to write the line items table into memory at this point and read it into calling programm. I will check this (performance and memory consumption) and post it here if i am successful 😉
Regards from Bavaria(South Germany),
Wolfgang
Thanks and post your update , if you found any thing to resolve your issue.