SAP ABAP - Create Profit Center With Using BAPI_PROFITCENTER_CREATE

 *&---------------------------------------------------------------------*

*& Report YPC_CREATE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ypc_create.
DATA:
  profitcenterid  TYPE  bapi0015id2,
  validfrom       TYPE  bapi0015_3-date,
  validto         TYPE  bapi0015_3-date,
  basicdata       TYPE  bapi0015_4,
  address         TYPE  bapi0015_5,
  communication   TYPE  bapi0015_6,
  indicators      TYPE  bapi0015_8,
  testrun         TYPE  bapi0015_9,
  language        TYPE  bapi0015_10,

  lt_companycodes  TYPE TABLE OF bapi0015_7,
  ls_companycodes  TYPE bapi0015_7,

  lsreturn        TYPE bapiret2,
  profitcenter    TYPE bapi0015id2-profit_ctr,
  controllingarea TYPE bapi0015id2-co_area.

START-OF-SELECTION.
  PERFORM append_data.
  PERFORM call_bapi.

FORM append_data.
  CLEARprofitcenteridbasicdatalanguage.
  profitcenterid-co_area    '2000'.
  profitcenterid-profit_ctr 'PC1000'.

  validfrom '20230101'.
  validto   '99991231'.

  "Basic Data
  basicdata-prctr_name 'Testing Profit Center'.
  basicdata-long_text  'Testing Profit Center'.
  basicdata-in_charge  'LOGISTIC'.
  basicdata-prctr_hier_grp 'PC10000'.

  "Language
  language-langu     sy-langu.
  language-langu_iso sy-langu.

  "Company Code
  REFRESH lt_companycodes.
  CLEAR ls_companycodes.
  ls_companycodes-comp_code       'SAP1'.
  ls_companycodes-assign_to_prctr 'X'.
  APPEND ls_companycodes TO lt_companycodes.
ENDFORM.

FORM call_bapi.
  CLEAR lsreturn.
  CALL FUNCTION 'BAPI_PROFITCENTER_CREATE'
    EXPORTING
      profitcenterid  profitcenterid
      validfrom       validfrom
      validto         validto
      basicdata       basicdata
*     ADDRESS         =
*     COMMUNICATION   =
*     INDICATORS      =
      testrun         testrun
      language        language
    IMPORTING
      return          lsreturn
      profitcenter    profitcenter
      controllingarea controllingarea
    TABLES
      companycodes    lt_companycodes.

  IF lsreturn-type 'S'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait abap_true.

    MESSAGE lsreturn-message TYPE 'S' DISPLAY LIKE 'S'.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    MESSAGE lsreturn-message TYPE 'S' DISPLAY LIKE 'E'.
  ENDIF.

ENDFORM.

Comments

Popular posts from this blog

PHP MySql CRUD Dengan Konsep MVC

Laravel - Sistem Informasi Perpustakaan Sederhana Laravel

IT Asset Management Dengan PHP MySQL