Quantcast
Channel: SCN : Document List - SAP ERP Financials
Viewing all articles
Browse latest Browse all 366

Posting CO-PA Document Using ‘BAPI_COPAACTUALS_POSTCOSTDATA’

$
0
0

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.

img1.png

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

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

 

img3.png


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

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

img5.png

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

img6.png

  • The same can be first tested which the above BAPI and can be copied and customized for further custom requirements.

Viewing all articles
Browse latest Browse all 366

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>