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_ebanFROM ebanWHERE banfn = lw_item-banfnAND 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'EXPORTINGinput = l_matnrIMPORTINGoutput = l_matnrEXCEPTIONSlength_error = 1OTHERS = 2.
* 取物料类型SELECT SINGLE mtartINTO l_mtartFROM maraWHERE 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:34OR 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:43OR 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-23DATA: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'EXPORTINGinput = lw_item-matnrIMPORTINGoutput = lw_item-matnrEXCEPTIONSlength_error = 1OTHERS = 2.IF sy-subrc <> 0.
* Implement suitable error handling hereENDIF.IF lw_item-posid IS NOT INITIAL.SELECT SINGLE *INTO lw_prpsFROM prpsWHERE 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 INITIALAND lw_item-matnr IS NOT INITIAL.l_knttp = 'Q'.ELSEIF lw_item-posid IS NOT INITIALAND lw_item-matnr IS INITIAL.l_knttp = 'P'.ELSEIF lw_item-gdzcbj IS NOT INITIALOR ( 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'EXPORTINGinput = lw_item-meins
* LANGUAGE = SY-LANGUIMPORTINGoutput = lw_item-meinsEXCEPTIONSunit_not_found = 1OTHERS = 2.IF sy-subrc <> 0.
* Implement suitable error handling hereENDIF.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 INITIALOR lw_item-aufnr IS NOT INITIALOR lw_item-anln1 IS NOT INITIALOR 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-16lw_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'EXPORTINGpoheader = lw_poheaderpoheaderx = lw_poheaderxpoaddrvendor = 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 =IMPORTINGexppurchaseorder = l_po
* EXPHEADER =
* EXPPOEXPIMPHEADER =TABLESreturn = lt_returnpoitem = lt_poitempoitemx = lt_poitemx
* POADDRDELIVERY =poschedule = lt_poscheduleposchedulex = lt_poschedulexpoaccount = lt_poaccount
* POACCOUNTPROFITSEGMENT =poaccountx = lt_poaccountx
* POCONDHEADER =
* POCONDHEADERX =pocond = lt_conditionpocondx = lt_conditionx
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =extensionin = lt_extensionin
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =potextheader = lt_textheaderpotextitem = 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'EXPORTINGwait = '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'EXPORTINGqname = l_qnamenosend = ' 'trfc_if_sysfail = ' 'call_event = ' 'EXCEPTIONSinvalid_queue_name = 1OTHERS = 2.CALL FUNCTION 'ZMM_PO_APPROVAL_AUTO'IN BACKGROUND TASKAS SEPARATE UNITDESTINATION 'NONE'EXPORTINGi_ebeln = l_po.COMMIT WORK .ENDFUNCTION.
FUNCTION zmm_po_approval_auto.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_EBELN) TYPE EBELN
*"----------------------------------------------------------------------*{ INSERT DS4K900045 1DATA: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_ekkoFROM ekkoWHERE ebeln = i_ebeln.IF sy-subrc <> 0.MESSAGE e001(zrsm).ENDIF.ENDIF.CHECK lw_ekko-frgke <> 'R'.
* 审批通过P1IF lw_ekko-frgke = 'B'.CALL FUNCTION 'BAPI_PO_RELEASE'EXPORTINGpurchaseorder = i_ebelnpo_rel_code = 'P1'TABLESreturn = lt_returnEXCEPTIONSauthority_check_fail = 1document_not_found = 2enqueue_fail = 3prerequisite_fail = 4release_already_posted = 5responsibility_fail = 6OTHERS = 7.IF sy-subrc <> 0.MESSAGE ID sy-msgidTYPE 'E'NUMBER sy-msgnoWITH sy-msgv1sy-msgv2sy-msgv3sy-msgv4.ENDIF.WAIT UP TO 1 SECONDS.ENDIF.
* 审批通过P2CALL FUNCTION 'BAPI_PO_RELEASE'EXPORTINGpurchaseorder = i_ebelnpo_rel_code = 'P2'TABLESreturn = lt_returnEXCEPTIONSauthority_check_fail = 1document_not_found = 2enqueue_fail = 3prerequisite_fail = 4release_already_posted = 5responsibility_fail = 6OTHERS = 7.IF sy-subrc <> 0.MESSAGE ID sy-msgidTYPE 'E'NUMBER sy-msgnoWITH sy-msgv1sy-msgv2sy-msgv3sy-msgv4.ENDIF.*} INSERTENDFUNCTION.