Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
495

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 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.
loop at it_user into wa_user.
  CALL FUNCTION 'ZMM_FAV_UPLOAD'
   EXPORTING
     UNAME                  = wa_user-bname
    TABLES
*      USERNAME               = it_user
gt_file = gt_file
*   EXCEPTIONS
*     ACTION_CANCELLED       = 1
*     OTHERS                 = 2
            .
  IF SY-SUBRC <> 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 SMENSAPLNT-TEXT,
        L_FIRST_NODE(1TYPE C,
        wa_username type usr02,
        L_ENCODING       TYPE ABAP_ENCOD,
        NEW_OBJECT_ID    LIKE GT_SMEN_C-OBJECT_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_C-OBJECT_ID,
            HIER_TEXT(1000),
          END OF GT_SMEN_C_HIER_TEXT.
    LOOP AT GT_SMEN_C.
      GT_SMEN_C_HIER_TEXT-OBJECT_ID = GT_SMEN_C-OBJECT_ID.
      IF GT_SMEN_C-REPORTTYPE IS INITIAL.
*       Folders: Use text
        GT_SMEN_C_HIER_TEXT-HIER_TEXT = GT_SMEN_C-TEXT.
      ELSE.
*       Other types: Use text, type, name, url
        CLEAR GT_SMEN_BUFFI.
        IF GT_SMEN_C-REPORTTYPE = 'OT'.
          READ TABLE GT_SMEN_BUFFI
            WITH KEY OBJECT_ID = GT_SMEN_C-OBJECT_ID.
        ENDIF.
        CONCATENATE GT_SMEN_C-TEXT
                    GT_SMEN_C-REPORTTYPE
                    GT_SMEN_C-REPORT
                    GT_SMEN_BUFFI-URL
            INTO GT_SMEN_C_HIER_TEXT-HIER_TEXT
            SEPARATED BY '#'.
      ENDIF.
      IF GT_SMEN_C-PARENT_ID > 1.
        DO.
          READ TABLE GT_SMEN_C WITH KEY OBJECT_ID = GT_SMEN_C-PARENT_ID.
          IF SY-SUBRC NE 0.
            EXIT.
          ENDIF.
          CONCATENATE GT_SMEN_C-TEXT GT_SMEN_C_HIER_TEXT-HIER_TEXT
            INTO GT_SMEN_C_HIER_TEXT-HIER_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_FILE-OBJECT_ID,
            HIER_TEXT(1000),
          END OF GT_FILE_HIER_TEXT.
    LOOP AT GT_FILE.
      GT_FILE_HIER_TEXT-OBJECT_ID = GT_FILE-OBJECT_ID.
      IF GT_FILE-RTYPE IS INITIAL.
*       Folders: Use text
        GT_FILE_HIER_TEXT-HIER_TEXT = GT_FILE-TEXT.
      ELSE.
*       Other types: Use text, type, name, url
        CONCATENATE GT_FILE-TEXT
                    GT_FILE-RTYPE
                    GT_FILE-TCODE
                    GT_FILE-URL
            INTO GT_FILE_HIER_TEXT-HIER_TEXT
            SEPARATED BY '#'.
      ENDIF.
      IF GT_FILE-PARENT_ID > 1.
        DO.
          READ TABLE GT_FILE WITH KEY OBJECT_ID = GT_FILE-PARENT_ID.
          IF SY-SUBRC NE 0.
            EXIT.
          ENDIF.
          CONCATENATE GT_FILE-TEXT GT_FILE_HIER_TEXT-HIER_TEXT
            INTO GT_FILE_HIER_TEXT-HIER_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_FILE-OBJECT_ID.
      CHECK SY-SUBRC = 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_TEXT-HIER_TEXT.
      IF SY-SUBRC = 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_FILE-PARENT_ID.
      CHECK SY-SUBRC = 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_TEXT-HIER_TEXT.
      IF SY-SUBRC = 0.
        LOOP AT GT_SMEN_C
          WHERE PARENT_ID = GT_SMEN_C_HIER_TEXT-OBJECT_ID.
          EXIT.
        ENDLOOP.
        IF SY-SUBRC = 0.
*         Last item in folder
          CLEAR L_FIRST_NODE.
        ELSE.
*         Empty folder
          L_FIRST_NODE = 'X'.
        ENDIF.
*       Add item and save
        P_TEXT = GT_FILE-TEXT.
        CALL FUNCTION 'FAVOS_EVENT_ADD_TO_USER_SHELF'
          EXPORTING
            USER_NAME   = UNAME             "note 1597175
            TARGET_ID   = GT_SMEN_C_HIER_TEXT-OBJECT_ID
            REPORTTYPE  = GT_FILE-RTYPE
            REPORT_NAME = GT_FILE-TCODE
            SAP_GUID    = gt_file-sap_guid    " space
            TEXT        = P_TEXT
            FIRST_NODE  = L_FIRST_NODE
            TARGET_SYST = SPACE               " Always local
            URL         = GT_FILE-URL
*          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_FILE-PARENT_ID.
    DATA: TARGET_ID LIKE SMEN_BUFFC-PARENT_ID.
    DATA: BEGIN OF REPLACED_OBJECT_ID OCCURS 0,
            OLD LIKE SMEN_BUFFC-OBJECT_ID,
            NEW LIKE SMEN_BUFFC-OBJECT_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_FILE-PARENT_ID > 1
        AND GT_FILE-PARENT_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_FILE-PARENT_ID.
*     Add item and save
      P_TEXT = GT_FILE-TEXT.
*     Find parent
      READ TABLE REPLACED_OBJECT_ID
        WITH KEY OLD = GT_FILE-PARENT_ID.
      IF SY-SUBRC = 0.
        TARGET_ID = REPLACED_OBJECT_ID-NEW.
      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_FILE-RTYPE
          REPORT_NAME = GT_FILE-TCODE
          SAP_GUID    = gt_file-sap_guid    " space
          TEXT        = P_TEXT
          FIRST_NODE  = L_FIRST_NODE
          TARGET_SYST = SPACE               " Always local
          URL         = GT_FILE-URL
        IMPORTING
          NEW_ID      = NEW_OBJECT_ID
        TABLES
          USER_SHELF  = GT_SMEN_C
          USER_LINKS  = GT_SMEN_BUFFI.
*     Store new object id
      REPLACED_OBJECT_ID-OLD = GT_FILE-OBJECT_ID.
      REPLACED_OBJECT_ID-NEW = NEW_OBJECT_ID.
      APPEND REPLACED_OBJECT_ID.
    ENDLOOP.
*    endloop.
  ENDIF.

ENDFUNCTION.

Labels in this area