‎2006 Jun 06 3:59 PM
Hi Friends,
I have the data in a Flat file format on the application Server and i need to read the data into an internal table. Similarly I need to do for a flat file on the presentation Server.
How should I proceed on this.
Thanks in Advance,
Srikanth.
‎2006 Jun 06 4:04 PM
Hii
this is for uploading data into apllicn server
OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}
IN {TEXT/BINARY} MODE
chk this program..
<b>DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
OPEN DATASET i_file FOR INPUT IN TEXT MODE.
IF sy-subrc NE 0.
MESSAGE e999(za) WITH 'Error opening file' i_file.
ENDIF.
DO.
Reads each line of file individually
READ DATASET i_file INTO wa_datatab.
Perform processing here
.....
ENDDO.</b>
Downloading files to SAP(Application Server)
Download internal table to Application server file(Unix)
<b>DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
open dataset e_file for output in text mode.
lOOP AT it_datatab......
transfer it_datatab to e_file.
ENDLOOP.
close dataset e_file.</b>
Regards
Naresh
‎2006 Jun 06 4:02 PM
hi
try this code
declare itab as per the file (here say gt_data)
data : v_file type string.
v_file = filename.
open dataset v_file for input in text mode encoding default.
if sy-subrc <> 0.
message e000 with 'ERROR OPENING FILE'.
endif.
do.
read dataset v_file into gt_data.
if sy-subrc <> 0.
exit.
to read data from pc use <b>gui_upload</b>
call function 'GUI_UPLOAD'
exporting
filename = v_file
filetype = p_type
has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = gt_data
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17
.
else.
append gt_data.
clear gt_data.
endif.
enddo.
close dataset v_file.
‎2006 Jun 06 4:02 PM
For App Server:
OPEN DATASET p_file FOR INPUT
IN TEXT MODE
ENCODING DEFAULT.
READ DATASET p_file INTO w_filedata.
CLOSE DATASET l_file.
For Pres Server:
Use FM GUI_DOWNLOAD
‎2006 Jun 06 4:03 PM
Hi Shejal,
You can use ABAP command OPEN DATASET <dsn>, READ DATASET <dsn> INTO <f> and CLOSE DATASET <dsn> to read data from application server.
DATA:
dsn(20) TYPE C VALUE '/usr/test.dat',
rec(80) TYPE C.
OPEN DATASET dsn FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ DATASET dsn INTO rec.
WHILE sy-subrc <> 0.
WRITE / rec. READ DATASET dsn INTO rec.
ENDWHILE.
CLOSE DATASET dsn.
For reading data from presentation server, you can use this FM <b>GUI_UPLOAD.</b>
Regards,
Ferry Lianto
‎2006 Jun 06 4:03 PM
For reading from app server:
types: begin of t_FC,
strText(80),
end of t_FC.
data: FC type table of t_FC with header line.
data: r_FC type t_FC.
open dataset YourFileNameHere for input in text mode encoding default.
if sy-subrc <> 0.
message i000(zz) with 'File Open error.'.
exit.
endif.
do.
clear r_FC.
read dataset FN into r_FC.
if sy-subrc <> 0.
exit.
endif.
append r_FC to temp_FC.
enddo.
close dataset YourFileNameHere.
‎2006 Jun 06 4:04 PM
Hii
this is for uploading data into apllicn server
OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}
IN {TEXT/BINARY} MODE
chk this program..
<b>DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
OPEN DATASET i_file FOR INPUT IN TEXT MODE.
IF sy-subrc NE 0.
MESSAGE e999(za) WITH 'Error opening file' i_file.
ENDIF.
DO.
Reads each line of file individually
READ DATASET i_file INTO wa_datatab.
Perform processing here
.....
ENDDO.</b>
Downloading files to SAP(Application Server)
Download internal table to Application server file(Unix)
<b>DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
open dataset e_file for output in text mode.
lOOP AT it_datatab......
transfer it_datatab to e_file.
ENDLOOP.
close dataset e_file.</b>
Regards
Naresh
‎2006 Jun 06 4:04 PM
For reading from presentation server, use the FM GUI_UPLOAD.
Sample usage:
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
TABLES
data_tab = it_pcc_file
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
REgards,
Ravi
‎2006 Jun 06 4:05 PM