Report printing

  • Follow


Hello,
Looking for a simple solution:-).

I have an input file containing many records, each field delimited by
a space e.g: 

CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44
CDN:DSG Descartes Sys Group 2.280 0.000 2.22
CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17

I need to print a 'nicely' formatted report e.g.

CDN:BBD.SVB  BOMBARDIER            2.780  +0.020   1.44
CDN:DSG          Descartes Sys Group  2.280    0.000   2.22
CDN:FLO           FLOWING ENERGY   0.750  +0.010   4.17

Is there a 'common/standard' way to achieve this? All my techniques
looks like sledgehammer code.
Please, thanks
Graham Hobbs
0
Reply ghobbs (110) 9/30/2011 4:03:24 PM

On Fri, 30 Sep 2011 12:03:24 -0400, Graham Hobbs <ghobbs@cdpwise.net>
wrote:

>Is there a 'common/standard' way to achieve this?

With some simple REXX you could convert this to HTML, display it in
your browser, and print it from there.

If you're not familiar with HTML then:

1. Start with <TABLE>
2. Preface each row with <TR> and insert <TD> to the left of each
column
3. End with </TABLE>

The slightly hard part is parsing out column 2 which contains a
variable number of words.

You could use something like this (assuming variable "line" contains
one line of data)

W = words(line)
Say
'<TR><TD>'word(line,1)'<TD>'subword(line,2,W-4)'<TD>'word(line,w-2)'<TD>'word(line,W-1)'<TD>'word(line,w)

I have an xword() function that takes a -ve word number as counting
from the end, which makes the REXX neater.

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
0
Reply Steve.J.Swift (321) 9/30/2011 4:38:09 PM


On Fri, 30 Sep 2011 17:38:09 +0100, Swifty <steve.j.swift@gmail.com>
wrote:

>On Fri, 30 Sep 2011 12:03:24 -0400, Graham Hobbs <ghobbs@cdpwise.net>
>wrote:
>
>>Is there a 'common/standard' way to achieve this?
>
>With some simple REXX you could convert this to HTML, display it in
>your browser, and print it from there.
>
>If you're not familiar with HTML then:
>
>1. Start with <TABLE>
>2. Preface each row with <TR> and insert <TD> to the left of each
>column
>3. End with </TABLE>
>
>The slightly hard part is parsing out column 2 which contains a
>variable number of words.
>
>You could use something like this (assuming variable "line" contains
>one line of data)
>
>W = words(line)
>Say
>'<TR><TD>'word(line,1)'<TD>'subword(line,2,W-4)'<TD>'word(line,w-2)'<TD>'word(line,W-1)'<TD>'word(line,w)
>
>I have an xword() function that takes a -ve word number as counting
>from the end, which makes the REXX neater.
---
Swifty,

I should have explained further - the 'printed' file will be written
to a file which can then be sorted and used by other rexx pgms
including printing, all art of a longish 'jobstream' so don't think
I'd want to involve HTML or manual intervention in this.

xword() could help? How about if I also said I'm old school, LRECL=FB
- you with me:-)!

As for the parsing I do know that as soon as two consecutive NUM
datatypes occur means the 'words' bit is over so no problem there. 
Graham
0
Reply ghobbs (110) 9/30/2011 5:11:58 PM

On 30 Sep., 18:03, Graham Hobbs <gho...@cdpwise.net> wrote:
> Hello,
> Looking for a simple solution:-).
>
> I have an input file containing many records, each field delimited by
> a space e.g:
>
> CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44
> CDN:DSG Descartes Sys Group 2.280 0.000 2.22
> CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17
>
I see no way around the sledgehammer. IF the company name never
contains a decimal point, you could
1) user parse var myline code rest
   myline being your file line
   code will be CDN:BBD.SYMB
   rest will be BOMBARDIER....
2) i = pos('.',rest)
   will find the decimal digit in the first figure within variable
rest.
3) j = lastpos(' ',rest,i)
   will find the blank separating the text from the figure within
variable rest.
4) parse var rest company =(j) num1 num2 num3 .
   will set company to BOMBADIER
   and num1 through num3 to the numbers which can be further formatted
using format().
If the company name may contain '.' an alternative would be to use
subword() and delword() to extract and delete the last three
"words" (e.g. the three figures) from variable rest. Then the company
name may hav any format.
As I said, its still a sledgehammer.
HTH
0
Reply JochemPeelen (1) 9/30/2011 6:41:18 PM

Graham Hobbs wrote:
> On Fri, 30 Sep 2011 17:38:09 +0100, Swifty <steve.j.swift@gmail.com>
> wrote:
> 
>> On Fri, 30 Sep 2011 12:03:24 -0400, Graham Hobbs <ghobbs@cdpwise.net>
>> wrote:
>>
>>> Is there a 'common/standard' way to achieve this?
>> With some simple REXX you could convert this to HTML, display it in
>> your browser, and print it from there.
>>
>> If you're not familiar with HTML then:
>>
>> 1. Start with <TABLE>
>> 2. Preface each row with <TR> and insert <TD> to the left of each
>> column
>> 3. End with </TABLE>
>>
>> The slightly hard part is parsing out column 2 which contains a
>> variable number of words.
>>
>> You could use something like this (assuming variable "line" contains
>> one line of data)
>>
>> W = words(line)
>> Say
>> '<TR><TD>'word(line,1)'<TD>'subword(line,2,W-4)'<TD>'word(line,w-2)'<TD>'word(line,W-1)'<TD>'word(line,w)
>>
>> I have an xword() function that takes a -ve word number as counting
>>from the end, which makes the REXX neater.
> ---
> Swifty,
> 
> I should have explained further - the 'printed' file will be written
> to a file which can then be sorted and used by other rexx pgms
> including printing, all art of a longish 'jobstream' so don't think
> I'd want to involve HTML or manual intervention in this.
> 
> xword() could help? How about if I also said I'm old school, LRECL=FB
> - you with me:-)!
> 
> As for the parsing I do know that as soon as two consecutive NUM
> datatypes occur means the 'words' bit is over so no problem there. 
> Graham

Tell us about your environment and which Rexx interpreter 
you're using.

-- 

Les               (Change Arabic to Roman to email me)
0
Reply 5mre20 (168) 10/1/2011 3:27:47 AM

In Message-ID:<kopb87l2lv06j3inivevbfgsta1roksb1b@4ax.com>,
Graham Hobbs <ghobbs@cdpwise.net> wrote: 

>I have an input file containing many records, each field delimited by
>a space e.g: 
>
>CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44
>CDN:DSG Descartes Sys Group 2.280 0.000 2.22
>CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17

     Unfortunately, the fields are not simply delimited.  The 2nd
field often contains internal spaces.  How can a program tell the end
of the 2nd field?

-- 
Arthur T. - ar23hur "at" intergate "dot" com
0
Reply arthur (21) 10/1/2011 4:13:40 AM

 >> CDN:DSG Descartes Sys Group 2.280 0.000 2.22

 > How can a program tell the end of the 2nd field?

It's the Word() after the first Word(), and with a Reverse() of the 
remaining part you've to skip the first 3 words. But the "file format"
is broken.

One remark about the "file fomat" is that the name occurs twice. One 
could create a file "CDN.LST" which links the symbol "DSG" or 
"CDN:DSG"  to "Descartes Sys Group", so the underlying "file format" 
can be reduced to "DSG 2.280 0.000 2.22" or "CDN:DSG 2.280 0.000 
2.22".

Using a HTML table (or Rexx' formatting) is fine. There's no need to 
store the complicated name as well as its symbol in the same file as 
the data. Solve the real problem: split it.  

Modified real example: an executable calculates the raw statistics, 
and creates a file CDN.PRN like this:

DSG       2.280     0.000     2.22

And uses a file CDN.LST like this:

DSG       Descartes SysGroup

Finally write a Rexx app which processes CDN.PRN and uses CDN.LST to 
link DSG to its full name. If you're using HTML, take care of special 
characters in the name, for example:

IF Pos('�',fullname,1)>0 THEN DO
   PARSE VAR fullname part1 '&' part2
   fullname=part1||'&pound;'||part2
END 

But do solve the real problem: "DSG" in one file, the matching long 
name "Descartes Sys Group" in another file. You can actually use that 
file to know that the name-part is "Descartes Sys Group" or 3 words, 
even if you have no control of the buggy data file. 


--
0
Reply what.ever (135) 10/1/2011 11:02:00 AM

 > I should have explained further - the 'printed' file will be 
written
 > to a file which can then be sorted and used by other rexx pgms

No need to explain. Fix your data, no matter what you're doing with 
it.

 > As for the parsing

See my other message:

1: create a LST file with fixed line lengths, with symbols/tickers and
full names (and maybe other properties, like a code for "Oil 
industrie"). This even  can be used to know what the "long name" in 
your buggy file format is.

2: use a better file format, e.g. "Metastocks's PRN file format". I 
recommend a file per year, i.e. 2011.PRN:

<TICKER>,<PER>,<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OI> 
CSG,D,20110929,2.20,2.25,2.175,2.183,7806
CSG,D,20110930,2.22,2.229,2.18,2.222,18897

3: whenever you create stats, use a PRN (fixed line length) to store 
the processed data

4: if needed, use this created PRN file and the LST file to create any
report.

The file format you use is crap, it stores both the symbol/ticker and 
the name in the same file. You'll be storing a lot of names if you 
have a record per symbol per day, but that's not the only problem. 
Split it. Get organized.


-- 
0
Reply what.ever (135) 10/1/2011 11:14:35 AM

 >>> CDN:DSG Descartes Sys Group 2.280 0.000 2.22

Albeit broken file formats already have nothing to do with Rexx, but 
if CDN:DSG is made up by you and and it actually refers to Google's 
TSE:DSG data, the data used may be unreliable too. For example 
rounding of quotes may be in use, and it's not always the same 
rounding humans or Rexx' Format() would produce.


--
0
Reply what.ever (135) 10/1/2011 11:56:48 AM

On Sep 30, 12:03=A0pm, Graham Hobbs <gho...@cdpwise.net> wrote:
> Hello,
> Looking for a simple solution:-).
>
> I have an input file containing many records, each field delimited by
> a space e.g:
>
> CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44
> CDN:DSG Descartes Sys Group 2.280 0.000 2.22
> CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17
>
> I need to print a 'nicely' formatted report e.g.
>
> CDN:BBD.SVB =A0BOMBARDIER =A0 =A0 =A0 =A0 =A0 =A02.780 =A0+0.020 =A0 1.44
> CDN:DSG =A0 =A0 =A0 =A0 =A0Descartes Sys Group =A02.280 =A0 =A00.000 =A0 =
2.22
> CDN:FLO =A0 =A0 =A0 =A0 =A0 FLOWING ENERGY =A0 0.750 =A0+0.010 =A0 4.17
>
> Is there a 'common/standard' way to achieve this? All my techniques
> looks like sledgehammer code.
> Please, thanks
> Graham Hobbs

I'm afraid you're making the mistakes of a beginner in this business -
if you can't describe your data accurately you can't parse it - so
your first task is to describe it - heard of JSP?
You may find that it will be easier to change the program producing
the file to use a delimiter not likely to be in any of the data fields
- even hex values below 30!
0
Reply adriangstern (1) 10/1/2011 12:42:01 PM

 > I'm afraid you're making the mistakes of a beginner in this 
business

 > use a delimiter not likely to be in any of the data fields - even 
hex
 > values below 30!

Yet another beginner's mistake: there's no need to make up any file 
format, including delimiters. Use an existing file format, readable or
not.

And the silly data still is PARSE'able. The symbol/ticker is always 
(not just in Hobbs' examples) one word. If not, don't even use this 
data source. The last 3 words are always one word, and the part 
between those 4 words at is the name (1-name-3). The name probably has
a maximum length, and typically contains every character related to 
company's names and currencies. So use the name as-is, e.g. "1L�s Foo&
B.a.r., Inc. 2 -I" (without the quotes!). Of course this can be 
formatted using Left(fullname,maxlengthofname). When using HTML 
tables, you may have to replace a "&" with "&amp;".

If this is the data he has to work with, split it up using an existing
file format. No need to make up one. No need to make up delimiters.


-- 

0
Reply what.ever (135) 10/1/2011 1:39:15 PM

On Fri, 30 Sep 2011 23:27:47 -0400, LesK <5mre20@tampabay.rr.com>
wrote:

>Graham Hobbs wrote:
>> On Fri, 30 Sep 2011 17:38:09 +0100, Swifty <steve.j.swift@gmail.com>
>> wrote:
>> 
>>> On Fri, 30 Sep 2011 12:03:24 -0400, Graham Hobbs <ghobbs@cdpwise.net>
>>> wrote:
>>>
>>>> Is there a 'common/standard' way to achieve this?
>>> With some simple REXX you could convert this to HTML, display it in
>>> your browser, and print it from there.
>>>
>>> If you're not familiar with HTML then:
>>>
>>> 1. Start with <TABLE>
>>> 2. Preface each row with <TR> and insert <TD> to the left of each
>>> column
>>> 3. End with </TABLE>
>>>
>>> The slightly hard part is parsing out column 2 which contains a
>>> variable number of words.
>>>
>>> You could use something like this (assuming variable "line" contains
>>> one line of data)
>>>
>>> W = words(line)
>>> Say
>>> '<TR><TD>'word(line,1)'<TD>'subword(line,2,W-4)'<TD>'word(line,w-2)'<TD>'word(line,W-1)'<TD>'word(line,w)
>>>
>>> I have an xword() function that takes a -ve word number as counting
>>>from the end, which makes the REXX neater.
>> ---
>> Swifty,
>> 
>> I should have explained further - the 'printed' file will be written
>> to a file which can then be sorted and used by other rexx pgms
>> including printing, all art of a longish 'jobstream' so don't think
>> I'd want to involve HTML or manual intervention in this.
>> 
>> xword() could help? How about if I also said I'm old school, LRECL=FB
>> - you with me:-)!
>> 
>> As for the parsing I do know that as soon as two consecutive NUM
>> datatypes occur means the 'words' bit is over so no problem there. 
>> Graham
>
>Tell us about your environment and which Rexx interpreter 
>you're using.
---
Les,
Windows XP SP3, ooREXX..

... to address other comments on this topic.

The data is transmitted to me and arrives as shown, I have no choice
with the format. Each record does have the same format. 

The 'only' dodgy bit is the company name - after that I will build the
remaining variable length fields into fixed length fields and
concatenate them into a record for writing and/or printing.

I know COBOL, REXX (procedural) with skill. Any suggestion that I use
another method such as  HTML, JSP, etc is not an option.

OK, thanks, will think to post my sledgehammer when done:-).
0
Reply ghobbs (110) 10/1/2011 5:27:18 PM

On Fri, 30 Sep 2011 13:11:58 -0400, Graham Hobbs <ghobbs@cdpwise.net>
wrote:

>xword() could help

Here is my xword() in all its glory:

::Routine xword public			/* Extended word(); adds -ve word  index. -1 = last word */
Parse arg string,N,char
If \datatype(N,'W') | length(char) > 1 then raise syntax 40
If char <> '' then string = translate(string,char' ',' 'char)
If N < 0 then N = words(string) + N + 1
If N <= 0 then return ''
Word = word(string,n)
If char <> '' then word = translate(word,char' ',' 'char)
Return word


As well as xword('Cat and Dog',-1) = 'Dog' you can specify the
separator character as the third parameter. This is useful for
extracting the filename from a fully qualified name:

Say xword('C:\temp\stuff',-1,'\')   	/* stuff */
Extension = xword('file.rex',-1,'.')	/* rex */

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
0
Reply Steve.J.Swift (321) 10/1/2011 7:02:32 PM

In <kopb87l2lv06j3inivevbfgsta1roksb1b@4ax.com>, on 09/30/2011
   at 12:03 PM, Graham Hobbs <ghobbs@cdpwise.net> said:

>Is there a 'common/standard' way to achieve this? All my techniques
>looks like sledgehammer code.

Not in Rexx. I'd use PL/I for that, or generate marked-up text for an
external program to render.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply spamtrap16 (3686) 10/2/2011 12:30:14 AM

On Sat, 01 Oct 2011 20:30:14 -0400, Shmuel (Seymour J.) Metz
<spamtrap@library.lspace.org.invalid> wrote:

>In <kopb87l2lv06j3inivevbfgsta1roksb1b@4ax.com>, on 09/30/2011
>   at 12:03 PM, Graham Hobbs <ghobbs@cdpwise.net> said:
>
>>Is there a 'common/standard' way to achieve this? All my techniques
>>looks like sledgehammer code.
>
>Not in Rexx. I'd use PL/I for that, or generate marked-up text for an
>external program to render.
---
'Not in Rexx' is what I've concluded.
0
Reply ghobbs (110) 10/2/2011 1:41:21 AM

Graham Hobbs wrote:
> On Sat, 01 Oct 2011 20:30:14 -0400, Shmuel (Seymour J.) Metz
> <spamtrap@library.lspace.org.invalid> wrote:
> 
>> In <kopb87l2lv06j3inivevbfgsta1roksb1b@4ax.com>, on 09/30/2011
>>   at 12:03 PM, Graham Hobbs <ghobbs@cdpwise.net> said:
>>
>>> Is there a 'common/standard' way to achieve this? All my techniques
>>> looks like sledgehammer code.
>> Not in Rexx. I'd use PL/I for that, or generate marked-up text for an
>> external program to render.
> ---
> 'Not in Rexx' is what I've concluded.
There has been some work done in this area by RexxLA 
members. See:

http://pragmaticlee.safedataisp.net/

Look for printerobject2.zip

That might get you started.

Additionally, someone just posted to our member maillist a 
note about using it and some additional work he has done.

For information about RexxLA, see:

http://rexxla.org

-- 

Les               (Change Arabic to Roman to email me)
0
Reply 5mre20 (168) 10/2/2011 7:57:25 AM

 > The data is transmitted to me and arrives as shown

IC, the blessings of El Cheapo's free data quality.

 > I have no choice with the format.

What's the rather strange, silly  reason you have to maintain and use 
the original file format with twice the company name in each line, and
you aren't allowed convert this data to a file format better matching 
your goals (like not having to including some sledgehammer in each 
Rexx app using this data)?! 

/* Data */
line='CDN:CSG Cervalier Systems Group 123 1234 12345'

/* Sledgehammer,  I don't care about optimized speed with Rexx*/
PARSE VAR line part.1 line
PARSE VALUE Reverse(line) WITH part.5 part.4 part.3 part.2
DO i=2 TO 5
   part.i=Reverse(part.i)
END i

/* Slightly formatted output */
CALL CharOut '',Left(part.1,10)
CALL CharOut '',Left(part.2,30)
CALL CharOut '',Format(part.3,9,3)
CALL CharOut '',Format(part.4,9,3)
SAY Format(part.5,9,3)
 
I had to make up te format of the last three unknown numbers, assumed 
company names aren't longer than 29-30 characters and the 
[exchange:]symbol has a maximum length of 9 characters (3+1+5, .e.g. 
"TSE:CLSG").

 > The 'only' dodgy bit is the company name

No. You can dynamically create a fixed line length LST file to PARSE, 
actually remove or typically query the full company name. Why do you 
want to "print" both the symbol and the full name (no need to explain,
it may have some use)? As such it may not be an issue, but about 50% 
of your data is the name of the company. Using an existing format also
has the advantage that you can share your data with other people, 
Metastock's PRN file format works fine with Rexx and the single header
line only describes the data fields used. Yet another advantage is 
that you don't have to rewrite a zillion apps if the file format, you 
claim to have no control, changes.


--
0
Reply what.ever (135) 10/2/2011 10:44:00 AM

Swifty wrote:
> As well as xword('Cat and Dog',-1) = 'Dog' you can specify the
> separator character as the third parameter. This is useful for
> extracting the filename from a fully qualified name:
>
> Say xword('C:\temp\stuff',-1,'\')   /* stuff */
> Extension = xword('file.rex',-1,'.') /* rex */

Unfortunately this is not a watertight algorithm for parsing a filespec. 
Example:

  C:\mydata.dir\datafile

(i.e. a file with no extension, and a directory WITH an extension)

-- from CyberSimian in the UK 


0
Reply CyberSimian3 (13) 10/2/2011 1:15:05 PM

 >> I have no choice with the format.

 > CALL CharOut '',Left(part.2,30)

Off-topic again. But if you would try to avoid such a sad data format 
situation, you could actually choose your own company names, based on 
the [exchange:]symbol, instead of having to use too long company names
destroying the mystic report layout. Cervalier, or Cervalier Systems, 
instead of Cervalier Systems Group if you limit it to e.g. 20 
characters. If you have to use the long company name in any report, of
course. Yet another advantage of an own LST file, being able to choose
your own company names.
  

--
0
Reply what.ever (135) 10/2/2011 2:29:42 PM

 > Unfortunately this is not a watertight algorithm for parsing a 
filespec. 

Most likely that was off-topic chatting again, there's no filespec in 
the data at all. Albeit the silly original data format as-is has a 
built-in limitation regarding filenames. It's not recommended, but 
sometimes it can be handy to use the symbol/ticker as a filename. If 
"CDN:CSG" isn't  a valid filename due to the ":", one may have to 
replace the ":" with a "." (or use a directory CDN, which is even more
complicated because that adds directory management to the mix).


--
0
Reply what.ever (135) 10/2/2011 3:01:57 PM

On Sun, 2 Oct 2011 13:15:05 -0000, "CyberSimian"
<CyberSimian3@BeeTeeInternet.com> wrote:

>Unfortunately this is not a watertight algorithm for parsing a filespec. 
>Example:

Ah, but anyone using my xword would know to use:

Ext = xword(xword(file,-1,slash),-1,'.')	/* fifteen all */

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
0
Reply Steve.J.Swift (321) 10/2/2011 6:21:10 PM

I'd use the following:

line = 'CDN:CSG Cervalier Systems Group 123 1234 12345'               
       
                                                                      
       
wx = wordIndex(line, words(line)-2)-1   /* -1 to eliminate trailing 
space */ 
parse var line w1 w2 =(wx) w3 w4 w5                                   
                                                                      
       
say w1'|'; say w2'|'; say w3'|'; say w4'|'; say w5'|' /* test output 
*/       
-- 
Andre
0
Reply anancoz (8) 10/2/2011 6:59:22 PM

 > I'd use the following:
 
 > line = 'CDN:CSG Cervalier Systems Group 123 1234 12345'            
  
 > wx = wordIndex(line, words(line)-2)-1
 > parse var line w1 w2 =(wx) w3 w4 w5                                
  
 > say w1'|'; say w2'|'; say w3'|'; say w4'|'; say w5'|'

This is one of the many possible solutions producing the same perfect 
PARSE-result. If it doesn't work, the original data file format 
actually is not usable. If needed, add a check to e.g. make sure "w5" 
isn't empty, which (for all we know) could happen if the company name 
is too lang and the space before the "123" is lost:

/**/
name='Test'
number='123'
SAY Left(name,5)||number
name='State'
SAY Left(name,5)||number

Not a likely event, but the composer of the data file already included
the name twice, so don't expect a smart design. Usability and 
standards weren't involved in the process. 

No matter which solution is, after hours of research, faster by 0.032 
seconds, it's still recommended to drop/remove the third-party company
name and use the key "CSG" (or "CDN:CSG") to locate the matching 
company name with a known, controllable, fitting company name. That 
can also detect missing recors, and so on.

Anyway, the number of Rexx Words() can always be used. If not, use a 
better data source.


--
0
Reply what.ever (135) 10/2/2011 9:31:37 PM

On Sun, 2 Oct 2011 21:31:37 UTC, "A.D. Fundum" <what.ever@neverm.ind> 
wrote:

> This is one of the many possible solutions producing the same perfect 
> PARSE-result. If it doesn't work, the original data file format 
> actually is not usable. If needed, add a check to e.g. make sure "w5" 
> isn't empty, which (for all we know) could happen if the company name 
> is too lang and the space before the "123" is lost:

No doubt several error checks would have to be included to verify the 
record. The last three fields probably would require a numeric check, 
etc.

-- 
Andre
0
Reply anancoz (8) 10/3/2011 3:23:33 PM

On Fri, 30 Sep 2011 16:03:24 UTC, Graham Hobbs <ghobbs@cdpwise.net> 
wrote:

Hi,

Interesting, but odd message thread...

> Hello,
> Looking for a simple solution:-).
> 
> I have an input file containing many records, each field delimited by
> a space e.g: 
> 
> CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44
> CDN:DSG Descartes Sys Group 2.280 0.000 2.22
> CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17
> 
> I need to print a 'nicely' formatted report e.g.
> 
> CDN:BBD.SVB  BOMBARDIER            2.780  +0.020   1.44
> CDN:DSG          Descartes Sys Group  2.280    0.000   2.22
> CDN:FLO           FLOWING ENERGY   0.750  +0.010   4.17

Looking at your input and your output, I have to suspect that your 
definition of a field in not quite correct.  What I mean is that you 
have what I would call fields that contain spaces.

If what you really have is records with 5 fields where the first field
and the last 3 fields are guaranteed not the contain spaces, splitting
the record into separate fields is not all that difficult.

Assuming my guess as to the the true definition of the fields is 
correct, I would just use word() and words() and a simple loop to 
extract the fields to a stem.  I would not call this a sledgehammer.  
The code can only be as simple as the input data allows.

Setting the output field width can be done by knowing the maximum 
fields widths or by stashing the parsed records in a stem can 
calculating the maximums.

Steven


-- 
---------------------------------------------------------------------
Steven Levine <steve53@earthlink.bogus.net>
eCS/Warp/DIY etc. www.scoug.com www.ecomstation.com
---------------------------------------------------------------------
0
Reply steve531 (9) 10/3/2011 4:05:12 PM

 > Assuming my guess as to the the true definition of the
 > fields is correct, I would just use word() and words()

Indeed each SUBWORD() of your guess is correct too. If it isn't, the 
original input file format basicly is unusable.

 > Setting the output field width can be done by knowing
 > the maximum fields widths

Mr. Hobbs has no control over the incoming data. He should use his own
ompany names (initially perhaps the provided ones, of course). The 
maximum field width you mention may exceed the size of the unknown 
report. Just printing the first e.g. 20 characters may fail with 
company names like "Steven Levine U.S.A." and "Steven Levine U.S.A. 
Holding".

Below is an old, real example. It's a LST file, initially filled with 
data provided by Yahoo!. The Yahoo!-symbol (i.e. the "CDN:CSG"-part) 
always is unique, but the provided Yahoo!-names with a length of 16 
characters may be near useless if you want to distinguish between two 
investment funds: 


AAHElb.AS      ABN AMRO Bank NV
AAHElc.AS      ABN AMRO Bank NV
AAHEld.AS      ABN AMRO Bank NV
AAHEle.AS      ABN AMRO Bank NV
AAHElg.AS      ABN AMRO Bank NV
AAHEs.AS       ABN AMRO Bank NV
AAHT.AS        ABN AMRO Bank NV
ADBS.AS        ABN AMRO Bank NV
ADJA.AS        ABN AMRO Bank NV
ADJE.AS        ABN AMRO Bank NV
AKSP.AS        ABN AMRO Bank NV
AMFF.AS        ABN AMRO Bank NV
AMFH.AS        ABN AMRO Bank NV
AMFO.AS        ABN AMRO Bank NV
AMFS.AS        ABN AMRO Bank NV
AMFT.AS        ABN AMRO Bank NV
AMFV.AS        ABN AMRO Bank NV
ANMK.AS        ABN AMRO Bank NV
ANMX.AS        ABN AMRO Bank NV
ANSD.AS        ABN AMRO Bank NV
ASAP.AS        ABN AMRO Bank NV
ASMX.AS        ABN AMRO Bank NV
JAPB.AS        ABN AMRO Bank NV
JAPBu.AS       ABN AMRO Bank NV
NL20909.AS     ABN AMRO Bank NV
NL20910.AS     ABN AMRO Bank NV
NL20911.AS     ABN AMRO Bank NV
NL20912.AS     ABN AMRO Bank NV
NL20913.AS     ABN AMRO Bank NV
NL23262.AS     ABN AMRO Bank NV
NL43600.AS     ABN AMRO Bank NV
NL43601.AS     ABN AMRO Bank NV
NL43602.AS     ABN AMRO Bank NV
NL43603.AS     ABN AMRO Bank NV
NL43604.AS     ABN AMRO Bank NV
NL43605.AS     ABN AMRO Bank NV
NL43606.AS     ABN AMRO Bank NV
NL43801.AS     ABN AMRO Bank NV
NL45507.AS     ABN AMRO Bank NV
NL45508.AS     ABN AMRO Bank NV
NL45509.AS     ABN AMRO Bank NV
NL45557.AS     ABN AMRO Bank NV
NL48106.AS     ABN AMRO Bank NV
NL48107.AS     ABN AMRO Bank NV
NL48108.AS     ABN AMRO Bank NV
NL48544.AS     ABN AMRO Bank NV
NL48549.AS     ABN AMRO Bank NV
NL48550.AS     ABN AMRO Bank NV
NL48551.AS     ABN AMRO Bank NV
NL48552.AS     ABN AMRO Bank NV
NL48553.AS     ABN AMRO Bank NV
NL48554.AS     ABN AMRO Bank NV
NL48563.AS     ABN AMRO Bank NV
NL48564.AS     ABN AMRO Bank NV
NL48565.AS     ABN AMRO Bank NV
NL48566.AS     ABN AMRO Bank NV
NL48567.AS     ABN AMRO Bank NV
NL48568.AS     ABN AMRO Bank NV
NL48613.AS     ABN AMRO Bank NV
NL48614.AS     ABN AMRO Bank NV
NL48726.AS     ABN AMRO Bank NV
NL48727.AS     ABN AMRO Bank NV
NL48798.AS     ABN AMRO Bank NV
NL48858.AS     ABN AMRO Bank NV
NL48881.AS     ABN AMRO Bank NV
TRAN.AS        ABN AMRO Bank NV


--
0
Reply what.ever (135) 10/3/2011 7:06:02 PM

Swifty wrote:
> Ah, but anyone using my xword would know to use:
> Ext = xword(xword(file,-1,slash),-1,'.') /* fifteen all */

I have no particular desire to rain on your parade, but your second suggestion
still does not give the correct answer for the example that I quoted:

E:\store\o\oorexx\test>rexxtry
REXX-ooRexx_4.1.0(MT) 6.03 5 Dec 2010
  rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
  Go on - try a few...            Enter 'exit' to end.
spec='C:\mydata.dir\datafile'
  ........................................... rexxtry.rex on WindowsNT
ext=xword(xword(spec,-1,'\'),-1,'.')
  ........................................... rexxtry.rex on WindowsNT
say '"'spec'"'
"C:\mydata.dir\datafile"
  ........................................... rexxtry.rex on WindowsNT
say '"'ext'"'
"datafile"
  ........................................... rexxtry.rex on WindowsNT
exit

For this example, the correct answer is (of course) the null string.  Wouldn't
it be easier to use the "filespec()" built-in function?

ext=filespec('E',spec)

And for those responsible for the ooRexx documentation, the description of the
"filespec()" function has these words:

   If filespec the requested information,

Shouldn't there be a "lacks" somewhere in that clause?

-- from CyberSimian in the UK 


0
Reply CyberSimian3 (13) 10/4/2011 9:21:43 AM

Andre Nancoz <anancoz@optonline.net> wrote:

[never mind]

Sorry to reply in the wrong place in the thread, but regarding the original
problem, how about doing something like this:

test.1 = "CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44"
test.2 = "CDNSG Descartes Sys Group 2.280 0.000 2.22"
test.3 = "CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17"
test.0 = 3

scale1 = "<...+....1....+....2....+....3....+....4....+....5"

do tt = 1 to test.0
   testline = test.tt
   maskline = translate(testline,"9999999999","0123456789")
   firstdig = pos("9",maskline)    /* find first digit in mask */
   parse var testline ticktokn ticktext =(firstdig) n1 n2 n3

   say "test line: '" || testline || "'"
   say "mask line: '" || maskline || "'"
   say "scale:      " || scale1
   say "firstdig: " firstdig
   say "tick tokn: '" || ticktokn || "'"
   say "tick text: '" || ticktext || "'"
   say "n1:        '" || n1 || "'"
   say "n2:        '" || n2 || "'"
   say "n3:        '" || n3 || "'"
   say
end 

which produces:

test line: 'CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44'         
mask line: 'CDN:BBD.SVB BOMBARDIER 9.999 +9.999 9.99'         
scale:      <...+....1....+....2....+....3....+....4....+....5
firstdig:  24                                                 
tick tokn: 'CDN:BBD.SVB'                                      
tick text: 'BOMBARDIER '                                      
n1:        '2.780'                                            
n2:        '+0.020'                                           
n3:        '1.44'                                             
                                                              
test line: 'CDNSG Descartes Sys Group 2.280 0.000 2.22'       
mask line: 'CDNSG Descartes Sys Group 9.999 9.999 9.99'       
scale:      <...+....1....+....2....+....3....+....4....+....5
firstdig:  27                                                 
tick tokn: 'CDNSG'                                            
tick text: 'Descartes Sys Group '                             
n1:        '2.280'                                            
n2:        '0.000'                                            
n3:        '2.22'                                             
                                                              
test line: 'CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17'    
mask line: 'CDN:FLO FLOWING ENERGY CORP 9.999 +9.999 9.99'    
scale:      <...+....1....+....2....+....3....+....4....+....5
firstdig:  29                                                 
tick tokn: 'CDN:FLO'                                          
tick text: 'FLOWING ENERGY CORP '                             
n1:        '0.750'                                            
n2:        '+0.010'                                           
n3:        '4.17'                                             



-- 
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsreplyaaa@wingsandbeaks.org.uk replacing "aaa" by "284".  
0
Reply jn.nntp.scrap007 (392) 10/4/2011 11:56:45 AM

On Mon, 3 Oct 2011 19:06:02 UTC, "A.D. Fundum" <what.ever@neverm.ind> 
wrote:

Hi,

> Mr. Hobbs has no control over the incoming data. He should use his own
> ompany names (initially perhaps the provided ones, of course).

You don't know this or I missed it in the problem spec.  There may be 
maximum fields widths which have not yet been specified.  If this data
is coming from a mainframe, this is almost surely the case.

Steven

-- 
---------------------------------------------------------------------
Steven Levine <steve53@earthlink.bogus.net>
eCS/Warp/DIY etc. www.scoug.com www.ecomstation.com
---------------------------------------------------------------------
0
Reply steve531 (9) 10/4/2011 5:09:47 PM

On Tue, 04 Oct 2011 12:09:47 -0500, "Steven Levine"
<steve53@nomail.earthlink.net> wrote:

>On Mon, 3 Oct 2011 19:06:02 UTC, "A.D. Fundum" <what.ever@neverm.ind> 
>wrote:
>
>Hi,
>
>> Mr. Hobbs has no control over the incoming data. He should use his own
>> ompany names (initially perhaps the provided ones, of course).
>
>You don't know this or I missed it in the problem spec.  There may be 
>maximum fields widths which have not yet been specified.  If this data
>is coming from a mainframe, this is almost surely the case.
>
>Steven
---
Steven,
Hilited, copied and pasted from a small list on a website into a .txt
file.
Company name is the problem being one or more space delimited fields.
Remaining fields always total 7 .. I deduce everything from that.
E.g. if parsing shows 10 fields then company name is 10 - 7 = 3
Graham
0
Reply ghobbs (110) 10/4/2011 7:40:41 PM

In <11p86vVJT4Oe-pn2-wzfsfjytvdSV@slamain.slainc.com>, on 10/04/2011
   at 12:09 PM, "Steven Levine" <steve53@nomail.earthlink.net> said:

>You don't know this or I missed it in the problem spec.  There may be
> maximum fields widths which have not yet been specified.  If this
>data is coming from a mainframe, this is almost surely the case.

If the data are coming from a mainframe then the fields are alsmost
certainly at fixed offsets and he doesn't need fancy parsing; a simple
substr() for each field, or the equivalent using parse, will do.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply spamtrap16 (3686) 10/5/2011 1:09:31 AM

Graham Hobbs <ghobbs@cdpwise.net> wrote:

> Company name is the problem being one or more space delimited fields.
> Remaining fields always total 7 .. I deduce everything from that.
> E.g. if parsing shows 10 fields then company name is 10 - 7 = 3

What's wrong with the method I posted?

-- 
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsreplyaaa@wingsandbeaks.org.uk replacing "aaa" by "284".  
0
Reply jn.nntp.scrap007 (392) 10/5/2011 8:18:04 PM

Jeremy Nicoll - news posts wrote:
> Graham Hobbs <ghobbs@cdpwise.net> wrote:
> 
>> Company name is the problem being one or more space delimited fields.
>> Remaining fields always total 7 .. I deduce everything from that.
>> E.g. if parsing shows 10 fields then company name is 10 - 7 = 3
> 
> What's wrong with the method I posted?
> 
What if the company name contains a numeric?

-- 

Les               (Change Arabic to Roman to email me)
0
Reply 5mre20 (168) 10/5/2011 11:22:53 PM

 >> What's wrong with the method I posted?

Not reviewing everything solving the same simple "problem", but ...
 
 > What if the company name contains a numeric?

.... you're still an ignorant idiot if you use unknown company names 
as-is, and this remark is also valid: both the symbol/ticker and name 
may contain "a numeric". For example:

   http://www.google.com/finance?q=ams%3A3wp

Albeit we can make up every name, there's no control over it, so I'ld 
agree with the use of "Interweb Holding 2.00" too.


--
0
Reply what.ever (135) 10/6/2011 9:11:41 AM

 > What if the company name contains a numeric?

Below is a full example, assuming a few things and ignoring displayed 
ignorance.. For one, it assumes the original data is in a file called 
"TODAY.TXT", it assumes there's more crap in a gathered line of data 
(like a % difference compared to the previous trading day), it assumes
the "CDN:" part may be stripped, and so on. It doesn't check the data 
nor all possible events, and so on.

0. This is just an example

1. Store the sample data from the OP in a file called "TODAY.TXT"

2. Run this Rexx file in the same directory

Daily work done. How it works and how to continue:

3. It loads all known stocks with basic data, i.e. the controlable 
full name we'll use with a length of <=20 characters, from a file 
called "STOCKS.LST" (will be created the first time)

4. It adds "new" stocks to STOCKS.LST

5. Using today's Date('S'), a file "2011.PRN" will be created using 
the company name defined in STOCKS.LST

6. In 2011.PRN, it stores each symbol/ticker, 'D' for day-related 
date, the Date('S') and the close 

7. Maintain basic data like full name(s) in STOCKS.LST

8. If needed: using data in YYYY.PRN to calculate results, store the 
calculated results in fixed line length PRN files

9. Gather data using those created PRN files to create the report(s)


--

/* THIS.CMD, not tested */
today=Date('S')
year=Left(today,4)
target=year||'.PRN'
stocks='STOCKS.LST'
listed=0
DO WHILE Lines(stocks>0)
   line=Strip(LineIn(stocks))
   IF line<>'' THEN DO
      listed=listed+1
       PARSE VAR line 1 symbol.listed 11 name.listed 31 .
   END
END
CALL LineOut stocks
source='TODAY.TXT'
IF Stream(source,'C','QUERY EXISTS')='' THEN DO
   SAY 'Error: file' source 'not found'
   EXIT
END
DO WHILE Lines(source)>0
   line=Strip(LineIn(source))
   IF line<>'' THEN DO
      IF Words(line)>4 THEN DO
         PARSE VAR line symbol line
         IF Pos(':',symbol,1)>0 THEN PARSE VAR symbol . ':' symbol
         PARSE VALUE Reverse(line) WITH . . close name
         close=Reverse(close)
         symbol=Translate(symbol)
         found=0
         DO i=1 TO listed
            IF symbol.i==symbol THEN DO 
               found=i
               i=listed
            END
         END i
         IF found=0 THEN DO    
            name=Reverse(name) 
            SAY 'New stock:' Left(symbol,10)||Left(name,20)
            CALL LineOut stocks,Left(symbol,10)||Left(name,20)
            CALL LineOut stocks
            listed=listed+1
            symbol.listed=symbol
            name.listed=Strip(Left(name,20))
         END
         IF Stream(target,'C','QUERY EXISTS')='' THEN DO         
            CALL LineOut target,'<TICKER>,<PER>,<DTYYYYMMDD>,<CLOSE>'
            CALL LineOut target
         END
         CALL LineOut target,symbol||',D,'||today||','||close
         CALL LineOut target
         SAY 'Added data w.r.t.' Left(symbol,10)||':' 
Format(close,10,3)
      END
   END
END
CALL LineOut source
EXIT
0
Reply what.ever (135) 10/6/2011 11:26:06 AM

 > /* THIS.CMD, not tested */

 > CALL LineOut target,symbol||',D,'||today||','||close
 > SAY 'Added data w.r.t.' Left(symbol,10)||':' Format(close,10,3)

FTR: this isn't consistent and just demonstrates formatting.

Actually one of the first this to fix would be to remove the possible 
last 0s after the decimal dot if the length of that part exceeds 2. So
in the 2011.PRN file, "2.222" remains "2.222" but "2.220" should  
become "2.22". The number of decimals in 2011.PRN should at least be 2
("7" becomes "7.00"). The SAY uses a formatted length of 3 for that 
part of the data, the LineOut should use this customized formatting. 
So, assuming the close is 2.220, 2.222 or 7:

/* Best practice (there are more than one) regarding */
/* the frequently used PRN file format */
close=Format(close,,3) 
PARSE VAR close part1 '.' part2
IF Length(part2)>2 THEN DO
   IF Right(part2,1)='0' THEN PARSE part2 1 part2 3 .
END
close=part1||'.'||part2
CALL LineOut target,symbol||',D,'||today||','||close
SAY 'Added data w.r.t.' Left(symbol,10)||':' close


--
0
Reply what.ever (135) 10/6/2011 11:46:55 AM

LesK <5mre20@tampabay.rr.com> wrote:

> What if the company name contains a numeric?

The examples suggested they don't.  Obviously it won't work if they do.

-- 
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsreplyaaa@wingsandbeaks.org.uk replacing "aaa" by "284".  
0
Reply jn.nntp.scrap007 (392) 10/6/2011 11:43:18 PM

On Sep 30, 6:03=A0pm, Graham Hobbs <gho...@cdpwise.net> wrote:
> Hello,
> Looking for a simple solution:-).
>
> I have an input file containing many records, each field delimited by
> a space e.g:
>
> CDN:BBD.SVB BOMBARDIER 2.780 +0.020 1.44
> CDN:DSG Descartes Sys Group 2.280 0.000 2.22
> CDN:FLO FLOWING ENERGY CORP 0.750 +0.010 4.17
>
> I need to print a 'nicely' formatted report e.g.
>
> CDN:BBD.SVB =A0BOMBARDIER =A0 =A0 =A0 =A0 =A0 =A02.780 =A0+0.020 =A0 1.44
> CDN:DSG =A0 =A0 =A0 =A0 =A0Descartes Sys Group =A02.280 =A0 =A00.000 =A0 =
2.22
> CDN:FLO =A0 =A0 =A0 =A0 =A0 FLOWING ENERGY =A0 0.750 =A0+0.010 =A0 4.17
>
> Is there a 'common/standard' way to achieve this? All my techniques
> looks like sledgehammer code.
> Please, thanks
> Graham Hobbs

simple, not optimized (we could check for prev. firm f.e.):
parse value strip(linein(input)) with l
w =3D words(l)
parse value (word(l,1)) (subword(l, 2, w - 4)) (word(l, w - 2))
(word(l, w - 1)) (word(l, w)) ,
    with a b c d e
/* those braces are required! */
.....
a little late, but
hth,
wolfgang
0
Reply wolfgang.riedel52 (16) 10/22/2011 7:25:54 PM

37 Replies
35 Views

(page loaded in 0.75 seconds)

Similiar Articles:


















7/25/2012 3:02:02 PM


Reply: