Scheduling Agreements 생성 BAPI

1. BAPI 명 : BAPI_SAG_CREATE

2. 소스코드

[#M_더보기|접기|

DATA: LS_HEADER  TYPE BAPIMEOUTHEADER.

DATA: LS_HEADERX TYPE BAPIMEOUTHEADERX.

DATA: LS_ITEM    TYPE BAPIMEOUTITEM.

DATA: LT_ITEM    TYPE TABLE OF BAPIMEOUTITEM.

DATA: LS_ITEMX   TYPE BAPIMEOUTITEMX.

DATA: LT_ITEMX   TYPE TABLE OF BAPIMEOUTITEMX.

DATA: LS_RETURN  TYPE BAPIRET2.

DATA: LT_RETURN  TYPE TABLE OF BAPIRET2.

DATA: LS_MARA TYPE MARA.

DATA: LT_MARA TYPE TABLE OF MARA.

DATA: LV_ITEM_NO(10) TYPE N.

* 자재코드 조회.

CLEAR: LT_MARA.

SELECT A~MATNR UP TO 1000 ROWS

             INTO CORRESPONDING FIELDS OF TABLE LT_MARA

             FROM MARA AS A INNER JOIN MARC AS C

               ON A~MATNR = C~MATNR

            INNER JOIN MARD AS D

               ON C~MATNR = D~MATNR

              AND C~WERKS = D~WERKS

            WHERE

*  A~MATNR LIKE ‘0000000000072%’

              A~LVORM EQ   SPACE

              AND A~MTART EQ   ‘ROH7’

              AND A~MATKL LIKE ‘Z73%’

              AND A~MEINS IN (‘EA’, ‘KG’)

              AND C~WERKS EQ   ‘1100’

              AND D~LGORT EQ   ‘1703’.

*              AND D~LABST GT 0.

* Header.

LS_HEADER-COMP_CODE = ‘TPYP’.

LS_HEADER-DOC_TYPE = ‘LPA’.

LS_HEADER-CREAT_DATE = SY-DATUM.

LS_HEADER-VENDOR = ‘0000020086’.

LS_HEADER-PMNTTRMS = ‘TP53’.

LS_HEADER-PURCH_ORG = ‘2000’.

LS_HEADER-PUR_GROUP = ‘276’.

LS_HEADER-CURRENCY = ‘KRW’.

LS_HEADER-VPER_START = SY-DATUM.

LS_HEADER-VPER_END = ‘99991231’.

LS_HEADERX-COMP_CODE = ‘X’.

LS_HEADERX-DOC_TYPE = ‘X’.

LS_HEADERX-CREAT_DATE = ‘X’.

LS_HEADERX-VENDOR = ‘X’.

LS_HEADERX-PMNTTRMS = ‘X’.

LS_HEADERX-PURCH_ORG = ‘X’.

LS_HEADERX-PUR_GROUP = ‘X’.

LS_HEADERX-CURRENCY = ‘X’.

LS_HEADERX-VPER_START = ‘X’.

LS_HEADERX-VPER_END = ‘X’.

* Item.

LOOP AT LT_MARA INTO LS_MARA.

  LV_ITEM_NO = SY-TABIX * 10.

  LS_ITEM-ITEM_NO = LV_ITEM_NO.

  LS_ITEM-MATERIAL = LS_MARA-MATNR. “‘000000000007240319’.

  LS_ITEM-PLANT = ‘1100’.

  LS_ITEM-TARGET_QTY = ‘100’.

  LS_ITEM-FUNDS_CTR = ‘DUMMY’.

  LS_ITEM-TAX_CODE = ‘VA’.  ” 다중건시 추가.

  IF LS_ITEM-NET_PRICE = 0.

    LS_ITEM-NET_PRICE = ‘100’. ” 다중건시 추가.

  ENDIF.

  APPEND LS_ITEM TO LT_ITEM.

  LS_ITEMX-ITEM_NO = LV_ITEM_NO.                            “‘00010’.

  LS_ITEMX-ITEM_NOX = ‘X’.

  LS_ITEMX-MATERIAL =   ‘X’.

  LS_ITEMX-PLANT =      ‘X’.

  LS_ITEMX-TARGET_QTY = ‘X’.

  LS_ITEMX-FUNDS_CTR =  ‘X’.

  LS_ITEMX-TAX_CODE = ‘X’. ” 다중건시 추가.

  IF LS_ITEM-NET_PRICE = 0.

    LS_ITEMX-NET_PRICE = ‘X’. ” 다중건시 추가.

  ENDIF.

  APPEND LS_ITEMX TO LT_ITEMX.

ENDLOOP.  ” LOOP AT LT_MARA INTO LS_MARA.

CALL FUNCTION ‘BAPI_SAG_CREATE’

  EXPORTING

    HEADER                      = LS_HEADER

    HEADERX                     = LS_HEADERX

*   VENDOR_ADDRESS              =

*   HEAD_EXPORT_IMPORT          =

*   HEAD_EXPORT_IMPORTX         =

*   TESTRUN                     =

*   TECHNICAL_DATA              =

* IMPORTING

*   PURCHASINGDOCUMENT          =

*   EXP_HEADER                  =

  TABLES

   RETURN                      = LT_RETURN

    ITEM                        = LT_ITEM

    ITEMX                       = LT_ITEMX

*   ACCOUNT                     =

*   ACCOUNTPROFITSEGMENT        =

*   ACCOUNTX                    =

*   SCHEDULE                    =

*   SCHEDULEX                   =

*   SC_COMPONENT                =

*   SC_COMPONENTX               =

*   SHIPPING                    =

*   SHIPPINGX                   =

*   SHIPPING_EXP                =

*   DELIVERY_ADDRESS            =

*   ITEM_COND_VALIDITY          =

*   ITEM_COND_VALIDITYX         =

*   ITEM_CONDITION              =

*   ITEM_CONDITIONX             =

*   ITEM_COND_SCALE_VALUE       =

*   ITEM_COND_SCALE_QUAN        =

*   EXPORT_IMPORT               =

*   EXPORT_IMPORTX              =

*   ITEM_TEXT                   =

*   HEADER_TEXT                 =

*   HEAD_COND_VALIDITY          =

*   HEAD_COND_VALIDITYX         =

*   HEAD_CONDITION              =

*   HEAD_CONDITIONX             =

*   HEAD_COND_SCALE_VAL         =

*   HEAD_COND_SCALE_QUAN        =

*   PARTNER                     =

*   PARTNERX                    =

*   EXTENSIONIN                 =

*   EXTENSIONOUT                =

          .

READ TABLE LT_RETURN WITH KEY TYPE = ‘E’ TRANSPORTING NO FIELDS.

IF SY-SUBRC = 0.

  CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

  LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = ‘E’.

    WRITE:/ LS_RETURN-FIELD, LS_RETURN-MESSAGE.

  ENDLOOP.

ELSE.

  CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.

  READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = ‘S’.

  WRITE:/ LS_RETURN-MESSAGE_V2.

ENDIF.  ” IF SY-SUBRC = 0.

_M#]

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments