*&--------------------------------------------------------------*
*& FUNCTION:ZRFC_MM_ME21N
*& Module : Function Group MEWF
*$ Short Text 发放采购订单
*& Function Group ZGRFC_MM
*& Maraco MC_CONDITION_INSERT
*& Short Text 采购订单审核功能RFC接口函数
*&--------------------------------------------------------------*
*& Created : Gary.C (2008.07.29) From Hanhe Information Technoligy CD. LTD.
*& Modified : Name (Date) From
* Intention : 1. User could use this function to Release purchase order.
* 2. This function Could build multilevel release.
*&--------------------------------------------------------------*
FUNCTION zrfc_mm_po_release.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(IP_PO_NUMBER) LIKE EKKO-EBELN
*" VALUE(COMMIT_AND_WORK) TYPE CHAR1 DEFAULT 'X'
*" EXPORTING
*" VALUE(EP_SUBRC) LIKE SY-SUBRC
*" VALUE(EP_MSG) TYPE CHAR255
*" TABLES
*" IT_PO_REL_CODE STRUCTURE ZRFC_ME21N_REL_CODE OPTIONAL
*" ET_LOG STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
**&---------------------------------Global Variant-----------------------------*
DATA gc_frggr LIKE ekko-frggr. "Release Group
DATA gc_frgsx LIKE ekko-frgsx. "Release Strategy
DATA gc_frgke LIKE ekko-frgke. "Release Status.
DATA: gt_t16fs LIKE t16fs OCCURS 0 WITH HEADER LINE.
DATA: gc_new_status LIKE bapimmpara-rel_status.
DATA: gc_indicator_new LIKE bapimmpara-po_rel_ind.
DATA: gt_log LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: gc_no_commit LIKE bapimmpara-selection.
IF commit_and_work = 'X'.
gc_no_commit = ''.
ELSE.
gc_no_commit = 'X'.
ENDIF.
**&---------------------------------Check Input-----------------------------*
SELECT SINGLE ekko~frgke INTO gc_frgke FROM ekko WHERE ekko~ebeln = ip_po_number.
IF gc_frgke = 'R'.
ep_subrc = -1.
CONCATENATE: ip_po_number '已经通过审核' INTO ep_msg.
EXIT.
ENDIF.
SELECT SINGLE ekko~frggr ekko~frgsx INTO (gc_frggr,gc_frgsx) FROM ekko WHERE ekko~ebeln = ip_po_number.
**&---------------------------------Po Release-----------------------------*
IF ( gc_frggr IS NOT INITIAL ) AND ( gc_frgsx IS NOT INITIAL ).
REFRESH gt_t16fs.
CLEAR gt_t16fs.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_t16fs FROM t16fs WHERE t16fs~frggr = gc_frggr AND t16fs~frgsx = gc_frgsx.
ELSE.
ep_subrc = -1.
ep_msg ='未找到对应审批策略,请检查输入'.
EXIT.
ENDIF.
IF gt_t16fs[] IS NOT INITIAL.
REFRESH it_po_rel_code.
CLEAR it_po_rel_code.
LOOP AT gt_t16fs.
IF gt_t16fs-frgc1 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc1.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc2 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc2.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc3 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc3.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc4 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc4.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc5 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc5.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc6 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc6.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc7 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc7.
APPEND it_po_rel_code.
ENDIF.
IF gt_t16fs-frgc8 IS NOT INITIAL.
it_po_rel_code-rel_code = gt_t16fs-frgc8.
APPEND it_po_rel_code.
ENDIF.
ENDLOOP.
ELSE.
ep_subrc = -1.
ep_msg = '未找到对应审批策略,请检查输入'.
EXIT.
ENDIF.
IF it_po_rel_code[] IS NOT INITIAL.
LOOP AT it_po_rel_code.
CLEAR gc_new_status.
CLEAR gc_indicator_new.
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
purchaseorder = ip_po_number
po_rel_code = it_po_rel_code-rel_code
use_exceptions = 'X'
no_commit = gc_no_commit
IMPORTING
rel_status_new = gc_new_status
rel_indicator_new = gc_indicator_new
* ret_code =
TABLES
return = gt_log.
.
IF sy-subrc = 0.
et_log-type = 'S'.
CONCATENATE: '采购订单通过审核码' it_po_rel_code-rel_code '的审核成功!' '返回采购订单审批状态为:' gc_new_status ' 审批标识为:'
gc_indicator_new INTO et_log-message.
APPEND et_log.
IF NOT gt_log[] IS INITIAL.
et_log-type = gt_log-type.
et_log-message = gt_log-message.
APPEND et_log.
ENDIF.
ENDIF.
ENDLOOP.
ELSE.
ep_subrc = -1.
ep_msg = '未找到对应审批策略,请检查输入'.
EXIT.
ENDIF.
READ TABLE et_log WITH KEY type = 'E'.
IF sy-subrc = 0.
ep_msg = 'po审核存在错误,请查看错误日志'.
ep_subrc = -1.
EXIT.
ELSE.
ep_msg = 'PO已审核成功,请查看日志'.
ep_subrc = 0.
ENDIF.
ENDFUNCTION.