06-19-2006 4:56 PM
How to extarct a comma delimited file from an internal table in to SAP application server.
06-19-2006 5:00 PM
data: lv_data type string.
open dataset .....
concatenate field1 field2
into lv_data separated by ','.
transfer lv_data into file.
close dataset.....
06-19-2006 5:02 PM
Hi Arun,
Can you be a bit more clearer? Are you uploading the dat to the appl server or downloading?
1) Comma separated info from itab to file server.
loop at itab.
concatenate itab-field1
itab-field2
itab-field3
into itab_new-data separated by ','.
append itab_new.
clear itab_new.
endloop.
open dataset dsn for output in text mode.
if sy-subrc = 0.
loop at itab_new.
transfer itab_new to dsn.
endloop.
endif.
close dataset.
2) Comma separated info from file to itab.
open dataset dsn for input in text mode.
if sy-subrc = 0.
do.
read datset dsn into itab-data.
if sy-subrc <> 0.
exit.
else.
append itab.
clear itab.
endif.
enddo.
endif.
close dataset.
loop at itab.
split itab-data at ',' into itab_new-field1
itab_new-field2
itab_new-field3.
append itab_new.
clear itab_new.
endloop.
REgards,
Ravi
06-19-2006 5:08 PM
Here is a sample program. This is a little different way, if you don't want to hardcode the fields with the concatenate.
report zrich_0001 .
data: it001 type table of t001 with header line.
data: iout type table of string .
data: xout type string.
field-symbols: <fs>.
Parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt'.
select * into table it001 from t001.
loop at it001.
clear xout.
do.
assign component sy-index of structure it001 to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
xout = <fs>.
else.
concatenate xout <fs> into xout separated by ','.
endif.
enddo.
append xout to iout.
endloop.
open dataset d1 for output in text mode.
loop at iout into xout
transfer xout to d1.
endloop.
close dataset d1.
Regards,
Rich Heilman
06-19-2006 5:14 PM
If you are reading the file <u>into</u> SAP, you will use OPEN DATASET, READ DATASET and CLOSE DATASET. Read the documentation on these keywords.
Your logic will roughly be like this.
data: v_string(1000).
open dataset myserverfile.
do.
read dataset myserverfile into v_string.
if sy-subrc <> 0.
exit.
endif.
split v_string at ',' into: itab-field1,
itab-field2.
.....and so on for all itab fields.
....
append itab.
clear itab.
enddo.