获利能力分析COPA的BAPI:BAPI_COPAACTUALS_POSTCOSTDATA 通过增强返回凭证号
用这个BAPI:BAPI_COPAACTUALS_POSTCOSTDATA 记录销售成本的时候,发现不能return生产的co凭证号,利用内存应该是最好的方法。
参照这个方法我做了第四代增强的开发
GV_CALL_COPA_BAPI_INDICATOR = 'Y' . EXPORT GV_CALL_COPA_BAPI_INDICATOR TO MEMORY ID 'ZCOPA_UPD_BAPI1'. 。
。
。 IMPORT GV_MEMID_COPADOC FROM MEMORY ID 'ZCOPA_UPD_BAPI'.
RKE_SERVE_ACT_DOC_NUMBER
代码如下:
*$*$-Start: ZEHM_POINT_001----------------------------------------------------------------------$*$* ENHANCEMENT 1 ZFICO_COPA_EHMP_UPD_BY_BAPI. "active version *EHM BY ZHAIMING 2016-10-20 23:39:29 bapi用 DATA: GV_MEMID_COPADOC TYPE RKE_BELNR, GV_CALL_COPA_BAPI_INDICATOR TYPE CHAR1. DATA: BEGIN OF LW_LINE_ITEM, BELNR TYPE RKE_BELNR, END OF LW_LINE_ITEM. FIELD-SYMBOLS <FS_COPADOC> TYPE ANY. IMPORT GV_CALL_COPA_BAPI_INDICATOR FROM MEMORY ID 'ZCOPA_UPD_#### . IF GV_CALL_COPA_BAPI_INDICATOR EQ 'Y'. ASSIGN LINE_ITEM_TAB TO <FS_COPADOC>. MOVE-CORRESPONDING <FS_COPADOC> TO LW_LINE_ITEM . GV_MEMID_COPADOC = LW_LINE_ITEM-BELNR . EXPORT GV_MEMID_COPADOC TO MEMORY ID 'ZCOPA_UPD####'. ENDIF. ENDENHANCEMENT. *$*$-End: ZEHM_POINT_001----------------------------------------------------------------------$*$*
我同事没有看我写的代码也做了这个增强,思路就是在增强里调用使用BAPI程序的子程序,方法可以 但是针对某个程序做开发,不能广泛适用。
*$*$-Start: (1)---------------------------------------------------------------------------------$*$* ENHANCEMENT 1 ZENH_####. "active version * PERFORM ######### IN PROGRAM ZFIR#### USING ERKRS T_PALEDGER LINE_ITEM_TAB[]. ENDENHANCEMENT. *$*$-End: (1)---------------------------------------------------------------------------------$*$*
附原帖内容:
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 .