关闭

一个简单的内部调用BAPI实例

1601人阅读 评论(0) 收藏 举报
REPORT  ztestusebapi.

*&---------------------------------------------------------------------*
*DATA DECLARATION.
*&---------------------------------------------------------------------*
TABLES bapimepoheader.

CONSTANTS : c_x VALUE 'X'.

DATA wa_poheader TYPE bapimepoheader.
DATA wa_poheaderx TYPE bapimepoheaderx.

DATA wa_poitem TYPE bapimepoitem.
DATA itab_poitem LIKE TABLE OF wa_poitem.
DATA wa_poitemx TYPE bapimepoitemx.
DATA itab_poitemx LIKE TABLE OF wa_poitemx.
DATA wa_return TYPE bapiret2.
DATA itab_return LIKE TABLE OF wa_return.


*&---------------------------------------------------------------------*
*parameters
*&---------------------------------------------------------------------*.
*head
PARAMETERS :p_poty LIKE bapimepoheader-doc_type DEFAULT 'ZPO1',
            p_ponm LIKE bapimepoheader-po_number,
            p_vendor LIKE bapimepoheader-vendor DEFAULT 'Y200707',
            p_poorg LIKE bapimepoheader-purch_org DEFAULT 'CN01',
            p_pogrp LIKE bapimepoheader-pur_group DEFAULT 'KXX',
            p_comcd LIKE bapimepoheader-comp_code DEFAULT 'CN01'.

*Item
PARAMETERS :p_poitem LIKE bapimepoitem-po_item DEFAULT 1,
p_matnr LIKE bapimepoitem-material DEFAULT 'FWA-3600',
p_plant LIKE bapimepoitem-plant DEFAULT 'CKB3',
p_lgort LIKE bapimepoitem-stge_loc DEFAULT '0021',
p_qty LIKE bapimepoitem-quantity DEFAULT 3.

*&---------------------------------------------------------------------*
*START-OF-SELECTION.
*&---------------------------------------------------------------------*
START-OF-SELECTION.


*&---------------------------------------------------------------------*
*PO HEADER DATA.
*&---------------------------------------------------------------------*

  wa_poheader-po_number = p_ponm.
  wa_poheader-comp_code = p_comcd.
  wa_poheader-doc_type = p_poty.
  wa_poheader-vendor = p_vendor.      "1 供应商,普通PO,和下面2二选一
*wa_poheader-SUPPL_PLNT = p_vendor. "2 供货工厂,STO
  wa_poheader-purch_org = p_poorg.
  wa_poheader-pur_group = p_pogrp.

*&---------------------------------------------------------------------*
*PO HEADER FLAG.
*&---------------------------------------------------------------------*

  wa_poheaderx-po_number = c_x.
  wa_poheaderx-comp_code = c_x.
  wa_poheaderx-doc_type = c_x.
  wa_poheaderx-vendor = c_x.        "1 供应商,普通PO,和下面2二选一
*wa_poheaderx-SUPPL_PLNT = c_X.   "2 供货工厂,STO
  wa_poheaderx-purch_org = c_x.
  wa_poheaderx-pur_group = c_x.

*&---------------------------------------------------------------------*
*PO ITEM DATA.
*&---------------------------------------------------------------------*
  wa_poitem-po_item = p_poitem.
  wa_poitem-material = p_matnr.
  wa_poitem-plant = p_plant.
  wa_poitem-stge_loc = p_lgort.
  wa_poitem-quantity = p_qty.
  wa_poitem-preq_name = 'xj'.
  APPEND wa_poitem TO itab_poitem.

*&---------------------------------------------------------------------*
*PO ITEM FLAG.
*&---------------------------------------------------------------------*
  wa_poitemx-po_item = p_poitem.
  wa_poitemx-material = c_x.
  wa_poitemx-plant = c_x.
  wa_poitemx-stge_loc = c_x.
  wa_poitemx-quantity = c_x.
  wa_poitemx-preq_name = c_x.
  APPEND wa_poitemx TO itab_poitemx.

*&---------------------------------------------------------------------*
*CALL BAPI
*&---------------------------------------------------------------------*

  CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      poheader                     = wa_poheader
      poheaderx                    = wa_poheaderx
*   POADDRVENDOR                 =
*   TESTRUN                      =
*   MEMORY_UNCOMPLETE            =
*   MEMORY_COMPLETE              =
*   POEXPIMPHEADER               =
*   POEXPIMPHEADERX              =
*   VERSIONS                     =
*   NO_MESSAGING                 =
*   NO_MESSAGE_REQ               =
*   NO_AUTHORITY                 =
*   NO_PRICE_FROM_PO             =
* IMPORTING
*   EXPPURCHASEORDER             =
*   EXPHEADER                    =
*   EXPPOEXPIMPHEADER            =
   TABLES
      return                       = itab_return
      poitem                       = itab_poitem
      poitemx                      = itab_poitemx
*   POADDRDELIVERY               =
*   POSCHEDULE                   =
*   POSCHEDULEX                  =
*   POACCOUNT                    =
*   POACCOUNTPROFITSEGMENT       =
*   POACCOUNTX                   =
*   POCONDHEADER                 =
*   POCONDHEADERX                =
*   POCOND                       =
*   POCONDX                      =
*   POLIMITS                     =
*   POCONTRACTLIMITS             =
*   POSERVICES                   =
*   POSRVACCESSVALUES            =
*   POSERVICESTEXT               =
*   EXTENSIONIN                  =
*   EXTENSIONOUT                 =
*   POEXPIMPITEM                 =
*   POEXPIMPITEMX                =
*   POTEXTHEADER                 =
*   POTEXTITEM                   =
*   ALLVERSIONS                  =
*   POPARTNER                    =
            .
  DATA error_log TYPE c.
  LOOP AT itab_return INTO wa_return.
    IF wa_return-type = 'E'.
      error_log = 'X'.
      EXIT.
    ENDIF.
    CLEAR wa_return.
  ENDLOOP.

  IF error_log = 'X'.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
*   RETURN        =
    .

    WRITE '有错误存在,不能生成PO'.
    LOOP AT itab_return INTO wa_return.
      WRITE: / wa_return-type,wa_return-message.
      CLEAR wa_return.
    ENDLOOP.

  ELSE.

*奇怪,未Commit已经提交了,似乎下面的是多余的.

*&---------------------------------------------------------------------*
*Confirm the document creation by calling database COMMIT
*&---------------------------------------------------------------------*

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
     EXPORTING
       wait          = 'X'
* IMPORTING
*   RETURN        =
              .

    LOOP AT itab_return INTO wa_return.
      WRITE: / wa_return-type,wa_return-message.
      CLEAR wa_return.
    ENDLOOP.


  ENDIF.
0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:28317次
    • 积分:517
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:3篇
    • 译文:0篇
    • 评论:7条
    文章分类
    最新评论
    旧的Blog