前台:ME31L
程序执行:
*&---------------------------------------------------------------------*标签:BAPI,ME31L,DEFAULT,DEMO,ITEM,LT,LS,SA,TYPE From: https://blog.51cto.com/u_15680210/5757896
*& Report ZLM_ME31L
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZLM_ME32L_SA.
PARAMETERS:
P_BUKRS TYPE BUKRS DEFAULT '',
P_BSART TYPE BSART DEFAULT '', "计划协议
P_LIFNR TYPE LIFNR DEFAULT '',
P_LLIEF TYPE LLIEF DEFAULT '', "供应商
P_EKORG TYPE EKORG DEFAULT '', "采购组织
P_EKGRP TYPE EKGRP DEFAULT '', "采购组
P_KDATB TYPE KDATB DEFAULT '20190920', "Validation START
P_KDATE TYPE KDATE DEFAULT '20190930', "Validation end
P_ZTERM TYPE DZTERM DEFAULT '',
P_RS TYPE LIFN2 DEFAULT '', "发票方
P_WL TYPE LIFN2 DEFAULT '', "商品供应商
P_EXLIN TYPE EXLIN DEFAULT '',
P_MATNR TYPE MATNR DEFAULT '',
P_MEINS TYPE MEINS DEFAULT '',
P_WERKS TYPE WERKS_D DEFAULT '',
P_SCHPR TYPE SCHPR DEFAULT '',
P_MWSKZ TYPE MWSKZ DEFAULT 'J1'.
********for BAPI...
DATA: LS_SA_HEAD TYPE BAPIMEOUTHEADER, " SA header
LS_SA_HEADX TYPE BAPIMEOUTHEADERX,
LS_SA_ITEM TYPE BAPIMEOUTITEM,
LS_SA_ITEMX TYPE BAPIMEOUTITEMX,
LS_SA_ACCOUNT TYPE BAPIMEOUTACCOUNT,
LS_SA_ACCOUNTX TYPE BAPIMEOUTACCOUNTX,
LS_SA_CONDITION TYPE BAPIMEOUTCONDITION,
LS_SA_CONDITIONX TYPE BAPIMEOUTCONDITIONX,
LS_SA_VALID TYPE BAPIMEOUTVALIDITY,
LS_SA_VALIDX TYPE BAPIMEOUTVALIDITYX,
LS_SA_PARTNER TYPE BAPIMEOUTPARTNER,
LS_SA_PARTNERX TYPE BAPIMEOUTPARTNERX,
LS_DLV_ADDRESS TYPE BAPIMEOUTADDRDELIVERY,
LS_EXTENTION TYPE BAPIPAREX.
**** Local Internal Table definition ...
DATA: LT_SAITEM TYPE STANDARD TABLE OF BAPIMEOUTITEM,
LT_SAITEMX TYPE STANDARD TABLE OF BAPIMEOUTITEMX,
LT_SAACCOUNT TYPE STANDARD TABLE OF BAPIMEOUTACCOUNT,
LT_SAACCOUNTX TYPE STANDARD TABLE OF BAPIMEOUTACCOUNTX,
LT_SACONDITION TYPE STANDARD TABLE OF BAPIMEOUTCONDITION,
LT_SACONDITIONX TYPE STANDARD TABLE OF BAPIMEOUTCONDITIONX,
LT_SAVALID TYPE STANDARD TABLE OF BAPIMEOUTVALIDITY,
LT_SAVALIDX TYPE STANDARD TABLE OF BAPIMEOUTVALIDITYX,
LT_SAPARTNER TYPE STANDARD TABLE OF BAPIMEOUTPARTNER,
LT_SAPARTNERX TYPE STANDARD TABLE OF BAPIMEOUTPARTNERX,
LT_SARETURN TYPE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE,
LT_DLV_ADDRESS TYPE STANDARD TABLE OF BAPIMEOUTADDRDELIVERY,
LT_L_EXTENTION TYPE STANDARD TABLE OF BAPIPAREX.
DATA:LV_SA_EBELN TYPE BAPIMEOUTHEADER-NUMBER.
START-OF-SELECTION.
LS_SA_HEAD-DOC_TYPE = P_BSART. "document type
LS_SA_HEADX-DOC_TYPE = 'X'.
LS_SA_HEAD-VENDOR = P_LIFNR. "vendor
LS_SA_HEADX-VENDOR = 'X'.
IF NOT P_LLIEF IS INITIAL.
LS_SA_HEAD-SUPPL_VEND = P_LLIEF. "vendor
LS_SA_HEADX-SUPPL_VEND = 'X'.
ENDIF.
LS_SA_HEAD-COMP_CODE = P_BUKRS. " company code
LS_SA_HEADX-COMP_CODE = 'X'.
LS_SA_HEAD-DOC_DATE = SY-DATUM. " Document date
LS_SA_HEADX-DOC_DATE = 'X'.
LS_SA_HEAD-PURCH_ORG = P_EKORG. " Puchase org.
LS_SA_HEADX-PURCH_ORG = 'X'.
LS_SA_HEAD-PUR_GROUP = P_EKGRP. "puchase group
LS_SA_HEADX-PUR_GROUP = 'X'.
LS_SA_HEAD-CURRENCY = 'CNY'. "currency
LS_SA_HEADX-CURRENCY = 'X'.
LS_SA_HEAD-VPER_START = P_KDATB. "Validation START
LS_SA_HEADX-VPER_START = 'X'.
LS_SA_HEAD-VPER_END = P_KDATE. " Validation end
LS_SA_HEADX-VPER_END = 'X'.
LS_SA_HEAD-PMNTTRMS = P_ZTERM. " payment term
LS_SA_HEADX-PMNTTRMS = 'X'.
* ls_sa_head-INCOTERMS1 = P_INCO1. "INT. TRADE TERM 1
* ls_sa_headX-INCOTERMS1 = 'X'.
IF NOT P_RS IS INITIAL.
LS_SA_PARTNER-PARTN_ROLE = 'RS'.
LS_SA_PARTNER-PARTNR = P_RS. "partner 1 for RS.
LS_SA_PARTNERX-PARTN_ROLE = 'RS'.
LS_SA_PARTNERX-PARTNR = 'X'. "partner 1 for RS..
APPEND LS_SA_PARTNER TO LT_SAPARTNER.
APPEND LS_SA_PARTNERX TO LT_SAPARTNERX.
CLEAR:LS_SA_PARTNER,LS_SA_PARTNER .
ENDIF.
IF NOT P_WL IS INITIAL.
LS_SA_PARTNER-PARTN_ROLE = 'WL'. "partner 2 for WL.
LS_SA_PARTNER-PARTNR = P_WL. "商品供应商
LS_SA_PARTNERX-PARTN_ROLE = 'WL'.
LS_SA_PARTNERX-PARTNR = 'X'.
APPEND LS_SA_PARTNER TO LT_SAPARTNER.
APPEND LS_SA_PARTNERX TO LT_SAPARTNERX.
CLEAR:LS_SA_PARTNER,LS_SA_PARTNER.
ENDIF.
LS_SA_ITEM-ITEM_NO = 10.
LS_SA_ITEMX-ITEM_NO = 10.
LS_SA_ITEMX-ITEM_NOX = 'X'.
LS_SA_ITEM-PLANT = P_WERKS.
LS_SA_ITEMX-PLANT = 'X'.
LS_SA_ITEM-EST_PRICE = P_SCHPR.
LS_SA_ITEMX-EST_PRICE = 'X'.
LS_SA_ITEM-TAX_CODE = P_MWSKZ.
LS_SA_ITEMX-TAX_CODE = 'X'.
IF P_EXLIN IS NOT INITIAL.
LS_SA_ITEM-VEND_MAT = P_EXLIN.
LS_SA_ITEMX-VEND_MAT = 'X'.
ENDIF.
LS_SA_ITEM-MATERIAL = P_MATNR.
LS_SA_ITEMX-MATERIAL = 'X'.
LS_SA_ITEM-TARGET_QTY = 10.
LS_SA_ITEMX-TARGET_QTY = 'X'.
LS_SA_ITEM-PO_UNIT = P_MEINS.
LS_SA_ITEMX-PO_UNIT = 'X'.
LS_SA_ITEM-NET_PRICE = 100.
LS_SA_ITEMX-NET_PRICE = 'X'.
LS_SA_ITEM-PRICE_UNIT = 1.
LS_SA_ITEMX-PRICE_UNIT = 'X'.
""SA fixed value......
LS_SA_ITEM-GR_BASEDIV = 'X'.
LS_SA_ITEMX-GR_BASEDIV = 'X'.
LS_SA_ITEM-INFO_UPD = 'B'.
LS_SA_ITEMX-INFO_UPD = 'X'.
LS_SA_VALID-ITEM_NO = 10.
LS_SA_VALID-SERIAL_ID = 1.
LS_SA_VALIDX-ITEM_NO = 10.
LS_SA_VALIDX-SERIAL_ID = 1.
LS_SA_VALIDX-ITEM_NOX = 'X'.
LS_SA_VALIDX-SERIAL_IDX = 'X'.
LS_SA_VALID-VALID_FROM = P_KDATB.
LS_SA_VALIDX-VALID_FROM = 'X'.
LS_SA_VALID-VALID_TO = P_KDATE.
LS_SA_VALIDX-VALID_TO = 'X'.
APPEND LS_SA_VALID TO LT_SAVALID.
APPEND LS_SA_VALIDX TO LT_SAVALIDX.
CLEAR :LS_SA_VALID,LS_SA_VALIDX.
* ****** Conditions in Agreement
LS_SA_CONDITION-ITEM_NO = 10.
LS_SA_CONDITIONX-ITEM_NO = 10.
LS_SA_CONDITIONX-ITEM_NOX = 'X'.
LS_SA_CONDITION-SERIAL_ID = 1.
LS_SA_CONDITIONX-SERIAL_ID = 1.
LS_SA_CONDITIONX-SERIAL_IDX = 'X'.
LS_SA_CONDITION-COND_COUNT = 1.
LS_SA_CONDITIONX-COND_COUNT = 1.
LS_SA_CONDITIONX-COND_COUNTX = 'X'.
LS_SA_CONDITION-COND_TYPE = 'PB00'.
LS_SA_CONDITIONX-COND_TYPE = 'X'.
LS_SA_CONDITION-COND_VALUE = 100.
LS_SA_CONDITIONX-COND_VALUE = 'X'.
LS_SA_CONDITION-CURRENCY = 'CNY'.
LS_SA_CONDITIONX-CURRENCY = 'X'.
LS_SA_CONDITION-COND_UNIT = P_MEINS.
LS_SA_CONDITIONX-COND_UNIT = 'X'.
LS_SA_CONDITION-CHANGE_ID = 'I'.
APPEND LS_SA_CONDITION TO LT_SACONDITION.
APPEND LS_SA_CONDITIONX TO LT_SACONDITIONX.
CLEAR:LS_SA_CONDITION, LS_SA_CONDITIONX.
LS_SA_CONDITION-COND_VALUE = 100.
LS_SA_CONDITION-COND_TYPE = 'ZYS1'.
APPEND LS_SA_CONDITION TO LT_SACONDITION.
APPEND LS_SA_CONDITIONX TO LT_SACONDITIONX.
APPEND LS_SA_ITEM TO LT_SAITEM.
APPEND LS_SA_ITEMX TO LT_SAITEMX.
APPEND LS_SA_ACCOUNT TO LT_SAACCOUNT.
APPEND LS_SA_ACCOUNTX TO LT_SAACCOUNTX.
CALL FUNCTION 'BAPI_SAG_CREATE'
EXPORTING
HEADER = LS_SA_HEAD
HEADERX = LS_SA_HEADX
* TESTRUN = IM_TEST
IMPORTING
PURCHASINGDOCUMENT = LV_SA_EBELN
TABLES
RETURN = LT_SARETURN
ITEM = LT_SAITEM
ITEMX = LT_SAITEMX
ACCOUNT = LT_SAACCOUNT
ACCOUNTX = LT_SAACCOUNTX
ITEM_COND_VALIDITY = LT_SAVALID
ITEM_COND_VALIDITYX = LT_SAVALIDX
ITEM_CONDITION = LT_SACONDITION
ITEM_CONDITIONX = LT_SACONDITIONX
PARTNER = LT_SAPARTNER
PARTNERX = LT_SAPARTNERX
EXTENSIONIN = LT_L_EXTENTION
EXCEPTIONS
ERROR_MESSAGE = 1.
IF LV_SA_EBELN IS NOT INITIAL.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
WRITE LV_SA_EBELN.