Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
VijayCR
Active Contributor
0 Kudos

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       
= sy-uname
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      = sy-datum
with mappe    = p_sesion
with von      = sy-datum
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_dat-record_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_field-fieldname = 'WWTP'.

append f_field to i_field.

clear: f_field.

f_field-fieldname = 'WWACT'.

append f_field to i_field.

clear: f_field.

f_field-fieldname = 'WWAT'.

append f_field to i_field.

clear: f_field.

f_field-fieldname = '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.

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

  • 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.


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

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.

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

  • The same can be first tested which the above BAPI and can be copied and customized for further custom requirements.
6 Comments
Labels in this area