All the Transaction code relevant to a Particular Role will be automatically rolled out to the User.

Business User will do not have to add Transaction code to the Favorite list.

Future addition of Transaction code by the Centralized team will be automatically added to the Favorite list.

Currently the Transaction code knowledge and usage seems to be local which can be made global by rolling the Favorite list.

The Program has the capability of loading a favorite list based on User as well as Roles. Please note that existing Transaction code will not be removed from Favorite list.

Code snippet

   select * into table it_user
  from usr02 where bname in s_user.

*  * This is probably not required as  ‘FILE_OPEN_DIALOG does the same
  CALL FUNCTION ‘NAVIGATION_FILENAME_HELP’
    EXPORTING
      DEFAULT_PATH_LONG = ‘*.*’                       “note 1572298
      MODE              = ‘O’
    IMPORTING
      SELECTED_FILENAME_LONG = FILENAME               “note 1572298
    CHANGING
      FILE_ENCODING     = L_ENCODING.

  IF FILENAME = SPACE.
    MESSAGE S232(S#) RAISING ACTION_CANCELLED.
  ENDIF.
  L_FILENAME = FILENAME.

REFRESH: GT_FILE, GT_CHECK.
  CALL FUNCTION ‘GUI_UPLOAD’
    EXPORTING
      FILENAME                = L_FILENAME
      FILETYPE                = ‘ASC’
      CODEPAGE                = L_ENCODING
    TABLES
      DATA_TAB                = GT_FILE
    EXCEPTIONS
      FILE_OPEN_ERROR         = 1
      FILE_READ_ERROR         = 2
      NO_BATCH                = 3
      GUI_REFUSE_FILETRANSFER = 4
      INVALID_TYPE            = 5
      NO_AUTHORITY            = 6                           “as of 4.6C
      OTHERS                  = 7.

  CASE SYSUBRC.
    WHEN 1. “FILE_OPEN_ERROR
      MESSAGE E036(PC). “Fehler beim Offnen der Download-Datei
    WHEN 2. “FILE_READ_ERROR
      MESSAGE E034(PC). “Fehler beim Schreiben der Daten
    WHEN 3. “NO_BATCH
      MESSAGE E005(PC).
    WHEN 4. “GUI_REFUSE_FILETRANSFER
      MESSAGE E015(PC).“Filetransfer nicht mit diesem Frontend
    WHEN 5. “INVALID_TYPE
      MESSAGE E132(PC). “Bitte gultigen Dateityp angeben
    WHEN 6. “NO_AUTHORITY                                    “as of 4.6C
      MESSAGE E001(BMEN).“keine Berechtigung zum Import
    WHEN 7. “OTHERS
      MESSAGE E038(PC). “Fehler beim Upload/Download
  ENDCASE.
loop at it_user into wa_user.
  CALL FUNCTION ‘ZMM_FAV_UPLOAD’
   EXPORTING
     UNAME                  = wa_userbname
    TABLES
*      USERNAME               = it_user
gt_file = gt_file
*   EXCEPTIONS
*     ACTION_CANCELLED       = 1
*     OTHERS                 = 2
            .
  IF SYSUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
endloop.

FM code

   FUNCTION ZMM_FAV_UPLOAD.
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     REFERENCE(UNAME) TYPE  SY-UNAME DEFAULT SY-UNAME
*”  TABLES
*”      USERNAME STRUCTURE  USR02 OPTIONAL
*”      GT_FILE STRUCTURE  ZFAV
*”  EXCEPTIONS
*”      ACTION_CANCELLED
*”———————————————————————-
  DATA: P_TEXT           TYPE SMENSAPLNTTEXT,
        L_FIRST_NODE(1TYPE C,
        wa_username type usr02,
        L_ENCODING       TYPE ABAP_ENCOD,
        NEW_OBJECT_ID    LIKE GT_SMEN_COBJECT_ID.

* This is probably not required as  ‘FILE_OPEN_DIALOG does the same
*  CALL FUNCTION ‘NAVIGATION_FILENAME_HELP’
*    EXPORTING
*      DEFAULT_PATH_LONG = ‘*.*’                       “note 1572298
*      MODE              = ‘O’
*    IMPORTING
*      SELECTED_FILENAME_LONG = FILENAME               “note 1572298
*    CHANGING
*      FILE_ENCODING     = L_ENCODING.
*
*  IF FILENAME = SPACE.
*    MESSAGE S232(S#) RAISING ACTION_CANCELLED.
*  ENDIF.
*  L_FILENAME = FILENAME.

* Load favorites
  REFRESH: GT_SMEN_C, GT_SMEN_BUFFI.
  CALL FUNCTION ‘NAVIGATION_LOAD_FAVORITES’
    EXPORTING
      USER_NAME     = UNAME
    TABLES
      FAVORITES_TAB = GT_SMEN_C
      LINKS_LIST    = GT_SMEN_BUFFI.

* Upload file
*  REFRESH: GT_FILE, GT_CHECK.
*  CALL FUNCTION ‘GUI_UPLOAD’
*    EXPORTING
*      FILENAME                = L_FILENAME
*      FILETYPE                = ‘ASC’
*      CODEPAGE                = L_ENCODING
*    TABLES
*      DATA_TAB                = GT_FILE
*    EXCEPTIONS
*      FILE_OPEN_ERROR         = 1
*      FILE_READ_ERROR         = 2
*      NO_BATCH                = 3
*      GUI_REFUSE_FILETRANSFER = 4
*      INVALID_TYPE            = 5
*      NO_AUTHORITY            = 6                           “as of 4.6C
*      OTHERS                  = 7.
*
*  CASE SY-SUBRC.
*    WHEN 1. “FILE_OPEN_ERROR
*      MESSAGE E036(PC). “Fehler beim Offnen der Download-Datei
*    WHEN 2. “FILE_READ_ERROR
*      MESSAGE E034(PC). “Fehler beim Schreiben der Daten
*    WHEN 3. “NO_BATCH
*      MESSAGE E005(PC).
*    WHEN 4. “GUI_REFUSE_FILETRANSFER
*      MESSAGE E015(PC).”Filetransfer nicht mit diesem Frontend
*    WHEN 5. “INVALID_TYPE
*      MESSAGE E132(PC). “Bitte gultigen Dateityp angeben
*    WHEN 6. “NO_AUTHORITY                                    “as of 4.6C
*      MESSAGE E001(BMEN).”keine Berechtigung zum Import
*    WHEN 7. “OTHERS
*      MESSAGE E038(PC). “Fehler beim Upload/Download
*  ENDCASE.

  DATA: ANSWER(1) TYPE C.
*  IF GT_SMEN_C[] IS INITIAL.
*    ANSWER = ‘2’.
*  ELSE.
**    CALL FUNCTION ‘POPUP_TO_CONFIRM’
**      EXPORTING
**        TITLEBAR                    = ‘Upload Favoriten'(TIT)
**        TEXT_QUESTION         = ‘How do you want to insert your Favorites'(001)
**        TEXT_BUTTON_1         = ‘Einmischen'(002)
**        TEXT_BUTTON_2         = ‘Anhängen'(003)
**        DEFAULT_BUTTON        = ‘1’
**        DISPLAY_CANCEL_BUTTON = ‘X’
**      IMPORTING
**        ANSWER                      = ANSWER
**      EXCEPTIONS
**        TEXT_NOT_FOUND              = 1
**        OTHERS                      = 2.
**    IF SY-SUBRC <> 0.
**      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
**    ENDIF.
    ANSWER = ‘2’.
*  ENDIF.

*———————————————————————–
* Merge
*———————————————————————–
  IF ANSWER = ‘1’.

    SORT GT_FILE STABLE BY PARENT_ID. ” No sort by object_id

*   1a. Build string of folder hierarchy for old favorites
    DATA: BEGIN OF GT_SMEN_C_HIER_TEXT OCCURS 0,
            OBJECT_ID LIKE GT_SMEN_COBJECT_ID,
            HIER_TEXT(1000),
          END OF GT_SMEN_C_HIER_TEXT.
    LOOP AT GT_SMEN_C.
      GT_SMEN_C_HIER_TEXTOBJECT_ID = GT_SMEN_COBJECT_ID.
      IF GT_SMEN_CREPORTTYPE IS INITIAL.
*       Folders: Use text
        GT_SMEN_C_HIER_TEXTHIER_TEXT = GT_SMEN_CTEXT.
      ELSE.
*       Other types: Use text, type, name, url
        CLEAR GT_SMEN_BUFFI.
        IF GT_SMEN_CREPORTTYPE = ‘OT’.
          READ TABLE GT_SMEN_BUFFI
            WITH KEY OBJECT_ID = GT_SMEN_COBJECT_ID.
        ENDIF.
        CONCATENATE GT_SMEN_CTEXT
                    GT_SMEN_CREPORTTYPE
                    GT_SMEN_CREPORT
                    GT_SMEN_BUFFIURL
            INTO GT_SMEN_C_HIER_TEXTHIER_TEXT
            SEPARATED BY ‘#’.
      ENDIF.
      IF GT_SMEN_CPARENT_ID > 1.
        DO.
          READ TABLE GT_SMEN_C WITH KEY OBJECT_ID = GT_SMEN_CPARENT_ID.
          IF SYSUBRC NE 0.
            EXIT.
          ENDIF.
          CONCATENATE GT_SMEN_CTEXT GT_SMEN_C_HIER_TEXTHIER_TEXT
            INTO GT_SMEN_C_HIER_TEXTHIER_TEXT
            SEPARATED BY ‘#’.
        ENDDO.
      ENDIF.
      APPEND GT_SMEN_C_HIER_TEXT.
    ENDLOOP.
*   1b. Build string of folder hierarchy for new favorites
    DATA: BEGIN OF GT_FILE_HIER_TEXT OCCURS 0,
            OBJECT_ID LIKE GT_FILEOBJECT_ID,
            HIER_TEXT(1000),
          END OF GT_FILE_HIER_TEXT.
    LOOP AT GT_FILE.
      GT_FILE_HIER_TEXTOBJECT_ID = GT_FILEOBJECT_ID.
      IF GT_FILERTYPE IS INITIAL.
*       Folders: Use text
        GT_FILE_HIER_TEXTHIER_TEXT = GT_FILETEXT.
      ELSE.
*       Other types: Use text, type, name, url
        CONCATENATE GT_FILETEXT
                    GT_FILERTYPE
                    GT_FILETCODE
                    GT_FILEURL
            INTO GT_FILE_HIER_TEXTHIER_TEXT
            SEPARATED BY ‘#’.
      ENDIF.
      IF GT_FILEPARENT_ID > 1.
        DO.
          READ TABLE GT_FILE WITH KEY OBJECT_ID = GT_FILEPARENT_ID.
          IF SYSUBRC NE 0.
            EXIT.
          ENDIF.
          CONCATENATE GT_FILETEXT GT_FILE_HIER_TEXTHIER_TEXT
            INTO GT_FILE_HIER_TEXTHIER_TEXT
            SEPARATED BY ‘#’.
        ENDDO.
      ENDIF.
      APPEND GT_FILE_HIER_TEXT.
    ENDLOOP.

*   2. Ignore existing folders and transactions in existing folders
    LOOP AT GT_FILE.
      READ TABLE GT_FILE_HIER_TEXT
        WITH KEY OBJECT_ID = GT_FILEOBJECT_ID.
      CHECK SYSUBRC = 0.
*     Find folder or transaction with same hirarchy text for current
*     item
      READ TABLE GT_SMEN_C_HIER_TEXT
        WITH KEY HIER_TEXT = GT_FILE_HIER_TEXTHIER_TEXT.
      IF SYSUBRC = 0.
*       Ignore item
        DELETE GT_FILE.
      ENDIF.
    ENDLOOP.
*   3. Append new transactions to existing folders
*      No merge on the first level (parent id = 1)
    LOOP AT GT_FILE
      WHERE RTYPE NE ‘  ‘
        AND PARENT_ID > 1.
      READ TABLE GT_FILE_HIER_TEXT
        WITH KEY OBJECT_ID = GT_FILEPARENT_ID.
      CHECK SYSUBRC = 0.
*     Find folder with same hirarchy text for
*     parent of currect item
      READ TABLE GT_SMEN_C_HIER_TEXT
        WITH KEY HIER_TEXT = GT_FILE_HIER_TEXTHIER_TEXT.
      IF SYSUBRC = 0.
        LOOP AT GT_SMEN_C
          WHERE PARENT_ID = GT_SMEN_C_HIER_TEXTOBJECT_ID.
          EXIT.
        ENDLOOP.
        IF SYSUBRC = 0.
*         Last item in folder
          CLEAR L_FIRST_NODE.
        ELSE.
*         Empty folder
          L_FIRST_NODE = ‘X’.
        ENDIF.
*       Add item and save
        P_TEXT = GT_FILETEXT.
        CALL FUNCTION ‘FAVOS_EVENT_ADD_TO_USER_SHELF’
          EXPORTING
            USER_NAME   = UNAME             “note 1597175
            TARGET_ID   = GT_SMEN_C_HIER_TEXTOBJECT_ID
            REPORTTYPE  = GT_FILERTYPE
            REPORT_NAME = GT_FILETCODE
            SAP_GUID    = gt_filesap_guid    ” space
            TEXT        = P_TEXT
            FIRST_NODE  = L_FIRST_NODE
            TARGET_SYST = SPACE               ” Always local
            URL         = GT_FILEURL
*          IMPORTING
*            NEW_ID      = NEW_OBJECT_ID ” A transaction cannot be used
*                                        ” as a parent
          TABLES
            USER_SHELF  = GT_SMEN_C
            USER_LINKS  = GT_SMEN_BUFFI.

*       Remove item to avoid additional append
        DELETE GT_FILE.
      ENDIF.
    ENDLOOP.
  ELSEIF ANSWER = ‘A’.                              ” Cancel
    MESSAGE S232(S#) RAISING ACTION_CANCELLED.
  ENDIF. ” Merge

*———————————————————————–
* Append remaining entries
*———————————————————————–
  IF NOT GT_FILE[] IS INITIAL.

*   Add to table
    DATA: L_PREV_PARENT_ID LIKE GT_FILEPARENT_ID.
    DATA: TARGET_ID LIKE SMEN_BUFFCPARENT_ID.
    DATA: BEGIN OF REPLACED_OBJECT_ID OCCURS 0,
            OLD LIKE SMEN_BUFFCOBJECT_ID,
            NEW LIKE SMEN_BUFFCOBJECT_ID,
          END OF REPLACED_OBJECT_ID.
*          loop at username into wa_username.
*            UNAME = wa_username-bname.
*            refresh REPLACED_OBJECT_ID.
    LOOP AT GT_FILE.
      IF    GT_FILEPARENT_ID > 1
        AND GT_FILEPARENT_ID NE L_PREV_PARENT_ID.
*       First item of a new folder
        L_FIRST_NODE = ‘X’.
      ELSE.
*       Next item of a forder
        CLEAR L_FIRST_NODE.
      ENDIF.
      L_PREV_PARENT_ID = GT_FILEPARENT_ID.
*     Add item and save
      P_TEXT = GT_FILETEXT.
*     Find parent
      READ TABLE REPLACED_OBJECT_ID
        WITH KEY OLD = GT_FILEPARENT_ID.
      IF SYSUBRC = 0.
        TARGET_ID = REPLACED_OBJECT_IDNEW.
      ELSE.
        TARGET_ID = 1.
      ENDIF.
      CALL FUNCTION ‘FAVOS_EVENT_ADD_TO_USER_SHELF’
        EXPORTING
          USER_NAME   = uname            “note 1597175
          TARGET_ID   = TARGET_ID
          REPORTTYPE  = GT_FILERTYPE
          REPORT_NAME = GT_FILETCODE
          SAP_GUID    = gt_filesap_guid    ” space
          TEXT        = P_TEXT
          FIRST_NODE  = L_FIRST_NODE
          TARGET_SYST = SPACE               ” Always local
          URL         = GT_FILEURL
        IMPORTING
          NEW_ID      = NEW_OBJECT_ID
        TABLES
          USER_SHELF  = GT_SMEN_C
          USER_LINKS  = GT_SMEN_BUFFI.
*     Store new object id
      REPLACED_OBJECT_IDOLD = GT_FILEOBJECT_ID.
      REPLACED_OBJECT_IDNEW = NEW_OBJECT_ID.
      APPEND REPLACED_OBJECT_ID.
    ENDLOOP.
*    endloop.
  ENDIF.

ENDFUNCTION.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply