2007 May 02 1:55 PM
Hi Guys,
I wanted to read/download unix file into internal table. I can use open,read, close dataset to get those data.
But at the same time i wanted to split the fields based on tabs / pipe symbols and put it into the corresponding internal table fields. Please let me know,,,,
2007 May 02 1:57 PM
Hi,
You can use the following statements to read data from application server.
1. OPEN DATASET statement is used to open a file on application server either for reading or writing.
2. READ DATASET statement - when we open a file for reading/uploading we use READ DATASET stmt.
e.g. READ DATASET <dsn> INTO <wa>.
open dataset fname for input in text mode encoding default.
if sy-subrc ne 0.
write:/ 'Unable to open file:', fname.
else.
do.
read datasset fname into <wa>.
if sy-subrc ne o.
exit.
else.
append <wa> to itab.
endif.
close dataset fname.
enddo.
endif.
You can first store in wa and then into an internal table or whatever you want.
Also.....
You can also use the FM RZL_READ_FILE_LOCAL
Regards,
Jayant
Please award if helpful.
2007 May 02 1:58 PM
Hi
Check this link for sample code:
http://www.thespot4sap.com/articles/SAP_Mail_UNIX_Example_ABAP.asp
OPEN DATASET P_FNAME FOR INPUT IN TEXT MODE.
if sy-subrc ne 0.
write : / 'File could not be uploaded.. Check file name.'.
stop.
endif.
CLEAR : it_pricing[], it_pricing.
DO.
READ DATASET P_FNAME INTO V_STR.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
SPLIT V_STR AT ',' INTO it_pricing-key
it_pricing-F1 it_pricing-F2 it_pricing-F3
it_pricing-F4 it_pricing-F5 .
APPEND it_pricing.
CLEAR it_pricing.
ENDDO.
reward if useful
regards
Anji
2007 May 02 1:59 PM
use open then read statements.
now, after reading data into a variable which is of type string append the data.
loop at variable.
split variable-line into itab at delimiter.
endloop.
2007 May 02 1:59 PM
HI,
Here is the Sample Program
*&---------------------------------------------------------------------*
*& Report ZUPLOADTAB *
*& *
*&---------------------------------------------------------------------*
*& Example of Uploading tab delimited file *
*& *
*&---------------------------------------------------------------------*
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE '|'. " Pipe Symbol
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
* Display report data for illustration purposes
loop at it_record into wa_record.
write:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
endloop.Regards
Sudheer