Download/Upload SAP Users Favorites

*
*  This program allows you to transfer the user Favorites from one PC to another. 
*
*  Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*                https://www.erpgreat.com
*
REPORT ZFAVORITES.

DATA :   G_FILE(128)   TYPE C.
DATA :   G_PATH(80)    TYPE C.
DATA :   G_END(8)      TYPE C.
DATA :   G_SUBRC       LIKE SY-SUBRC.

PARAMETERS: P_UNAME LIKE SY-UNAME DEFAULT SY-UNAME.
PARAMETERS: P_LANGU LIKE SY-LANGU DEFAULT SY-LANGU.

SELECTION-SCREEN SKIP.

PARAMETERS:     P_IMP  RADIOBUTTON GROUP ACT .
PARAMETERS:     P_EXP  RADIOBUTTON GROUP ACT DEFAULT 'X'.

SELECTION-SCREEN ULINE.
SELECTION-SCREEN BEGIN OF BLOCK FIL.
PARAMETERS:     P_TYPE LIKE RLGRAP-FILETYPE DEFAULT 'ASC'.
PARAMETERS:     P_PATH LIKE G_PATH DEFAULT 'C:\TEMP\XXX.MEN'.

SELECTION-SCREEN END   OF BLOCK FIL.

DATA: IT_USER_NODES TYPE TABLE OF BXMNODES1 WITH HEADER LINE.
DATA: IT_FAV_NODES TYPE TABLE OF BXMNODES  WITH HEADER LINE.

DATA: BEGIN OF IT_PCF OCCURS 0,
       LINE(4096) TYPE C.
DATA: END OF IT_PCF.

INITIALIZATION.
  REPLACE 'XXX' WITH SY-UNAME INTO P_PATH.
  CONDENSE P_PATH NO-GAPS.
  SY-TITLE = 'UPLOAD/DOWNLOAD FAVORITE'.

START-OF-SELECTION.

  CLEAR IT_USER_NODES[].
  CLEAR IT_FAV_NODES[].

  G_FILE = P_UNAME.

  IF P_UNAME <> SY-UNAME.
    MESSAGE W398(00) WITH 'CURRENT USER <> USER TO BE MODIFIED!'.
  ENDIF.

  IF P_IMP  = 'X'.
    PERFORM IMPORT_FAV         TABLES IT_FAV_NODES.
    PERFORM WRITE_FAV_DB       TABLES IT_FAV_NODES.
  ELSEIF P_EXP  = 'X'.
    PERFORM EXPORT_FAV         TABLES IT_FAV_NODES.
  ENDIF.

FORM DATA_EXPORT TABLES   PIT_PCF
                 USING    P_FILE.
    CALL FUNCTION 'DOWNLOAD'
         EXPORTING
              FILENAME               = P_FILE
             FILETYPE                = P_TYPE
         TABLES
              DATA_TAB                = PIT_PCF
         EXCEPTIONS
              FILE_OPEN_ERROR         = 1
              FILE_WRITE_ERROR        = 2
              INVALID_FILESIZE        = 3
              INVALID_TABLE_WIDTH     = 4
              INVALID_TYPE            = 5
              NO_BATCH                = 6
              UNKNOWN_ERROR           = 7
              GUI_REFUSE_FILETRANSFER = 8
              OTHERS                  = 9.
    IF SY-SUBRC NE 0.
      WRITE: / 'FAILURE IN DOWNLOAD' , P_FILE.
    ENDIF.
ENDFORM.

FORM DATA_IMPORT TABLES   PIT_PCF
                 USING    P_FILE P_SUBRC.
    CALL FUNCTION 'UPLOAD'
         EXPORTING
              FILENAME                = P_FILE
              FILETYPE                = P_TYPE
         TABLES
              DATA_TAB                = PIT_PCF
         EXCEPTIONS
              CONVERSION_ERROR        = 1
              FILE_OPEN_ERROR         = 2
              FILE_READ_ERROR         = 3
              INVALID_TABLE_WIDTH     = 4
              INVALID_TYPE            = 5
              NO_BATCH                = 6
              UNKNOWN_ERROR           = 7
              GUI_REFUSE_FILETRANSFER = 8
              OTHERS                  = 9.
    IF SY-SUBRC NE 0.
      WRITE: / 'UPLOAD FAILED' , P_FILE.
      P_SUBRC = SY-SUBRC .
    ENDIF.
ENDFORM.

FORM IMPORT_FAV TABLES   PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
  G_FILE = P_PATH.
  PERFORM DATA_IMPORT  TABLES IT_FAV_NODES USING  G_FILE G_SUBRC .
ENDFORM.

FORM EXPORT_FAV TABLES   PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
  CALL FUNCTION 'BX_FAVOS_READ_ALL_NODES'
       EXPORTING
            USER_NAME              = P_UNAME
            LANGUAGE               = P_LANGU
       TABLES
            OUTPUT_NODES_AND_TEXTS = IT_FAV_NODES.

  G_FILE = P_PATH.
  PERFORM DATA_EXPORT  TABLES IT_FAV_NODES USING  G_FILE .
ENDFORM.

FORM WRITE_FAV_DB TABLES   PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
    CALL FUNCTION 'BX_FAVOS_WRITE_ALL_NODES'
         EXPORTING
              USER_NAME             = P_UNAME
              TARGET_CLIENT         = SY-MANDT
         TABLES
              INPUT_NODES_AND_TEXTS = PIT_FAV_NODES.

ENDFORM.

Fast Links:
Sample Download Programs:

Get help for your ABAP problems
Do you have a ABAP Question?

SAP Books
SAP Certification, Functional, Basis Administration and ABAP Programming Reference Books

ABAP Programming Tips
ABAP and Samples Program Codes for Abapers

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.