Problem solve Get help with specific problems with your technologies, process and projects.

Assigning Tcodes to new roles from a text file

Creating a new role from scratch can be tedious and SAP hasn't provided a user friendly way of assigning a large number of Tcodes to a new role.

Creating a new role from scratch can be tedious and SAP hasn't provided a user friendly way of assigning a large number of Tcodes to a new role. This program allows you to take a text file (converted from Excel) and insert the Tcodes directly into the role menu. It is then a simple matter of creating the authorization profile from the new Tcodes.
The code was written in R/3 4.6C.
REPORT z_role_tcode_addition .
************************************************************************
* Program to write tcodes from text file to a Role
*
************************************************************************
* 10.07.03 CWC Created
************************************************************************
TABLES: cus_actobj, agr_tcodes.

DATA: iagrtc LIKE agr_tcodes OCCURS 1000 WITH HEADER LINE.


* Table to store the uploaded file.
DATA : BEGIN OF itab OCCURS 0,
         tcode LIKE agr_tcodes-tcode,
       END OF itab.


*  Input file parameter.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: role LIKE agr_tcodes-agr_name OBLIGATORY.
PARAMETERS: ifile LIKE rlgrap-filename OBLIGATORY .
SELECTION-SCREEN END OF BLOCK b1.


**** Drop down for the file search
AT SELECTION-SCREEN ON VALUE-REQUEST FOR ifile.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            def_path         = '*.txt'  " ifile
            mask             = ',*.*,*.*.'
            mode             = '0'
            title            = 'Select The Input File'
       IMPORTING
            filename         = ifile
       EXCEPTIONS
            inv_winsys       = 1
            no_batch         = 2
            selection_cancel = 3
            selection_error  = 4
            OTHERS           = 5.

  IF sy-subrc <:> 0.
    STOP.
  ENDIF.



START-OF-SELECTION.
  PERFORM up_load.
  PERFORM process_itab.

*&---------------------------------------------------------------------*
*&      Form  up_load
*&---------------------------------------------------------------------*
FORM up_load.

  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            filename = ifile
            filetype = 'DAT'
       TABLES
            data_tab = itab.

  IF sy-subrc NE 0.
    MESSAGE e368(00) WITH 'Error in uploading the file ' .
  ENDIF.

ENDFORM.                    " up_load


*&---------------------------------------------------------------------*
*&      Form  process_itab
*&---------------------------------------------------------------------*
FORM process_itab.

  iagrtc-agr_name = role.
  iagrtc-type = 'TR'.
  iagrtc-direct = 'X'.
  LOOP AT itab.
    iagrtc-tcode = itab-tcode.
    APPEND iagrtc.
    write: / iagrtc-agr_name, iagrtc-tcode.
  ENDLOOP.
  MODIFY agr_tcodes FROM TABLE iagrtc.

ENDFORM.                    " process_itab

Dig Deeper on SAP Basis

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchContentManagement

SearchHRSoftware

Close