bapi
*&---------------------------------------------------------------------*
*& Form ZCREATE_PO_BAPI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- LT_OUTPUT
*&---------------------------------------------------------------------*
FORM ZCREATE_PO_BAPI TABLES LT_OUTPUT structURE GS_OUTPUT.
DATA: LV_ERROR,
LV_MSG TYPE STRING.
DATA: LV_EBELN TYPE EBELN.
DATA: LT_ZTPP_PH TYPE TABLE OF ZTPP_PH,
LS_ZTPP_PH LIKE LINE OF LT_ZTPP_PH.
DATA: LT_OUTPUT_COPY TYPE TABLE OF TY_OUTPUT,
LS_OUTPUT_COPY LIKE LINE OF LT_OUTPUT_COPY.
DATA: ls_poheader TYPE bapimepoheader,
ls_poheaderx TYPE bapimepoheaderx.
DATA: lt_poitems TYPE TABLE OF bapimepoitem WITH HEADER LINE,
lt_poitemx TYPE TABLE OF bapimepoitemx WITH HEADER LINE,
lt_pocond TYPE TABLE OF bapimepocond WITH HEADER LINE,
lt_pocondx TYPE TABLE OF bapimepocondx WITH HEADER LINE,
lt_poschedule TYPE TABLE OF bapimeposchedule WITH HEADER LINE,
lt_poaccount TYPE TABLE OF bapimepoaccount WITH HEADER LINE,
lt_poschedulex TYPE TABLE OF bapimeposchedulx WITH HEADER LINE,
lt_poaccountx TYPE TABLE OF bapimepoaccountx WITH HEADER LINE,
lt_potextitem TYPE TABLE OF bapimepotext WITH HEADER LINE,
lt_extensionin LIKE TABLE OF bapiparex WITH HEADER LINE.
DATA: bapi_te_mepoitem LIKE bapi_te_mepoitem,
bapi_te_mepoitemx LIKE bapi_te_mepoitemx,
bapi_te_mepoheader LIKE bapi_te_mepoheader,
bapi_te_mepoheaderx LIKE bapi_te_mepoheaderx.
DATA lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA: lt_poshippingexp LIKE TABLE OF bapimeposhippexp WITH HEADER LINE.
DATA lv_number TYPE ebeln.
DATA: lv_item TYPE i.
DATA: L_ZAUFNR TYPE ZTPP_PH-ZAUFNR,
L_ZHTBM TYPE EKKO-ZHTBM.
DATA: LV_KEY1_HTHSC TYPE ZEZVKEY.
DATA: LV_KEY2_HTHSC TYPE ZEZVKEY.
DATA: LV_KEY3_HTHSC TYPE ZEZVKEY.
DATA: L_ZZNF TYPE ZZT_MARA_EXT-ZZNF,
L_ZSaiSO TYPE ZZT_MARA_EXT-ZSAISO.
DATA: O_ZHTBM TYPE ZZEZHTBM.
DATA: O_ZNO TYPE ZZEZNO.
LOOP AT LT_OUTPUT assignING field-symbol(<FW_LS_OUTPUT>).
"采购订单 抬头
AT FIRST.
ls_poheader-doc_type = <FW_LS_OUTPUT>-bsart."凭证类型
ls_poheader-comp_code = <FW_LS_OUTPUT>-DWERK."公司代码
ls_poheader-purch_org = <FW_LS_OUTPUT>-ekorg."采购组织
ls_poheader-pur_group = <FW_LS_OUTPUT>-ekgrp."采购组
ls_poheader-vendor = <FW_LS_OUTPUT>-lifnr."供应商
ls_poheader-creat_date = sy-datum.
ls_poheader-created_by = sy-uname.
ls_poheader-pmnttrms = <FW_LS_OUTPUT>-zterm.
ls_poheaderx-doc_type = 'X'. "凭证类型
ls_poheaderx-comp_code = 'X'."公司代码
ls_poheaderx-vendor = 'X'. "供应商
ls_poheaderx-purch_org = 'X'. "采购组织
ls_poheaderx-pur_group = 'X'. "采购组
ls_poheaderx-creat_date = 'X'.
ls_poheaderx-created_by = 'X'.
ls_poheaderx-pmnttrms = 'X'.
"解锁
LV_KEY1_HTHSC = <FW_LS_OUTPUT>-BSART.
LV_KEY2_HTHSC = <FW_LS_OUTPUT>-DWERK.
LV_KEY3_HTHSC = <FW_LS_OUTPUT>-EKORG.
"取合同编码流水
CALL FUNCTION 'ZZF_NEXT_ZNO'
EXPORTING
I_BSART = <FW_LS_OUTPUT>-BSART
I_BUKRS = <FW_LS_OUTPUT>-DWERK
I_EKORG = <FW_LS_OUTPUT>-EKORG
IMPORTING
O_ZHTBM = L_ZHTBM
O_ZNO = O_ZNO
.
"更新表更新流水号表
UPDATE ZTMM_HTHSC
SET ZNO = O_ZNO
CRNAM = SY-UNAME
CRDAT = SY-DATUM
CRTIM = SY-UZEIT
WHERE BSART = <FW_LS_OUTPUT>-BSART
AND BUKRS = <FW_LS_OUTPUT>-DWERK
AND EKORG = <FW_LS_OUTPUT>-EKORG.
CALL FUNCTION 'ZZF_OBJ_UNLOCK' "解锁
EXPORTING
E_ZPROG = SY-CPROG
E_ZTCODE = SY-TCODE
* E_ZTABNAM =
E_ZVKEY1 = LV_KEY1_HTHSC
E_ZVKEY2 = LV_KEY2_HTHSC
E_ZVKEY3 = LV_KEY3_HTHSC.
ENDAT.
MOVE L_ZHTBM TO <FW_LS_OUTPUT>-ZHTBM.
"item 赋值
lv_item = lv_item + 10.
CLEAR lt_poitems.
lt_poitems-po_item = lv_item.
lt_poitems-item_cat = '0'.
lt_poitems-material_long = <FW_LS_OUTPUT>-matnr."物料
lt_poitems-plant = <FW_LS_OUTPUT>-DWERK."工厂
lt_poitems-stge_loc = <FW_LS_OUTPUT>-lgort."接收库存地点
lt_poitems-quantity = <FW_LS_OUTPUT>-ZXDSL.
lt_poitems-net_price = <FW_LS_OUTPUT>-NETPR.
lt_poitems-tax_code = <FW_LS_OUTPUT>-MWSKZ."税代码
lt_poitems-UNDER_DLV_TOL = <FW_LS_OUTPUT>-UNTTO.
lt_poitems-OVER_DLV_TOL = <FW_LS_OUTPUT>-UEBTO.
* lt_poitems-ret_item = lt_list-retpo."
lt_poitems-UNlimitED_DLV = 'X' .
IF <FW_LS_OUTPUT>-KPEIN IS INITIAL OR <FW_LS_OUTPUT>-KPEIN EQ 0 .
<FW_LS_OUTPUT>-KPEIN = 1.
ENDIF.
lt_poitems-price_unit = <FW_LS_OUTPUT>-KPEIN.
* IF lt_list-zis_jg = 'X'.
lt_poitems-acctasscat = 'F'.
* ENDIF.
APPEND lt_poitems.
CLEAR lt_poitemx.
lt_poitemx-po_item = lv_item.
lt_poitemx-item_cat = 'X'.
lt_poitemx-material_long = 'X'.
lt_poitemx-plant = 'X'.
lt_poitemx-stge_loc = 'X'.
lt_poitemx-quantity = 'X'.
lt_poitemx-net_price = 'X'.
lt_poitemx-tax_code = 'X'."税代码
* lt_poitemx-ret_item = 'X'."
lt_poitemx-UNLIMITED_DLV = 'X' .
* IF lt_list-zis_jg = 'X'.
lt_poitemx-acctasscat = 'X'.
lt_poitemx-UNDER_DLV_TOL = 'X'.
lt_poitemx-OVER_DLV_TOL = 'X'.
lt_poitemx-PRICE_UNIT = 'X'.
* ENDIF.
append lt_poitemx.
"增强字段 HEAD
CLEAR lt_extensionin.
SELECT SINGLE
ZZNF
ZSAISO
INTO (L_ZZNF , L_ZSAISO)
FROM ZZT_MARA_EXT
WHERE MATNR EQ <FW_LS_OUTPUT>-MATNR.
BAPI_TE_MEPOHEADER-ZHTBM = <FW_LS_OUTPUT>-ZHTBM."合同编码
BAPI_TE_MEPOHEADER-ZZNF = L_ZZNF. "年份
BAPI_TE_MEPOHEADER-ZSAISO = L_ZSAISO."季节
BAPI_TE_MEPOHEADER-ZCGXY = <FW_LS_OUTPUT>-ZCGXY."采购协议号
BAPI_TE_MEPOHEADER-ZYFK = <FW_LS_OUTPUT>-ZYFK. "是否预付款
lt_extensionin-structure = 'BAPI_TE_MEPOHEADER'.
lt_extensionin+30(960) = BAPI_TE_MEPOHEADER.
APPEND lt_extensionin.
CLEAR lt_extensionin.
*
BAPI_TE_MEPOHEADERX-ZHTBM = 'X'.
BAPI_TE_MEPOHEADERX-ZZNF = 'X'.
BAPI_TE_MEPOHEADERX-ZSAISO = 'X'.
BAPI_TE_MEPOHEADERX-ZCGXY = 'X'.
BAPI_TE_MEPOHEADERX-ZYFK = 'X'.
* BAPI_TE_MEPOHEADERX-ZTERM = 'X'.
lt_extensionin-structure = 'BAPI_TE_MEPOHEADERX'.
lt_extensionin+30(960) = BAPI_TE_MEPOHEADERX.
APPEND lt_extensionin.
"增强字段 item
CLEAR lt_extensionin.
bapi_te_mepoitem-po_item = lv_item.
bapi_te_mepoitem-zmatnrg = <FW_LS_OUTPUT>-SATNR. "款号
bapi_te_mepoitem-ZAUFNR = <FW_LS_OUTPUT>-ZAUFNR. "生产批号
bapi_te_mepoitem-ZSCXQ_NO = <FW_LS_OUTPUT>-ZSCXQ_NO."生产需求单号
bapi_te_mepoitem-ZZEZSCXQ_NO = <FW_LS_OUTPUT>-POSNR. "行项目
bapi_te_mepoitem-ZZESEQNO = <FW_LS_OUTPUT>-SEQNO. "序号
lt_extensionin-structure = 'BAPI_TE_MEPOITEM'.
lt_extensionin+30(960) = bapi_te_mepoitem.
APPEND lt_extensionin.
CLEAR lt_extensionin.
bapi_te_mepoitemx-po_item = lv_item.
*
bapi_te_mepoitemx-zmatnrg = 'X'.
bapi_te_mepoitemx-zmatnrcl = 'X'.
bapi_te_mepoitemx-ZAUFNR = 'X'.
bapi_te_mepoitemx-ZSCXQ_NO = 'X'.
bapi_te_mepoitemx-ZZEZSCXQ_NO = 'X'.
bapi_te_mepoitemx-ZZESEQNO = 'X'.
* bapi_te_mepoitemx-zzppbm = 'X'.
lt_extensionin-structure = 'BAPI_TE_MEPOITEMX'.
lt_extensionin+30(960) = bapi_te_mepoitemx.
APPEND lt_extensionin.
CLEAR lt_poschedule.
lt_poschedule-po_item = lv_item.
lt_poschedule-sched_line = 1.
lt_poschedule-delivery_date = <FW_LS_OUTPUT>-ZDDJQ."交期
lt_poschedule-quantity = <FW_LS_OUTPUT>-ZXDSL. "数量
APPEND lt_poschedule.
CLEAR lt_poschedulex.
lt_poschedulex-po_item = lv_item.
lt_poschedulex-sched_line = 1.
lt_poschedulex-delivery_date = 'X'."交期
lt_poschedulex-quantity = 'X'. "数量
APPEND lt_poschedulex.
CLEAR lt_potextitem.
lt_potextitem-po_number = <FW_LS_OUTPUT>-bsart.
lt_potextitem-po_item = lv_item.
lt_potextitem-text_id = 'F01'.
* lt_potextitem-text_line = P_FW_OUTPUT-remark.
APPEND lt_potextitem.
* IF lt_list-zis_jg = 'X'.
CLEAR lt_poaccount.
lt_poaccount-po_item = lv_item.
* 检查生产订单是否创建成功
IF <FW_LS_OUTPUT>-aufnr IS NOT INITIAL.
SELECT COUNT( * ) FROM aufk WHERE aufnr = <FW_LS_OUTPUT>-aufnr.
IF sy-subrc <> 0.
WAIT UP TO 1 SECONDS.
ENDIF.
ENDIF.
lt_poaccount-orderid = <FW_LS_OUTPUT>-aufnr.
APPEND lt_poaccount.
CLEAR lt_poaccountx.
lt_poaccountx-po_item = lv_item.
lt_poaccountx-orderid = 'X'.
APPEND lt_poaccountx.
* ENDIF.
CLEAR lt_poshippingexp.
lt_poshippingexp-po_item = lv_item.
lt_poshippingexp-customer = <FW_LS_OUTPUT>-DWERK.
APPEND lt_poshippingexp.
"赋值行
APPEND <FW_LS_OUTPUT> TO LT_OUTPUT_COPY.
"创建PO
AT LAST.
IF <FW_LS_OUTPUT>-AUFNR IS NOT INITIAL.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = ls_poheader
poheaderx = ls_poheaderx
no_price_from_po = 'X' " ls_poheader_add_data = ls_poheader_add_data
" header_add_data_relevant = 'X'
IMPORTING
exppurchaseorder = lv_number
TABLES
poitem = lt_poitems
poitemx = lt_poitemx
pocond = lt_pocond
pocondx = lt_pocondx
extensionin = lt_extensionin " po_item_add_data
poschedule = lt_poschedule
poschedulex = lt_poschedulex
poaccount = lt_poaccount
poaccountx = lt_poaccountx
potextitem = lt_potextitem
poshippingexp = lt_poshippingexp " lt_extensionin = lt_extensionin
return = lt_return.
READ TABLE lt_return WITH KEY type = 'E'.
IF sy-subrc = 0.
* rollback WORK.
CALL FUNCTION 'BAPI_transaction_ROLLBACK'.
LOOP AT lt_return WHERE type = 'E'.
concatenate <FW_LS_OUTPUT>-message lt_return-message ';' INTO <FW_LS_OUTPUT>-MESSAGE SEPARATED BY SPACE.
ENDLOOP.
MOVE GC_LIGHT_R TO <FW_LS_OUTPUT>-STATUS.
LOOP AT GT_OUTPUT ASSIGNING <FW_OUTPUT> WHERE SLBOX EQ 'X' AND LIFNR EQ <FW_LS_OUTPUT>-LIFNR
AND EKORG EQ <FW_LS_OUTPUT>-EKORG AND EKGRP EQ <FW_LS_OUTPUT>-EKGRP
AND DWERK EQ <FW_LS_OUTPUT>-DWERK."AND ZHTBM EQ <FW_LS_OUTPUT>-ZHTBM
CONCATENATE <FW_LS_OUTPUT>-MESSAGE lt_return-message ';' INTO <FW_OUTPUT>-MESSAGE SEPARATED BY SPACE.
MOVE GC_LIGHT_R TO <FW_OUTPUT>-STATUS.
ENDLOOP.
ELSE.
COMMIT WORK AND WAIT.
READ TABLE lt_return WITH KEY type = 'S'.
LOOP AT GT_OUTPUT ASSIGNING <FW_OUTPUT> WHERE SLBOX EQ 'X' AND LIFNR EQ <FW_LS_OUTPUT>-LIFNR AND EKORG EQ <FW_LS_OUTPUT>-EKORG
AND EKGRP EQ <FW_LS_OUTPUT>-EKGRP AND DWERK EQ <FW_LS_OUTPUT>-DWERK ."AND ZHTBM EQ <FW_LS_OUTPUT>-ZHTBM
<FW_OUTPUT>-EBELN = lv_number.
MOVE lt_return-message TO <FW_OUTPUT>-MESSAGE.
MOVE GC_LIGHT_G TO <FW_OUTPUT>-STATUS."状态灯
READ TABLE LT_OUTPUT_COPY INTO LS_OUTPUT_COPY WITH KEY ZSCXQ_NO = <FW_OUTPUT>-ZSCXQ_NO POSNR = <FW_OUTPUT>-POSNR SEQNO = <FW_OUTPUT>-SEQNO.
IF SY-SUBRC EQ 0.
MOVE LS_OUTPUT_COPY-ZHTBM TO <FW_OUTPUT>-ZHTBM."合同编码
ENDIF.
"更新 ZTPP_PH
UPDATE ZTPP_PH
SET LIFNR = <FW_OUTPUT>-LIFNR
MATNR = <FW_OUTPUT>-SATNR
UPNAM = SY-UNAME
UPDAT = SY-DATUM
UPTIM = SY-UZEIT
WHERE AUFNR EQ <FW_OUTPUT>-AUFNR.
ENDLOOP.
ENDIF.
CLEAR: ls_poheader,ls_poheaderx,lt_poitems,lt_poschedule,lt_return,lt_extensionin,lt_poitemx,lt_poschedulex,
lt_poitems[],lt_poitemx[],lt_poschedule[],lt_poschedulex[],lt_return[],lt_extensionin[],
lt_pocond[],lt_pocondx[],lt_potextitem[],
LT_POACCOUNT[],LT_POACCOUNTX[],
lv_item.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM.
相关阅读
你生活中,没有一件事情是偶然的。你知道的是“意识创造”的,你不知道的是“潜意识创造”的。由于单位全是已婚人士,所以在一次同事聚
京东网上商城在国内电商行业一直有着不错的成绩,特别是京东的自营式物流覆盖了我国大部分地区,同时在多个地方成立了物流集散中心和
A5创业网(公众号:iadmin5)6月1日报道,海外媒体称,德国戴乐格半导体公司的市值继续大幅度缩水,该公司的市值已经缩水近一半左右。德国戴
打开电脑左下角开始菜单,在下方搜索蓝输入【CMD】 进入CMD命令行,输入【conn / as sysdba】进入oralce控制台 进入控
1.首先我们可以用scott用户以sysdba的身份登录oracle. conn scott/tiger as sysdba 2.然后我就可以来创建用户了. cre