Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

read csv file from application server

Former Member
0 Likes
11,794

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 .

1 ACCEPTED SOLUTION
Read only

Former Member
4,207

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.

9 REPLIES 9
Read only

Former Member
4,207

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

Read only

0 Likes
4,207

Hi krishna ,

I undrstnd u r correct.

but can u pls elaborate ur answer.

plz

jowar

Read only

peter_ruiz2
Active Contributor
0 Likes
4,207

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

Read only

0 Likes
4,207

Hi peter,

thanks for ur responce.

But i want to read it from application server.

jowar

Read only

Former Member
4,208

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.

Read only

0 Likes
4,207

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

Read only

0 Likes
4,207

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.

Read only

0 Likes
4,207

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

Read only

0 Likes
4,207

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.