‎2009 May 07 1:48 PM
How to download CSV file from application server into internal table?
I know the open dataset ,read dataset & close dataset But how to mention CSV file .
‎2009 May 07 1:56 PM
HI,
OPEN DATASET filename FOR INPUT IN TEXT MODE
ENCODING DEFAULT MESSAGE msg.
IF SY-SUBRC EQ 0.
DO.
READ DATASET filename INTO l_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT l_string AT ',' INTO WA-FIELD1 WA-FIELD2 ..... WA-FIELDn.
APPEND wa to datatab.
ENDIF.
ENDDO.
CLOSE DATASET filename.
ENDIF.
‎2009 May 07 1:51 PM
Hi,
Download CSV file into a flat structure(Declare a internal table with text(500)) using open dataset and close data set
and then split at ',' becuase you CSV file will be comma separated
Regards
Krishna
‎2009 May 07 1:56 PM
Hi krishna ,
I undrstnd u r correct.
but can u pls elaborate ur answer.
plz
jowar
‎2009 May 07 1:52 PM
hi jowar,
use the FM GUI_DOWNLOAD. this will download the file into a internal table with 1 field. after that, use SPLIT command to split each row of the internal table since each row of the CSV file will be transfered into the internal table as 1 field.
Regards,
Peter
‎2009 May 07 1:55 PM
Hi peter,
thanks for ur responce.
But i want to read it from application server.
jowar
‎2009 May 07 1:56 PM
HI,
OPEN DATASET filename FOR INPUT IN TEXT MODE
ENCODING DEFAULT MESSAGE msg.
IF SY-SUBRC EQ 0.
DO.
READ DATASET filename INTO l_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT l_string AT ',' INTO WA-FIELD1 WA-FIELD2 ..... WA-FIELDn.
APPEND wa to datatab.
ENDIF.
ENDDO.
CLOSE DATASET filename.
ENDIF.
‎2009 May 07 1:58 PM
nice reply avinash.
but i want to read CSv file .
And ur examples is for text file .
so is it wrking for CSV file also.
plz reply.
jowar
Edited by: jowar saha on May 7, 2009 2:58 PM
‎2009 May 07 2:01 PM
Hi,
Yes it will work for csv file also. The only thing you need to do after reading the entry from the application server you need to split the fields at comma later move them to work area and append them to internal table.
‎2009 May 07 2:04 PM
thanks avinash.
REallly good answer.
Only last ques :
DATA: l_string TYPE tline, IS it?
And can u specify the other declearation also.
Plz
jowar
‎2009 May 07 2:10 PM
Hi,
DATA: l_string TYPE sting,
or
DATA: l_string(3000) TYPE c, " try to take the max record length you get from the application server so that record will not get truncated.