下载SE78上的图片

*&---------------------------------------------------------------------*
*& Report  ZDGRSE78
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

"有时候我们需要备份图片从SE78, 可以利用下面的代码实现:
REPORT ZDGRSE78 NO STANDARD PAGE HEADING.
DATA : G_BYTECOUNT             TYPE I,
       G_CONTENT               TYPE STANDARD TABLE OF
                                    BAPICONTEN INITIAL SIZE 0,
       G_BITMAP_FILE_BYTECOUNT TYPE I,
       G_FILE_NAME             TYPE STRING,
       BEGIN OF G_BITMAP_FILE OCCURS 0,
        LINE(255) TYPE X,
       END OF G_BITMAP_FILE,
       L_BITMAPS TYPE TABLE OF STXBITMAPS WITH HEADER LINE,
       LIT_SCRFIELDS TYPE TABLE OF DYNPREAD WITH HEADER LINE.
PARAMETER: P_BTYPE LIKE STXBITMAPS-TDBTYPE DEFAULT 'BMON', " 'BMON'."BMON:black/white, BCOL:color
           P_IMAGE LIKE  STXBITMAPS-TDNAME
                   DEFAULT 'ENJOY', "name of the image
           P_FILE  LIKE  IBIPPARMS-PATH
                   DEFAULT 'D:\enjoy.bmp'.

*F4 help to get file path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      FILE_NAME = P_FILE.

*F4 help search for image files
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IMAGE.
  CALL FUNCTION 'SAPSCRIPT_SEARCH_GRAPHIC_BDS'
    EXPORTING
      SELECTION_SCREEN   = 'X'
      SELECT_ENTRY       = 'X'
      SELECTION_SHOW     = 'X'
    IMPORTING
      E_NAME             = P_IMAGE
    TABLES
      T_SELECTIONS       = L_BITMAPS
    EXCEPTIONS
      NOTHING_FOUND      = 1
      SELECTION_CANCELED = 2
      INTERNAL_ERROR     = 3
      OTHERS             = 4.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

START-OF-SELECTION.
  MOVE P_FILE TO G_FILE_NAME.
*Get graphics to BDS
  CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'
    EXPORTING
      I_OBJECT       = 'GRAPHICS'
      I_NAME         = P_IMAGE
      I_ID           = 'BMAP'
      I_BTYPE        = P_BTYPE
    IMPORTING
      E_BYTECOUNT    = G_BYTECOUNT
    TABLES
      CONTENT        = G_CONTENT
    EXCEPTIONS
      NOT_FOUND      = 1
      BDS_GET_FAILED = 2
      BDS_NO_CONTENT = 3
      OTHERS         = 4.
  IF SY-SUBRC <> 0.
    MESSAGE I208(00) WITH 'Image does not exists.'(000).
  ENDIF.

  IF NOT G_CONTENT[] IS INITIAL.
*Convert to BITMAP
    CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
      EXPORTING
        OLD_FORMAT               = 'BDS'
        NEW_FORMAT               = 'BMP'
        BITMAP_FILE_BYTECOUNT_IN = G_BYTECOUNT
      IMPORTING
        BITMAP_FILE_BYTECOUNT    = G_BITMAP_FILE_BYTECOUNT
      TABLES
        BDS_BITMAP_FILE          = G_CONTENT
        BITMAP_FILE              = G_BITMAP_FILE
      EXCEPTIONS
        OTHERS                   = 1.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
*Download to PC
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        BIN_FILESIZE            = G_BITMAP_FILE_BYTECOUNT
        FILENAME                = G_FILE_NAME
        FILETYPE                = 'BIN'
      TABLES
        DATA_TAB                = G_BITMAP_FILE
      EXCEPTIONS
        FILE_WRITE_ERROR        = 1
        NO_BATCH                = 2
        GUI_REFUSE_FILETRANSFER = 3
        INVALID_TYPE            = 4
        NO_AUTHORITY            = 5
        UNKNOWN_ERROR           = 6
        HEADER_NOT_ALLOWED      = 7
        SEPARATOR_NOT_ALLOWED   = 8
        FILESIZE_NOT_ALLOWED    = 9
        HEADER_TOO_LONG         = 10
        DP_ERROR_CREATE         = 11
        DP_ERROR_SEND           = 12
        DP_ERROR_WRITE          = 13
        UNKNOWN_DP_ERROR        = 14
        ACCESS_DENIED           = 15
        DP_OUT_OF_MEMORY        = 16
        DISK_FULL               = 17
        DP_TIMEOUT              = 18
        FILE_NOT_FOUND          = 19
        DATAPROVIDER_EXCEPTION  = 20
        CONTROL_FLUSH_ERROR     = 21
        OTHERS                  = 22.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.

你可能感兴趣的:(SAP,SE78,下载图片)