Overblog
Edit post Folge diesem Blog Administration + Create my blog
SAPManDoo - SAP Resource

Der vorliegende Blog enthält von mir im Laufe meiner beruflichen Tätigkeit als SAP-Berater zusammengetragene Informationen / Beispiel-Codings zum Themenkreis SAP, speziell FI/CO.

Tarifierung mit BAPI analog zur KP26

Veröffentlicht am 11. Dezember 2018 von sapmandoo in CO

Die Planung von Leistungserbringungen und Tarifen erfolgt im Dialog mithilfe der KP26. In einigen Planungsszenarien stellt sich die Aufgabe, externe Daten ins SAP-System zu laden. Hierfür können verschiedene Importszenarien verwendet werden, u.a. der Upload via BAPI BAPI_COSTACTPLN_POSTACTOUTPUT.

Die Schnittstelle des BAPIs ist dabei nicht gerade ein Ausbund an selbsterklärender Offenherzigkeit, deshalb nachfolgend ein Mustercoding sowohl für periodische als auch Gesamt-Planung. 

Das nachfolgende Coding habe ich auf einem S/4 HANA on premise (1709)  getestet, es sollte aber auch auf älteren Releases lauffähig sein.

*&---------------------------------------------------------------------*
*& Report ZTEST_KP26
*&---------------------------------------------------------------------*
*& KP26 tariff planning
*&---------------------------------------------------------------------*
REPORT ztest_kp26.

DATAit_actout_index    LIKE bapiacpstru OCCURS WITH HEADER LINE.
DATAit_actout_pervalue LIKE bapiacpval  OCCURS WITH HEADER LINE.
DATAit_actout_totvalue LIKE bapiacptot  OCCURS WITH HEADER LINE.
DATAit_actout_object   LIKE bapiacpobj  OCCURS WITH HEADER LINE.
DATAit_return          LIKE bapiret2    OCCURS WITH HEADER LINE.
DATArec_headerinfo     LIKE bapiplnhdr.
DATAfp_error(1TYPE c.

" Object index / value index:
" You can post several objects/values at once (with one BAPI call).
" Please make sure, that object and value key correspond in object
" and value tables...
DATAgw_objcnt(6TYPE n,
      gw_valcnt(6TYPE n.

PARAMETERSp_tariff LIKE bapiacpval-price_var_per01 OBLIGATORY,
            p_kokrs  LIKE rec_headerinfo-co_area OBLIGATORY,
            p_kostl  LIKE it_actout_object-costcenter OBLIGATORY,
            p_lstar  LIKE it_actout_object-acttype OBLIGATORY,
            p_year   LIKE rec_headerinfo-fisc_year OBLIGATORY,
            p_from   LIKE rec_headerinfo-period_from OBLIGATORY,
            p_to     LIKE rec_headerinfo-period_to OBLIGATORY,
            p_versn  LIKE rec_headerinfo-version OBLIGATORY.
PARAMETERSp_tot RADIOBUTTON GROUP r1 DEFAULT 'X',    "totals planning
            p_per RADIOBUTTON GROUP r1.                "periodic planning

START-OF-SELECTION.
  IF p_per 'X'.
    PERFORM make_bapi_data_for_actout_per.
  ELSE.
    PERFORM make_bapi_data_for_actout_tot.
  ENDIF.

*&---------------------------------------------------------------------*
* TOTALS
*&---------------------------------------------------------------------*
FORM make_bapi_data_for_actout_tot.

* init. variables
  CLEARgw_objcntgw_valcnt.

* header data
  CLEARrec_headerinfo.
  rec_headerinfo-co_area       p_kokrs.        "Controlling area
  rec_headerinfo-fisc_year     p_year.         "Fiscal year
  rec_headerinfo-period_from   p_from.         "From period
  rec_headerinfo-period_to     p_to.           "To period
  rec_headerinfo-version       p_versn.        "Version
  rec_headerinfo-plan_currtype 'C'.            "Planning Currency

  ADD TO gw_objcnt.

* object list (cost center/activity type or business process)
  CLEARit_actout_object.
  it_actout_object-costcenter   p_kostl.       "Costcenter
  it_actout_object-acttype      =  p_lstar.      "act. type
  it_actout_object-object_index gw_objcnt.     "Object Index
  APPEND it_actout_object.

  ADD TO gw_valcnt.

* plan values totals
  CLEARit_actout_totvalue.
* check structure of table for other values such as quantities, capacities...
  it_actout_totvalue-value_index        gw_valcnt.       "Value Index
  it_actout_totvalue-price_unit         1.               "price unit
  it_actout_totvalue-price_var          p_tariff.        "var. tariff
  it_actout_totvalue-currency           'EUR'.
  it_actout_totvalue-dist_key_price_var '2'.             "distr.key
  APPEND it_actout_totvalue.

* assignment of objects, values and control data
  "the items given in the object and value tables are linked by  the index value
  "this is important, if you want to plan multiple objects with one BAPI call
  CLEARit_actout_index.
  it_actout_index-object_index gw_objcnt.          "Object Index
  it_actout_index-value_index  gw_valcnt.          "Value Index
  APPEND it_actout_index.

  CALL FUNCTION 'BAPI_COSTACTPLN_POSTACTOUTPUT'
    EXPORTING
      headerinfo     rec_headerinfo
    TABLES
      indexstructure it_actout_index
      coobject       it_actout_object
      totvalue       it_actout_totvalue
      return         it_return.

  IF it_return[] IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait 'X'.
  ELSE.
    fp_error 'X'.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.

ENDFORM.                    " MAKE_BAPI_DATA_FOR_ACTOUT

*&---------------------------------------------------------------------*
* PERIODIC VALUES
*&---------------------------------------------------------------------*
FORM make_bapi_data_for_actout_per .

* init. variables
  CLEARgw_objcntgw_valcnt,
         it_actout_index[],    it_actout_object[],
         it_actout_pervalue[].

* header data
  CLEARrec_headerinfo.
  rec_headerinfo-co_area       p_kokrs.        "Controlling area
  rec_headerinfo-fisc_year     p_year.         "Fiscal year
  rec_headerinfo-period_from   p_from.         "From period
  rec_headerinfo-period_to     p_to.           "To period
  rec_headerinfo-version       p_versn.        "Version
  rec_headerinfo-plan_currtype 'C'.            "Planning Currency

  ADD TO gw_objcnt.

*  object list (cost center/activity type or business process)
  CLEARit_actout_object.
  it_actout_object-costcenter   p_kostl.       "Costcenter
  it_actout_object-acttype      =  p_lstar.      "act. type
  it_actout_object-object_index gw_objcnt.     "Object Index
  APPEND it_actout_object.

  ADD TO gw_valcnt.

* plan values per period
  CLEARit_actout_pervalue.
* check structure of table for other values such as quantities, capacities...
  it_actout_pervalue-value_index   gw_valcnt.       "Value Index
  it_actout_pervalue-price_unit_per01 1.            "price unit per.
  it_actout_pervalue-price_unit_per02 1.
  it_actout_pervalue-price_unit_per03 1.
  it_actout_pervalue-price_unit_per04 1.
  it_actout_pervalue-price_unit_per05 1.
  it_actout_pervalue-price_unit_per06 1.
  it_actout_pervalue-price_unit_per07 1.
  it_actout_pervalue-price_unit_per08 1.
  it_actout_pervalue-price_unit_per09 1.
  it_actout_pervalue-price_unit_per10 1.
  it_actout_pervalue-price_unit_per11 1.
  it_actout_pervalue-price_unit_per12 1.
  it_actout_pervalue-price_var_per01 p_tariff.     "var. tariff per.
  it_actout_pervalue-price_var_per02 p_tariff.
  it_actout_pervalue-price_var_per03 p_tariff.
  it_actout_pervalue-price_var_per04 p_tariff.
  it_actout_pervalue-price_var_per05 p_tariff.
  it_actout_pervalue-price_var_per06 p_tariff.
  it_actout_pervalue-price_var_per07 p_tariff.
  it_actout_pervalue-price_var_per08 p_tariff.
  it_actout_pervalue-price_var_per09 p_tariff.
  it_actout_pervalue-price_var_per10 p_tariff.
  it_actout_pervalue-price_var_per11 p_tariff.
  it_actout_pervalue-price_var_per12 p_tariff.
  it_actout_pervalue-currency 'EUR'.
  APPEND it_actout_pervalue.

* assignment of objects, values and control data
  CLEARit_actout_index.
  it_actout_index-object_index gw_objcnt.          "Object Index
  it_actout_index-value_index  gw_valcnt.          "Value Index
  APPEND it_actout_index.

  CALL FUNCTION 'BAPI_COSTACTPLN_POSTACTOUTPUT'
    EXPORTING
      headerinfo     rec_headerinfo
    TABLES
      indexstructure it_actout_index
      coobject       it_actout_object
      pervalue       it_actout_pervalue
      return         it_return.

  IF it_return[] IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait 'X'.
  ELSE.
    fp_error 'X'.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.

ENDFORM.                    " MAKE_BAPI_DATA_FOR_ACTOUT

Eingabewerte BAPI

Eingabewerte BAPI

Kommentiere diesen Post