*&---------------------------------------------------------------------*
*& Report ZBAPI_REQUISITION_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
"场景 公司需求采购某物料,需求部门或者物资部门通过创建采购申请来提出自己的需求。
"因测试系统配置有限,采购申请的其他功能暂时不能实现,待后续
REPORT zbapi_requisition_create.
DATA:gt_item TYPE TABLE OF bapiebanc,"采购申请项目内表
gw_item LIKE LINE OF gt_item,
gt_text TYPE TABLE OF bapiebantx,"采购申请项目文本内表
gw_text LIKE LINE OF gt_text,
gt_retu TYPE TABLE OF bapireturn,"返回消息内表
gw_retu LIKE LINE OF gt_retu,
gv_rdno TYPE banfn.
"行项目数据添加
gw_item-preq_item = 10."行项目号
gw_item-doc_type = 'ZB'."采购申请类型
gw_item-pur_group = 'D01'."采购组
*gw_item-pur_group = '137'."采购组
gw_item-created_by = 'LIYUAN'."创建人
gw_item-preq_name = 'ANDYLEE'."需求人
gw_item-preq_date = '20210603'."采购组
gw_item-short_text = 'short text'."项目短文本
gw_item-material = 'K300000'."采购申请行物料号
*gw_item-material = 'T60602475'."采购申请行物料号
*gw_item-batch = 'HS'."采购申请行物料号
gw_item-plant = '6375'."采购申请工厂
*gw_item-plant = '8380'."采购申请工厂
gw_item-quantity = '2'."采购申请数量
gw_item-deliv_date = '20210715'."采购申请发运日期
APPEND gw_item TO gt_item.
"行文本
gw_text-preq_item = 10."项目号
gw_text-text_id = 'Z001'."文本号
gw_text-text_form = '*'."文本号
gw_text-text_line = 'test for purchase requisition'."文本号
APPEND gw_text TO gt_text.
CALL FUNCTION 'BAPI_REQUISITION_CREATE'
IMPORTING
number = gv_rdno
TABLES
requisition_items = gt_item
requisition_item_text = gt_text
return = gt_retu.
READ TABLE gt_retu INTO gw_retu WITH KEY type = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WRITE gv_rdno.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.