How to Get SAP VIM Default Approval

SAP VIM OpenText

SAP VIM Default Approval can be set in SAP VIM ( Vendor Invoice Management) to allow SAP VIM to retrieve the an?pprover by default in the workflow of DP validation.

This Article will explain ?How to retrieve SAP VIM Default Approval will explain from a Cost Center and a Document Type.

First, I am explaining technically the complexity of how Approval Data is stored in different SAP Table.
Second, I am giving away the full ABAP program ( actually it is a function module I developed) to retrieve the list of Default Approval.

Technical Overview of SAP VIM Default Approval

The Default Approval in SAP VIM can be maintained by Cost Center.

DP Document Type DOCTYPE

DP Document Type defines the type of Document Processing.
The information is set on Document Header in the SAP field /OPT/VIM_1HEAD-DOCTYPE.

Cost Center KOSTL

The cost Center is defined on Document Line level.
The Value can be retrieve from SAP Table /OPT/VIM_1ITEM-KOSTL.

Customizing for Document Type and Cost Center

The Second step is to Read the customizing of Cost Center by the Document Type.
In Order to get all the Data, we need a join between

  • Key Determination Range Configuration /PTGWFI/Z_KEYRNG
  • Webflow Key Determination Configuration /PTGWFI/Z_KEYDET

All we need is to retrieve the right key?/ptgwfi/z_keydet-OKEY

Key Determination Range Configuration : /PTGWFI/Z_KEYRNG

This table sets the Rules to link?with Selection-Option Kind Rules between

  • Document Type and a RangeId
  • Cost Center and a Range ID
Field Description
MANDT Client
RANGEID Range ID for Key Determination
SEQUENCE Four-digit number
SIGN I/E (include/exclude values)
ZOPTION Selection option (EQ/BT/CP/…)
LOW ABAP/4: Selection value
HIGH ABAP/4: Selection value

Webflow Key Determination Configuration /PTGWFI/Z_KEYDET

This table sets the links between

  • The RangeId and the Attribut Value (OBJATTRIB)
Field Description
MANDT Client
ZPDCD Client
OKDEF Product Code
OKEY Output Key Definition
FIELDID Output Key Value
RANGEID Character Field Length = 10
OBJTYP Range ID for Key Determination
OBJATTRIB Object Type
SUBOFFSET Object key
SUBLENGTH Natural Number
ZORGL Natural Number
ZDUP Natural Number

Retrieve list of SAP VIM Default Approver User form Hierarchy

With the OKEY retrieve previously and filtered by the input COST Center and DocType, we retrieve the users list from the /PTGWFI/W_ORG with these parameters:

  • ZRSP =?’XXXX_DFLT_APPR’ ?” XXXX must be remplaced with your customizing schema.
  • OBJTY =?’US’ ? ” Person

Check this link for More information on SAP VIM Tables

How to retrieve SAP VIM Default Approval from Cost Center

Function Retrieve Default Approval from Cost Center

function ZVIM_GET_DFLT_APPR .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_DOCTYPE) TYPE  /OPT/DOCTYPE OPTIONAL
*"  EXPORTING
*"     REFERENCE(ET_DFLT_APPR) TYPE  USMD_T_USER
*"  TABLES
*"      INDEX_ITEM STRUCTURE  /OPT/VIM_1ITEM
*"----------------------------------------------------------------------

  types: begin of ty_keys,
            okey        like /ptgwfi/z_keydet-okey,
            objattrib   like /ptgwfi/z_keydet-objattrib,
            sign        like /ptgwfi/z_keyrng-sign,
            zoption     like /ptgwfi/z_keyrng-zoption,
            low         like /ptgwfi/z_keyrng-low,
            high        like /ptgwfi/z_keyrng-high,
    end of ty_keys.

  data: lv_kostl              type kostl.
  data: lr_doctype            type range of /opt/doctype.
  data: lr_kostl              type range of kostl.
  data: lt_keys               type table of ty_keys.
  data: lv_okey               like /ptgwfi/z_keydet-okey.
  data: ls_item               type /opt/vim_1item.

  field-symbols:     like line of lt_keys.
  field-symbols:  like line of lr_doctype.
  field-symbols:    like line of lr_kostl.

  " Get Cost center from Item
  read table index_item into ls_item index 1.
  if sy-subrc = 0 .
    lv_kostl = ls_item-kostl.
  endif.

  check lv_kostl is not initial .

  if iv_doctype is initial and lv_kostl is initial  .
    return.
  endif.

  "-----------------------------------------------------------------------"
  " Read the Customizing for Doc Type & Cost Center
  "-----------------------------------------------------------------------"
  select det~okey det~objattrib rng~sign rng~zoption rng~low rng~high
    from /ptgwfi/z_keyrng as rng
    inner join /ptgwfi/z_keydet as det
    on rng~rangeid = det~rangeid
    into table lt_keys
    where det~okdef     = 'XXXX_DFLT_APPR'
    and   ( det~objattrib = 'DOCUMENTTYPE' or det~objattrib = 'COSTCENTER' ) .

  sort lt_keys by okey.

  "-----------------------------------------------------------------------"
  " Keep only relevant OKEY
  "-----------------------------------------------------------------------"
  loop at lt_keys assigning  .

    lv_okey = -okey.

    " Check by Okey Id
    at new okey.
      refresh: lr_doctype, lr_kostl.
    endat.

    " Fill Selection Option
    case -objattrib.
      when 'DOCUMENTTYPE'. populate_range_doctype .
      when 'COSTCENTER'.   populate_range_kostl.
      when others.
    endcase.

    " Check relevant Keys ?
    at end of okey.
      if not ( iv_doctype in lr_doctype
        and lv_kostl in lr_kostl ).
        " Not Relevant -> Delete
        delete lt_keys where okey =  lv_okey.
      endif.
    endat.
  endloop.


  " We only need the OKEY id
  if lt_keys[] is not initial .
    delete adjacent duplicates from lt_keys comparing okey.
  endif.

  "-----------------------------------------------------------------------"
  " Get Users with these OKEY Ids
  "-----------------------------------------------------------------------"
  select objid from /ptgwfi/w_org into table et_dflt_appr
    for all entries in lt_keys
    where zrsp = 'XXXX_DFLT_APPR'
    and   objty = 'US'
    and   zadky = lt_keys-okey.

  if et_dflt_appr[] is initial .
    return.
  else.
    sort et_dflt_appr .
    delete adjacent duplicates from et_dflt_appr comparing all fields.
  endif.

endfunction.

Defintion of Macro to populate Range

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

define populate_range_doctype.
  append initial line to lr_doctype assigning .
  -sign   = -sign.
  -option = -zoption.
  -low    = -low.
  -high   = -high.
end-of-definition.

The Second macro will populate a range for Cost Center ( KOSTL )

define populate_range_kostl.
  append initial line to lr_kostl assigning .
  -sign   = -sign.
  -option = -zoption.
  -low    = -low.
  -high   = -high.
end-of-definition.