0% found this document useful (0 votes)
128 views3 pages

SAP VIM Default Approval

This SAP function retrieves default approvers based on document type and cost center. It reads customizing data to populate ranges for document type and cost center. It then selects user IDs of default approvers matching these criteria and returns them.

Uploaded by

Sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views3 pages

SAP VIM Default Approval

This SAP function retrieves default approvers based on document type and cost center. It reads customizing data to populate ranges for document type and cost center. It then selects user IDs of default approvers matching these criteria and returns them.

Uploaded by

Sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Retrieve SAP VIM Default Approval from

Cost Center
Function Retrieve Default Approval from Cost
Center
1 function ZVIM_GET_DFLT_APPR .
2 *"----------------------------------------------------------------------
3 *"*"Local Interface:
4 *" IMPORTING
5 *" VALUE(IV_DOCTYPE) TYPE /OPT/DOCTYPE OPTIONAL
6 *" EXPORTING
7 *" REFERENCE(ET_DFLT_APPR) TYPE USMD_T_USER
8 *" TABLES
9 *" INDEX_ITEM STRUCTURE /OPT/VIM_1ITEM
10 *"----------------------------------------------------------------------
11
12 types: begin of ty_keys,
13 okey like /ptgwfi/z_keydet-okey,
14 objattrib like /ptgwfi/z_keydet-objattrib,
15 sign like /ptgwfi/z_keyrng-sign,
16 zoption like /ptgwfi/z_keyrng-zoption,
17 low like /ptgwfi/z_keyrng-low,
18 high like /ptgwfi/z_keyrng-high,
19 end of ty_keys.
20
21 data: lv_kostl type kostl.
22 data: lr_doctype type range of /opt/doctype.
23 data: lr_kostl type range of kostl.
24 data: lt_keys type table of ty_keys.
25 data: lv_okey like /ptgwfi/z_keydet-okey.
26 data: ls_item type /opt/vim_1item.
27
28 field-symbols: <fs_keys> like line of lt_keys.
29 field-symbols: <fr_doctype> like line of lr_doctype.
30 field-symbols: <fr_kostl> like line of lr_kostl.
31
32 " Get Cost center from Item
33 read table index_item into ls_item index 1.
34 if sy-subrc = 0 .
35 lv_kostl = ls_item-kostl.
36 endif.
37
38 check lv_kostl is not initial .
39
40 if iv_doctype is initial and lv_kostl is initial .
41 return.
42 endif.
43
44 "-----------------------------------------------------------------------"
45 " Read the Customizing for Doc Type & Cost Center
46 "-----------------------------------------------------------------------"
47 select det~okey det~objattrib rng~sign rng~zoption rng~low rng~high
48 from /ptgwfi/z_keyrng as rng
49 inner join /ptgwfi/z_keydet as det
50 on rng~rangeid = det~rangeid
51 into table lt_keys
52 where det~okdef = 'XXXX_DFLT_APPR'
53 and ( det~objattrib = 'DOCUMENTTYPE' or det~objattrib = 'COSTCENTER' ) .
54
55 sort lt_keys by okey.
56
57 "-----------------------------------------------------------------------"
58 " Keep only relevant OKEY
59 "-----------------------------------------------------------------------"
60 loop at lt_keys assigning <fs_keys> .
61
62 lv_okey = </fs_keys><fs_keys>-okey.
63
64 " Check by Okey Id
65 at new okey.
66 refresh: lr_doctype, lr_kostl.
67 endat.
68
69 " Fill Selection Option
70 case </fs_keys><fs_keys>-objattrib.
71 when 'DOCUMENTTYPE'. populate_range_doctype .
72 when 'COSTCENTER'. populate_range_kostl.
73 when others.
74 endcase.
75
76 " Check relevant Keys ?
77 at end of okey.
78 if not ( iv_doctype in lr_doctype
79 and lv_kostl in lr_kostl ).
80 " Not Relevant -> Delete
81 delete lt_keys where okey = lv_okey.
82 endif.
83 endat.
84 endloop.
85
86
87 " We only need the OKEY id
88 if lt_keys[] is not initial .
89 delete adjacent duplicates from lt_keys comparing okey.
90 endif.
91
92 "-----------------------------------------------------------------------"
93 " Get Users with these OKEY Ids
94 "-----------------------------------------------------------------------"
95 select objid from /ptgwfi/w_org into table et_dflt_appr
96 for all entries in lt_keys
97 where zrsp = 'XXXX_DFLT_APPR'
98 and objty = 'US'
99 and zadky = lt_keys-okey.
10
0 if et_dflt_appr[] is initial .
10 return.
1 else.
10 sort et_dflt_appr .
2 delete adjacent duplicates from et_dflt_appr comparing all fields.
10 endif.
3
10
4
10
5
10
6 endfunction.
10 </fs_keys></fr_kostl></fr_doctype></fs_keys>
7
10
8
10
9

Defintion of Macro to populate Range


The first need is to create a range for DP DocType (DOCTYPE)

define populate_range_doctype.
1
append initial line to lr_doctype assigning <fr_doctype>.
2
</fr_doctype><fr_doctype>-sign = <fs_keys>-sign.
3
<fr_doctype>-option = <fs_keys>-zoption.
4
<fr_doctype>-low = <fs_keys>-low.
5
<fr_doctype>-high = <fs_keys>-high.
6
end-of-definition.
7
</fs_keys></fr_doctype></fs_keys></fr_doctype></fs_keys></fr_doctype></fs_keys></fr_doctype
8
>
The Second macro will populate a range for Cost Center ( KOSTL )

1 define populate_range_kostl.
2 append initial line to lr_kostl assigning <fr_kostl>.
3 </fr_kostl><fr_kostl>-sign = <fs_keys>-sign.
4 <fr_kostl>-option = <fs_keys>-zoption.
5 <fr_kostl>-low = <fs_keys>-low.
6 <fr_kostl>-high = <fs_keys>-high.
7 end-of-definition.
8 </fs_keys></fr_kostl></fs_keys></fr_kostl></fs_keys></fr_kostl></fs_keys></fr_kostl>

You might also like