SAP ABAP 顾问(开发工程师)能力模型-CSDN博客文章浏览阅读1k次。目标:基于对SAP abap 顾问能力模型的梳理,给一年左右经验的abaper 快速成长为三年经验提供超级燃料!https://blog.csdn.net/java_zhong1990/article/details/132469977
一、背景说明
二、代码实现
2.1 队列实现
SMQ1 SMQ2 SMQ3
2.2 队列执行失败设置定时任务
待定....
FUNCTION zmm_create_po_core.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IS_HEAD) TYPE ZMMS_PO_HEAD
*" VALUE(IT_ITEM) TYPE ZMMT_PO_ITEM
*" EXPORTING
*" VALUE(E_EBELN) TYPE EBELN
*" VALUE(E_STATUS) TYPE CHAR1
*" VALUE(E_MESSAGE) TYPE CHAR100
*" VALUE(E_BSART) TYPE BSART
*"----------------------------------------------------------------------
DATA:
lw_prps TYPE prps,
lw_exheader TYPE bapi_te_mepoheader,
lw_exheaderx TYPE bapi_te_mepoheaderx,
lw_extensionin TYPE bapiparex,
lt_extensionin TYPE STANDARD TABLE OF bapiparex,
lw_textheader TYPE bapimepotextheader,
lt_textheader TYPE STANDARD TABLE OF bapimepotextheader,
lw_textitem TYPE bapimepotext,
lt_textitem TYPE STANDARD TABLE OF bapimepotext,
l_bsart TYPE bsart,
l_knttp TYPE knttp,
lw_eban TYPE eban,
l_matnr TYPE matnr,
l_mtart TYPE mtart,
l_lifnr_o TYPE char10,
l_text TYPE char200,
l_status TYPE char1,
l_ebelp TYPE ebelp,
l_posid TYPE ps_posid,
lw_poaccount TYPE bapimepoaccount,
lt_poaccount TYPE STANDARD TABLE OF bapimepoaccount,
lw_poaccountx TYPE bapimepoaccountx,
lt_poaccountx TYPE STANDARD TABLE OF bapimepoaccountx,
l_po TYPE bapimepoheader-po_number, "PO号
lw_poaddr TYPE bapimepoaddrvendor,
lw_poheader TYPE bapimepoheader, "采购抬头
lw_poheaderx TYPE bapimepoheaderx, "采购抬头确认
lw_poitem TYPE bapimepoitem, "采购行项目
lt_poitem TYPE bapimepoitem OCCURS 0, "采购行项目
lw_poitemx TYPE bapimepoitemx, "采购行项目确认
lt_poitemx TYPE bapimepoitemx OCCURS 0, "采购行项目确认
lw_condition TYPE bapimepocond, "行项目定价条件
lt_condition TYPE bapimepocond OCCURS 0, "行项目定价条件
lw_conditionx TYPE bapimepocondx, "行项目定价条件确认
lt_conditionx TYPE bapimepocondx OCCURS 0, "行项目定价条件确认
lw_poschedule TYPE bapimeposchedule,
lt_poschedule TYPE bapimeposchedule OCCURS 0,
lw_poschedulex TYPE bapimeposchedulx,
lt_poschedulex TYPE bapimeposchedulx OCCURS 0,
lt_return TYPE bapiret2 OCCURS 0, "返回消息
lw_return TYPE bapiret2. "返回消息
DATA:l_ktokk LIKE lfa1-ktokk."供应商账户组
*-------------------------------------
* 基本检查
*-------------------------------------
IF it_item[] IS INITIAL.
e_status = 'E'.
e_message = '行项目不能为空!'.
RETURN.
ENDIF.
* 确定采购订单类型
READ TABLE it_item INTO DATA(lw_item) INDEX 1.
IF lw_item-banfn IS NOT INITIAL.
* 取采购申请的物料
SELECT SINGLE *
INTO lw_eban
FROM eban
WHERE banfn = lw_item-banfn
AND bnfpo = lw_item-bnfpo
.
l_matnr = lw_eban-matnr.
l_knttp = lw_eban-knttp.
ELSE.
l_matnr = lw_item-matnr.
ENDIF.
* IF l_matnr IS INITIAL.
* e_status = 'E'.
* e_message = '无法确定物料!'.
* RETURN.
* ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = l_matnr
IMPORTING
output = l_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
* 取物料类型
SELECT SINGLE mtart
INTO l_mtart
FROM mara
WHERE matnr = l_matnr
.
l_lifnr_o = |{ is_head-lifnr ALPHA = IN }|.
SELECT SINGLE ktokk
INTO l_ktokk
FROM lfa1
WHERE lifnr = l_lifnr_o.
l_lifnr_o = |{ is_head-lifnr ALPHA = OUT }|.
* 确定订单类型
IF is_head-oaxjlx = 'Z'.
l_bsart = 'A01'.
ELSEIF lw_eban-pstyp = '3'.
l_bsart = 'A04'.
ELSEIF ( l_mtart = 'A100'
OR l_mtart = 'A110' "MODIFY BY LIQUAN 2021.10.26 鲁文慧确认
OR l_mtart = 'A120'
OR l_mtart = 'A130'
OR l_mtart = 'A140'
OR l_mtart = 'A150'
OR l_mtart = 'A200'
OR l_mtart = 'A300'
OR l_mtart = 'A310'
OR l_mtart = 'A320'
OR l_mtart = 'A330'
OR l_mtart = 'A340'
OR l_mtart = 'A350'
OR l_mtart = 'A400'
OR l_mtart = 'AL00'
"*******Added by zhong on 14.08.2023 15:55:34
OR l_mtart = 'A160'
OR l_mtart = 'A170'
)
* AND l_lifnr_o CP '1*'.
AND l_ktokk <> 'A002' AND l_ktokk <> ''.
l_bsart = 'NB'.
ELSEIF ( l_mtart = 'A100'
OR l_mtart = 'A110' "MODIFY BY LIQUAN 2021.10.26 鲁文慧确认
OR l_mtart = 'A120'
OR l_mtart = 'A130'
OR l_mtart = 'A140'
OR l_mtart = 'A150'
OR l_mtart = 'A200'
OR l_mtart = 'A300'
OR l_mtart = 'A310'
OR l_mtart = 'A320'
OR l_mtart = 'A330'
OR l_mtart = 'A340'
OR l_mtart = 'AL00'
"*******Added by zhong on 14.08.2023 15:55:43
OR l_mtart = 'A160'
OR l_mtart = 'A170'
)
AND l_ktokk = 'A002' .
l_bsart = 'A01'.
ELSEIF lw_item-matnr IS NOT INITIAL AND lw_item-posid IS NOT INITIAL AND l_mtart = 'A350'.
l_bsart = 'NB'.
ELSEIF ( ( l_mtart = 'A350' AND ( lw_item-matnr IS INITIAL OR lw_item-posid IS INITIAL ) )
OR l_mtart = 'A400'
OR l_mtart = 'A700' ).
l_bsart = 'A02'.
ELSEIF lw_item-matnr IS INITIAL AND lw_item-gdzcbj = 'X' .
l_bsart = 'A06'.
ELSEIF lw_item-matnr IS INITIAL.
l_bsart ='A03'.
ENDIF.
IF l_bsart IS INITIAL.
e_status = 'E'.
e_message = '无法确定凭证类型'.
RETURN.
ENDIF.
"增加非祥瑞 选择祥瑞物料组 限制 2022-02-23
DATA:l_flag TYPE n.
l_flag = 0.
IF is_head-bukrs <> 2030.
LOOP AT it_item ASSIGNING FIELD-SYMBOL(<fs>).
IF <fs>-matkl = '8099001' OR <fs>-matkl = '8099002' OR <fs>-matkl = '8099003'.
l_flag = 1.
ENDIF.
ENDLOOP.
IF l_flag = 1.
e_status = 'E'.
e_message = '物料组选择错误'.
RETURN.
ENDIF.
ENDIF.
"增加判断祥瑞工厂收货未评估未勾选
l_flag = 0.
IF is_head-bukrs = 2030 OR is_head-bukrs = 3020.
LOOP AT it_item ASSIGNING FIELD-SYMBOL(<its>).
IF ( <its>-werks = 2031 OR <its>-werks = 3021 ) AND ( <its>-matkl = '8099001' OR <its>-matkl = '8099002' OR <its>-matkl = '8099003' ).
IF <its>-weunb IS INITIAL.
l_flag = 1.
ENDIF.
ENDIF.
ENDLOOP.
IF l_flag = 1.
e_status = 'E'.
e_message = '收货未评估未勾选'.
RETURN.
ENDIF.
ENDIF.
*-------------------------------------
* bapi字段处理
*-------------------------------------
***************抬头***************
lw_poheader-doc_type = l_bsart . "凭证类型
lw_poheader-vendor = |{ is_head-lifnr ALPHA = IN }|."供应商帐户号
lw_poheader-purch_org = is_head-ekorg. "采购组织
lw_poheader-pur_group = is_head-ekgrp. "采购组
lw_poheader-comp_code = is_head-bukrs. "公司代码
lw_poheader-doc_date = sy-datum . "采购凭证日期
lw_poheader-pmnttrms = is_head-zterm. "收付条件代码
lw_poheader-currency = is_head-waers. "货币
*————确认————
lw_poheaderx-doc_type = 'X'. "凭证类型
lw_poheaderx-vendor = 'X'. "供应商帐户号
lw_poheaderx-purch_org = 'X'. "采购组织
lw_poheaderx-pur_group = 'X'. "采购组
lw_poheaderx-comp_code = 'X'. "公司代码
IF lw_poheader-doc_date IS NOT INITIAL OR lw_poheader-doc_date <> ''.
lw_poheaderx-doc_date = 'X'. "采购凭证日期
ENDIF.
IF lw_poheader-pmnttrms IS NOT INITIAL.
lw_poheaderx-pmnttrms = 'X'. "收付条件代码
ENDIF.
IF lw_poheader-currency IS NOT INITIAL.
lw_poheaderx-currency = 'X'. "货币
ENDIF.
IF lw_poheader-vendor = '0000900000'.
lw_poaddr-name = is_head-name1.
lw_poaddr-country = 'CN'.
lw_poaddr-city = is_head-city1.
lw_poaddr-po_box = '未知'.
lw_poaddr-street = is_head-street.
lw_poaddr-postl_cod1 = is_head-post_code1.
ENDIF.
IF is_head-oauser IS NOT INITIAL.
lw_exheader-zuser = is_head-oauser.
lw_extensionin-structure = 'BAPI_TE_MEPOHEADER'.
lw_extensionin-valuepart1 = lw_exheader..
APPEND lw_extensionin TO lt_extensionin.
lw_exheaderx-zuser = 'X'.
lw_extensionin-structure = 'BAPI_TE_MEPOHEADERX'.
lw_extensionin-valuepart1 = lw_exheaderx.
APPEND lw_extensionin TO lt_extensionin.
ENDIF.
*————抬头文本————
IF is_head-bktxt IS NOT INITIAL.
CLEAR lw_textheader.
lw_textheader-text_id = 'F01'.
lw_textheader-text_form = '/'.
lw_textheader-text_line = is_head-bktxt+0(132).
APPEND lw_textheader TO lt_textheader.
IF is_head-bktxt+132(132) IS NOT INITIAL.
CLEAR lw_textheader.
lw_textheader-text_id = 'F01'.
lw_textheader-text_form = '/'.
lw_textheader-text_line = is_head-bktxt+132(132).
APPEND lw_textheader TO lt_textheader.
ENDIF.
ENDIF.
***************行项目*************
LOOP AT it_item INTO lw_item.
l_ebelp = l_ebelp + 10.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = lw_item-matnr
IMPORTING
output = lw_item-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF lw_item-posid IS NOT INITIAL.
SELECT SINGLE *
INTO lw_prps
FROM prps
WHERE posid = lw_item-posid.
IF sy-subrc <> 0.
e_status = 'E'.
e_message = 'WBS元素' && lw_item-posid && '不存在'.
RETURN.
ENDIF.
ENDIF.
CLEAR l_knttp.
IF lw_item-kostl IS NOT INITIAL.
l_knttp = 'K'.
ELSEIF lw_item-aufnr IS NOT INITIAL.
l_knttp = 'F'.
ELSEIF lw_item-posid IS NOT INITIAL
AND lw_item-matnr IS NOT INITIAL.
l_knttp = 'Q'.
ELSEIF lw_item-posid IS NOT INITIAL
AND lw_item-matnr IS INITIAL.
l_knttp = 'P'.
ELSEIF lw_item-gdzcbj IS NOT INITIAL
OR ( lw_item-anln1 IS NOT INITIAL AND lw_item-anln2 IS NOT INITIAL ).
l_knttp = 'A'.
* ELSE.
* l_knttp = 'L'.
ENDIF.
lw_poitem-po_item = l_ebelp. "行项目编号
lw_poitem-material = lw_item-matnr. "物料编码
lw_poitem-matl_group = lw_item-matkl. "物料组
lw_poitem-short_text = lw_item-txz01.
lw_poitem-plant = lw_item-werks. "工厂
lw_poitem-stge_loc = lw_item-lgort. "库存地点
lw_poitem-quantity = lw_item-menge. "数量
"lw_poitem-plan_del = lw_item-eindt."交货日期
IF lw_item-menge IS INITIAL AND lw_eban-menge IS NOT INITIAL.
lw_poitem-quantity = lw_eban-menge.
ENDIF.
IF lw_item-meins IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = lw_item-meins
* LANGUAGE = SY-LANGU
IMPORTING
output = lw_item-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
lw_poitem-po_unit = lw_item-meins. "单位
IF lw_item-meins IS INITIAL AND lw_eban-menge IS NOT INITIAL.
lw_poitem-po_unit = lw_eban-meins.
ENDIF.
lw_poitem-preq_no = lw_item-banfn. "采购申请编号
lw_poitem-preq_item = lw_item-bnfpo. "采购申请行项目
lw_poitem-tax_code = lw_item-mwskz. "税码
lw_poitem-acctasscat = l_knttp. "科目分配类别
lw_poitem-item_cat = lw_eban-pstyp. "项目类别
* IF lw_item-kostl IS NOT INITIAL.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* input = lw_item-kostl
* IMPORTING
* output = lw_poitem-costcenter.
*
* ENDIF.
lw_poitem-costcenter = lw_item-kostl. "成本中心
lw_poitem-over_dlv_tol = lw_item-uebto. "
lw_poitem-under_dlv_tol = lw_item-untto. "
lw_poitem-gr_non_val = lw_item-weunb. "
lw_poitem-gr_basediv = 'X'. "
APPEND lw_poitem TO lt_poitem.
* ————确认————
lw_poitemx-po_item = l_ebelp. "行项目编号
IF lw_poitem-material IS NOT INITIAL.
lw_poitemx-material = 'X'. "物料编码
ENDIF.
IF lw_poitem-short_text IS NOT INITIAL.
lw_poitemx-short_text = 'X'.
ENDIF.
IF lw_poitem-plant IS NOT INITIAL.
lw_poitemx-plant = 'X'. "工厂
ENDIF.
IF lw_poitem-stge_loc IS NOT INITIAL.
lw_poitemx-stge_loc = 'X'. "库存地点
ENDIF.
IF lw_poitem-quantity IS NOT INITIAL.
lw_poitemx-quantity = 'X'. "数量
ENDIF.
IF lw_poitem-po_unit IS NOT INITIAL.
lw_poitemx-po_unit = 'X'. "单位
ENDIF.
IF lw_poitem-preq_no IS NOT INITIAL.
lw_poitemx-preq_no = 'X'. "采购申请编号
ENDIF.
IF lw_poitem-preq_item IS NOT INITIAL.
lw_poitemx-preq_item = 'X'. "采购申请行项目
ENDIF.
IF lw_poitem-tax_code IS NOT INITIAL.
lw_poitemx-tax_code = 'X'. "税码
ENDIF.
IF lw_poitem-acctasscat IS NOT INITIAL.
lw_poitemx-acctasscat = 'X'. "科目分配类别
ENDIF.
IF lw_poitem-item_cat IS NOT INITIAL.
lw_poitemx-item_cat = 'X'. "项目类别
ENDIF.
IF lw_poitem-costcenter IS NOT INITIAL.
lw_poitemx-costcenter = 'X'. "成本中心
ENDIF.
IF lw_poitem-matl_group IS NOT INITIAL.
lw_poitemx-matl_group = 'X'.
ENDIF.
IF lw_poitem-over_dlv_tol IS NOT INITIAL.
lw_poitemx-over_dlv_tol = 'X'.
ENDIF.
IF lw_poitem-under_dlv_tol IS NOT INITIAL.
lw_poitemx-under_dlv_tol = 'X'.
ENDIF.
IF lw_poitem-gr_non_val IS NOT INITIAL.
lw_poitemx-gr_non_val = 'X'.
ENDIF.
IF lw_poitem-gr_basediv IS NOT INITIAL.
lw_poitemx-gr_basediv = 'X'.
ENDIF.
APPEND lw_poitemx TO lt_poitemx.
* ************账户设置************
IF lw_item-posid IS NOT INITIAL
OR lw_item-aufnr IS NOT INITIAL
OR lw_item-anln1 IS NOT INITIAL
OR lw_item-kostl IS NOT INITIAL.
CLEAR lw_poaccount.
lw_poaccount-po_item = l_ebelp.
lw_poaccount-orderid = lw_item-aufnr.
lw_poaccount-wbs_element = lw_item-posid.
lw_poaccount-asset_no = lw_item-anln1.
lw_poaccount-sub_number = lw_item-anln2.
lw_poaccount-costcenter = lw_item-kostl.
APPEND lw_poaccount TO lt_poaccount .
CLEAR lw_poaccountx.
lw_poaccountx-po_item = l_ebelp.
IF lw_poaccount-orderid IS NOT INITIAL.
lw_poaccountx-orderid = 'X'.
ENDIF.
IF lw_poaccount-wbs_element IS NOT INITIAL.
lw_poaccountx-wbs_element = 'X'.
ENDIF.
IF lw_poaccount-asset_no IS NOT INITIAL.
lw_poaccountx-asset_no = 'X'.
ENDIF.
IF lw_poaccount-sub_number IS NOT INITIAL.
lw_poaccountx-sub_number = 'X'.
ENDIF.
IF lw_poaccount-costcenter IS NOT INITIAL.
lw_poaccountx-costcenter = 'X'.
ENDIF.
APPEND lw_poaccountx TO lt_poaccountx.
ENDIF.
* ************定价条件************
IF lw_item-netpr IS INITIAL AND lw_eban-preis IS NOT INITIAL.
lw_item-netpr = lw_eban-preis.
lw_item-peinh = lw_eban-peinh.
ENDIF.
IF lw_item-peinh IS INITIAL.
lw_item-peinh = '1'.
ENDIF.
IF lw_item-netpr IS NOT INITIAL.
lw_condition-itm_number = l_ebelp. "行项目号
lw_condition-cond_type = 'PBXX'. "条件类型
lw_condition-cond_value = lw_item-netpr. "金额
lw_condition-cond_p_unt = lw_item-peinh.
lw_condition-currency = 'CNY'. "货币
lw_condition-change_id = 'I'.
APPEND lw_condition TO lt_condition.
*————确认————
lw_conditionx-itm_number = l_ebelp. "行项目号
lw_conditionx-cond_type = 'X'. "条件类型
lw_conditionx-cond_value = 'X'. "金额
lw_conditionx-cond_p_unt = 'X'. "金额
lw_conditionx-currency = 'X'. "货币
lw_conditionX-change_id = 'X'.
APPEND lw_conditionx TO lt_conditionx.
ENDIF.
*————行项目文本————
IF lw_item-sgtxt IS NOT INITIAL.
CLEAR lw_textitem.
lw_textitem-po_item = l_ebelp.
lw_textitem-text_id = 'F01'.
lw_textitem-text_form = '/'.
lw_textitem-text_line = lw_item-sgtxt+0(132).
APPEND lw_textitem TO lt_textitem.
IF lw_item-sgtxt+132(132) IS NOT INITIAL.
CLEAR lw_textitem.
lw_textitem-po_item = l_ebelp.
lw_textitem-text_id = 'F01'.
lw_textitem-text_form = '/'.
lw_textitem-text_line = lw_item-sgtxt+132(132).
APPEND lw_textitem TO lt_textitem.
ENDIF.
ENDIF.
"add by gxx 2022-02-16
lw_poschedule-po_item = l_ebelp.
lw_poschedule-delivery_date = lw_item-eindt."交货日期
APPEND lw_poschedule TO lt_poschedule.
lw_poschedulex-po_item = l_ebelp.
lw_poschedulex-po_itemx = 'X'.
lw_poschedulex-delivery_date = 'X'.
APPEND lw_poschedulex TO lt_poschedulex.
ENDLOOP.
SET UPDATE TASK LOCAL .
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = lw_poheader
poheaderx = lw_poheaderx
poaddrvendor = lw_poaddr
* TESTRUN = 'X'
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* PARK_COMPLETE =
* PARK_UNCOMPLETE =
IMPORTING
exppurchaseorder = l_po
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = lt_return
poitem = lt_poitem
poitemx = lt_poitemx
* POADDRDELIVERY =
poschedule = lt_poschedule
poschedulex = lt_poschedulex
poaccount = lt_poaccount
* POACCOUNTPROFITSEGMENT =
poaccountx = lt_poaccountx
* POCONDHEADER =
* POCONDHEADERX =
pocond = lt_condition
pocondx = lt_conditionx
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
extensionin = lt_extensionin
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
potextheader = lt_textheader
potextitem = lt_textitem
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* SERIALNUMBER =
* SERIALNUMBERX =
* INVPLANHEADER =
* INVPLANHEADERX =
* INVPLANITEM =
* INVPLANITEMX =
.
* 结果处理
* 状态判定
CLEAR l_text.
LOOP AT lt_return INTO lw_return .
IF lw_return-type = 'E'
OR lw_return-type = 'A' .
l_status = 'E'.
ELSE.
CONTINUE.
ENDIF.
IF l_text IS INITIAL.
l_text = lw_return-message.
ELSE.
CONCATENATE l_text lw_return-message INTO l_text SEPARATED BY '//'.
ENDIF.
ENDLOOP.
****** ADD 20230106 状态判断里面加入判断单号为空时
IF l_po IS INITIAL.
l_status = 'E'.
CONCATENATE '创建失败' l_text lw_return-message INTO l_text SEPARATED BY '//'.
ENDIF.
******
* 结果处理
IF l_status = 'E' .
e_status = 'E'.
e_message = l_text.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
e_ebeln = l_po.
e_status = 'S'.
e_bsart = l_bsart.
ENDIF.
* 产生队列,后台进行自动审批
DATA l_qname TYPE trfcqout-qname.
l_qname = 'PO_SP_' && l_po.
CONDENSE l_qname NO-GAPS.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME'
EXPORTING
qname = l_qname
nosend = ' '
trfc_if_sysfail = ' '
call_event = ' '
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
CALL FUNCTION 'ZMM_PO_APPROVAL_AUTO'
IN BACKGROUND TASK
AS SEPARATE UNIT
DESTINATION 'NONE'
EXPORTING
i_ebeln = l_po.
COMMIT WORK .
ENDFUNCTION.
FUNCTION zmm_po_approval_auto.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_EBELN) TYPE EBELN
*"----------------------------------------------------------------------
*{ INSERT DS4K900045 1
DATA:
lw_ekko TYPE ekko,
lt_return TYPE STANDARD TABLE OF bapireturn,
lw_return TYPE bapireturn.
* 1.检查采购订单是否存在
IF i_ebeln IS NOT INITIAL.
SELECT SINGLE *
INTO lw_ekko
FROM ekko
WHERE ebeln = i_ebeln.
IF sy-subrc <> 0.
MESSAGE e001(zrsm).
ENDIF.
ENDIF.
CHECK lw_ekko-frgke <> 'R'.
* 审批通过P1
IF lw_ekko-frgke = 'B'.
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
purchaseorder = i_ebeln
po_rel_code = 'P1'
TABLES
return = lt_return
EXCEPTIONS
authority_check_fail = 1
document_not_found = 2
enqueue_fail = 3
prerequisite_fail = 4
release_already_posted = 5
responsibility_fail = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE 'E'
NUMBER sy-msgno
WITH sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4.
ENDIF.
WAIT UP TO 1 SECONDS.
ENDIF.
* 审批通过P2
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
purchaseorder = i_ebeln
po_rel_code = 'P2'
TABLES
return = lt_return
EXCEPTIONS
authority_check_fail = 1
document_not_found = 2
enqueue_fail = 3
prerequisite_fail = 4
release_already_posted = 5
responsibility_fail = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE 'E'
NUMBER sy-msgno
WITH sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4.
ENDIF.
*} INSERT
ENDFUNCTION.