본문 바로가기
SD

[SD] 판매오더 생성 BAPI

by clode 2023. 2. 27.
728x90
반응형

BAPI_CUSTOMERRETURN_CREATE

BAPI_SALESORDER_CREATEFROMDAT2

오더유형(헤더 DOC_TYPE)이 반품이면 BAPI_CUSTOMERRETURN_CREATE 바피를 수행하고, 일반오더이면 BAPI_SALESORDER_CREATEFROMDAT2 바피를 수행한다.

오더유형 조회 테이블 -필드
TVAKAUART, TVAKTBEZEI, , TVAK~VBTYP

*"*"Local interface:
*"  IMPORTING
*"     VALUE(ORDER_HEADER_IN) LIKE  BAPISDHD1 STRUCTURE  BAPISDHD1
*"  EXPORTING
*"     VALUE(SALESDOCUMENT) TYPE  BAPIVBELN-VBELN
*"  TABLES
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      ORDER_ITEMS_IN STRUCTURE  BAPISDITM OPTIONAL
*"      ORDER_PARTNERS STRUCTURE  BAPIPARNR
*"      ORDER_CONDITIONS_IN STRUCTURE  BAPICOND OPTIONAL
*"      ORDER_TEXT STRUCTURE  BAPISDTEXT OPTIONAL
*"      ORDER_SERNR_IN STRUCTURE  ZSSD00170 (ITM_NUMBER, MATNR, SERNR) OPTIONAL
*"----------------------------------------------------------------------

  DATA: ORDER_HEADER_INX     LIKE BAPISDHD1X,
        ORDER_ITEMS_INX      LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE,
        ORDER_CONDITIONS_INX LIKE BAPICONDX  OCCURS 0 WITH HEADER LINE,
        ORDER_SCHEDULES_IN   LIKE BAPISCHDL OCCURS 0 WITH HEADER LINE,
        ORDER_SCHEDULES_INX  LIKE BAPISCHDLX OCCURS 0 WITH HEADER LINE,
        CONVERT_PARVW_AUART  LIKE BAPIFLAG-BAPIFLAG,
        PARTNERADDRESSES     LIKE BAPIADDR1  OCCURS 0 WITH HEADER LINE,
        LOGIC_SWITCH         LIKE TABLE OF BAPISDLS   WITH HEADER LINE,
        TEXT                 LIKE BAPISDTEXT OCCURS 0 WITH HEADER LINE.

* ALPHA
  PERFORM CONVERSION_EXIT_ALPHA_INPUT USING : ORDER_ITEMS_IN-ITM_NUMBER,
                                              ORDER_ITEMS_IN-MATERIAL,
                                              ORDER_PARTNERS-PARTN_NUMB,
                                              ORDER_SCHEDULES_IN-ITM_NUMBER,
                                              ORDER_CONDITIONS_IN-ITM_NUMBER.



* HEADER (MPP I/F VALUE)
  ORDER_HEADER_IN-REFOBJKEY = 'VBBK'.
  ORDER_HEADER_INX-DOC_TYPE   = 'X'.
  ORDER_HEADER_INX-SALES_ORG  = 'X'.
  ORDER_HEADER_INX-DISTR_CHAN = 'X'.
  ORDER_HEADER_INX-DIVISION   = 'X'.
  ORDER_HEADER_INX-SALES_GRP   = 'X'.
  ORDER_HEADER_INX-SALES_OFF   = 'X'.
  ORDER_HEADER_INX-REQ_DATE_H   = 'X'.
  ORDER_HEADER_INX-INCOTERMS1   = 'X'.
  ORDER_HEADER_INX-PMNTTRMS   = 'X'.
  ORDER_HEADER_INX-PRICE_DATE   = 'X'.
  ORDER_HEADER_INX-PURCH_NO_C   = 'X'.


* CONVERT FLAG (중요)
  CONVERT_PARVW_AUART = 'X'.


* LGOIC_SWITCH (중요)
  LOGIC_SWITCH-PRICING = 'G'. " Pricing type
  APPEND LOGIC_SWITCH.



* ITEM

  LOOP AT ORDER_ITEMS_IN.
*    ORDER_ITEMS_IN-ITM_NUMBER = ORDER_ITEMS_IN-ITM_NUMBER.
*    ORDER_ITEMS_IN-MATERIAL = ORDER_ITEMS_IN-MATERIAL.
*    ORDER_ITEMS_IN-PLANT = ORDER_ITEMS_IN-ITM_NUMBER.
*    ORDER_ITEMS_IN-TARGET_QTY = ORDER_ITEMS_IN-TARGET_QTY.
*    APPEND ORDER_ITEMS_IN.
    ORDER_ITEMS_INX-ITM_NUMBER = 'X'.
    ORDER_ITEMS_INX-MATERIAL = 'X'.
    ORDER_ITEMS_INX-PLANT = 'X'.
    ORDER_ITEMS_INX-TARGET_QTY = 'X'.


* SCHEDULES
    ORDER_SCHEDULES_IN-ITM_NUMBER = ORDER_ITEMS_IN-ITM_NUMBER.
    ORDER_SCHEDULES_IN-REQ_DATE = ORDER_HEADER_IN-REQ_DATE_H.
    ORDER_SCHEDULES_IN-REQ_QTY = ORDER_ITEMS_IN-TARGET_QTY.
    APPEND ORDER_SCHEDULES_IN.
    ORDER_SCHEDULES_INX-ITM_NUMBER =  'X'.
    ORDER_SCHEDULES_INX-REQ_DATE =  'X'.
    ORDER_SCHEDULES_INX-REQ_QTY =  'X'.


* CONDITION
*    ORDER_CONDITIONS_IN-ITM_NUMBER = ORDER_CONDITIONS_IN-ITM_NUMBER.
*    ORDER_CONDITIONS_IN-COND_TYPE = ORDER_CONDITIONS_IN-COND_TYPE.
*    ORDER_CONDITIONS_IN-COND_VALUE = ORDER_CONDITIONS_IN-COND_VALUE.
*    ORDER_CONDITIONS_IN-CURRENCY = ORDER_CONDITIONS_IN-CURRENCY.
*    APPEND ORDER_CONDITIONS_IN.
    ORDER_CONDITIONS_INX-ITM_NUMBER = 'X'.
    ORDER_CONDITIONS_INX-COND_TYPE = 'X'.
    ORDER_CONDITIONS_INX-COND_VALUE = 'X'.
*  ORDER_CONDITIONS_INX-CURRENCY = 'X'.


  ENDLOOP.


** PARTNERS
*  PARTNERS-PARTN_ROLE = 'AG'. "SOLD-TO-PARTY
*  PARTNERS-PARTN_NUMB = T_DATA-PARTN_NUMB.
*  APPEND PARTNERS.
*  PARTNERS-PARTN_ROLE = 'WE'. "SHIP-TO-PARTY
*  PARTNERS-PARTN_NUMB = T_DATA-PARTN_NUMB.
*  APPEND PARTNERS.
*  PARTNERS-PARTN_ROLE = 'RE'. "BILL-TO
*  PARTNERS-PARTN_NUMB = T_DATA-PARTN_NUMB.
*  APPEND PARTNERS.
*  PARTNERS-PARTN_ROLE = 'RG'. "PAYER
*  PARTNERS-PARTN_NUMB = T_DATA-PARTN_NUMB.
*  APPEND PARTNERS.
*
*  PARTNERS-PARTN_ROLE = 'SE'.
*  PARTNERS-PARTN_NUMB = T_DATA-PARTN_NUMB.
*  APPEND PARTNERS.

** TEXT
  LOOP AT ORDER_TEXT.
    ORDER_TEXT-DOC_NUMBER = 'VBBK'.
    ORDER_TEXT-TEXT_ID = 'Z002'.
    ORDER_TEXT-LANGU = '3'.
    MODIFY ORDER_TEXT.
  ENDLOOP.

  IF ORDER_HEADER_IN-DOC_TYPE EQ 'ZRE' OR
    ORDER_HEADER_IN-DOC_TYPE EQ 'ZRE1'.
    CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
      EXPORTING
        RETURN_HEADER_IN     = ORDER_HEADER_IN
        RETURN_HEADER_INX    = ORDER_HEADER_INX
        LOGIC_SWITCH         = LOGIC_SWITCH
        CONVERT              = CONVERT_PARVW_AUART
      IMPORTING
        SALESDOCUMENT        = SALESDOCUMENT
      TABLES
        RETURN               = RETURN
        RETURN_ITEMS_IN      = ORDER_ITEMS_IN
        RETURN_ITEMS_INX     = ORDER_ITEMS_INX
        RETURN_PARTNERS      = ORDER_PARTNERS
        RETURN_SCHEDULES_IN  = ORDER_SCHEDULES_IN
        RETURN_CONDITIONS_IN = ORDER_CONDITIONS_IN
        RETURN_TEXT          = ORDER_TEXT.
*        PARTNERADDRESSES      = PARTNERADDRESSES.
  ELSE.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
      EXPORTING
        ORDER_HEADER_IN      = ORDER_HEADER_IN
        ORDER_HEADER_INX     = ORDER_HEADER_INX
        LOGIC_SWITCH         = LOGIC_SWITCH
        CONVERT              = CONVERT_PARVW_AUART
      IMPORTING
        SALESDOCUMENT        = SALESDOCUMENT
      TABLES
        RETURN               = RETURN
        ORDER_ITEMS_IN       = ORDER_ITEMS_IN
        ORDER_ITEMS_INX      = ORDER_ITEMS_INX
        ORDER_PARTNERS       = ORDER_PARTNERS
        ORDER_SCHEDULES_IN   = ORDER_SCHEDULES_IN
        ORDER_SCHEDULES_INX  = ORDER_SCHEDULES_INX
        ORDER_CONDITIONS_IN  = ORDER_CONDITIONS_IN
        ORDER_CONDITIONS_INX = ORDER_CONDITIONS_INX
        ORDER_TEXT           = ORDER_TEXT.
*        PARTNERADDRESSES     = PARTNERADDRESSES.

  ENDIF.



  IF SALESDOCUMENT IS NOT INITIAL.    
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    WAIT UP TO 1 SECONDS.
*    READ TABLE RETURN WITH KEY TYPE = 'S' ID = 'V1' NUMBER = '260'.

    IF ORDER_HEADER_IN-DOC_TYPE EQ 'ZRE' OR
      ORDER_HEADER_IN-DOC_TYPE EQ 'ZRE1'.
      PERFORM ADD_SERIAL_NUMBER TABLES ORDER_SERNR_IN
                                 USING SALESDOCUMENT.
    ENDIF.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

  ENDIF.
ENDFUNCTION.
728x90
반응형

'SD' 카테고리의 다른 글

[SD] 대금청구 Billing  (0) 2023.03.10
[SD] 출고 Shipping  (0) 2023.03.09
[SD] 판매오더 Sales order  (1) 2023.03.09
[SD] 조직 및 기준정보 Master data  (0) 2023.03.09
[SD] Order-Serial number Mapping BAPI  (0) 2023.02.27

댓글