Read text file from PC one line at a time

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
q4u
Posts: 441
Joined: Wed Mar 08, 2006 7:02 am

Read text file from PC one line at a time

Post by q4u » Thu May 15, 2008 9:23 am

Hi,
Need something similar to a READ DATASET but for the PC...
Everything I've come across seems to read the whole file into an internal table at one go.

Thanks.

MattG
Posts: 809
Joined: Wed Oct 23, 2002 2:06 pm
Location: England

Re: Read text file from PC one line at a time

Post by MattG » Thu May 15, 2008 9:37 am

Why do you need read the file only one line at a time?
MattG.
Image Search SAPfans

q4u
Posts: 441
Joined: Wed Mar 08, 2006 7:02 am

Re: Read text file from PC one line at a time

Post by q4u » Thu May 15, 2008 10:30 am

'cause i'm a sadist.. :twisted:

MattG
Posts: 809
Joined: Wed Oct 23, 2002 2:06 pm
Location: England

Re: Read text file from PC one line at a time

Post by MattG » Thu May 15, 2008 3:47 pm

You're trying to code this, so you must be a masochist :roll:
MattG.
Image Search SAPfans

q4u
Posts: 441
Joined: Wed Mar 08, 2006 7:02 am

Re: Read text file from PC one line at a time

Post by q4u » Thu May 15, 2008 3:59 pm

So I'm getting the distinct impression that it's not possible then... :|

m@t
Posts: 4119
Joined: Thu Sep 04, 2003 7:37 am
Location: Switzerland

Re: Read text file from PC one line at a time

Post by m@t » Fri May 16, 2008 2:48 am

Read the file in one go, using the standard upload, then write it to the appserver. Then read it from the appserver a line at a time. Alternatively, use ftp, or other file transfer means, to get it to the appserver.

If you would explain WHY you want to read it a line at a time, you might get more help.

m@t
TULY Image The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

phillipm
Posts: 376
Joined: Fri Oct 25, 2002 3:54 am
Location: Lyon, France

Re: Read text file from PC one line at a time

Post by phillipm » Fri May 16, 2008 2:52 am

Maybe the functional consultant wants it done that way.
...and functional consultant always knows best... :mrgreen:

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Re: Read text file from PC one line at a time

Post by Rich » Fri May 16, 2008 6:16 am

Well.

Just defer the reading of the uploaded text till later.

Stick it all into a table and then Loop around (That's reading it one line at a time), or even use READ TABLE ..... INDEX and just keep incrementing the index. If said functional consultant asks if you are reading it one line at a time just point to the code and say with conviction 'YES'.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

BradB
Posts: 685
Joined: Wed Mar 22, 2006 10:27 am
Location: Standing right behind you

Re: Read text file from PC one line at a time

Post by BradB » Fri May 16, 2008 8:18 am

MattG wrote:You're trying to code this, so you must be a masochist :roll:
Here's how you turn sadistic - this will really hurt the person that asked for it :wink:

Code: Select all

DO.
* Call file open dialog
* Call file upload (to internal table)
* Delete all lines in the internal table except the one matching the index of the current DO loop
* If all lines deleted --> Exit
* Read internal table index 1 - move line to other internal table
ENDDO.

* Now process your other internal table

When you're asked why they have to process the file open dialog so many times, just say 'That's what you asked for' 8)
Ironman Triathlete and SAP Dev/Config Expert
(which is harder?)

m@t
Posts: 4119
Joined: Thu Sep 04, 2003 7:37 am
Location: Switzerland

Re: Read text file from PC one line at a time

Post by m@t » Fri May 16, 2008 12:47 pm

phillipm wrote:Maybe the functional consultant wants it done that way.
...and functional consultant always knows best... :mrgreen:
No. The functional consultant is always a loony, who's best not let out on their own. Anyway, what self-respecting functional conslutant even knows what a line in a file is?
TULY Image The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

maen
Posts: 141
Joined: Wed Feb 21, 2007 7:01 am

Re: Read text file from PC one line at a time

Post by maen » Tue May 20, 2008 9:31 am

A true functional consultant will notice it and say: "you're still reading the complete file in 1 go!"

Best to ask for seperate files with only 1 line in it. :twisted:

m@t
Posts: 4119
Joined: Thu Sep 04, 2003 7:37 am
Location: Switzerland

Re: Read text file from PC one line at a time

Post by m@t » Tue May 20, 2008 10:34 am

You could write some kind of OLE program to split the file into seperate lines, I suppose.

m@t
TULY Image The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

wilhitern1
Posts: 135
Joined: Thu May 15, 2008 4:25 pm
Location: Butterball LLC., Goldsboro, NC, USA
Contact:

Re: Read text file from PC one line at a time

Post by wilhitern1 » Tue May 20, 2008 10:53 am

If the file were an excel, you could read row 1 and then delete row 1. Or is that to obvious? I didn't see that you said what format the file was in.
Neal Wilhite (WilhiteRN1)Image

Post Reply