0% found this document useful (0 votes)
186 views6 pages

Files

The document discusses how to perform file operations like providing F4 help, uploading and downloading files using ABAP on SAP presentation server. It provides code examples to use function modules F4_FILENAME, GUI_UPLOAD and GUI_DOWNLOAD or methods of CL_GUI_FRONTEND_SERVICES class to provide F4 help for files, upload data from file to internal table and download data from internal table to file.

Uploaded by

bharath_sajja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
186 views6 pages

Files

The document discusses how to perform file operations like providing F4 help, uploading and downloading files using ABAP on SAP presentation server. It provides code examples to use function modules F4_FILENAME, GUI_UPLOAD and GUI_DOWNLOAD or methods of CL_GUI_FRONTEND_SERVICES class to provide F4 help for files, upload data from file to internal table and download data from internal table to file.

Uploaded by

bharath_sajja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Archive for the Files Category

ABAP F4 Help for File on SAP Presentation Server


To provide F4 help for SAP presentation server file using ABAP use
function module F4_FILENAME or FILE_OPEN_DIALOG method of
CL_GUI_FRONTEND_SERVICES class.
Upload File from SAP Presentation Server using ABAP
To upload a file from SAP presentation server using ABAP use function
module GUI_UPLOAD or GUI_UPLOAD method of
CL_GUI_FRONTEND_SERVICES class.
Download File to SAP Presentation Server using ABAP
To download a file to SAP presentation server using ABAP try function
module GUI_DOWNLOAD or GUI_DOWNLOAD method of
CL_GUI_FRONTEND_SERVICES class.

ABAP F4 Help for File on SAP Presentation Server

Use the following steps to provide ABAP F4 help for SAP presentation
server file on selection screen.
Declare a input field(PARAMETER) for filename.
Use function module F4_FILENAME or FILE_OPEN_DIALOG method of
CL_GUI_FRONTEND_SERVICES class in AT SELECTION-SCREEN ON VALUEREQUEST FOR FIELD event to provide F4 help for SAP presentation server
file.
Upload data from/Download data to file.
Below program uses function module F4_FILENAME to provide ABAP F4 help
for a file on presentation server.
*---------------------------------------------------------------------*
*
SELECTION-SCREEN
*---------------------------------------------------------------------*
PARAMETERS: p_file TYPE ibipparms-path OBLIGATORY.
*---------------------------------------------------------------------*
*
AT SELECTION-SCREEN ON VALUE-REQUEST

*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*
*
*
*

CALL FUNCTION 'F4_FILENAME'


EXPORTING
PROGRAM_NAME
=
DYNPRO_NUMBER
=
FIELD_NAME
=
IMPORTING
file_name
= p_file.

*---------------------------------------------------------------------*
*
START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
WRITE:/ 'Filename : ', p_file.
When you execute the above program and press F4 help for file on
selection screen, file dialog pop up will be displayed.
You can also use FILE_OPEN_DIALOG method of CL_GUI_FRONTEND_SERVICES
class to provide the F4 help for presentation server file on selection
screen. Below program uses FILE_OPEN_DIALOG method of
CL_GUI_FRONTEND_SERVICES class to provide ABAP F4 help for a file on
presentation server.
*---------------------------------------------------------------------*
*
DATA DECLARATION
*---------------------------------------------------------------------*
DATA: gv_rc TYPE i.
DATA: gt_file_table TYPE filetable,
gwa_file_table TYPE file_table.
*---------------------------------------------------------------------*
*
SELECTION-SCREEN
*---------------------------------------------------------------------*
PARAMETERS: p_file TYPE ibipparms-path OBLIGATORY.
*---------------------------------------------------------------------*
*
AT SELECTION-SCREEN ON VALUE-REQUEST
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select a file'
CHANGING

file_table
= gt_file_table
rc
= gv_rc.
IF sy-subrc = 0.
READ TABLE gt_file_table INTO gwa_file_table INDEX 1.
p_file = gwa_file_table-filename.
ENDIF.
*---------------------------------------------------------------------*
*
START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
WRITE:/ 'Filename : ', p_file.

Upload File from SAP Presentation Server using ABAP

Use the following steps to upload data from a file in SAP application
server to ABAP internal table.
Declare a ABAP internal table.
Use function module GUI_UPLOAD or GUI_UPLOAD method of
CL_GUI_FRONTEND_SERVICES class to upload the data to ABAP internal
table.
Process the data in the internal table.
Below program uses the function module GUI_UPLOAD to upload the file.
*---------------------------------------------------------------------*
*
Data Decalaration
*---------------------------------------------------------------------*
DATA: gt_spfli TYPE TABLE OF spfli,
gwa_spfli TYPE spfli.
DATA: gv_filename TYPE string,
gv_filetype TYPE char10.
*---------------------------------------------------------------------*
*
START-OF-SELECTION
*---------------------------------------------------------------------*
PERFORM read_file.
PERFORM process_data.
*&--------------------------------------------------------------------*

*&
Form read_file
*&--------------------------------------------------------------------*
FORM read_file.
*Move complete file path to file name
gv_filename = 'C:\test\data.txt'.
*Upload the data from a file in SAP presentation server to internal
*table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename
= gv_filename
filetype
= 'ASC'
has_field_separator = 'X'
TABLES
data_tab
= gt_spfli.
ENDFORM.

" read_file

*&--------------------------------------------------------------------*
*&
Form process_data
*&--------------------------------------------------------------------*
FORM process_data.
*Display the internal table data
LOOP AT gt_spfli INTO gwa_spfli.
WRITE:/ gwa_spfli-carrid,
gwa_spfli-connid,
gwa_spfli-countryfr,
gwa_spfli-cityfrom,
gwa_spfli-airpfrom,
gwa_spfli-countryto,
gwa_spfli-cityto,
gwa_spfli-airpto,
gwa_spfli-arrtime.
CLEAR: gwa_spfli.
ENDLOOP.
ENDFORM.
" process_data
When you execute the above program reads the data from the file in
presentation server and displays the following output.
You can also use GUI_UPLOAD method of CL_GUI_FRONTEND_SERVICES class
to upload file from presentation server. Instead of calling GUI_UPLOAD
function module in the read_file subroutine of above program, call the
GUI_UPLOAD method of **CL_GUI_FRONTEND_SERVICES class.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename
= gv_filename
filetype
= 'ASC'
has_field_separator = 'X'

CHANGING
data_tab

= gt_spfli.

Download File to SAP Presentation Server using ABAP

Use the following steps to download the ABAP internal table data to a
file in SAP application server.
Declare a ABAP internal table.
Fill the internal table with required data.
Use function module GUI_DOWNLOAD or GUI_DOWNLOAD method of
CL_GUI_FRONTEND_SERVICES class to download the data.
Below program uses function module GUI_DOWNLOAD to download the file.
*---------------------------------------------------------------------*
*
Data Decalaration
*---------------------------------------------------------------------*
DATA: gt_spfli TYPE TABLE OF spfli,
gwa_spfli TYPE spfli.
DATA: gv_filename TYPE string,
gv_filetype TYPE char10.
*---------------------------------------------------------------------*
*
START-OF-SELECTION
*---------------------------------------------------------------------*
PERFORM get_data.
IF NOT gt_spfli[] IS INITIAL.
PERFORM save_file.
ELSE.
MESSAGE 'No data found' TYPE 'I'.
ENDIF.
*&--------------------------------------------------------------------*
*&
Form get_data
*&--------------------------------------------------------------------*
FORM get_data.
*Get data from table SPFLI
SELECT * FROM spfli
INTO TABLE gt_spfli.
ENDFORM.
" get_data

*&--------------------------------------------------------------------*
*&
Form save_file
*&--------------------------------------------------------------------*
FORM save_file.
*Move complete file path to file name
gv_filename = 'C:\test\data.txt'.
*Download the internal table data into a file in SAP presentation
server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename
= gv_filename
filetype
= 'ASC'
write_field_separator
= 'X'
TABLES
data_tab
= gt_spfli.
ENDFORM.
" save_file
When you execute the above program, the file data.txt will be
downloaded to C:\test.
We can also use GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES class
to download the file. Instead of calling GUI_DOWNLOAD function module
in the save_file subroutine of above program, call the GUI_DOWNLOAD
method of CL_GUI_FRONTEND_SERVICES class.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename
= gv_filename
filetype
= 'ASC'
write_field_separator = 'X'
CHANGING
data_tab
= gt_spfli.

You might also like