SU53 als Funktionsbaustein

Nützliche Abap Codes und Code Fragmente

SU53 als Funktionsbaustein

Postby Tron » Mon Sep 20, 2021 2:11 pm

Fehlgeschlagenen Berechtigungen (SU53) als Funktionsbaustein
In Hintergrund Prozessen ist es manchmal nur schwer möglich die Fehlerursache zu ermitteln, besonders ärgerlich ist es, wenn Berechtigungen der Grund sind.
Hier ein Baustein der bei der Fehlersuche helfen soll. Besonders in ODATA Services eine willkommene Hilfe. ;)

Implementation:
1.) Struktur anlegen
2.) Tabellentyp ZTTAU_SU53BUFFER für die Struktur ZAU_SU53BUFFER anlegen.
3.) RFC Baustein anlegen

006.png
006.png (127.05 KiB) Viewed 117 times

007.png
007.png (12.07 KiB) Viewed 117 times

ZAU_SU53BUFFER.zip
(373 Bytes) Downloaded 20 times

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION z_au_read_auth_status.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     VALUE(I_USER) TYPE  XUBNAME DEFAULT SY-UNAME
  6. *"  EXPORTING
  7. *"     VALUE(TT_SU53_BUFF) TYPE  ZTTAU_SU53BUFFER
  8. *"----------------------------------------------------------------------
  9. *&---------------------------------------------------------------------*
  10. *&      Form  get_authorization_checks / see SAPMS01G
  11. *&---------------------------------------------------------------------*
  12.   PERFORM get_authorization_checks USING i_user ' ' tt_su53_buff.
  13.  
  14.  
  15. *&---------------------------------------------------------------------*
  16. *&      Form  get_authorization_checks from last call
  17. *&---------------------------------------------------------------------*
  18. FORM get_authorization_checks CHANGING iv_bname     TYPE xubname
  19.                                     iv_read_from_db TYPE char01
  20.                                     it_su53_buff TYPE zttau_su53buffer.
  21. *---------------------------------------------------------------------*
  22. *     Global TYPES
  23. *---------------------------------------------------------------------*
  24.         gc_last_seconds          TYPE i VALUE 10800
  25.       , gc_last_entries          TYPE i VALUE 100
  26.       .
  27.  
  28.   DATA: g_buffer_method(10)
  29. *      , gv_new_kernel_avail      TYPE          abap_bool
  30. *      , gv_save_available        TYPE          abap_bool
  31.       , gv_checks_since_time     TYPE          timestampl
  32.       , g_bname                  TYPE          usr07-bname     "Current user (global variable)
  33.       , g_refuser                TYPE          usrefus-refuser
  34.       , g0010_bname              TYPE          usr07-bname     "Screen fields
  35.       , g0010_read_from_db       TYPE          char01
  36.       , g_ok_code                TYPE          sy-ucomm
  37.       , g_datum                  TYPE          sy-datum     "#EC NEEDED
  38.       , g_zeit                   TYPE          sy-uzeit     "#EC NEEDED
  39.       , gt_usr07_new             TYPE          tt_usr07_new
  40.       , gt_range_object          TYPE RANGE OF xuobject
  41.       , g_result_item_key_table  TYPE          treemiks
  42.       , g_find_string            TYPE          string
  43.       , g_instance               TYPE          msxxlist-name.
  44.  
  45.   DATA: ls_usr07_new     TYPE          ty_usr07_new
  46.       , lr_usr07_new     TYPE REF TO   ty_usr07_new
  47.       , lv_retcode       TYPE          sy-subrc
  48.       , lt_su53buf       TYPE          cl_susr_tools_kernel=>tt_usr07p
  49.       , lr_su53buf       TYPE REF TO   cl_susr_tools_kernel=>ty_usr07p
  50.       , ls_range_object  LIKE LINE OF  gt_range_object
  51.       , ls_usr07         TYPE          usr07
  52.       , lv_since_hours   TYPE          timestampl
  53.       , lv_lines         TYPE          i.
  54.  
  55.   DATA:   BEGIN OF usr07key,
  56.             objct TYPE usr07-objct,
  57.             fiel1 TYPE usr07-fiel0,
  58.             fiel2 TYPE usr07-fiel0,
  59.             fiel3 TYPE usr07-fiel0,
  60.             fiel4 TYPE usr07-fiel0,
  61.             fiel5 TYPE usr07-fiel0,
  62.             fiel6 TYPE usr07-fiel0,
  63.             fiel7 TYPE usr07-fiel0,
  64.             fiel8 TYPE usr07-fiel0,
  65.             fiel9 TYPE usr07-fiel0,
  66.             fiel0 TYPE usr07-fiel0,
  67.           END OF usr07key.
  68.  
  69.   DATA:   BEGIN OF usr07val1,
  70.             val01 TYPE usr07-val01,
  71.             val02 TYPE usr07-val01,
  72.             val03 TYPE usr07-val01,
  73.             val04 TYPE usr07-val01,
  74.             val05 TYPE usr07-val01,
  75.             val06 TYPE usr07-val01,
  76.           END OF usr07val1.
  77.  
  78.   DATA:   BEGIN OF usr07val2,
  79.             val07 TYPE usr07-val01,
  80.             val08 TYPE usr07-val01,
  81.             val09 TYPE usr07-val01,
  82.             val10 TYPE usr07-val01,
  83.           END OF usr07val2.
  84.  
  85.  
  86.   CLEAR: gt_usr07_new
  87.        , gt_range_object
  88.        , gv_checks_since_time
  89.        .
  90.   PERFORM check_environment.
  91.  
  92.   " Get local instance
  93.   g_instance = cl_abap_syst=>get_instance_name( ).
  94.  
  95.   IF gv_new_kernel_avail EQ abap_true.
  96.     " ----  New kernel -------
  97.     IF iv_read_from_db EQ space.
  98.  
  99.       " Read last hours from shared memory
  100.       GET TIME STAMP FIELD gv_checks_since_time.
  101.  
  102.       TRY.
  103.           CALL METHOD cl_abap_tstmp=>subtractsecs
  104.             EXPORTING
  105.               tstmp   = gv_checks_since_time
  106.               secs    = gc_last_seconds
  107.             RECEIVING
  108.               r_tstmp = gv_checks_since_time.
  109.         CATCH cx_parameter_invalid_range cx_parameter_invalid_type.
  110.           GET TIME STAMP FIELD gv_checks_since_time.
  111.       ENDTRY.
  112.       lv_since_hours = gv_checks_since_time.
  113.  
  114.       CALL METHOD cl_susr_tools_kernel=>get_su53_buffer
  115.         EXPORTING
  116.           iv_bname         = iv_bname
  117.           iv_no_auth_only  = abap_true
  118.           iv_max_entries   = gc_last_entries
  119.           iv_entries_since = gv_checks_since_time
  120.         IMPORTING
  121.           et_su53_buffer   = lt_su53buf
  122.           ev_entries_since = gv_checks_since_time
  123.           ev_retcode       = lv_retcode.
  124.  
  125.       IF lv_retcode EQ 0.
  126.         SORT lt_su53buf BY timestamp DESCENDING.
  127.  
  128.         LOOP AT lt_su53buf REFERENCE INTO lr_su53buf.
  129.           MOVE-CORRESPONDING lr_su53buf->* TO ls_usr07_new.
  130.           IF lr_su53buf->authrc = 'A'.
  131.             ls_usr07_new-rc = 40.
  132.           ELSE.
  133.             ls_usr07_new-rc = lr_su53buf->authrc * 4.
  134.           ENDIF.
  135.           " Set instance
  136.           ls_usr07_new-instance = g_instance.
  137.           APPEND ls_usr07_new TO gt_usr07_new.
  138.         ENDLOOP.
  139.  
  140.         " Time since checks..
  141.         IF gv_checks_since_time LT lv_since_hours.
  142.           gv_checks_since_time = lv_since_hours.
  143.         ENDIF.
  144.         DESCRIBE TABLE lt_su53buf LINES lv_lines.
  145.         IF lv_lines EQ gc_last_entries.
  146.           READ TABLE lt_su53buf REFERENCE INTO lr_su53buf INDEX lv_lines.
  147.           IF sy-subrc EQ 0.
  148.             gv_checks_since_time = lr_su53buf->timestamp.
  149.           ENDIF.
  150.         ENDIF.
  151.       ENDIF.
  152.  
  153.       it_su53_buff[] = lt_su53buf[].
  154.  
  155.  
  156.  
  157.     ELSE.
  158.       " Read from USR07
  159.       SELECT * FROM usr07
  160.         INTO CORRESPONDING FIELDS OF TABLE gt_usr07_new ##too_many_itab_fields
  161.         WHERE bname EQ iv_bname.
  162.  
  163.       SORT gt_usr07_new BY timestamp DESCENDING.
  164.  
  165.       " Get instance from database
  166.       READ TABLE gt_usr07_new REFERENCE INTO lr_usr07_new INDEX 1.
  167.       IF sy-subrc EQ 0.
  168.         g_instance = lr_usr07_new->instance.
  169.       ELSE.
  170.         CLEAR: g_instance.
  171.       ENDIF.
  172.     ENDIF.
  173.  
  174.   ELSE.
  175.     " ---- Old kernel with parameter ---------------
  176.     IF sy-uname EQ iv_bname.
  177.       " Get result of last authorization check
  178.       GET PARAMETER ID 'XU1' FIELD usr07key.                "#EC EXISTS
  179.       GET PARAMETER ID 'XU2' FIELD usr07val1.               "#EC EXISTS
  180.       GET PARAMETER ID 'XU7' FIELD usr07val2.               "#EC EXISTS
  181.  
  182.       " Store result of last authorization check
  183.       CLEAR ls_usr07.
  184.       ls_usr07-bname = iv_bname.
  185.       MOVE-CORRESPONDING usr07key  TO ls_usr07.
  186.       MOVE-CORRESPONDING usr07val1 TO ls_usr07.
  187.       MOVE-CORRESPONDING usr07val2 TO ls_usr07.
  188.       DELETE FROM usr07 WHERE bname EQ iv_bname.
  189.       IF ls_usr07-objct IS NOT INITIAL.
  190.         " Store on db
  191.         INSERT usr07 FROM ls_usr07.
  192.  
  193.         " Fill internal table
  194.         MOVE-CORRESPONDING ls_usr07 TO ls_usr07_new.
  195.         APPEND ls_usr07_new TO gt_usr07_new.
  196.       ENDIF.
  197.  
  198.     ELSE.
  199.       " Read from USR07
  200.       SELECT * FROM usr07
  201.         INTO CORRESPONDING FIELDS OF TABLE gt_usr07_new ##too_many_itab_fields
  202.         WHERE bname = iv_bname.
  203.       " Only one entry allowed
  204.       DELETE gt_usr07_new WHERE timestamp IS NOT INITIAL.
  205.     ENDIF.
  206.   ENDIF.
  207.  
  208.   " Get objects
  209.   LOOP AT gt_usr07_new REFERENCE INTO lr_usr07_new.
  210.     CLEAR: ls_range_object.
  211.     ls_range_object-low    = lr_usr07_new->objct.
  212.     ls_range_object-sign   = 'I'.
  213.     ls_range_object-option = 'EQ'.
  214.     APPEND ls_range_object TO gt_range_object.
  215.  
  216.   SORT gt_range_object BY low.
  217.   DELETE ADJACENT DUPLICATES FROM gt_range_object COMPARING low.
  218.  
  219. ENDFORM.                    "get_authorization_checks
  220. *&---------------------------------------------------------------------*
  221. *&      Form  check_environment
  222. *&---------------------------------------------------------------------*
  223. *       text
  224. *----------------------------------------------------------------------*
  225. FORM check_environment.
  226.  
  227.   DATA: ls_dfies    TYPE dfies
  228.       , lv_status   TYPE char01
  229.       .
  230.  
  231.  
  232.   CALL METHOD cl_susr_tools_kernel=>get_su53_status
  233.     RECEIVING
  234.       rv_status = lv_status.
  235.  
  236.   IF lv_status NE 'F'.
  237.     gv_new_kernel_avail = abap_true.
  238.  
  239.     CALL FUNCTION 'DDIF_NAMETAB_GET'
  240.       EXPORTING
  241.         tabname    = 'USR07'
  242.         lfieldname = 'TIMESTAMP'
  243.       IMPORTING
  244.         dfies_wa   = ls_dfies
  245.       EXCEPTIONS
  246.         not_found  = 0
  247.         OTHERS     = 0.
  248.  
  249.     IF ls_dfies-fieldname EQ 'TIMESTAMP'.
  250.       gv_save_available = abap_true.
  251.     ENDIF.
  252.   ENDIF.
  253. ENDFORM.                    "check_environment
GeSHi ©


TOP INCLUDE
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION-POOL ZMD_ODATA.                    "MESSAGE-ID ..
  2.  
  3. * INCLUDE LZMD_ODATAD...                     " Local class definition
  4. * INCLUDE LZBC_READ_FAILED_AUTHD...          " Local class definition
  5. *&---------------------------------------------------------------------*
  6. *&      Form  get_authorization_checks / see SAPMS01G
  7. *&---------------------------------------------------------------------*
  8.  
  9.   TYPES:  BEGIN OF ty_usr07_new
  10.             , mandt      TYPE usr07-mandt
  11.             , bname      TYPE usr07-bname
  12.             , timestamp  TYPE timestampl     " New
  13.             , objct      TYPE usr07-objct
  14.             , fiel1      TYPE usr07-fiel0
  15.             , fiel2      TYPE usr07-fiel0
  16.             , fiel3      TYPE usr07-fiel0
  17.             , fiel4      TYPE usr07-fiel0
  18.             , fiel5      TYPE usr07-fiel0
  19.             , fiel6      TYPE usr07-fiel0
  20.             , fiel7      TYPE usr07-fiel0
  21.             , fiel8      TYPE usr07-fiel0
  22.             , fiel9      TYPE usr07-fiel0
  23.             , fiel0      TYPE usr07-fiel0
  24.             , val01      TYPE usr07-val01
  25.             , val02      TYPE usr07-val01
  26.             , val03      TYPE usr07-val01
  27.             , val04      TYPE usr07-val01
  28.             , val05      TYPE usr07-val01
  29.             , val06      TYPE usr07-val01
  30.             , val07      TYPE usr07-val01
  31.             , val08      TYPE usr07-val01
  32.             , val09      TYPE usr07-val01
  33.             , val10      TYPE usr07-val01
  34.             , tcode      TYPE usr07-tcode
  35.             , progname   TYPE usr07-progname
  36.             , cdate      TYPE usr07-cdate
  37.             , ctime      TYPE usr07-ctime
  38.             , abapline   TYPE i             " New
  39.             , abapprog   TYPE programm      " New
  40.             , foruser    TYPE sutrforuser   " New
  41.             , rc         TYPE int4          " New
  42.             , reason     TYPE char01        " New
  43.             , p_tcode    TYPE tcode         " New
  44.             , name       TYPE sobj_name     " New
  45.             , type       TYPE usobtype      " New
  46.             , instance   TYPE msxxlist-name " New
  47.         , END OF ty_usr07_new.
  48.   TYPES: tt_usr07_new TYPE STANDARD TABLE OF ty_usr07_new.
  49.  
  50.   data:
  51.   gv_new_kernel_avail      type          abap_bool
  52. , gv_save_available        type          abap_bool.
GeSHi ©
Tron
.....
.....
 
Posts: 1104
Joined: Sat Aug 04, 2007 10:21 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron
  • Latest Topics