FORM frm_create_ykpo CHANGING cs_outtab TYPE ty_outtab.
DATA: ls_outtab TYPE ty_outtab,
ls_header TYPE bapimepoheader,
ls_headerx TYPE bapimepoheaderx,
lv_ebeln TYPE ebeln,
ls_poitem TYPE bapimepoitem,
lt_poitem TYPE TABLE OF bapimepoitem,
ls_poitemx TYPE bapimepoitemx,
lt_poitemx TYPE TABLE OF bapimepoitemx,
ls_schedule TYPE bapimeposchedule,
lt_schedule TYPE TABLE OF bapimeposchedule,
ls_schedulex TYPE bapimeposchedulx,
lt_schedulex TYPE TABLE OF bapimeposchedulx,
ls_te_header TYPE bapi_te_mepoheader,
ls_te_headerx TYPE bapi_te_mepoheaderx,
ls_ext_in TYPE bapiparex,
lt_ext_in TYPE TABLE OF bapiparex,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE,
lv_etenr TYPE etenr,"交货计划行号
lv_errmsg TYPE bapi_msg,
ls_zsdt004 TYPE zsdt004,
lt_zsdt004 TYPE TABLE OF zsdt004.
FIELD-SYMBOLS <ls_outtab> TYPE ty_outtab.
LOOP AT gt_outtab INTO ls_outtab WHERE zkhdd = cs_outtab-zkhdd
AND zddbb = cs_outtab-zddbb.
ls_poitem-po_item = ls_outtab-zddhh.
ls_poitem-material = ls_outtab-matnr.
ls_poitem-plant = '1100'.
ls_poitem-stge_loc = ls_outtab-zshkw.
ls_poitem-suppl_stloc = ls_outtab-zfhkw.
ls_poitem-quantity = ls_outtab-menge.
ls_poitem-po_unit = ls_outtab-meins.
ls_poitem-item_cat = 'U'.
APPEND ls_poitem TO lt_poitem.
ls_poitemx-po_item = ls_outtab-zddhh.
ls_poitemx-po_itemx = 'X'.
ls_poitemx-material = 'X'.
ls_poitemx-plant = 'X'.
ls_poitemx-stge_loc = 'X'.
ls_poitemx-suppl_stloc = 'X'.
ls_poitemx-quantity = 'X'.
ls_poitemx-po_unit = 'X'.
ls_poitemx-item_cat = 'X'.
APPEND ls_poitemx TO lt_poitemx.
lv_etenr = lv_etenr + 1.
ls_schedule-po_item = ls_outtab-zddhh.
ls_schedule-sched_line = lv_etenr.
ls_schedule-delivery_date = ls_outtab-eeind."交货日期
APPEND ls_schedule TO lt_schedule.
ls_schedulex-po_item = ls_outtab-zddhh.
ls_schedulex-sched_line = lv_etenr.
ls_schedulex-delivery_date = 'X'.
APPEND ls_schedulex TO lt_schedulex.
AT END OF zddbb.
"Header
ls_header-comp_code = p_bukrs.
ls_header-doc_type = 'ZUB1'.
ls_header-suppl_plnt = '1100'.
ls_header-purch_org = p_ekorg.
ls_header-pur_group = p_ekgrp.
ls_header-doc_date = p_datum.
ls_header-creat_date = sy-datum.
"Headerx
ls_headerx-comp_code = 'X'.
ls_headerx-doc_type = 'X'.
ls_headerx-suppl_plnt = 'X'.
ls_headerx-purch_org = 'X'.
ls_headerx-pur_group = 'X'.
ls_headerx-doc_date = 'X'.
ls_headerx-creat_date = 'X'.
"Header增强字段
CLEAR:ls_ext_in,lt_ext_in.
ls_te_header-zkhckd = cs_outtab-zkhckd.
ls_te_header-zkhdd = cs_outtab-zkhdd.
ls_te_header-zddbb = cs_outtab-zddbb.
ls_ext_in-structure = 'BAPI_TE_MEPOHEADER'.
ls_ext_in-valuepart1 = ls_te_header.
APPEND ls_ext_in TO lt_ext_in.
CLEAR ls_ext_in.
ls_ext_in-structure = 'BAPI_TE_MEPOHEADERX'.
ls_ext_in-valuepart1+10(1) = 'X'.
ls_ext_in-valuepart1+11(1) = 'X'.
ls_ext_in-valuepart1+12(1) = 'X'.
APPEND ls_ext_in TO lt_ext_in.
CLEAR: lv_ebeln,lt_return[].
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = ls_header
poheaderx = ls_headerx
* TESTRUN =
IMPORTING
exppurchaseorder = lv_ebeln
TABLES
return = lt_return[]
poitem = lt_poitem
poitemx = lt_poitemx
extensionin = lt_ext_in.
LOOP AT lt_return WHERE type CA 'EAX'.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
cs_outtab-zlcstatus = 'E11'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT lt_return WHERE type = 'E'.
IF lt_return-id = 'BAPI' OR lt_return-id = 'MEPO'.
CONTINUE.
ENDIF.
IF lv_errmsg IS INITIAL.
lv_errmsg = lt_return-message.
ELSE.
CONCATENATE lv_errmsg ';' lt_return-message INTO lv_errmsg.
ENDIF.
ENDLOOP.
LOOP AT gt_outtab ASSIGNING <ls_outtab> WHERE zkhdd = cs_outtab-zkhdd
AND zddbb = cs_outtab-zddbb.
<ls_outtab>-icon = icon_red_light.
<ls_outtab>-msg = lv_errmsg.
<ls_outtab>-zlcstatus = 'E11'.
"取状态域值描述
CALL METHOD zcl_common_tool=>get_domain_text
EXPORTING
im_domname = 'ZDE_LCSTATUS'
im_domvalue = <ls_outtab>-zlcstatus
IMPORTING
ev_text = <ls_outtab>-statu_desc.
MOVE-CORRESPONDING <ls_outtab> TO ls_zsdt004.
ls_zsdt004-aedat = sy-datum.
ls_zsdt004-aezet = sy-uzeit.
APPEND ls_zsdt004 TO lt_zsdt004.
ENDLOOP.
ELSE.
cs_outtab-zlcstatus = 'S11'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
DATA lv_zykcghh TYPE zsdt004-zykcghh.
CLEAR lv_zykcghh.
LOOP AT gt_outtab ASSIGNING <ls_outtab> WHERE zkhdd = cs_outtab-zkhdd
AND zddbb = cs_outtab-zddbb.
lv_zykcghh = lv_zykcghh + 10.
<ls_outtab>-icon = icon_green_light.
<ls_outtab>-msg = '移库采购订单创建成功'.
<ls_outtab>-zlcstatus = 'S11'.
"取状态域值描述
CALL METHOD zcl_common_tool=>get_domain_text
EXPORTING
im_domname = 'ZDE_LCSTATUS'
im_domvalue = <ls_outtab>-zlcstatus
IMPORTING
ev_text = <ls_outtab>-statu_desc.
<ls_outtab>-zykcgdh = lv_ebeln.
<ls_outtab>-zykcghh = lv_zykcghh.
MOVE-CORRESPONDING <ls_outtab> TO ls_zsdt004.
ls_zsdt004-aedat = sy-datum.
ls_zsdt004-aezet = sy-uzeit.
APPEND ls_zsdt004 TO lt_zsdt004.
ENDLOOP.
ENDIF.
CLEAR: ls_header,ls_headerx,lt_poitem,lt_poitemx,lt_ext_in,lv_etenr,lv_errmsg.
ENDAT.
ENDLOOP.
IF lt_zsdt004 IS NOT INITIAL.
MODIFY zsdt004 FROM TABLE lt_zsdt004.
COMMIT WORK AND WAIT.
ENDIF.
ABAP移库采购订单创建2023-02-01
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目需求根据科目分配类别ekpo-knttp不同有不同的处理逻辑,特别是knttp = 'A'(资产采购订单)时如...
- SAP MM初阶创建服务采购订单时订购单位和物料组的缺省值 执行事务代码ME21N 创建采购订单,输入了单据类型,...
- SAP RETAIL 基于分配表创建采购订单的时候按工厂拆分? 1, 使用事务代码WA01创建好了一个分配表13。...