Skip to Content

Introduction:

‘BAPI_COPAACTUALS_POSTCOSTDATA’ is a Standard SAP BAPI provided to post COPA documents in the system. This BAPI is ideal to post CO-PA documents through ABAP programs by providing all requisite information as input.

As-Is situation:

  • Currently SAP is using the below mentioned function module to execute the KE21 transaction for posting CO-PA documents.

call function ‘RKE_CREATE_BATCH_INPUT’
exporting
erkrs      
= p_erkrs
group       = p_sesion
user       
= syuname
tables
ep_tab     
= it_batchinput
fieldtab   
= it_dbtable
exceptions
no_ep_found
= 1
others      = 2
.

  • Once the above sessions are created then run the below program

submit rsbdcsub exporting list to memory
with bis      = sydatum
with mappe    = p_sesion
with von      = sydatum
with z_verarb = true
and return
.

  • The above FM creates a BDC and creates the session for which it will be run from SM35 Transactions.

Cons of using the FM ‘RKE_CREATE_BATCH_INPUT’

  • In case of any errors the entire session has to be reprocessed.
  • Also time taken to create the session and the run the session in SM35 is tedious job.
  • No track of the Document number in the output display is possible if the posting is done through the standard reporting.
  • Many performance impacts are possible as we are using the BDC recording.

Usage of the BAPI ‘BAPI_COPAACTUALS_POSTCOSTDATA’:

  • The mentioned FM can be replaced with the BAPI

  call function ‘BAPI_COPAACTUALS_POSTCOSTDATA’
     
exporting
      operatingconcern
= i_erkrs
      testrun         
= i_testrun
     
tables
      inputdata       
= t_dat
      fieldlist       
= t_field
     
return           = t_return
.

The above BAPI provides the below advantages for postings :

  • Test Mode functionality for which it will identify if there are any errors which are present.
  • In the return parameters if there are errors in the postings then the erros can be shown in the report .
  • Individual document postings are also possible which was happening as a session in the case of the above BDC Fm.
  • Below is the sample code with which shows program logic to post CO-PA documents using BAPI ‘BAPI_COPAACTUALS_POSTCOSTDATA’.

f_datrecord_id  = w_recno.
f_dat
fieldname = ‘WWTP’.
f_dat
value     = w_bukrs.
append f_dat to t_dat.

clear f_dat.
f_dat
record_id  = w_recno.
f_dat
fieldname = ‘WWACT’.
f_dat
value     = <fs_final>wwact.
append f_dat to t_dat.

clear f_dat.
f_dat
record_id  = w_recno.
f_dat
fieldname = ‘WWAT’.
f_dat
value     = <fs_final>wwat.
append f_dat to t_dat.

clear f_dat.
f_dat
record_id  = w_recno.
f_dat
fieldname = ‘VRGAR’.
f_dat
value     = ‘J’.
append f_dat to t_dat.

clear: f_field.

f_fieldfieldname = ‘WWTP’.

append f_field to i_field.

clear: f_field.

f_fieldfieldname = ‘WWACT’.

append f_field to i_field.

clear: f_field.

f_fieldfieldname = ‘WWAT’.

append f_field to i_field.

clear: f_field.

f_fieldfieldname = ‘VRGAR’.

append f_field to i_field.

Call function ‘BAPI_COPAACTUALS_POSTCOSTDATA’
exporting
operatingconcern
= i_erkrs
testrun         
= i_testrun
tables
inputdata       
= t_dat
fieldlist       
= t_field
return           = t_return.

If the posting is successful

if sy-subrc is  initial  .

call function ‘BAPI_TRANSACTION_COMMIT’

exporting
wait = ‘X’.

                             Endif.

  • Use the below enhancement to fetch the document number from each posting :
  • Before calling the BAPI ‘BAPI_COPAACTUALS_POSTCOSTDATA’ write the below code.

/wp-content/uploads/2015/08/img1_766777.png

  • Inside the FM RKE_SERVE_ACT_DOC_NUMBER write the below code and fetch the document number as mentioned below :

/wp-content/uploads/2015/08/img2_766814.png

  • So after the posting of the each document number we can fetch the document numbers if the posting is successful which makes life easier for the reporting as shown in the below screen shot.

/wp-content/uploads/2015/08/img3_766815.png


  • For more details on the BAPI read the below documentation :

/wp-content/uploads/2015/08/img4_766816.png

SAP standard Report for testing the above BAPI:

  • SAP has provided a standard program for the COPA_BAPI_TEST through which the postings can be tested as done in the KE21 report.
  • Below are the steps for which this BAPI has to be tested.When you enter the BAPI it will have an option to enter the operating concern and do the postings based on either Costing-based or account-based.

/wp-content/uploads/2015/08/img5_766817.png

  • Then it will provide various option through which posting can be done as done in case of KE21.

/wp-content/uploads/2015/08/img6_766818.png

  • The same can be first tested which the above BAPI and can be copied and customized for further custom requirements.
To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Velsankar Sundar

    Hi Vijay,

    The post is very helpful. But  i am not getting the document number , i have added the code as mentioned in the FM RKE_SERVE_ACT_DOC_NUMBER. I have done a program where after the BAPI post and commit. The memory id is not getting any value. Do you have any idea

    (0) 

Leave a Reply