首页 > 其他分享 >DEMO:ME31L 创建计划协议 BAPI_SAG_CREATE

DEMO:ME31L 创建计划协议 BAPI_SAG_CREATE

时间:2022-10-14 20:40:09浏览次数:56  
标签:BAPI ME31L DEFAULT DEMO ITEM LT LS SA TYPE

前台:ME31L

DEMO:ME31L 创建计划协议 BAPI_SAG_CREATE_sed

DEMO:ME31L 创建计划协议 BAPI_SAG_CREATE_sed_02

DEMO:ME31L 创建计划协议 BAPI_SAG_CREATE_sed_03



程序执行:

DEMO:ME31L 创建计划协议 BAPI_SAG_CREATE_sed_04

*&---------------------------------------------------------------------*
*& 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.

标签:BAPI,ME31L,DEFAULT,DEMO,ITEM,LT,LS,SA,TYPE
From: https://blog.51cto.com/u_15680210/5757896

相关文章

  • ALV demo 05:cl_salv_table event
    效果图:定义的statuscode:*&---------------------------------------------------------------------**&ReportZLM_ALV005*&*&-----------------------------------------......
  • ALV demo 04:cl_salv_table (ICONs and Tooltips)
    QQ群:SAP干货铺, 群号:775662808干货:​效果图:code:*&---------------------------------------------------------------------**&ReportZLM_ALV003*&*&sapliumeng*&----......
  • ALV demo 05:cl_salv_table(Apply Styles to Cell)
    QQ群:SAP干货铺, 群号:775662808所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!效果:carrid列的第二行设置为热键,CONNID第三行设置为buttoncode:*&---------......
  • DEMO: BAPI_SALESORDER_CREATEFROMDAT2 创建订单
    REPORTzdemo_va01.PARAMETERSp_kunnrTYPEkunnrDEFAULT'1004615'.PARAMETERSp_vkorgTYPEvkorgDEFAULT'S600'.PARAMETERSp_vtwegTYPEvtwegDEFAULT'10'.PARAM......
  • DEMO: ALV显示明细
    本来需求是ALV双击某个字段的时候,弹出一个新ALV显示对应的明细,但是明细字段太多了,弹出来以后也挺难看的。就想起来SE11进去,查看数据点明细的时候于是就debug了下这个按钮大......
  • BAPI_ACC_DOCUMENT_POST更新BSED数据增强
    FB03查看凭证对于特殊总账类型为W的,双击进入可见出票人出票行票据号等信息这些数据是保存在bsed表的。而BAPI_ACC_DOCUMENT_POST 并没有提供这些字段。所以需要走增强。......
  • Demo:选择屏幕写页签
    效果图:demo代码需要特别注意的是abapmemory的应用文本版:*&---------------------------------------------------------------------**&ReportZLM_SCREEN3*&------------......
  • DEMO:冲销交货单过账凭证WS_REVERSE_GOODS_ISSUE
    reportzdemo_vl09.parametersp_vbelntypevbeln_vl.data:lt_likptypetableoflikp.data:ls_likplikelineoflt_likp.data:lt_mesg......
  • DEMO:MB1B 311 移库 BAPI_GOODSMVT_CREATE
    *&---------------------------------------------------------------------**&ReportZDEMO_MB1B*&*&---------------------------------------------------------------......
  • WDA DEMO 11 根据BAPI/Function创建WDA
    货铺QQ群号:834508274进群统一修改群名片,例如BJ_ABAP_森林木。群内禁止发广告及其他一切无关链接,小程序等,进群看公告,谢谢配合不修改昵称会被不定期踢除,谢谢配合事先声明下,本......