Workflow For Create PR & Adding Approvers for Release strategy in PR.
Refer -- Release strategy in PR header
Refer -- Basic workflow in PR
-------------------------------------------------------Changing custom class-------------------------------------------------------------------
Step 1: Continue from Above basic workflow.
Step 2: Create a Structure and table type for release codes.
* Structure
* Table type -- ZTT_REL_CODE
Step 3: Create a structure and table type for approvers.
* Structure
* Table type -- ZTT_MM_APPROVERS
Step 4: Create a method GET_APPROVERS with import and export parameters.
* Write the Code for storing approvers.
METHOD get_approvers.
* Fetching PR creator from ebanSELECT SINGLE ernam
FROM eban INTO @DATA(l_f_ernam)
WHERE banfn EQ @i_f_banfn.
IF sy-subrc = 0.
" based on PR initiator fetching levels of approvers.
SELECT SINGLE *
FROM ztl_ab_approver1
INTO @DATA(l_r_approvers)
WHERE zuser = @l_f_ernam.
"Fetching L1 Approvers( PR Initiator)
IF l_r_approvers-zapprover1 IS NOT INITIAL.
SELECT SINGLE *
FROM ztl_ab_approver1
INTO @DATA(l_r_l1_appr)
WHERE zuser = @l_r_approvers-zapprover1.
IF sy-subrc = 0.
APPEND INITIAL LINE TO e_t_l1_appr ASSIGNING
FIELD-SYMBOL(<l_f_apprs>).
<l_f_apprs>-objid = l_f_ernam. " Pr Creator
<l_f_apprs>-otype = g_c_us. " US
ENDIF.
ENDIF.
"Fetching L2 Approvers
IF l_r_approvers-zapprover2 IS NOT INITIAL.
SELECT SINGLE *
FROM ztl_ab_approver1
INTO @DATA(l_r_l2_appr)
WHERE zuser = @l_r_approvers-zapprover2.
IF sy-subrc = 0.
DATA(l_v) = 1.
DO 5 TIMES.
CASE l_v.
WHEN 1.
APPEND INITIAL LINE TO e_t_l2_appr ASSIGNING
FIELD-SYMBOL(<l_f_apprs2>).
<l_f_apprs2>-objid = l_r_l2_appr-zapprover1.
<l_f_apprs2>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 2.
APPEND INITIAL LINE TO e_t_l2_appr ASSIGNING <l_f_apprs2>.
<l_f_apprs2>-objid = l_r_l2_appr-zapprover2.
<l_f_apprs2>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 3.
APPEND INITIAL LINE TO e_t_l2_appr ASSIGNING <l_f_apprs2>.
<l_f_apprs2>-objid = l_r_l2_appr-zapprover3.
<l_f_apprs2>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 4.
APPEND INITIAL LINE TO e_t_l2_appr ASSIGNING <l_f_apprs2>.
<l_f_apprs2>-objid = l_r_l2_appr-zapprover4.
<l_f_apprs2>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 5.
APPEND INITIAL LINE TO e_t_l2_appr ASSIGNING <l_f_apprs2>.
<l_f_apprs2>-objid = l_r_l2_appr-zapprover5.
<l_f_apprs2>-otype = g_c_us. " US
l_v = l_v + 1.
ENDCASE.
ENDDO.
ENDIF.
ENDIF.
"Fetching L3 Approvers
IF l_r_approvers-zapprover3 IS NOT INITIAL.
SELECT SINGLE *
FROM ztl_ab_approver1
INTO @DATA(l_r_l3_appr)
WHERE zuser = @l_r_approvers-zapprover3.
IF sy-subrc = 0.
l_v = 1.
DO 5 TIMES.
CASE l_v.
WHEN 1.
APPEND INITIAL LINE TO e_t_l3_appr ASSIGNING
FIELD-SYMBOL(<l_f_apprs3>).
<l_f_apprs3>-objid = l_r_l3_appr-zapprover1.
<l_f_apprs3>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 2.
APPEND INITIAL LINE TO e_t_l3_appr ASSIGNING <l_f_apprs3>.
<l_f_apprs3>-objid = l_r_l3_appr-zapprover2.
<l_f_apprs3>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 3.
APPEND INITIAL LINE TO e_t_l3_appr ASSIGNING <l_f_apprs3>.
<l_f_apprs3>-objid = l_r_l3_appr-zapprover3.
<l_f_apprs3>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 4.
APPEND INITIAL LINE TO e_t_l3_appr ASSIGNING <l_f_apprs3>.
<l_f_apprs3>-objid = l_r_l3_appr-zapprover4.
<l_f_apprs3>-otype = g_c_us. " US
l_v = l_v + 1.
WHEN 5.
APPEND INITIAL LINE TO e_t_l3_appr ASSIGNING <l_f_apprs3>.
<l_f_apprs3>-objid = l_r_l3_appr-zapprover5.
<l_f_apprs3>-otype = g_c_us. " US
l_v = l_v + 1.
ENDCASE.
ENDDO.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
Step 5: Create a method GET_REL_CODES with import and export parameters.
* Write Code.
METHOD get_rel_codes.
DATA : l_t_return TYPE ewa_bapireturn_tab,l_t_rel_posted TYPE ztt_mm_pr_rel_code,
l_t_rel_final TYPE ztt_mm_pr_rel_code.
CALL FUNCTION 'BAPI_REQUISITION_GETRELINFO'
EXPORTING
number = i_f_banfn
TABLES
release_already_posted = l_t_rel_posted
release_final = l_t_rel_final
return = l_t_return.
IF line_exists( l_t_return[ type = g_c_err ] ).
e_t_return = l_t_return.
RETURN.
ELSE.
DATA(l_r_rel) = l_t_rel_final[ 1 ].
ENDIF.
CLEAR e_count.
IF l_r_rel-rel_code1 IS NOT INITIAL.
APPEND INITIAL LINE TO e_t_rel_code ASSIGNING FIELD-SYMBOL(<l_f_relcode>).
<l_f_relcode>-relcode = l_r_rel-rel_code1.
e_count = e_count + 1.
ENDIF.
IF l_r_rel-rel_code2 IS NOT INITIAL.
APPEND INITIAL LINE TO e_t_rel_code ASSIGNING <l_f_relcode>.
<l_f_relcode>-relcode = l_r_rel-rel_code2.
e_count = e_count + 1.
ENDIF.
IF l_r_rel-rel_code3 IS NOT INITIAL.
APPEND INITIAL LINE TO e_t_rel_code ASSIGNING <l_f_relcode>.
<l_f_relcode>-relcode = l_r_rel-rel_code3.
e_count = e_count + 1.
ENDIF.
CALL METHOD get_approvers
EXPORTING
i_f_banfn = i_f_banfn " Purchase Requisition Number
IMPORTING
e_t_l1_appr = e_t_l1_appr " Approver1
e_t_l2_appr = e_t_l2_appr " Approver2
e_t_l3_appr = e_t_l3_appr. " Approver3
ENDMETHOD.
Step 6: Create method RELEASE_PR with import and export parameters.
* Write code.METHOD release_pr.
DATA : l_t_return TYPE mewi_t_return.CALL FUNCTION 'BAPI_REQUISITION_RELEASE_GEN'
EXPORTING
number = i_f_banfn
rel_code = i_f_rel_code
no_commit_work = space
TABLES
return = l_t_return.
IF line_exists( l_t_return[ type = g_c_err ] ).
ELSE.
e_f_released = 'X'.
ENDIF.
ENDMETHOD.
Step 7: Create a method GET_STEP_LEV_REL with import & export parameters.
* Write Code.
METHOD get_step_lev_rel.
CLEAR : e_f_relcode.
*get the release code based on tabix as step counter
* DATA(l_t_relcode) = i_t_relcode.
* DELETE l_t_relcode WHERE relcode = g_c_l1.
e_f_relcode = i_t_relcode[ i_f_counter ]-relcode.
CLEAR: e_t_hier_appr.
CASE e_f_relcode.
WHEN 'L1'.
e_t_hier_appr = i_t_l1_appr.
WHEN 'L2'.
e_t_hier_appr = i_t_l2_appr.
WHEN 'L3'.
e_t_hier_appr = i_t_l3_appr.
ENDCASE.
ENDMETHOD.
Step 8: Check and activate whole class.
-------------------------------------------------------------Adding workflow-----------------------------------------------------------------------
Step 1: Create Workflow containers.
* Release codes with import and export.
* L1 Approvers with import and export.
* L2 Approvers with import and export.
* L3 Approvers with import and export.
* Constant for L1 with data type char2 and pass initial value L1.
* Create L2, L3 with data type char2 and pass initial value L2 and L3(same like L1).
* Create E_COUNT for storing number of release codes.
* For count import & export.
* For storing hierarical approvers for approving PR(Import & Export ).
Step 2: Create an activity after 'PR Linking Workflow' name as 'Get Release codes & Approvers'
* Binding must be important (Task <--> Method).
* Binding Task <--> Workflow container (Below step name).
* Workflow.
Step 3: Create Loop Until after Get release codes & approvers.
* Give Outcome names in below True -Stop & False - Continue.
Step 4: Create a container operation.
Step 5: Create an activity after container operation for step level release code.
* Binding Task<--> Method
* Binding Workflow<-->Step.
Step 6: Create user decision after step level release code.
Step 7: Create process control for cancel workflow if user is rejected.
Step 8: Create an activity for Approved.
* Binding Task<--> Method
* Binding Workflow<-->Step.
Step 9: Final workflow will be like this.
Step 10: Save and activate.
----------------------------------------------------------------Testing the workflow-------------------------------------------------------------------------------
Step 1: Create a PR.
Step 2: Check the Release codes in PR Header.
Step 3: Approve the PR in SWIA (In this case 3 levels of approvers. I approved 3 times L1, L2, L3).
********************************Thank You*****************************
Comments
Post a Comment