使用如下代码最方便:
REPORT ZDOWN_LOGO.
*********************************************************************
* Variable declaration
*********************************************************************
DATA: V_GRAPHIC_SIZE TYPE I,
V_GRAPHIC_XSTR TYPE XSTRING,
V_GRAPHIC_CONV TYPE I,
V_GRAPHIC_OFFS TYPE I,
V_FILE TYPE STRING.
*********************************************************************
* Table declaration
*********************************************************************
DATA: BEGIN OF I_GRAPHIC_TABLE OCCURS 0,
LINE(255) TYPE X,
END OF I_GRAPHIC_TABLE.
*********************************************************************
* Structure declaration
*********************************************************************
DATA: ST_STXBITMAPS TYPE STXBITMAPS.
*********************************************************************
* Selection screen
*********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_OBJECT LIKE ST_STXBITMAPS-TDOBJECT DEFAULT 'GRAPHICS'
MODIF ID ABC ,
P_NAME LIKE ST_STXBITMAPS-TDNAME,
P_ID LIKE ST_STXBITMAPS-TDID DEFAULT 'BMAP'
MODIF ID ABC ,
P_TYPE LIKE ST_STXBITMAPS-TDBTYPE,
P_DIR TYPE LOCALFILE.SELECTION-SCREEN END OF BLOCK B1.
*********************************************************************
* At Selection-screen output event
*********************************************************************
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'ABC' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
*********************************************************************
* At Selection-screen on value-request event
*********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_DIR.
DATA: L_FOLDER TYPE STRING.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
EXPORTING
WINDOW_TITLE = 'Select Folder'
INITIAL_FOLDER = 'C:/'
CHANGING
SELECTED_FOLDER = L_FOLDER
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4. IF SY-SUBRC = 0. P_DIR = L_FOLDER. ENDIF.
*********************************************************************
* Start-of-selection event
*********************************************************************
START-OF-SELECTION.
ST_STXBITMAPS-TDOBJECT = P_OBJECT.
ST_STXBITMAPS-TDNAME = P_NAME.
ST_STXBITMAPS-TDID = P_ID.
ST_STXBITMAPS-TDBTYPE = P_TYPE.
* Get the bmp image from BDS in hex string format
CALL METHOD CL_SSF_XSF_UTILITIES=>GET_BDS_GRAPHIC_AS_BMP
EXPORTING
P_OBJECT = ST_STXBITMAPS-TDOBJECT
P_NAME = ST_STXBITMAPS-TDNAME
P_ID = ST_STXBITMAPS-TDID
P_BTYPE = ST_STXBITMAPS-TDBTYPE
RECEIVING
P_BMP = V_GRAPHIC_XSTR
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC = 0.
* Find the length of hex string
V_GRAPHIC_SIZE = XSTRLEN( V_GRAPHIC_XSTR ).
CHECK V_GRAPHIC_SIZE > 0.
V_GRAPHIC_CONV = V_GRAPHIC_SIZE.
V_GRAPHIC_OFFS = 0.
* Populate internal table from this hex string
WHILE V_GRAPHIC_CONV > 255.
I_GRAPHIC_TABLE-LINE = V_GRAPHIC_XSTR+V_GRAPHIC_OFFS(255).
APPEND I_GRAPHIC_TABLE.
V_GRAPHIC_OFFS = V_GRAPHIC_OFFS + 255.
V_GRAPHIC_CONV = V_GRAPHIC_CONV - 255.
ENDWHILE.
I_GRAPHIC_TABLE-LINE = V_GRAPHIC_XSTR+V_GRAPHIC_OFFS(V_GRAPHIC_CONV).
APPEND I_GRAPHIC_TABLE.
* Prepare file name and file path
CONCATENATE P_DIR '/' P_NAME '.BMP' INTO V_FILE.
* Download image
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = V_GRAPHIC_SIZE
FILENAME = V_FILE
FILETYPE = 'BIN'
TABLES
DATA_TAB = I_GRAPHIC_TABLE
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.
WRITE: 'File downloaded successfully'(002).
ELSE.
WRITE: 'Error during file download'(003).
ENDIF.
ELSE.
CASE SY-SUBRC.
WHEN 1.
WRITE: 'Image not found'(004).
WHEN OTHERS.
WRITE: 'Error in Image retrieval'(005).
ENDCASE.
ENDIF.