首页 > 其他分享 >VL01N/VL02N/VL09 BAPI

VL01N/VL02N/VL09 BAPI

时间:2024-08-13 17:07:38浏览次数:10  
标签:BAPI DATA VALUE lt VL09 OPTIONAL VL01N items TYPE

1.VL01N

FUNCTION zfmsd_create_dn.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(SHIP_POINT) TYPE  BAPIDLVCREATEHEADER-SHIP_POINT OPTIONAL
*"     VALUE(DUE_DATE) TYPE  BAPIDLVCREATEHEADER-DUE_DATE OPTIONAL
*"     VALUE(IT_PARTNER_UPDATE) TYPE  SHP_PARTNER_UPDATE_T OPTIONAL
*"     VALUE(IS_ZLIKP) TYPE  ZSSD_ZLIKP OPTIONAL
*"     VALUE(IV_WADAT) TYPE  WADAT OPTIONAL
*"  EXPORTING
*"     VALUE(DELIVERY) TYPE  BAPISHPDELIVNUMB-DELIV_NUMB
*"     VALUE(NUM_DELIVERIES) TYPE  BAPIDLVCREATEHEADER-NUM_DELIVERIES
*"  TABLES
*"      SALES_ORDER_ITEMS STRUCTURE  BAPIDLVREFTOSALESORDER
*"      SERIAL_NUMBERS STRUCTURE  BAPIDLVSERIALNUMBER OPTIONAL
*"      EXTENSION_IN STRUCTURE  BAPIPAREX OPTIONAL
*"      DELIVERIES STRUCTURE  BAPISHPDELIVNUMB OPTIONAL
*"      CREATED_ITEMS STRUCTURE  BAPIDLVITEMCREATED OPTIONAL
*"      EXTENSION_OUT STRUCTURE  BAPIPAREX OPTIONAL
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      IT_BAPIADDR1 STRUCTURE  BAPIADDR1 OPTIONAL
*"      VBPOK_TAB STRUCTURE  VBPOK OPTIONAL
*"      IT_TEXTL STRUCTURE  TEXTL_GN
*"      IT_VBPOK STRUCTURE  VBPOK
*"----------------------------------------------------------------------
  DATA:vbkok_wa  TYPE vbkok,
       ls_zlikp  TYPE zlikp,
       prot      TYPE STANDARD TABLE OF prott,
       lt_items  TYPE TABLE OF bapidlvitemcreated,
       lt_items2 TYPE TABLE OF bapidlvreftosalesorder.
  DATA:lv_create(1),
       lv_create2(1).

  due_date = '99991231'.
  IF sales_order_items[] IS NOT INITIAL.
    SELECT * FROM vbap
      INTO TABLE @DATA(lt_vbap)
      FOR ALL ENTRIES IN @sales_order_items
      WHERE vbeln = @sales_order_items-ref_doc
        AND posnr = @sales_order_items-ref_item.
*    SELECT * FROM vbep
*      INTO TABLE @DATA(lt_vbep)
*      FOR ALL ENTRIES IN @sales_order_items
*      WHERE vbeln = @sales_order_items-ref_doc
*        AND posnr = @sales_order_items-ref_item..

    lt_items2 = sales_order_items[].
    WITH +i AS ( SELECT DISTINCT ref_doc,ref_item
                   FROM @lt_items2 AS k )
  SELECT i~ref_doc,i~ref_item,SUM( a~ordqty_bu ) AS ordqty_bu
    FROM +i AS i
    LEFT JOIN vbep AS a
      ON i~ref_doc EQ a~vbeln
     AND i~ref_item EQ a~posnr
   GROUP BY ref_doc,ref_item
    INTO TABLE @DATA(lt_vbep).
    IF lt_vbap[] IS NOT INITIAL.
      SELECT matnr, werks,disgr  FROM marc
        INTO TABLE @DATA(lt_marc)
        FOR ALL ENTRIES IN @lt_vbap
        WHERE matnr = @lt_vbap-matnr
          AND werks = @lt_vbap-werks.
      SELECT * FROM mard
        INTO TABLE @DATA(lt_mard)
        FOR ALL ENTRIES IN @lt_vbap
       WHERE matnr = @lt_vbap-matnr
         AND werks = @lt_vbap-werks
         AND lgort = @lt_vbap-lgort.
      SELECT * FROM mska
      INTO TABLE @DATA(lt_mska)
      FOR ALL ENTRIES IN @lt_vbap
     WHERE matnr = @lt_vbap-matnr
       AND werks = @lt_vbap-werks
       AND lgort = @lt_vbap-lgort
       AND vbeln = @lt_vbap-vbeln
       AND posnr = @lt_vbap-posnr.
    ENDIF.
  ENDIF.
  IF vbpok_tab[] IS NOT INITIAL.

  ENDIF.
  SORT lt_vbap BY vbeln posnr.
  SORT lt_vbep BY ref_doc ref_item.
  SORT lt_marc BY matnr werks.
  SORT lt_mard BY matnr werks lgort.
  SORT lt_mska BY matnr werks lgort vbeln posnr.
  LOOP AT sales_order_items.
    READ TABLE lt_vbap INTO DATA(ls_vbap) WITH KEY vbeln = sales_order_items-ref_doc
                                                   posnr = sales_order_items-ref_item
                                                   BINARY SEARCH.
    IF sy-subrc <> 0.
      return-type = 'E'.
      return-message = |{ '销售订单:' }{ sales_order_items-ref_doc }{ '行项目:' }{ sales_order_items-ref_item }{ '不存在!' }|.
      APPEND return.
    ENDIF.
*    READ TABLE lt_vbep INTO DATA(ls_vbep) WITH  KEY vbeln = sales_order_items-ref_doc
*                                                    posnr = sales_order_items-ref_item
*                                                    BINARY SEARCH.
*    IF sy-subrc = 0.
*
*      IF ls_vbep-edatu > due_date.
*        return-type = 'E'.
*        return-message = |{ '创建日期:' }{ due_date }{ '小于计划交货日期' }{ ls_vbep-edatu }|.
*        APPEND return.
*      ENDIF.
*      IF ls_vbep-ordqty_bu < sales_order_items-dlv_qty.
*        return-type = 'E'.
*        return-message = |{ '行' }{ sales_order_items-ref_item }{ '剩余可交货数量:' }{ ls_vbep-ordqty_bu }{ '不满足交货数量' }{ sales_order_items-dlv_qty }|.
*        APPEND return.
*      ENDIF.
*    ENDIF.
    READ TABLE lt_vbep INTO DATA(ls_vbep) WITH  KEY ref_doc = sales_order_items-ref_doc
                                                    ref_item = sales_order_items-ref_item
                                                    BINARY SEARCH.
    IF ls_vbep-ordqty_bu < sales_order_items-dlv_qty.
      return-type = 'E'.
      return-message = |{ '行' }{ sales_order_items-ref_item }{ '剩余可交货数量:' }{ ls_vbep-ordqty_bu }{ '不满足交货数量' }{ sales_order_items-dlv_qty }|.
      APPEND return.
    ENDIF.

  ENDLOOP.
  SORT return BY type message.
  DELETE ADJACENT DUPLICATES FROM return COMPARING ALL FIELDS.
  CHECK return IS INITIAL.

  lv_create = 'X'.
  EXPORT lv_create = lv_create TO MEMORY ID 'ZFMSD_CREATE_DN'."MV50AFZ1


  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
    EXPORTING
      ship_point        = ship_point
      due_date          = due_date
    IMPORTING
      delivery          = delivery
    TABLES
      sales_order_items = sales_order_items
*     SERIAL_NUMBERS    =
      extension_in      = extension_in
*     DELIVERIES        =
      created_items     = lt_items
*     EXTENSION_OUT     =
      return            = return.
ENDFUNCTION.

2.VL02N

交货单日期字段更改

 交货单更新:

  DATA:LV_ERROR TYPE C,
       LS_ZLIKP TYPE ZLIKP.

  "修改交货单标准字段
  IF DELIVERY IS NOT INITIAL.
    CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
      EXPORTING
        HEADER_DATA             = HEADER_DATA
        HEADER_CONTROL          = HEADER_CONTROL
        DELIVERY                = DELIVERY
        TECHN_CONTROL           = TECHN_CONTROL
        HEADER_DATA_SPL         = HEADER_DATA_SPL
        HEADER_CONTROL_SPL      = HEADER_CONTROL_SPL
        SENDER_SYSTEM           = SENDER_SYSTEM
      TABLES
        HEADER_PARTNER          = HEADER_PARTNER
        HEADER_PARTNER_ADDR     = HEADER_PARTNER_ADDR
        HEADER_DEADLINES        = HEADER_DEADLINES
        ITEM_DATA               = ITEM_DATA
        ITEM_CONTROL            = ITEM_CONTROL
        ITEM_SERIAL_NO          = ITEM_SERIAL_NO
        SUPPLIER_CONS_DATA      = SUPPLIER_CONS_DATA
        EXTENSION1              = EXTENSION1
        EXTENSION2              = EXTENSION2
        RETURN                  = RETURN
        TOKENREFERENCE          = TOKENREFERENCE
        ITEM_DATA_SPL           = ITEM_DATA_SPL
        COLLECTIVE_CHANGE_ITEMS = COLLECTIVE_CHANGE_ITEMS
        NEW_ITEM_DATA           = NEW_ITEM_DATA
        NEW_ITEM_DATA_SPL       = NEW_ITEM_DATA_SPL
        NEW_ITEM_ORG            = NEW_ITEM_ORG
        ITEM_DATA_DOCU_BATCH    = ITEM_DATA_DOCU_BATCH
        CWM_ITEM_DATA           = CWM_ITEM_DATA.
  ENDIF.

  CLEAR LV_ERROR.
  LOOP AT RETURN INTO DATA(LS_RETURN) WHERE TYPE CA 'AEX'.
    LV_ERROR = 'X'.
    EXIT.
  ENDLOOP.


  IF IS_ZLIKP IS NOT INITIAL.
    IF IS_ZLIKP-VBELN IS INITIAL.
      CLEAR LS_RETURN.
      LS_RETURN-TYPE       = 'E'.
      LS_RETURN-ID         = 'V1'.
      LS_RETURN-NUMBER     = '899'.
      LS_RETURN-MESSAGE    = '交货抬头增强字段无交货单号'.
      APPEND LS_RETURN TO RETURN.
      LV_ERROR = 'X'.
    ENDIF.
  ENDIF.

  IF LV_ERROR IS INITIAL.
    IF IS_ZLIKP IS NOT INITIAL.
      CLEAR LS_ZLIKP.
      MOVE-CORRESPONDING IS_ZLIKP TO LS_ZLIKP.
      MODIFY ZLIKP FROM LS_ZLIKP.
    ENDIF.
  ENDIF.
    "交货日期字段更新
        DATA:ls_header         TYPE bapiobdlvhdrchg,
             ls_header_control TYPE bapiobdlvhdrctrlchg,
             lv_dn             TYPE bapiobdlvhdrchg-deliv_numb,
             ls_time           TYPE bapidlvdeadln,
             lt_time           TYPE TABLE OF bapidlvdeadln,
             lt_return_2       TYPE TABLE OF bapiret2.

        ls_header-deliv_numb = delivery.
        ls_header_control-deliv_numb = delivery.
        lv_dn = delivery.

        ls_time-deliv_numb = delivery.
        ls_time-timetype = 'WSHDRWADAT'.
        ls_time-timestamp_utc = iv_wadat && '000000'.
        APPEND ls_time TO lt_time.

        CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
          EXPORTING
            header_data      = ls_header
            header_control   = ls_header_control
            delivery         = lv_dn
          TABLES
            header_deadlines = lt_time
            return           = lt_return_2.

交货单过账:

 L_HEADER_DATA-DELIV_NUMB         = PV_VBELD.
  L_HEADER_CONTROL-DELIV_NUMB  = PV_VBELD.
  L_HEADER_CONTROL-POST_GI_FLG   = 'X'.
  L_HEADER_CONTROL-VOLUME_FLG  = 'X'.

 "外向交货单发货过账
  CALL FUNCTION ' BAPI_OUTB_DELIVERY_CONFIRM_DEC '
    EXPORTING
       HEADER_DATA             = L_HEADER_DATA
       HEADER_CONTROL       = L_HEADER_CONTROL
       DELIVERY                       = PV_VBELD
    TABLES
*     iT_HEADER_PARTNER      =
*     iT_HEADER_PARTNER_ADDR =
*     iT_HEADER_DEADLINES    =
*     iT_ITEM_DATA           =
*     iT_ITEM_CONTROL        =
*     iT_ITEM_CODING_BLOCK   =
       RETURN              = LT_RETURN_BAPI.

交货单过账冲销:

FUNCTION ZFM_SD_REVERSE_GOODS_ISSUE .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_VBELN) LIKE  LIKP-VBELN
*"     VALUE(I_BUDAT) LIKE  SY-DATLO
*"     VALUE(I_COUNT) LIKE  SY-MSGNO OPTIONAL
*"     VALUE(I_MBLNR) LIKE  MKPF-MBLNR OPTIONAL
*"     VALUE(I_TCODE) LIKE  SY-TCODE OPTIONAL
*"     VALUE(I_VBTYP) LIKE  LIKP-VBTYP OPTIONAL
*"     VALUE(I_MBLPO) LIKE  MSEG-ZEILE OPTIONAL
*"     VALUE(I_MJAHR) LIKE  MSEG-MJAHR OPTIONAL
*"     VALUE(I_POSNR) LIKE  LIPS-POSNR OPTIONAL
*"     VALUE(I_SIMULATE) TYPE  CHAR1 DEFAULT SPACE
*"     VALUE(I_SPE_BUDAT_UHR) TYPE  WAUHR OPTIONAL
*"     VALUE(I_SPE_BUDAT_ZONE) TYPE  TZNZONE OPTIONAL
*"     VALUE(I_SPE_MDNUM_EWM) TYPE  /SPE/MDNUM_EWM OPTIONAL
*"     VALUE(I_SPE_LOGSYS) TYPE  /SPE/_LOGSYS_MD OPTIONAL
*"     VALUE(I_SPE_CONFIRM_CENTRAL) TYPE  XFLAG DEFAULT SPACE
*"     VALUE(I_SPE_BILLING_REVERSAL) TYPE  CHAR1 DEFAULT SPACE
*"     VALUE(I_PGR_FLG) TYPE  CHAR1 OPTIONAL
*"     VALUE(I_BLDAT) LIKE  MKPF-BLDAT OPTIONAL
*"     VALUE(I_OIB_BLTIME) LIKE  SY-UZEIT OPTIONAL
*"     VALUE(I_OIKIMPORT) LIKE  ROIKIMPORT STRUCTURE  ROIKIMPORT
*"       OPTIONAL
*"  EXPORTING
*"     VALUE(ES_EMKPF) TYPE  EMKPF
*"  TABLES
*"      T_MESG STRUCTURE  MESG
*"      T_VBAPF STRUCTURE  VBAPF OPTIONAL
*"      T_VBFA STRUCTURE  VBFAVB OPTIONAL
*"      T_OIA11 STRUCTURE  OIA11 OPTIONAL
*"  EXCEPTIONS
*"      ERROR_REVERSE_GOODS_ISSUE
*"----------------------------------------------------------------------
  DATA:LS_MESG TYPE MESG.

  CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
    EXPORTING
      I_VBELN                   = I_VBELN
      I_BUDAT                   = I_BUDAT
      I_COUNT                   = I_COUNT
      I_MBLNR                   = I_MBLNR
      I_TCODE                   = I_TCODE
      I_VBTYP                   = I_VBTYP
      I_MBLPO                   = I_MBLPO
      I_MJAHR                   = I_MJAHR
      I_POSNR                   = I_POSNR
      I_SIMULATE                = I_SIMULATE
      I_SPE_BUDAT_UHR           = I_SPE_BUDAT_UHR
      I_SPE_BUDAT_ZONE          = I_SPE_BUDAT_ZONE
      I_SPE_MDNUM_EWM           = I_SPE_MDNUM_EWM
      I_SPE_LOGSYS              = I_SPE_LOGSYS
      I_SPE_CONFIRM_CENTRAL     = I_SPE_CONFIRM_CENTRAL
      I_SPE_BILLING_REVERSAL    = I_SPE_BILLING_REVERSAL
      I_PGR_FLG                 = I_PGR_FLG
    IMPORTING
      ES_EMKPF                  = ES_EMKPF
    TABLES
      T_MESG                    = T_MESG
      T_VBAPF                   = T_VBAPF
      T_VBFA                    = T_VBFA
    EXCEPTIONS
      ERROR_REVERSE_GOODS_ISSUE = 1
      OTHERS                    = 2.
  IF SY-SUBRC <> 0.
    CLEAR LS_MESG.
    LS_MESG-ZEILE = ''.
    LS_MESG-MSGTY = 'E'.
    LS_MESG-TEXT = 'ERROR_REVERSE_GOODS_ISSUE'.
    LS_MESG-ARBGB = SY-MSGID.
    LS_MESG-TXTNR = SY-MSGNO.
    LS_MESG-MSGV1 = SY-MSGV1.
    LS_MESG-MSGV2 = SY-MSGV2.
    LS_MESG-MSGV3 = SY-MSGV3.
    LS_MESG-MSGV4 = SY-MSGV4.
    APPEND LS_MESG TO T_MESG.
  ENDIF.

ENDFUNCTION.

 

标签:BAPI,DATA,VALUE,lt,VL09,OPTIONAL,VL01N,items,TYPE
From: https://www.cnblogs.com/ap-ad-java-abap/p/18357349

相关文章

  • VF01/VF02/VF03屏幕增强及BAPI增强字段处理
    1.在销售发票抬头表中增加增强字段2.创建处理程序主程序SAPMV60A中的所有包含文件都是以MV60AF打头的,所以我们创建一个独立的程序SE38(ZSDU0001) 来存放所有的处理代码 创建屏幕9001,确保屏幕类型为子屏幕 屏幕字段可从VBRK表中获取*&---------------------------......
  • 【BAPI_ACC_DOCUMENT_POST 】会计凭证创建抬头文本没有写入
    如果实现AC_DOCUMENT中的类IF_EX_AC_DOCUMENT的方法CHANGE_INITIAL或CHANGE_AFTER_CHECK,当使用BAPI_ACC_DOCUMENT_POST创建会计凭证时,抬头文本将会为空。解决方法就是将一段逻辑添加到CHANGE_INITIAL和CHANGE_AFTER_CHECK中。后来发现项目中确实有人使用了AC_DOCUMENT这个......
  • netcore webapi部署到docker容器,api调用后显示中文乱码
    vs2022webapi部署到docker容器,api调用后显示中文乱码。原因是:源代码文件不是utf-8编码(用vscode打开是乱码,在vscode修改后,再提交,正常)解决方法一:在中文环境下用过微软家Visualstudio的都知道,新建文件的保存编码都默认为当前系统语言,所以你的文件编码永远都是GB2312,非常令人......
  • 在webapi中发起HttpPost请求
    1.第一步,在启动文件添加builder.Services.AddHttpClient();实体类: publicclassSearchReq{publicstringName{get;set;}publicstringDescription{get;set;}publicintPageIndex{get;set;}publicintPageSize{get;set;}}u......
  • WebApi连接数据库报错:尝试加载Oracle客户端时引发BadImageFormatException
    出现的问题  今天在公司用C#搭建一个WebApi服务,接受请求并连接数据库进行查询,但连接数据库时报错:尝试加载Oracle客户端时引发BadImageFormatException。如果安装32位客户端组件的情况下以64位模式运行,将出现此问题。问题点  我之后了解点,确定了OracleClient客户端确实安装......
  • 搭建.Net WebApi并配置Swagger(一)
    C#进阶之WebAPI(一)那么首先第一点:什么是WebAPI?首先我们了解一下.netframework的框架构成:   可以看到,WebAPI和mvc同属于B/S模板框架的一种,官方对于WebApi的定义是:WebAPI是一个框架,可以轻松构建HTTP服务,覆盖广泛的客户端,包括浏览器和移动设备,WebAPI是在.NetFramwo......
  • WebAPI 参数和返回值
    四季该很好,你若尚在场。--zhu控制器类1、ControllerBase与Controller2、控制器类可以不显式的继承自任何类。Action方法的异步1、Action方法既可以同步也可以异步。2、异步Action方法的名字一般不需要以Async结尾。3、WebAPI中Action方法的返回值如果是普通数据类型,那么返......
  • 如何通过 BAPI_SALESORDER_CREATEFROMDAT2 批量创建多个销售订单
    准备工作:准备数据结构:首先,你需要为每个销售订单准备一个数据集,这可以是一个内部表(在ABAP程序中)或一个外部数据源(如数据库表或Excel文件)。循环处理:遍历你的数据集,对于每个销售订单数据,创建相应的数据结构并填充必要的字段。调用BAPI:对于每个填充好数据的订单,调用一......
  • SAP常用的 BAPI 及其用途
    FI模块(财务模块):BAPI_ACC_DOCUMENT_POST:创建会计凭证BAPI_ACC_DOCUMENT_REV_POST:反冲会计凭证,可以冲销自开发程序生成的凭证,必须传入交易码参数BAPI_INCOMINGINVOICE_CREATE:发票检验(MIRO)BAPI_INCOMINGINVOICE_CANCEL:发票校验冲销(MR8M)SD模块(销售和分销模块):BA......
  • SAP中冲销会计凭证的BAPI【BAPI_ACC_DOCUMENT_REV_POST 】的使用方法
    BAPI_ACC_DOCUMENT_REV_POST支持的参数以下是BAPI_ACC_DOCUMENT_REV_POST支持的一些关键参数及其说明:OBJ_TYPE:对象类型,通常指凭证类型。OBJ_KEY:对象键,通常指凭证编号。OBJ_SYS:对象系统标识,指SAP系统的逻辑系统编号。COMP_CODE:公司代码。PSTNG_DATE:过账日期,冲销凭证的过......