‎2007 Nov 22 6:59 AM
Hi,
Can anyone please tell how to create files in application server through reports.
I need to write a report on executing it a file in application server is to be created.
And when file is created how can i knew the path of it?
‎2007 Nov 22 7:58 AM
Hi,
DATA : lv_file TYPE rlgrap-filename.
CONCATENATE '.FILENAME' INTO lv_file.
OPEN DATASET lv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ITAB.
CONCATENATE ITAB-F1 ITAB-F2 INTO v_record.
TRANSFER v_record TO lv_file.
ENDLOOP.
CLOSE DATASET lv_file.
the above piece of code will create a file in dir_temp folder in appl. server, u can view the file in AL11-tcode.
rewards if useful...
kavitha
‎2007 Nov 22 7:01 AM
Hi,
At the application server level:
->OPEN DATASET : open a file in the application server for reading or writing.
->READ DATASET : used to read from a file on the application server that has been opened for reading
-> TRANSFER DATASET : writing data to a file.
-> CLOSE DATASET : closes the file
-> DELETE DATASET : delete file
<b>reward points if useful.</b>
regards,
Vinod Samuel.
‎2007 Nov 22 7:01 AM
Hi,
cehck the beloe link for sampel programs..
http://www.sapdevelopment.co.uk/file/filehome.htm
Reward if helpful.
Regards,
Nagaraj
‎2007 Nov 22 7:06 AM
HI
see this simple example
i am creating a file on the application server
EXCEL TO INTERNAL TABLE AND THEN TO APPLICATION SERVER
REPORT ZSD_EXCEL_INT_APP.
parameter: file_nm type localfile.
types : begin of it_tab1,
f1(20),
f2(40),
f3(20),
end of it_tab1.
data : it_tab type table of ALSMEX_TABLINE with header line,
file type rlgrap-filename.
data : it_tab2 type it_tab1 occurs 1,
wa_tab2 type it_tab1,
w_message(100) TYPE c.
at selection-screen on value-request for file_nm.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = 'X'
MASK = ' '
CHANGING
file_name = file_nm
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
.
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.
refresh it_tab2[].clear wa_tab2.
file = file_nm.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '10'
i_end_row = '35'
tables
intern = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 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.
ENDIF.
loop at it_tab.
case it_tab-col.
when '002'.
wa_tab2-f1 = it_tab-value.
when '004'.
wa_tab2-f2 = it_tab-value.
when '008'.
wa_tab2-f3 = it_tab-value.
endcase.
at end of row.
append wa_tab2 to it_tab2.
clear wa_tab2.
endat.
endloop.
data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*--- Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT it_tab2 INTO wa_tab2.
TRANSFER wa_tab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
loop at it_tab2 into wa_tab2.
write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
endloop.
‎2007 Nov 22 7:10 AM
Hi,
Use Open dataset for that
refer code.
&----
*& Form open_file
&----
form open_file.
if p_aserv eq 'X'.
open dataset p_path for output in text mode encoding default.
if sy-subrc ne 0.
WRITE 😕 'Download Failed'.
message e000(8i) with 'Error in File opening for download'.
endif.
endif.
endform. " open_file
Regards,
Prashant
‎2007 Nov 22 7:21 AM
Hi,
The file can be created by using OPEN DATASET
Data to the file can be added using TRANSFER DATASET
The created files can be checked in AL11 transaction in the temp directory DIR_TEMP /tmp.
Thanks,
Rashmi Joshi
Message was edited by:
Rashmi Joshi
‎2007 Nov 22 7:58 AM
Hi,
DATA : lv_file TYPE rlgrap-filename.
CONCATENATE '.FILENAME' INTO lv_file.
OPEN DATASET lv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ITAB.
CONCATENATE ITAB-F1 ITAB-F2 INTO v_record.
TRANSFER v_record TO lv_file.
ENDLOOP.
CLOSE DATASET lv_file.
the above piece of code will create a file in dir_temp folder in appl. server, u can view the file in AL11-tcode.
rewards if useful...
kavitha