Dynamic check of authorization object

The ABAP statement AUTHORITY-CHECK OBJECT has quite static syntax and doesn't accept an internal table with authorization fields. There are maximum 10 fields possible. You can provide all 10 fields also for objects, which have fewer fields. The additional fields are ignored. This is the basic idea of dynamic call, here sample program:
REPORT zauth_check.

TYPES:
  BEGIN OF ts_auth,
    id    TYPE xufield,
    field TYPE xuval,
  END OF ts_auth,
  tt_auth TYPE STANDARD TABLE OF ts_auth.

DATA:
  lt_auth  TYPE tt_auth,
  ls_auth  TYPE ts_auth,
  lv_subrc TYPE sy-subrc.

ls_auth-id = 'RFC_TYPE'.   ls_auth-field = 'FUGR'.   APPEND ls_auth TO lt_auth.
ls_auth-id = 'RFC_NAME'.   ls_auth-field = 'SYST'.   APPEND ls_auth TO lt_auth.
ls_auth-id = 'ACTVT'.      ls_auth-field = '16'.     APPEND ls_auth TO lt_auth.

PERFORM auth_check USING 'S_RFC' lt_auth CHANGING lv_subrc.

WRITE: / lv_subrc.

*&---------------------------------------------------------------------*
*&      Form  auth_check
*&---------------------------------------------------------------------*
FORM auth_check USING    pi_object TYPE xuobject
                         pt_auth   TYPE tt_auth
                CHANGING po_subrc  TYPE sy-subrc.

  DATA:
    lv_fname    TYPE string,
    lv_tabix(2) TYPE n,
    ls_auth     TYPE ts_auth,
    lv_id_01    TYPE xufield,   lv_field_01 TYPE xuval,
    lv_id_02    TYPE xufield,   lv_field_02 TYPE xuval,
    lv_id_03    TYPE xufield,   lv_field_03 TYPE xuval,
    lv_id_04    TYPE xufield,   lv_field_04 TYPE xuval,
    lv_id_05    TYPE xufield,   lv_field_05 TYPE xuval,
    lv_id_06    TYPE xufield,   lv_field_06 TYPE xuval,
    lv_id_07    TYPE xufield,   lv_field_07 TYPE xuval,
    lv_id_08    TYPE xufield,   lv_field_08 TYPE xuval,
    lv_id_09    TYPE xufield,   lv_field_09 TYPE xuval,
    lv_id_10    TYPE xufield,   lv_field_10 TYPE xuval.

  FIELD-SYMBOLS:
    <fs>.

  LOOP AT pt_auth INTO ls_auth TO 10 " max 10 iterations
    WHERE field <> ''.               " field = '' -> DUMMY

    lv_tabix = sy-tabix.

    CONCATENATE 'LV_ID_' lv_tabix INTO lv_fname.
    ASSIGN (lv_fname) TO <fs>.
    <fs> = ls_auth-id.

    CONCATENATE 'LV_FIELD_' lv_tabix INTO lv_fname.
    ASSIGN (lv_fname) TO <fs>.
    <fs> = ls_auth-field.
  ENDLOOP.

  AUTHORITY-CHECK OBJECT pi_object
           ID lv_id_01 FIELD lv_field_01
           ID lv_id_02 FIELD lv_field_02
           ID lv_id_03 FIELD lv_field_03
           ID lv_id_04 FIELD lv_field_04
           ID lv_id_05 FIELD lv_field_05
           ID lv_id_06 FIELD lv_field_06
           ID lv_id_07 FIELD lv_field_07
           ID lv_id_08 FIELD lv_field_08
           ID lv_id_09 FIELD lv_field_09
           ID lv_id_10 FIELD lv_field_10.

  po_subrc = sy-subrc.
ENDFORM.                    "auth_check
See other related notes in my infodepot:
User exits in the transaction PFCG
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2015 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.