Data:gt_t16fs TYPE Standard TABLE of T16FS, "approval policy
"Define approval information for purchase orders
BEGIN of Gt_ekko occurs 0,
Ebeln like Ekko-ebeln, "Purchase order number
Frggr like Ekko-frggr, "approval group
Frgsx like EKKO-FRGSX, "approval policy
Frgzu like Ekko-frgzu, "version status
Bsart like Ekko-bsart, "purchase voucher type
Ekorg like ekko-ekorg, "procurement organization
END of Gt_ekko.
*& ——————————————————————— *
*& Form Get_approval_strategy
*& ——————————————————————— *
* Take the approval group and approval policy corresponding to the purchase order
* Then the approval group for each level is taken according to the approval group and approval management.
*———————————————————————-*
FORM Get_approval_strategy.
"Fetch purchase order corresponding to approval group"
Select Ebeln "Purchase order
Frggr "Approval Group
FRGSX "Approval policy
Frgzu "Version Status
Bsart "Purchase voucher type
Ekorg "Procurement organization
Into TABLE Gt_ekko
From Ekko
WHERE Ebeln = L_ebeln.
"Take the corresponding approval policy according to the approval group
SELECT *
Into TABLE gt_t16fs
From T16fs
For all ENTRIES in Gt_ekko
WHERE Frggr = gt_ekko-frggr "approval Group
and frgsx = gt_ekko-frgsx. The approval policy
EndForm. "Get_approval_strategy
*& ——————————————————————— *
*& Form Process_po
*& ——————————————————————— *
* Process purchase orders, including cancellation approvals and approvals
*———————————————————————-*
*–>value (Fv_approve) handles the identity, N: Indicates cancellation approval, Y: Indicates approval
*———————————————————————-*
FORM Process_po USING Value (fv_approve).
Data:l_level TYPE N, "the current order has been approved through the number of levels
L_last_char TYPE N, "Current order final approval pass level
L_pre_field TYPE string VALUE ' FRGC ', "All approval group corresponds to the same part of the field
L_fieldname TYPE String. The corresponding approval group field is made up of L_pre_field + L_last_char
Field-symbols: <fs_field> TYPE t16fs-frgc1. The current approval group value
Clear:l_level,
L_last_char,
L_fieldname.
READ TABLE Gt_ekko assigning <fs_ekko> with KEY Ebeln = W_poheader-po_number.
IF SY-SUBRC EQ 0 and <fs_ekko>-frgzu are not INITIAL.
The corresponding approval group based on the purchase order's approval group, approval policy
READ TABLE gt_t16fs assigning <fs_t16fs> with KEY Frggr = <fs_ekko>-frggr
frgsx = <fs_ekko>-frgsx.
"Calculation approval passes the series
L_level = STRLEN (<fs_ekko>-frgzu).
"Cancel the purchase order, only cancel the first level of approval can be, do not need to step-off approval, if the level of approval caused by the purchase order is locked wrong
IF fv_approve = ' N '.
"Make a field name
Concatenate L_pre_field ' 1 ' into l_fieldname.
"Get approval codes with pointers
ASSIGN COMPONENT L_fieldname of STRUCTURE <fs_t16fs> to <fs_field>.
PERFORM approve_po USING <fs_ekko>-ebeln ' N ' <fs_field>.
ENDIF.
"Approval of purchase orders from
IF fv_approve = ' Y '.
Do l_level times.
L_last_char = Sy-index.
Concatenate L_pre_field L_last_char into L_fieldname.
ASSIGN COMPONENT L_fieldname of STRUCTURE <fs_t16fs> to <fs_field>.
PERFORM approve_po USING <fs_ekko>-ebeln ' Y ' <fs_field>.
Enddo.
ENDIF.
ENDIF.
EndForm. "Process_po
*& ——————————————————————— *
*& Form Approve_po
*& ——————————————————————— *
* Approve or cancel purchase order approval
*———————————————————————-*
*–>value (Fv_ebeln) Purchase order number
*–>value (fv_approve) Approval Status
*–>value (fv_rel_cod) Approval code
*———————————————————————-*
FORM Approve_po USING Value (Fv_ebeln)
Value (Fv_approve)
Value (FV_REL_COD).
Call FUNCTION ' Z_mm_approve_po '
Exporting
PurchaseOrder = Fv_ebeln
approve = Fv_approve
Rel_cod = Fv_rel_cod.
IF SY-SUBRC EQ 0.
WAIT up to 1 SECONDS.
ENDIF.
EndForm. "Approve_po
FUNCTION Z_mm_approve_po.
*"———————————————————————-
* "*" Update function module:
*"
* "*" Local Interface:
* "Importing
* "VALUE (purchaseorder) TYPE Bapimmpara-po_number
* "VALUE (APPROVE) TYPE CHAR1
* "VALUE (rel_cod) TYPE bapimmpara-po_rel_cod
*"———————————————————————-
IF approve = ' Y '.
Call FUNCTION ' Bapi_po_release '
Exporting
PurchaseOrder = PurchaseOrder
Po_rel_code = Rel_cod
* use_exceptions = ' X '
* No_commit = "
* Importing
* Rel_status_new =
* Rel_indicator_new =
* Ret_code =
* TABLES
* return = 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 sy-msgty number Sy-msgno
With Sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSEIF approve = ' N '.
Call FUNCTION ' Bapi_po_reset_release '
Exporting
PurchaseOrder = PurchaseOrder
Po_rel_code = Rel_cod
* use_exceptions = ' X '
* Importing
* Rel_status_new =
* Rel_indicator_new =
* TABLES
* return = return
EXCEPTIONS
Authority_check_fail = 1
Document_not_found = 2
Enqueue_fail = 3
Prerequisite_fail = 4
release_already_posted = 5
Responsibility_fail = 6
No_release_already = 7
No_new_release_indicator = 8
OTHERS = 9
.
IF SY-SUBRC <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty number Sy-msgno
With Sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
Endfunction.
Purchase order approval/Cancellation approval procedure (Bapi_po_reset_release, bapi_po_release)