To Download Data From App Server To Present Server
To Download Data From App Server To Present Server
Applies to:
ABAP
Summary
Since it’s not possible to download data to presentation server in background, we first download the data to
application server file, then read this application server file and save it to presentation server in foreground,
which ideally means each such download program requires another program which takes the file structure
into consideration and download it to presentation server.
This code snippet can be used to download data from files on application server to presentation server in
foreground.
Author: Raghavendra AY
Company: Infosys Technologies Limited
Created on: 24 Jan 2007
Author Bio
© 2006 SAP AG 1
To download data from Application server files to presentation server
Table of Contents
© 2006 SAP AG 2
To download data from Application server files to presentation server
Example
In this example we consider two report programs Sales Report and Purchase order report on execution of
which the data will be stored on application server files.
Sales Report
© 2006 SAP AG 3
To download data from Application server files to presentation server
© 2006 SAP AG 4
To download data from Application server files to presentation server
In a typical scenario if we need to download these two application server files to desktop, we need to write
Two programs as the file structure is different for these two application server files
© 2006 SAP AG 5
To download data from Application server files to presentation server
Short text
This program can be used to download files from Application server to presentaion server.
2)Maximum length of the field can be changed by specifying the length in selection screen
parameter
3)First line of the Application server file should contain the description of each field.
*&---------------------------------------------------------------------*
*& Report ZDOWNLOADFILE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZDOWNLOADFILE
MESSAGE-ID B1 .
*---------------------------------------------------------------------*
* INCLUDES *
*---------------------------------------------------------------------*
INCLUDE ZDOWNLOADFILE_TOP.
INCLUDE ZDOWNLOADFILE_FORM.
*---------------------------------------------------------------------*
* EVENT-AT SELECTION-SCREEN *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON pa_appl.
PERFORM check_file_exists USING pa_appl.
© 2006 SAP AG 6
To download data from Application server files to presentation server
*---------------------------------------------------------------------*
* EVENT INITIALIZATION *
*---------------------------------------------------------------------*
INITIALIZATION.
PERFORM initialization.
*---------------------------------------------------------------------*
* EVENT START-OF-SELECTION *
*---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Include ZDOWNLOADFILE_TOP *
*&---------------------------------------------------------------------*
*--------------------------------------------------------------------*
* Internal tables *
© 2006 SAP AG 7
To download data from Application server files to presentation server
*--------------------------------------------------------------------*
DATA: gt_header TYPE STANDARD TABLE OF ty_header,
gt_fieldcat TYPE lvc_t_fcat.
*---------------------------------------------------------------------*
* Work areas *
*---------------------------------------------------------------------*
DATA: gs_header TYPE ty_header,
gs_fieldcat TYPE lvc_s_fcat.
*---------------------------------------------------------------------*
* SELECTION SCREEN *
© 2006 SAP AG 8
To download data from Application server files to presentation server
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-f01.
PARAMETERS: pa_appl LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& Include ZDOWNLOADFILE_FORM *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form f4_dxfilename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_pa_appl text
*----------------------------------------------------------------------*
form f4_dxfilename using p_file.
DATA: wa_file LIKE dxfields-longpath.
CLEAR: wa_file.
© 2006 SAP AG 9
To download data from Application server files to presentation server
importing
o_path = wa_file
exceptions
rfc_error =1
error_with_gui =2
others =3
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
p_file = wa_file.
endif.
*&---------------------------------------------------------------------*
*& Form f4_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_pa_pres text
*----------------------------------------------------------------------*
form f4_filename using p_data.
*&---------------------------------------------------------------------*
*& Form check_file_exists
*&---------------------------------------------------------------------*
© 2006 SAP AG 10
To download data from Application server files to presentation server
* text
*----------------------------------------------------------------------*
* -->P_pa_appl text
*----------------------------------------------------------------------*
form check_file_exists using p_file.
DATA: wa_file LIKE rlgrap-filename.
wa_file = p_file.
OPEN DATASET wa_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 8.
MESSAGE E714
WITH text-m01 p_file text-m02.
ELSE.
CLOSE DATASET p_file.
ENDIF.
*&---------------------------------------------------------------------*
*& Form build_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_header .
concatenate sy-uname
co_slash
gs_adrp-name_text(36)
co_slash
into gs_char50.
© 2006 SAP AG 11
To download data from Application server files to presentation server
condense gs_char50.
clear gs_usr02-class.
select single class
into (gs_usr02-class)
from usr02
where bname = sy-uname.
concatenate gs_char50
gs_usr02-class
into gs_char50.
condense gs_char50.
© 2006 SAP AG 12
To download data from Application server files to presentation server
*&---------------------------------------------------------------------*
*& Form determine_fields
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form determine_fields .
DATA: wa_data(600) TYPE c.
CLEAR: wa_count,wa_start,wa_end,wa_data.
wa_start = 0.
wa_end = 1.
OPEN DATASET pa_appl FOR INPUT IN TEXT MODE ENCODING DEFAULT.
READ DATASET pa_appl INTO wa_data.
wa_len = STRLEN( wa_data ).
DO wa_len TIMES.
IF wa_data+wa_start(wa_end) EQ
cl_abap_char_utilities=>horizontal_tab.
wa_count = wa_count + 1.
ENDIF.
wa_start = wa_start + 1.
ENDDO.
CLOSE DATASET pa_appl.
wa_count = wa_count + 1.
endform. " determine_fields
© 2006 SAP AG 13
To download data from Application server files to presentation server
*&---------------------------------------------------------------------*
*& Form build_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_itab .
DATA: wa_len(4) TYPE c.
CLEAR: wa_len.
IF pa_len IS INITIAL.
wa_len = 40.
ELSE.
wa_len = pa_len.
ENDIF.
col = 1.
DO wa_count TIMES.
CONCATENATE 'FIELD' col INTO wa_field.
gs_fieldcat-fieldname = wa_field.
gs_fieldcat-outputlen = wa_len.
gs_fieldcat-datatype = 'CHAR'.
gs_fieldcat-col_pos = col.
col = col + 1.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR: wa_field.
ENDDO.
© 2006 SAP AG 14
To download data from Application server files to presentation server
col = 1.
OPEN DATASET pa_appl FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET pa_appl INTO wa_data.
IF sy-subrc <> 0.
CLOSE DATASET pa_appl.
RETURN.
ELSE.
wa_start = 0.
lv_index = 1.
DO wa_count TIMES.
ASSIGN COMPONENT lv_index OF STRUCTURE <wa_line> TO <fs_line>.
FIND cl_abap_char_utilities=>horizontal_tab
IN wa_data+wa_start(*) MATCH OFFSET wa_off.
IF sy-subrc = 0.
IF wa_off NE 0.
<fs_line> = wa_data+wa_start(wa_off).
ENDIF.
wa_start = wa_start + wa_off + 1.
lv_index = lv_index + 1.
ELSE.
<fs_line> = wa_data+wa_start(*).
ENDIF.
ENDDO.
APPEND <wa_line> TO <itab>.
CLEAR: <wa_line>,<fs_line>.
ENDIF.
ENDDO.
*&---------------------------------------------------------------------*
*& Form download_data
© 2006 SAP AG 15
To download data from Application server files to presentation server
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form download_data .
clear: wa_filename.
wa_filename = pa_pres.
*&---------------------------------------------------------------------*
*& Form initialization
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
© 2006 SAP AG 16
To download data from Application server files to presentation server
* <-- p2 text
*----------------------------------------------------------------------*
form initialization .
REFRESH: gt_header,gt_fieldcat,gt_header.
*&---------------------------------------------------------------------*
*& Form delete_files
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form delete_files .
IF pa_deld EQ 'X'.
DELETE DATASET pa_appl.
ENDIF.
© 2006 SAP AG 17
To download data from Application server files to presentation server
© 2006 SAP AG 18
To download data from Application server files to presentation server
© 2006 SAP AG 19
To download data from Application server files to presentation server
Related Content
www.sdn.sap.com
Help.sap.com
© 2006 SAP AG 20
To download data from Application server files to presentation server
© 2006 SAP AG 21