2008 May 21 10:56 AM
Hi Experts,
I need to download data from internal table to application server to specified directory given dinamically and also to the presentation server using radio button to choose between the server.
can someone help me out with some sample code?
2008 May 21 11:02 AM
2008 May 21 11:02 AM
2008 May 21 11:07 AM
Hi,
Download to presentation server
Use GUI_DOWNLOAD function module
Download to Application server
Use this code
Data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*---Data is downloaded to the application server file path
LOOP AT lt_error_file INTO ls_error_file.
TRANSFER ls_error_file TO p_file.
ENDLOOP.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
if its useful reward points
2008 May 21 11:07 AM
Hi,
Check the below code.....
****File download to application server & presentation server
-&----
*
*& Report YBTEST14
&----
REPORT YBTEST14.
tables : YMMBROKER.
CONSTANTS: c_x TYPE char1 VALUE 'X'.
TYPES: BEGIN OF tl_rec,
len(3000) TYPE c,
END OF tl_rec.
DATA: w_count TYPE i,
wf_file type string value 'C:\Bisu.xls',
wf_file1 type string,
l_rec TYPE tl_rec.
TYPE-POOLS: truxs.
DATA : itab1 TYPE truxs_t_text_data.
data : begin of t_header occurs 0 ,
field1(20) ,
field2(20) ,
field3(20) ,
field4(20) ,
field5(20) ,
field6(20) ,
field7(20) ,
end of t_header .
t_header-field1 = 'Client' .
t_header-field2 = 'Plant'.
t_header-field3 = 'Storage location' .
t_header-field4 = 'Date' .
t_header-field5 = 'Date' .
t_header-field6 = 'Brokerage %' .
t_header-field7 = 'Currency' .
append t_header.
data : begin of itab occurs 0,
MANDT type MANDT,
AUCTION_CENTER type WERKS_D,
LGORT type LGORT_D,
EFFECTIVE TYPE DATUM,
EFFECTIVE_TO TYPE DATUM,
BROKERAGE_PER TYPE YBROKERAGE_PER1,
CAP TYPE BBP_BAPI_BAPICUREXT,
END OF ITAB.
DATA itab2 LIKE TABLE OF itab WITH HEADER LINE.
****Selection screen
select-options : auction for YMMBROKER-AUCTION_CENTER.
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-998.
PARAMETERS: r_appl RADIOBUTTON GROUP rad1
USER-COMMAND ucom,
r_pres RADIOBUTTON GROUP rad1 DEFAULT 'X'.
PARAMETERS: p_ofile TYPE rlgrap-filename
DEFAULT '/data/tea/extdom/'
MODIF ID g1 no-display,
p_opfile TYPE rlgrap-filename
default 'C:\Bisu.xls'
MODIF ID g2.
SELECTION-SCREEN END OF BLOCK a.
&----
*& AT SELECTION-SCREEN
&----
AT SELECTION-SCREEN OUTPUT.
PERFORM disable_path.
start-of-selection.
select * from YMMBROKER into table itab where AUCTION_CENTER in auction.
*BREAK-POINT.
**---Download the file
perform down_load.
form down_load.
*----Download the file into Application Server, if Chosen
IF r_appl = c_x.
perform down_load_app.
endif.
*----Download the file into Presentaion Server, if Chosen
IF r_pres = c_x.
perform down_load_pre.
endif.
endform.
**---End
----
**---Form download
----
form down_load_pre .
break-point.
concatenate wf_file '.xls' into wf_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = wf_file
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
tables
data_tab = t_header
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = wf_file
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
APPEND = 'X'
tables
data_tab = itab
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform. " down_load
*****application server
form down_load_app .
CONCATENATE '/data/tea/extdom/' 'STO' wf_file INTO wf_file .
if not itab[] is initial.
OPEN DATASET wf_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
break-point.
concatenate 'Client' 'Plant' 'Storage location' 'Date' 'Date' 'Brokerage %' 'Currency'
into wf_file1 separated by ','.
transfer wf_file1 to wf_file.
loop at itab.
CLEAR l_rec.
PERFORM concatenate_into_rec USING itab
CHANGING l_rec.
break-point.
TRANSFER l_rec TO wf_file.
clear itab.
endloop.
endif.
close DATASET wf_file.
endif.
endform. " down_load_app
&----
*& Form disable_path
----
form disable_path .
w_count = w_count + 1.
LOOP AT SCREEN.
IF ( w_count GE 1 ) AND ( screen-group1 = 'G1' ).
IF r_appl <> 'X'.
screen-input = 0.
ENDIF.
ELSEIF ( w_count GE 1 ) AND ( screen-group1 = 'G2' ).
IF r_pres <> 'X'.
screen-input = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
endform. " disable_path
&----
*& Form down_load_app
----
&----
*& Form concatenate_into_rec
&----
text
----
-->P_ITAB text
<--P_L_REC text
----
form concatenate_into_rec using itab like itab
changing l_rec like l_rec.
data : w_mandt type char4,
w_effective type char15,
w_effective1 type char15,
w_BROKERAGE_PER type char15,
w_CAP type char15.
w_mandt = itab-MANDT.
w_effective = itab-EFFECTIVE.
w_effective1 = itab-EFFECTIVE_TO.
w_BROKERAGE_PER = itab-BROKERAGE_PER.
w_CAP = itab-cap.
condense w_mandt no-gaps.
condense w_effective no-gaps.
condense w_effective1 no-gaps.
condense w_BROKERAGE_PER no-gaps.
condense w_CAP no-gaps.
concatenate w_mandt itab-AUCTION_CENTER itab-LGORT w_effective w_effective1 w_BROKERAGE_PER w_CAP
into l_rec-len SEPARATED BY ','.
endform. " concatenate_into_rec
****End
2008 May 21 11:08 AM
Hi,
code can b like...
if p_presentn = 'x'.
perform present_download.
else.
perform appln_download.
endif.
in "form present_download" call FM GUI_DOWNLOAD and in "form appln_download" use OPEN DATASET FOR OUTPUT, TRANSFER ITAB TO DATASET and CLOSE DATASET.
Reward if helpful
Regards.
2008 May 21 11:22 AM
hi,
try this code
data : it_mara type table of mara with header line.
PARAMETERs : rb RADIOBUTTON GROUP grp,
rb1 RADIOBUTTON GROUP grp.
parameters : file type string.
select * from mara into table it_mara up to 10 rows.
if rb = 'X'. " for presentation server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = file
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
tables
data_tab = it_mara.
if sy-subrc = 0.
write 'Success.'.
endif.
elseif rb1 = 'X'. " for application server
OPEN DATASET file FOR output in BINARY MODE.
if sy-subrc = 0.
write 'Success.'.
endif.
endif.
reward if helpful
prasanth