BAPI_ACC_DOCUMENT_POST

*---BAPI_ACC_DOCUMENT_POST 所需要的参数
  DATA: OBJ_TYPE LIKE BAPIACHE09-OBJ_TYPE,
        OBJ_KEY LIKE BAPIACHE09-OBJ_KEY,
        OBJ_SYS LIKE BAPIACHE09-OBJ_SYS,
        DOCUMENTHEADER LIKE BAPIACHE09.

DATA: ACCOUNTGL LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
        ACCOUNTRECEIVABLE LIKE BAPIACAR09 OCCURS 0 WITH HEADER LINE,
        CURRENCYAMOUNT LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
        RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
        BAPI_RETN_INFO LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
        EXTENSION1 LIKE BAPIACEXTC OCCURS 0 WITH HEADER LINE,
        CRITERIA LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE.

DATA: ERROR_FLAG.

IF ZJSJ > ZGDJ."支出
*---调用 BAPI_ACC_DOCUMENT_POST 创建应付凭证
    LOOP AT TAB_ZZHJYJS INTO REC_ZZHJYJS WHERE ZCHKBOX = 'X'.

DOCUMENTHEADER-BUS_ACT = 'RFBU'.
      DOCUMENTHEADER-USERNAME = SY-UNAME.
      DOCUMENTHEADER-HEADER_TXT = '纸货交易结算凭证(应付)'.
      DOCUMENTHEADER-COMP_CODE = ZGSDM.
      DOCUMENTHEADER-DOC_DATE = REC_ZZHJYJS-ZJSRQ.
      DOCUMENTHEADER-PSTNG_DATE = REC_ZZHJYJS-ZJSRQ.
      DOCUMENTHEADER-DOC_TYPE = 'SA'.

ACCOUNTGL-ITEMNO_ACC = '1'.
      ACCOUNTGL-GL_ACCOUNT = '1002000000'.
      ACCOUNTGL-COMP_CODE = ZGSDM.
      ACCOUNTGL-PSTNG_DATE = REC_ZZHJYJS-ZJSRQ.
      ACCOUNTGL-DOC_TYPE = 'SA'.
      ACCOUNTGL-ACCT_TYPE = 'S'.
      ACCOUNTGL-PROFIT_CTR = '1022000001'.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

ACCOUNTGL-ITEMNO_ACC = '2'.
      ACCOUNTGL-GL_ACCOUNT = '2121000000'.
      ACCOUNTGL-COMP_CODE = ZGSDM.
      ACCOUNTGL-PSTNG_DATE = REC_ZZHJYJS-ZJSRQ.
      ACCOUNTGL-DOC_TYPE = 'SA'.
      ACCOUNTGL-ACCT_TYPE = 'K'.
*---获得客户所对应的供应商
      SELECT SINGLE *
       FROM KNA1
        WHERE KUNNR = REC_ZZHJYJS-ZFDZF.
      IF SY-SUBRC = 0.
        ACCOUNTGL-VENDOR_NO = KNA1-LIFNR.
      ENDIF.
      ACCOUNTGL-PROFIT_CTR = '1022000001'.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

CURRENCYAMOUNT-ITEMNO_ACC = '1'.
      CURRENCYAMOUNT-CURRENCY = 'CNY'.
      CURRENCYAMOUNT-AMT_DOCCUR = REC_ZZHJYJS-ZGDJG.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

CURRENCYAMOUNT-ITEMNO_ACC = '2'.
      CURRENCYAMOUNT-CURRENCY = 'CNY'.
      CURRENCYAMOUNT-AMT_DOCCUR = -1 * REC_ZZHJYJS-ZGDJG.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
        EXPORTING
          DOCUMENTHEADER = DOCUMENTHEADER
        IMPORTING
          OBJ_TYPE       = OBJ_TYPE
          OBJ_KEY        = OBJ_KEY
          OBJ_SYS        = OBJ_SYS
        TABLES
          ACCOUNTGL      = ACCOUNTGL
          CURRENCYAMOUNT = CURRENCYAMOUNT
          RETURN         = RETURN
          EXTENSION1     = EXTENSION1
        EXCEPTIONS
          OTHERS         = 1.
      IF SY-SUBRC <> 0.
        MESSAGE E999(RE) WITH '创建应付会计凭证时出错'.
      ELSE.
        LOOP AT RETURN.
          IF RETURN-TYPE = 'S'.
            CLEAR BAPI_RETN_INFO.
            MOVE-CORRESPONDING RETURN TO BAPI_RETN_INFO.
            EXIT.
          ELSEIF RETURN-TYPE = 'A' OR RETURN-TYPE = 'E'.
            CLEAR BAPI_RETN_INFO.
            MOVE-CORRESPONDING RETURN TO BAPI_RETN_INFO.
            ERROR_FLAG = 'X'.
            EXIT.
          ENDIF.
        ENDLOOP.
        IF ERROR_FLAG = 'X'.
          ROLLBACK WORK.
          MESSAGE I066(Z1) WITH BAPI_RETN_INFO-MESSAGE.
        ELSE.
          COMMIT WORK.
          REC_ZZHJYJS-ZJSPZ = OBJ_KEY+0(10).
          MODIFY TAB_ZZHJYJS FROM REC_ZZHJYJS.
          MESSAGE I066(Z1) WITH BAPI_RETN_INFO-MESSAGE.
          UPDATE ZZHJYJS SET ZJSPZ = OBJ_KEY+0(10)
                             WHERE ZZGSDM = REC_ZZHJYJS-ZZGSDM
                               AND ZJYLB_ZH = REC_ZZHJYJS-ZJYLB_ZH
                               AND ZJYDH = REC_ZZHJYJS-ZJYDH
                               AND ZJSRQ = REC_ZZHJYJS-ZJSRQ.
        ENDIF.
      ENDIF.

ENDLOOP.

ELSEIF ZJSJ < ZGDJ."收入
*---调用 BAPI_ACC_DOCUMENT_POST 创建应收凭证
    LOOP AT TAB_ZZHJYJS INTO REC_ZZHJYJS WHERE ZCHKBOX = 'X'.

DOCUMENTHEADER-BUS_ACT = 'RFBU'.
      DOCUMENTHEADER-USERNAME = SY-UNAME.
      DOCUMENTHEADER-HEADER_TXT = '纸货交易结算凭证(应收)'.
      DOCUMENTHEADER-COMP_CODE = ZGSDM.
      DOCUMENTHEADER-DOC_DATE = REC_ZZHJYJS-ZJSRQ.
      DOCUMENTHEADER-PSTNG_DATE = REC_ZZHJYJS-ZJSRQ.
      DOCUMENTHEADER-DOC_TYPE = 'SA'.

ACCOUNTGL-ITEMNO_ACC = '1'.
      ACCOUNTGL-GL_ACCOUNT = '5101100000'.
      ACCOUNTGL-COMP_CODE = ZGSDM.
      ACCOUNTGL-PSTNG_DATE = REC_ZZHJYJS-ZJSRQ.
      ACCOUNTGL-DOC_TYPE = 'SA'.
      ACCOUNTGL-ACCT_TYPE = 'S'.
      ACCOUNTGL-PROFIT_CTR = '1022000001'.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

ACCOUNTGL-ITEMNO_ACC = '2'.
      ACCOUNTGL-GL_ACCOUNT = '1131010000'.
      ACCOUNTGL-COMP_CODE = ZGSDM.
      ACCOUNTGL-PSTNG_DATE = REC_ZZHJYJS-ZJSRQ.
      ACCOUNTGL-DOC_TYPE = 'SA'.
      ACCOUNTGL-ACCT_TYPE = 'D'.
      ACCOUNTGL-CUSTOMER = REC_ZZHJYJS-ZFDZF.
      APPEND ACCOUNTGL.
      CLEAR ACCOUNTGL.

CURRENCYAMOUNT-ITEMNO_ACC = '1'.
      CURRENCYAMOUNT-CURRENCY = 'CNY'.
      CURRENCYAMOUNT-AMT_DOCCUR = -1 * REC_ZZHJYJS-ZGDJG.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

CURRENCYAMOUNT-ITEMNO_ACC = '2'.
      CURRENCYAMOUNT-CURRENCY = 'CNY'.
      CURRENCYAMOUNT-AMT_DOCCUR = REC_ZZHJYJS-ZGDJG.
      APPEND CURRENCYAMOUNT.
      CLEAR CURRENCYAMOUNT.

*CO-PA Account Assignment Characteristics(获利能力段分配)

CLEAR CRITERIA.
      CRITERIA-ITEMNO_ACC = '1'.
      CRITERIA-FIELDNAME  = 'WW004'.
      CRITERIA-CHARACTER  = 'Z3'.
      APPEND CRITERIA.

CLEAR CRITERIA.
      CRITERIA-ITEMNO_ACC = '1'.
      CRITERIA-FIELDNAME  = 'SPART'.
      CRITERIA-CHARACTER  = '01'.
      APPEND CRITERIA.

CLEAR CRITERIA.
      CRITERIA-ITEMNO_ACC = '1'.
      CRITERIA-FIELDNAME  = 'WW007'.
      CRITERIA-CHARACTER  = '01'.
      APPEND CRITERIA.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
        EXPORTING
          DOCUMENTHEADER = DOCUMENTHEADER
        IMPORTING
          OBJ_TYPE       = OBJ_TYPE
          OBJ_KEY        = OBJ_KEY
          OBJ_SYS        = OBJ_SYS
        TABLES
          ACCOUNTGL      = ACCOUNTGL
          CURRENCYAMOUNT = CURRENCYAMOUNT
          CRITERIA       = CRITERIA
          RETURN         = RETURN
          EXTENSION1     = EXTENSION1
        EXCEPTIONS
          OTHERS         = 1.

IF SY-SUBRC <> 0.
        MESSAGE E999(RE) WITH '创建应收会计凭证时出错'.
      ELSE.
        LOOP AT RETURN.
          IF RETURN-TYPE = 'S'.
            CLEAR BAPI_RETN_INFO.
            MOVE-CORRESPONDING RETURN TO BAPI_RETN_INFO.
            EXIT.
          ELSEIF RETURN-TYPE = 'A' OR RETURN-TYPE = 'E'.
            CLEAR BAPI_RETN_INFO.
            MOVE-CORRESPONDING RETURN TO BAPI_RETN_INFO.
            ERROR_FLAG = 'X'.
            EXIT.
          ENDIF.
        ENDLOOP.
        IF ERROR_FLAG = 'X'.
          ROLLBACK WORK.
          MESSAGE I066(Z1) WITH BAPI_RETN_INFO-MESSAGE.
        ELSE.
          COMMIT WORK.
          REC_ZZHJYJS-ZJSPZ = OBJ_KEY+0(10).
          MODIFY TAB_ZZHJYJS FROM REC_ZZHJYJS.
          MESSAGE I066(Z1) WITH BAPI_RETN_INFO-MESSAGE.
          UPDATE ZZHJYJS SET ZJSPZ = OBJ_KEY+0(10)
                             WHERE ZZGSDM = REC_ZZHJYJS-ZZGSDM
                               AND ZJYLB_ZH = REC_ZZHJYJS-ZJYLB_ZH
                               AND ZJYDH = REC_ZZHJYJS-ZJYDH
                               AND ZJSRQ = REC_ZZHJYJS-ZJSRQ.
        ENDIF.
      ENDIF.

ENDLOOP.

ENDIF.

BAPI_SALESORDER_CREATEFROMDAT2

*---------------------------------------------------------------------*
*创建销售订单(带订单价格)
*---------------------------------------------------------------------*
DATA:  LOGIC_SWITCH           TYPE BAPISDLS.
DATA:  ORDER_HEADER_IN1       LIKE BAPISDHD1.
DATA:  ORDER_HEADER_INTX      LIKE BAPISDHD1X.
DATA:  SALESDOCUMENT1         TYPE BAPIVBELN-VBELN.
DATA:  RETURN2                TYPE BAPIRET2.
DATA:  ORDER_PARTNERS1        TYPE BAPIPARNR  OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_ITEMS_IN1        TYPE BAPISDITM  OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_ITEMS_IN1X       TYPE BAPISDITMX OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_SCHEDULES_IN1    TYPE BAPISCHDL  OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_SCHEDULES_IN1X   TYPE BAPISCHDLX OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_CONDITIONS_IN1   TYPE BAPICOND OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_CONDITIONS_INX   TYPE BAPICONDX OCCURS 0 WITH HEADER LINE.
DATA:  RETURN1                TYPE BAPIRET2   OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

LOGIC_SWITCH-COND_HANDL = 'X'.

ORDER_HEADER_IN1-DOC_TYPE   = 'Z093'.
  ORDER_HEADER_IN1-SALES_ORG  =  '1046'.
  ORDER_HEADER_IN1-DISTR_CHAN =  '98'.
  ORDER_HEADER_IN1-DIVISION   =  '00'.
  ORDER_HEADER_IN1-REQ_DATE_H =  '20081016'.
  ORDER_HEADER_IN1-PURCH_NO_C = 'PO-2008-10-16'.
  ORDER_HEADER_IN1-REF_1      = 'PO-2008-10-16'.
*  ORDER_HEADER_IN1-SD_DOC_CAT = 'C'.
*  ORDER_HEADER_IN1-REF_DOC    =  '0040000820'.
*  ORDER_HEADER_IN1-REF_DOC_L  =  '40000820'.
*  ORDER_HEADER_IN1-REFDOCTYPE = 'Z067'.
*  ORDER_HEADER_IN1-REFDOC_CAT = 'G'.
*  ORDER_HEADER_IN1-PRICE_DATE = '20081006'."定价日期
*  ORDER_HEADER_IN1-INCOTERMS1 = VBKD-INCO1.
*  ORDER_HEADER_IN1-INCOTERMS2 = VBKD-INCO2.
*  ORDER_HEADER_IN1-PMNTTRMS   = VBKD-ZTERM.
*  ORDER_HEADER_IN1-SALES_OFF  = VBAK-VKBUR.

CLEAR ORDER_ITEMS_IN1.
  ORDER_ITEMS_IN1-ITM_NUMBER       = '000010'.
  ORDER_ITEMS_IN1-PO_ITM_NO        = '000010'.
  ORDER_ITEMS_IN1-MATERIAL         = '000000000080013569'.
  ORDER_ITEMS_IN1-PLANT            = '1270'.
  ORDER_ITEMS_IN1-STORE_LOC        = '0001'.
*  ORDER_ITEMS_IN1-REF_DOC          = '0040000820'.
*  ORDER_ITEMS_IN1-REF_DOC_IT       = '000010'.
*  ORDER_ITEMS_IN1-REF_DOC_CA       = 'G'.
  APPEND ORDER_ITEMS_IN1.

CLEAR ORDER_SCHEDULES_IN1.
  ORDER_SCHEDULES_IN1-ITM_NUMBER   = '000010'.
  ORDER_SCHEDULES_IN1-SCHED_LINE   = '0001'.
  ORDER_SCHEDULES_IN1-REQ_QTY      = 1.
  APPEND ORDER_SCHEDULES_IN1.

CLEAR ORDER_PARTNERS1.
  ORDER_PARTNERS1-PARTN_ROLE         = 'AG'.
  ORDER_PARTNERS1-PARTN_NUMB         = '0400000135'.
  APPEND ORDER_PARTNERS1.

CLEAR ORDER_CONDITIONS_IN1.
  ORDER_CONDITIONS_IN1-ITM_NUMBER = '000010'.
  ORDER_CONDITIONS_IN1-COND_ST_NO = '010'.
  ORDER_CONDITIONS_IN1-COND_COUNT = '01'.
  ORDER_CONDITIONS_IN1-COND_TYPE = 'Z089'.
  ORDER_CONDITIONS_IN1-COND_VALUE = '90'.
  ORDER_CONDITIONS_IN1-CURRENCY = 'USD'.
  ORDER_CONDITIONS_IN1-CURR_ISO = 'BBL'.
  APPEND ORDER_CONDITIONS_IN1.

CLEAR: ORDER_CONDITIONS_INX .
  ORDER_CONDITIONS_INX-ITM_NUMBER = '000010'.
  ORDER_CONDITIONS_INX-COND_ST_NO = '010'.
  ORDER_CONDITIONS_INX-COND_COUNT = '01'.
  ORDER_CONDITIONS_INX-COND_TYPE = 'Z089'.
  ORDER_CONDITIONS_INX-UPDATEFLAG = 'U'.
  ORDER_CONDITIONS_INX-COND_VALUE = 'X'.
  ORDER_CONDITIONS_INX-CURRENCY = 'X'.
  APPEND ORDER_CONDITIONS_INX.

PERFORM CALL_FUNCTION.

*&---------------------------------------------------------------------*
*& Form call_function
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_FUNCTION .

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
*    SALESDOCUMENTIN               = P_NEW
    ORDER_HEADER_IN               = ORDER_HEADER_IN1
   ORDER_HEADER_INX               = ORDER_HEADER_INTX
*   SENDER                        =
*   BINARY_RELATIONSHIPTYPE       =
*   INT_NUMBER_ASSIGNMENT         =
*   BEHAVE_WHEN_ERROR             =
   LOGIC_SWITCH                   = LOGIC_SWITCH
*   TESTRUN                       =
*   CONVERT                       = ' '
  IMPORTING
    SALESDOCUMENT                 = SALESDOCUMENT1
  TABLES
    RETURN                        = RETURN1
    ORDER_ITEMS_IN                = ORDER_ITEMS_IN1
    ORDER_ITEMS_INX               = ORDER_ITEMS_IN1X
    ORDER_PARTNERS                = ORDER_PARTNERS1
    ORDER_SCHEDULES_IN            = ORDER_SCHEDULES_IN1
*   ORDER_SCHEDULES_INX           = ORDER_SCHEDULES_IN1X
   ORDER_CONDITIONS_IN            = ORDER_CONDITIONS_IN1
   ORDER_CONDITIONS_INX           = ORDER_CONDITIONS_INX
*   ORDER_CFGS_REF                =
*   ORDER_CFGS_INST               =
*   ORDER_CFGS_PART_OF            =
*   ORDER_CFGS_VALUE              =
*   ORDER_CFGS_BLOB               =
*   ORDER_CFGS_VK                 =
*   ORDER_CFGS_REFINST            =
*   ORDER_CCARD                   =
*   ORDER_TEXT                    =
*   ORDER_KEYS                    =
*   EXTENSIONIN                   =
*   PARTNERADDRESSES              =
            .

*

IF NOT SALESDOCUMENT1 IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = RETURN2.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.

ENDFORM.                    "call_function

BAPI_SALESORDER_CHANGE

*---------------------------------------------------------------------*
*销售订单价格修改
*---------------------------------------------------------------------*
DATA:  ZSALESDOCUMENT1        TYPE BAPIVBELN-VBELN.
DATA:  LOGIC_SWITCH           TYPE BAPISDLS.
DATA:  ORDER_HEADER_IN1       LIKE BAPISDH1.
DATA:  ORDER_HEADER_INTX      LIKE BAPISDH1X.
DATA:  ORDER_ITEMS_IN1        TYPE BAPISDITM  OCCURS 0 WITH HEADER LINE.
DATA:  ORDER_ITEMS_IN1X       TYPE BAPISDITMX OCCURS 0 WITH HEADER LINE.
DATA:  SCHEDULE_LINES         TYPE BAPISCHDL  OCCURS 0 WITH HEADER LINE.
DATA:  SCHEDULE_LINESX        TYPE BAPISCHDLX OCCURS 0 WITH HEADER LINE.
DATA:  RETURN1                TYPE BAPIRET2   OCCURS 0 WITH HEADER LINE.
DATA:  RETURN2                TYPE BAPIRET2   OCCURS 0 WITH HEADER LINE.
DATA:  CONDITIONS_IN          TYPE BAPICOND   OCCURS 0 WITH HEADER LINE.
DATA:  CONDITIONS_INX         TYPE BAPICONDX  OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

ZSALESDOCUMENT1 = '0000004013'.

ORDER_HEADER_INTX-UPDATEFLAG = 'U'.
  LOGIC_SWITCH-COND_HANDL = 'X'.

CONDITIONS_IN-ITM_NUMBER = '000010'.
  CONDITIONS_IN-COND_ST_NO = '010'.
  CONDITIONS_IN-COND_COUNT = '01'.
  CONDITIONS_IN-COND_TYPE = 'Z089'.
  CONDITIONS_IN-COND_VALUE = '90'.
  CONDITIONS_IN-CURRENCY = 'USD'.
  CONDITIONS_IN-CURR_ISO = 'BBL'.
  APPEND CONDITIONS_IN.

CONDITIONS_INX-ITM_NUMBER = '000010'.
  CONDITIONS_INX-COND_ST_NO = '010'.
  CONDITIONS_INX-COND_COUNT = '01'.
  CONDITIONS_INX-COND_TYPE = 'Z089'.
  CONDITIONS_INX-UPDATEFLAG = 'U'.
  CONDITIONS_INX-COND_VALUE = 'X'.
  CONDITIONS_INX-CURRENCY = 'X'.
  APPEND CONDITIONS_INX.

PERFORM CALL_FUNCTION.

*&---------------------------------------------------------------------*
*& Form call_function
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_FUNCTION .

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
      SALESDOCUMENT               = ZSALESDOCUMENT1
*                ORDER_HEADER_IN             =
      ORDER_HEADER_INX            = ORDER_HEADER_INTX
*                SIMULATION                  =
*                BEHAVE_WHEN_ERROR           = ' '
*                INT_NUMBER_ASSIGNMENT       = ' '
                LOGIC_SWITCH                = LOGIC_SWITCH
*                NO_STATUS_BUF_INIT          = ' '
    TABLES
      RETURN                      = RETURN1
*                ORDER_ITEM_IN               = ORDER_ITEMS_IN1
*                ORDER_ITEM_INX              = ORDER_ITEMS_IN1X
*                PARTNERS                    =
*                PARTNERCHANGES              =
*                PARTNERADDRESSES            =
*                ORDER_CFGS_REF              =
*                ORDER_CFGS_INST             =
*                ORDER_CFGS_PART_OF          =
*                ORDER_CFGS_VALUE            =
*                ORDER_CFGS_BLOB             =
*                ORDER_CFGS_VK               =
*                ORDER_CFGS_REFINST          =
*                SCHEDULE_LINES              = SCHEDULE_LINES
*                SCHEDULE_LINESX             = SCHEDULE_LINESX
*                ORDER_TEXT                  =
*                ORDER_KEYS                  =
                CONDITIONS_IN               = CONDITIONS_IN
                CONDITIONS_INX              = CONDITIONS_INX
*                EXTENSIONIN                 =
            .

IF SY-SUBRC = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = RETURN2.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.

ENDFORM.                    "call_function

BAPI_PO_CHANGE

*&---------------------------------------------------------------------*
*&      Form  ZMM_FR0003
*&---------------------------------------------------------------------*
*       保存PO时对非服务行项目将"交货已完成"标识设置为L
*       对服务行项目将"交货已完成"标识设置为S
*----------------------------------------------------------------------*
FORM ZMM_FR0003 .

DATA: ZMESSAGE TYPE STRING.
  DATA: PURCHASEORDER LIKE BAPIMEPOHEADER-PO_NUMBER.
  DATA: POHEADER LIKE BAPIMEPOHEADER OCCURS 0 WITH HEADER LINE.
  DATA: POHEADERX LIKE BAPIMEPOHEADERX OCCURS 0 WITH HEADER LINE.
  DATA: POITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE.
  DATA: POITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE.
  DATA: RETURN1 LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.

CLEAR: REC_MSG,TAB_MSG[].
  LOOP AT TAB_PO_CLOSE INTO REC_PO_CLOSE WHERE ZCHKBOX = 'X'.
    PURCHASEORDER = REC_PO_CLOSE-EBELN.
    POHEADER-PO_NUMBER = REC_PO_CLOSE-EBELN.
    APPEND POHEADER.
    POHEADERX-PO_NUMBER = 'X'.
    APPEND POHEADERX.
    POITEM-PO_ITEM = REC_PO_CLOSE-EBELP.
    IF REC_PO_CLOSE-PSTYP <> '9'.
      POITEM-NO_MORE_GR = 'X'.
    ELSE.
      POITEM-DELETE_IND = 'S'.
    ENDIF.
    APPEND POITEM.
    POITEMX-PO_ITEM = REC_PO_CLOSE-EBELP.
    POITEMX-PO_ITEMX = 'X'.
    IF REC_PO_CLOSE-PSTYP <> '9'.
      POITEMX-NO_MORE_GR = 'X'.
    ELSE.
      POITEMX-DELETE_IND = 'X'.
    ENDIF.
    APPEND POITEMX.
    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        PURCHASEORDER = PURCHASEORDER
        POHEADER      = POHEADER
        POHEADERX     = POHEADERX
      TABLES
        RETURN        = RETURN1
        POITEM        = POITEM
        POITEMX       = POITEMX.
    READ TABLE RETURN1 WITH KEY TYPE = 'E' TRANSPORTING NO FIELDS.
    IF SY-SUBRC <> 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          WAIT = 'X'.
    ENDIF.
    LOOP AT RETURN1.
      REC_MSG-TYP = RETURN1-TYPE.
      CONCATENATE '采购订单' REC_PO_CLOSE-EBELN '行项目' REC_PO_CLOSE-EBELP RETURN1-MESSAGE INTO REC_MSG-MESSAGE.
      APPEND REC_MSG TO TAB_MSG.
      CLEAR: REC_MSG,RETURN1.
    ENDLOOP.
  ENDLOOP.

SORT TAB_MSG BY TYP MESSAGE.
  DELETE ADJACENT DUPLICATES FROM TAB_MSG COMPARING TYP MESSAGE.

CALL SCREEN 100 STARTING AT 40 1
                  ENDING AT 140 20.

ENDFORM.                    " ZMM_FR0003

BAPI_REQUISITION_CREATE

DATA: LS_SELECTED_LINE LIKE LVC_S_ROW,
        LF_ROW_INDEX TYPE LVC_INDEX.
  DATA: NUM(5) TYPE N.
  DATA: ZMESSAGE TYPE STRING.
  DATA: H(20) TYPE C.
  DATA: TLINK TYPE TABLE OF TLINE.
  DATA: PRHEADER LIKE BAPIMEREQHEADER OCCURS 0 WITH HEADER LINE.
  DATA: PRHEADERX LIKE BAPIMEREQHEADERX OCCURS 0 WITH HEADER LINE.
  DATA: NUMBER LIKE BAPIMEREQHEADER-PREQ_NO.
  DATA: PRITEM LIKE BAPIMEREQITEMIMP OCCURS 0 WITH HEADER LINE.
  DATA: PRITEMX LIKE BAPIMEREQITEMX OCCURS 0 WITH HEADER LINE.
  DATA: PRHEADERTEXT LIKE BAPIMEREQHEADTEXT OCCURS 0 WITH HEADER LINE.
  DATA: RETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE.
  DATA: BAPIRET LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
  DATA: REQUISITION_ITEMS_TO_DELETE LIKE BAPIEBAND OCCURS 0 WITH HEADER LINE.
  DATA: ZRETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE.
  DATA: REQUISITION_ITEMS LIKE BAPIEBANC OCCURS 0 WITH HEADER LINE.

LOOP AT LT_ROWS INTO LS_SELECTED_LINE.
    LF_ROW_INDEX = LS_SELECTED_LINE-INDEX.
* read selected row from internal table tab_eban
    READ TABLE TAB_EBAN INDEX LF_ROW_INDEX INTO REC_EBAN.
* creating new purchase requisition
    CLEAR NUM.
    NUM = SY-TABIX * 10.
    REQUISITION_ITEMS-PREQ_ITEM = NUM.
    REQUISITION_ITEMS-DOC_TYPE = REC_EBAN-BSART.
    REQUISITION_ITEMS-PUR_GROUP = P_EBAN_EKGRP.
    REQUISITION_ITEMS-PREQ_NAME = REC_EBAN-BANFN.
    REQUISITION_ITEMS-MATERIAL = REC_EBAN-MATNR.
    REQUISITION_ITEMS-PLANT = REC_EBAN-WERKS.
    REQUISITION_ITEMS-STORE_LOC = REC_EBAN-LGORT.
    IF REC_EBAN-ZXGSL <> 0.
      REQUISITION_ITEMS-QUANTITY = REC_EBAN-ZXGSL.
    ELSE.
      REQUISITION_ITEMS-QUANTITY = REC_EBAN-MENGE.
    ENDIF.
    REQUISITION_ITEMS-DELIV_DATE = REC_EBAN-LFDAT.
    REQUISITION_ITEMS-C_AMT_BAPI = REC_EBAN-PREIS.
    APPEND REQUISITION_ITEMS.
    CLEAR: REQUISITION_ITEMS,REC_EBAN.
  ENDLOOP.

* call bapi for creating new purchase requisition
  CALL FUNCTION 'BAPI_REQUISITION_CREATE'
    IMPORTING
      NUMBER            = NUMBER
    TABLES
      REQUISITION_ITEMS = REQUISITION_ITEMS
      RETURN            = RETURN.

BAPI_REQUISITION_DELETE

LOOP AT LT_ROWS INTO LS_SELECTED_LINE.
        LF_ROW_INDEX = LS_SELECTED_LINE-INDEX.
* read selected row from internal table tab_eban
        READ TABLE TAB_EBAN INDEX LF_ROW_INDEX INTO REC_EBAN.
* deleting old purchase requisition
        REQUISITION_ITEMS_TO_DELETE-PREQ_ITEM = REC_EBAN-BNFPO.
        REQUISITION_ITEMS_TO_DELETE-DELETE_IND = 'X'.
        APPEND REQUISITION_ITEMS_TO_DELETE.
        CALL FUNCTION 'BAPI_REQUISITION_DELETE'
          EXPORTING
            NUMBER                      = REC_EBAN-BANFN
          TABLES
            REQUISITION_ITEMS_TO_DELETE = REQUISITION_ITEMS_TO_DELETE
            RETURN                      = ZRETURN.
        REFRESH BAPIRET.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT   = 'X'
          IMPORTING
            RETURN = BAPIRET.
        REC_EBAN-ZFLAG = 'X'.
        MODIFY TAB_EBAN FROM REC_EBAN INDEX LF_ROW_INDEX.
      ENDLOOP.

BAPI_PR_CHANGE

DATA: LS_SELECTED_LINE LIKE LVC_S_ROW,
        LF_ROW_INDEX TYPE LVC_INDEX.
  DATA: NUM(5) TYPE N.
  DATA: ZMESSAGE TYPE STRING.
  DATA: PRHEADER LIKE BAPIMEREQHEADER OCCURS 0 WITH HEADER LINE.
  DATA: PRHEADERX LIKE BAPIMEREQHEADERX OCCURS 0 WITH HEADER LINE.
  DATA: PRITEM LIKE BAPIMEREQITEMIMP OCCURS 0 WITH HEADER LINE.
  DATA: PRITEMX LIKE BAPIMEREQITEMX OCCURS 0 WITH HEADER LINE.
  DATA: PRITEMEXP LIKE BAPIMEREQITEM OCCURS 0 WITH HEADER LINE.
  DATA: PRACCOUNT LIKE BAPIMEREQACCOUNT OCCURS 0 WITH HEADER LINE.
  DATA: PRACCOUNTX LIKE BAPIMEREQACCOUNTX OCCURS 0 WITH HEADER LINE.
  DATA: RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
  DATA: BAPIRET LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
  DATA: REQUISITION_ITEMS_TO_DELETE LIKE BAPIEBAND OCCURS 0 WITH HEADER LINE.
  DATA: ZRETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE.
  DATA: REQUISITION_ITEMS LIKE BAPIEBAN OCCURS 0 WITH HEADER LINE.
  DATA: REQUISITION_ITEMS_OLD LIKE BAPIEBANV OCCURS 0 WITH HEADER LINE.
  DATA: REQUISITION_ITEMS_NEW LIKE BAPIEBANV OCCURS 0 WITH HEADER LINE.

LOOP AT LT_ROWS INTO LS_SELECTED_LINE.
      LF_ROW_INDEX = LS_SELECTED_LINE-INDEX.
* Read selected row from internal table tab_eban
      READ TABLE TAB_EBAN INDEX LF_ROW_INDEX INTO REC_EBAN.
      SELECT SINGLE *
       FROM MBEW
        WHERE MATNR = REC_EBAN-MATNR
          AND BWKEY = REC_EBAN-WERKS
          AND LBKUM = '0.000'
          AND VERPR = '0.00'.
      IF SY-SUBRC = 0.
* Call bdc for updating the material price
        PERFORM ZMM_FR0005.
      ELSE.
* Can't adding new line item when there is stock but no price
        SELECT SINGLE *
         FROM MBEW
          WHERE MATNR = REC_EBAN-MATNR
            AND BWKEY = REC_EBAN-WERKS
            AND LBKUM <> '0.000'
            AND VERPR = '0.00'.
        IF SY-SUBRC = 0.
          FLAG = 'F'.
          EXIT.
        ENDIF.
      ENDIF.
* Can't adding new line item when there is released item
      SELECT SINGLE *
       FROM EBAN
        WHERE BANFN = P_EBAN_BANFN
          AND FRGZU = 'X'.
      IF SY-SUBRC = 0.
        FLAG = 'G'.
        EXIT.
      ENDIF.
      NUM = NUM + 10.
      REC_NETVALUE-NUM = NUM.
      REC_NETVALUE-PREIS = REC_EBAN-PREIS.
      APPEND REC_NETVALUE TO TAB_NETVALUE.
      CLEAR REC_NETVALUE.
      PRITEM-PREQ_ITEM = NUM.
      PRITEM-PUR_GROUP = P_EBAN_EKGRP.
      PRITEM-PREQ_NAME = REC_EBAN-BANFN.
      PRITEM-MATERIAL = REC_EBAN-MATNR.
      PRITEM-PLANT = REC_EBAN-WERKS.
      PRITEM-STORE_LOC = REC_EBAN-LGORT.
      IF REC_EBAN-ZXGSL <> 0.
        PRITEM-QUANTITY = REC_EBAN-ZXGSL.
      ELSE.
        PRITEM-QUANTITY = REC_EBAN-MENGE.
      ENDIF.
      PRITEM-DELIV_DATE = REC_EBAN-LFDAT.
      PRITEM-PREQ_PRICE = REC_EBAN-PREIS.
      PRITEM-PRICE_UNIT = '1'.
      PRITEM-MRP_CTRLER = REC_EBAN-DISPO.
      APPEND PRITEM.
      CLEAR PRITEM.
      PRITEMX-PREQ_ITEM = NUM.
      PRITEMX-PREQ_ITEMX = 'X'.
      PRITEMX-PUR_GROUP = 'X'.
      PRITEMX-PREQ_NAME = 'X'.
      PRITEMX-MATERIAL = 'X'.
      PRITEMX-PLANT = 'X'.
      PRITEMX-STORE_LOC = 'X'.
      PRITEMX-QUANTITY = 'X'.
      PRITEMX-DELIV_DATE = 'X'.
      PRITEMX-PREQ_PRICE = 'X'.
      PRITEMX-PRICE_UNIT = 'X'.
      PRITEMX-MRP_CTRLER = 'X'.
      APPEND PRITEMX.
      CLEAR PRITEMX.
    ENDLOOP.

CALL FUNCTION 'BAPI_PR_CHANGE'
        EXPORTING
          NUMBER  = P_EBAN_BANFN
        TABLES
          RETURN  = RETURN
          PRITEM  = PRITEM
          PRITEMX = PRITEMX.

BAPI_REQUISITION_GETDETAIL

CALL FUNCTION 'BAPI_REQUISITION_GETDETAIL'
          EXPORTING
            NUMBER            = P_EBAN_BANFN
          TABLES
            REQUISITION_ITEMS = REQUISITION_ITEMS.

BAPI_REQUISITION_CHANGE

LOOP AT REQUISITION_ITEMS.
          MOVE-CORRESPONDING REQUISITION_ITEMS TO REQUISITION_ITEMS_OLD.
          APPEND REQUISITION_ITEMS_OLD.
          MOVE-CORRESPONDING REQUISITION_ITEMS TO REQUISITION_ITEMS_NEW.
          APPEND REQUISITION_ITEMS_NEW.
          CLEAR: REQUISITION_ITEMS,REQUISITION_ITEMS_OLD,REQUISITION_ITEMS_NEW.
        ENDLOOP.

* Change the evaluating price and Replace purchase group
        LOOP AT REQUISITION_ITEMS_NEW.
          READ TABLE TAB_NETVALUE INTO REC_NETVALUE WITH KEY NUM = REQUISITION_ITEMS_NEW-PREQ_ITEM.
          IF SY-SUBRC = 0.
            REQUISITION_ITEMS_NEW-C_AMT_BAPI = REC_NETVALUE-PREIS.
          ENDIF.
          REQUISITION_ITEMS_NEW-PUR_GROUP = P_EBAN_EKGRP.
          MODIFY REQUISITION_ITEMS_NEW.
          CLEAR: REC_NETVALUE,REQUISITION_ITEMS_NEW.
        ENDLOOP.

* Change Purchase Requisition
        CALL FUNCTION 'BAPI_REQUISITION_CHANGE'
          EXPORTING
            NUMBER                = P_EBAN_BANFN
          TABLES
            REQUISITION_ITEMS_OLD = REQUISITION_ITEMS_OLD
            REQUISITION_ITEMS_NEW = REQUISITION_ITEMS_NEW.

*&20150122

订单
BAPI_SALESORDER_CREATEFROMDAT2创建销售订单
BAPISDORDER_GETDETAILEDLIST销售订单明细
BAPI_SALESORDER_GETLIST销售订单列表
BAPI_SALESORDER_CHANGE修改销售订单
交货单
BAPI_OUTB_DELIVERY_READ_SLS根据销售订单创建交货单,得到交货单创建初始页面所需的数据
BAPI_OUTB_DELIVERY_GETDETAIL根据交货单号读取单据的详细内容
BAPI_OUTB_DELIVERY_CREATE_SLS根据销售订单创建交货单
BAPI_OUTB_DELIVERY_CHANGE根据交货单号修改、删除单据的详细内容
采购订单
BAPI_PO_CREATEREF_PR根据采购申请创建采购订单,得到采购订单创建初始页面所需的数据
BAPI_READ_GOODS_RECEIPT根据采购订单创建收货,得到货物接收初始页面所需的数据
BAPI_PO_RELEASE审批采购订单
BAPI_PO_RESET_RELEASE取消审批采购订单
BAPI_PO_CHANGE修改采购订单
BAPI_PO_CREATE1创建采购订单
BAPI_PO_GETDETAIL1采购订单明细
BAPI_PO_GET_LIST采购订单列表
BAPI_PO_GETITEMS采购订单明细列表
报价单
BAPI_QUOTATION_GETDETAILBOS报价单明细
BAPI_CUSTOMERQUOTATION_CHANGE修改销售订单
BAPI_QUOTATION_CREATEFROMDATA2创建报价单

功能描述                事务码  BAPI函数名称 

检验批    
 修改建议批              QA02  暂未找到
 查看检验批明细      QA03  BAPI_INSPLOT_GETDETAIL
 
检验结果    
 记录检验点结果            QE11 BAPI_INSPPOINT_CREATEFROMDATA
 修改检验点结果            QE12 BAPI_INSPPOINT_CHANGE
 显示检验点结果明细     QE13 BAPI_INSPPOINT_GETREQUIREMENTS
    
缺陷检验    
 记录缺陷 QF01   QFFE_FAILURE_RECORDING 
 修改缺陷 QF02   暂未找到 
 显示缺陷 QF03   暂未找到 
    
使用决策    
 记录使用决策 QA11  BAPI_INSPLOT_SETUSAGEDECISION 
 修改使用决策 QA12  暂未找到 
 显示使用决策 QA13  暂未找到 
    
质量结果通知单    
 创建质量通知单           QM01 BAPI_QNOTIFICAT_CREATE
 修改质量通知单           QM02 BAPI_QUALNOT_MODIFY_DATA
 显示质量通知单明细    QM03 BAPI_QUALNOT_GETDETAIL

检验批清单    
       检验批清单列表        QA32    BAPI_INSPLOT_GETLIST 选择检验批

04-28 00:20