Home > Archive > Cobol > August 2006 > Inspect tallying?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| jeff@sum-it.com 2006-07-17, 6:55 pm |
| I was wondering if anyone could help me out here on what is the best
way to accomplsh this:
I have a customer-name stored in a 40 byte field ie Joe Johnson
I need to move this to:
01 cust-rec.
03 cust-key-1.
05 cust-name.
07 cust-last-name pic x(20).
07 cust-first-name pic x(20).
In order to read it. Trying to figure out if/how would I use the
inspect statement to move the first name to cust-first-name and last
name to cust-last-name.
| |
| Howard Brazee 2006-07-17, 6:55 pm |
| On 17 Jul 2006 09:49:24 -0700, jeff@sum-it.com wrote:
>I was wondering if anyone could help me out here on what is the best
>way to accomplsh this:
>
>I have a customer-name stored in a 40 byte field ie Joe Johnson
>I need to move this to:
> 01 cust-rec.
> 03 cust-key-1.
> 05 cust-name.
> 07 cust-last-name pic x(20).
> 07 cust-first-name pic x(20).
>In order to read it. Trying to figure out if/how would I use the
>inspect statement to move the first name to cust-first-name and last
>name to cust-last-name.
First, do you know what you want to do about people with two last
names, Jr. and other variations from the "standard"?
| |
| jeff@sum-it.com 2006-07-17, 6:55 pm |
|
Howard Brazee wrote:
> On 17 Jul 2006 09:49:24 -0700, jeff@sum-it.com wrote:
>
>
> First, do you know what you want to do about people with two last
> names, Jr. and other variations from the "standard"?
Not sure how to handle that as well. This is for a sales report.
Another part of the key is the cust no, but the system allows no
cust-no and enter a Cust-name in any format, most enter as Joe Johnson.
Should I use an inspect tally before initial space? Or a perform
varying loop?
| |
| Howard Brazee 2006-07-17, 6:55 pm |
| On 17 Jul 2006 10:17:04 -0700, jeff@sum-it.com wrote:
>
>Not sure how to handle that as well. This is for a sales report.
>Another part of the key is the cust no, but the system allows no
>cust-no and enter a Cust-name in any format, most enter as Joe Johnson.
>Should I use an inspect tally before initial space? Or a perform
>varying loop?
I used to use INSPECT for this kind of thing, I've pretty much
switched to using reference modification loops.
When I'm given an assignment like this, I have learned to expect that
there will need to be some further data manipulation to handle
exceptions.
| |
| jeff@sum-it.com 2006-07-17, 6:55 pm |
|
Howard Brazee wrote:
> On 17 Jul 2006 10:17:04 -0700, jeff@sum-it.com wrote:
>
>
> I used to use INSPECT for this kind of thing, I've pretty much
> switched to using reference modification loops.
>
> When I'm given an assignment like this, I have learned to expect that
> there will need to be some further data manipulation to handle
> exceptions.
2 seperate loops? perform move first-name
perform move last-name
| |
| Howard Brazee 2006-07-17, 6:55 pm |
| On 17 Jul 2006 11:05:26 -0700, jeff@sum-it.com wrote:
>
>
>2 seperate loops? perform move first-name
> perform move last-name
Here's an approach (without error checking):
PERFORM VARYING LAST-CHAR FROM 40 BY -1 UNTIL FULL-NAME (LAST-CHAR >
space)
END-PERFORM.
PERFORM VARYING FIRST-CHARACTER FROM LAST-CHAR by -1 UNTIL FULL-NAME
(FIRST-CHAR) = SPACE
END-PERFORM.
ADD 1 TO FIRST-CHAR.
MOVE FULL-NAME (FIRST-CHAR:LAST-CHAR) TO CUST-LAST-NAME.
SUBTRACT 2 from FIRST-CHAR GIVING LAST-CHAR.
MOVE FULL-NAME (1:LAST-CHAR) TO CUST-FIRST-NAME.
This fails for Ken Griffey jr., for Madonna, Maria Gomez y Jones.
| |
| jeff@sum-it.com 2006-07-17, 6:55 pm |
|
Howard Brazee wrote:
> On 17 Jul 2006 11:05:26 -0700, jeff@sum-it.com wrote:
>
>
>
> Here's an approach (without error checking):
>
> PERFORM VARYING LAST-CHAR FROM 40 BY -1 UNTIL FULL-NAME (LAST-CHAR >
> space)
> END-PERFORM.
>
> PERFORM VARYING FIRST-CHARACTER FROM LAST-CHAR by -1 UNTIL FULL-NAME
> (FIRST-CHAR) = SPACE
> END-PERFORM.
>
> ADD 1 TO FIRST-CHAR.
> MOVE FULL-NAME (FIRST-CHAR:LAST-CHAR) TO CUST-LAST-NAME.
>
> SUBTRACT 2 from FIRST-CHAR GIVING LAST-CHAR.
> MOVE FULL-NAME (1:LAST-CHAR) TO CUST-FIRST-NAME.
>
> This fails for Ken Griffey jr., for Madonna, Maria Gomez y Jones.
Thanks, I was going to move full-name to a char-array pic x occurs and
look for first space move to first-name. add 2 to i and do the same for
last name. I will try your way.
| |
| jeff@sum-it.com 2006-07-17, 6:55 pm |
|
Howard Brazee wrote:
> On 17 Jul 2006 11:05:26 -0700, jeff@sum-it.com wrote:
>
>
>
> Here's an approach (without error checking):
>
> PERFORM VARYING LAST-CHAR FROM 40 BY -1 UNTIL FULL-NAME (LAST-CHAR >
> space)
> END-PERFORM.
>
> PERFORM VARYING FIRST-CHARACTER FROM LAST-CHAR by -1 UNTIL FULL-NAME
> (FIRST-CHAR) = SPACE
> END-PERFORM.
>
> ADD 1 TO FIRST-CHAR.
> MOVE FULL-NAME (FIRST-CHAR:LAST-CHAR) TO CUST-LAST-NAME.
>
> SUBTRACT 2 from FIRST-CHAR GIVING LAST-CHAR.
> MOVE FULL-NAME (1:LAST-CHAR) TO CUST-FIRST-NAME.
>
> This fails for Ken Griffey jr., for Madonna, Maria Gomez y Jones.
Getting these errors on the compile
\salescust.cbl, line 2208: ':' expected, '>' found
\salescust.cbl, line 2208: identifier expected, '>' found
\salescust.cbl, line 2208: Verb expected, '>' found
\salescust.cbl, line 2211: ':' expected, ')' found
\salescust.cbl, line 2211: identifier expected, ')' found
\salescust.cbl, line 2211: Verb expected, ')' found
2206 move-name-fields.
2207 perform varying last-char from 40 by -1 until
2208 ws-psc-cust-name(last-char > " ").
2210 perform varying first-char from last-char by -1 until
2211 ws-psc-cust-name(first-char) = " ".
2213 add 1 to first-char.
2214 move ws-psc-cust-name(first-char:last-char) to
2215 cust-last-name.
2216 subtract 2 from first-char giving last-char.
2217 move ws-psc-cust-name(1:last-char) to cust-first-name.
| |
| Howard Brazee 2006-07-17, 6:55 pm |
| On 17 Jul 2006 11:38:42 -0700, jeff@sum-it.com wrote:
>Getting these errors on the compile
>\salescust.cbl, line 2208: ':' expected, '>' found
>\salescust.cbl, line 2208: identifier expected, '>' found
>\salescust.cbl, line 2208: Verb expected, '>' found
>\salescust.cbl, line 2211: ':' expected, ')' found
>\salescust.cbl, line 2211: identifier expected, ')' found
>\salescust.cbl, line 2211: Verb expected, ')' found
>
>2206 move-name-fields.
>2207 perform varying last-char from 40 by -1 until
>2208 ws-psc-cust-name(last-char > " ").
>
>2210 perform varying first-char from last-char by -1 until
>2211 ws-psc-cust-name(first-char) = " ".
>
>2213 add 1 to first-char.
>2214 move ws-psc-cust-name(first-char:last-char) to
>2215 cust-last-name.
>2216 subtract 2 from first-char giving last-char.
>2217 move ws-psc-cust-name(1:last-char) to cust-first-name.
Sorry, wrote fast. The format of the UNTIL is:
until (ws-pc-cust-name(last-char:1) > space).
Look up reference modification to see what it does. I recommend
working backwards on the assumption that the last name is the
important one.
| |
| William M. Klein 2006-07-17, 6:55 pm |
| Others have already hinted at this, but there is a world of difference between
doing this as a "class assignment" (or for a VERY simply database) versus doing
this for a real business. There are business and (sold) software that do
nothing but try and "parse" name fields.
If your input has already been "cleaned" or this is a class assignment or you
are GUARANTEED that someone has already verified that all the first names are
single strings of non-blank characters and the last names are single strings of
non-blank characters, then using INSPECT, loops, whatever should work.
Otherwise (in the "real world") this is a VERY complex assignment.
--
Bill Klein
wmklein <at> ix.netcom.com
<jeff@sum-it.com> wrote in message
news:1153154964.045841.165730@m73g2000cwd.googlegroups.com...
>I was wondering if anyone could help me out here on what is the best
> way to accomplsh this:
>
> I have a customer-name stored in a 40 byte field ie Joe Johnson
> I need to move this to:
> 01 cust-rec.
> 03 cust-key-1.
> 05 cust-name.
> 07 cust-last-name pic x(20).
> 07 cust-first-name pic x(20).
> In order to read it. Trying to figure out if/how would I use the
> inspect statement to move the first name to cust-first-name and last
> name to cust-last-name.
>
| |
| Richard 2006-07-17, 6:55 pm |
|
jeff@sum-it.com wrote:
> Getting these errors on the compile
> \salescust.cbl, line 2208: ':' expected, '>' found
> \salescust.cbl, line 2208: identifier expected, '>' found
> \salescust.cbl, line 2208: Verb expected, '>' found
> \salescust.cbl, line 2211: ':' expected, ')' found
> \salescust.cbl, line 2211: identifier expected, ')' found
> \salescust.cbl, line 2211: Verb expected, ')' found
>
> 2206 move-name-fields.
> 2207 perform varying last-char from 40 by -1 until
> 2208 ws-psc-cust-name(last-char > " ").
The close bracket is misplaced.
You should terminate this correctly with an end-perform.
You should cater for a completely blank field by testing for this first
or by including a test for it with:
until last-char < 1 or ws-psc-cust-name(last-char) > space
> 2210 perform varying first-char from last-char by -1 until
> 2211 ws-psc-cust-name(first-char) = " ".
test for < 0
> 2213 add 1 to first-char.
> 2214 move ws-psc-cust-name(first-char:last-char) to
> 2215 cust-last-name.
Reference modification is (first-char:length) not (first:last)
> 2216 subtract 2 from first-char giving last-char.
> 2217 move ws-psc-cust-name(1:last-char) to cust-first-name.
| |
| Donald Tees 2006-07-17, 6:55 pm |
| jeff@sum-it.com wrote:
> I was wondering if anyone could help me out here on what is the best
> way to accomplsh this:
>
> I have a customer-name stored in a 40 byte field ie Joe Johnson
> I need to move this to:
> 01 cust-rec.
> 03 cust-key-1.
> 05 cust-name.
> 07 cust-last-name pic x(20).
> 07 cust-first-name pic x(20).
> In order to read it. Trying to figure out if/how would I use the
> inspect statement to move the first name to cust-first-name and last
> name to cust-last-name.
>
Move space to custname.
unstring customer-name delimited by all space into cust-first-name,
cust-last-name.
Tally counts things.
Of course, that only works if there are two valid names. It might be
preferable to unstring into first, middle and last, then move the middle
to last if it ends up blank.
Donald
| |
| Pete Dashwood 2006-07-18, 7:55 am |
|
<jeff@sum-it.com> wrote in message
news:1153154964.045841.165730@m73g2000cwd.googlegroups.com...
>I was wondering if anyone could help me out here on what is the best
> way to accomplsh this:
>
> I have a customer-name stored in a 40 byte field ie Joe Johnson
> I need to move this to:
> 01 cust-rec.
> 03 cust-key-1.
> 05 cust-name.
> 07 cust-last-name pic x(20).
> 07 cust-first-name pic x(20).
> In order to read it. Trying to figure out if/how would I use the
> inspect statement to move the first name to cust-first-name and last
> name to cust-last-name.
>
Don Tees solution is the best in my opinion.
Use UNSTRING for this...it is silly to run through it char by char.
And Bill Klein made a very valid point, that to do this properly is a
non-trivial exercise...
If you want a detailed solution using unstring, post here and request it. I
have one somewhere, but it would take me a while to find it...
Pete.
| |
| Howard Brazee 2006-07-18, 6:55 pm |
| On Mon, 17 Jul 2006 17:28:16 -0400, Donald Tees
<donald_tees@sympatico.ca> wrote:
>Move space to custname.
>unstring customer-name delimited by all space into cust-first-name,
>cust-last-name.
>
>Tally counts things.
>
>Of course, that only works if there are two valid names. It might be
>preferable to unstring into first, middle and last, then move the middle
>to last if it ends up blank.
Or 4 names, or 2 last names, or Jr. or III, or with commas
apostrophes...
| |
| James J. Gavan 2006-07-18, 6:55 pm |
| jeff@sum-it.com wrote:
> Howard Brazee wrote:
>
>
> Thanks, I was going to move full-name to a char-array pic x occurs and
> look for first space move to first-name. add 2 to i and do the same for
> last name. I will try your way.
You used the term "char-array" - a bit unusual in COBOL. Are you using
Net Express ? As an adaptation of what Donald suggested there is an OO
Class that will let you split the name :-
Jean Baptiste de la Salle (Jean Baptiste is the 'first name').
The OO technique will give you a collection of FIVE elements for the
above - it drops ALL intervening spaces, which you can STRING back
together again, introducing SINGLE spaces in between. But how you figure
first name = 'Jean Baptiste' and last name = 'de la Salle' - you are on
your own :-). It's the same probem Howard quoted above "Jr" and "Gomez y
Jones".
If it *is* Net Express I can post an example of the code - but you would
have to figure out first and last names.
Jimmy
| |
| ShadowFox 2006-08-01, 6:55 pm |
| Hey Pete,
I usually use unstring for things like this.
unstring name field delimited by ' ' into
aa count in a
bb count in b
cc count in c
dd count in d.
In this example if c = 0 and d = 0 asume aa is fname and bb is lname.
if d = 0 and c not = 0 then you have 3 parts. fname mname lname or prefix
fname lname or fname lname suffix. Believe me there are quit a few bazillion
combinations that come up so now I use a program by Peoplesmith Software
called STYLELIST that does a super job. When you start getting names like Mr
G Howard Smith Senior you can go bats. But If you really want to get into it
I could send you some old code I have.
Bob
"Pete Dashwood" <dashwood@enternet.co.nz> wrote in message
news:4i4051F2243nU1@individual.net...
>
> <jeff@sum-it.com> wrote in message
> news:1153154964.045841.165730@m73g2000cwd.googlegroups.com...
> Don Tees solution is the best in my opinion.
>
> Use UNSTRING for this...it is silly to run through it char by char.
>
> And Bill Klein made a very valid point, that to do this properly is a
> non-trivial exercise...
>
> If you want a detailed solution using unstring, post here and request it.
> I have one somewhere, but it would take me a while to find it...
>
> Pete.
>
| |
| Clark F Morris 2006-08-01, 6:55 pm |
| On Tue, 1 Aug 2006 17:50:16 -0400, "ShadowFox" <Fixit4you@comcast.net>
wrote:
>Hey Pete,
>I usually use unstring for things like this.
>unstring name field delimited by ' ' into
> aa count in a
> bb count in b
> cc count in c
> dd count in d.
>In this example if c = 0 and d = 0 asume aa is fname and bb is lname.
>if d = 0 and c not = 0 then you have 3 parts. fname mname lname or prefix
>fname lname or fname lname suffix. Believe me there are quit a few bazillion
>combinations that come up so now I use a program by Peoplesmith Software
>called STYLELIST that does a super job. When you start getting names like Mr
>G Howard Smith Senior you can go bats. But If you really want to get into it
>I could send you some old code I have.
And then there is Harold Junior Theriault (I think I recall the
spelling of the last name correctly), a member of the Legislative
Assembly of Nova Scotia from the Digby area. I believe that Social
Security in the US once gagged on someone who had a number as part of
their name. There is Avenue of the Americas in Manhattan under which
runs the Sixth Avenue subway. There are a number of Martin Luther
King, Jr. Boulevards, Streets and Avenues in the United States. Makes
for great fun in parsing names and addresses.
Incidentally the businesses should get together and push to have the
decision to renumber the postal codes in New Zealand reversed. The
confusion caused by reuse of a number for a different address is
something that should have been avoided even if the codes had to be
expanded.
>
>Bob
>"Pete Dashwood" <dashwood@enternet.co.nz> wrote in message
>news:4i4051F2243nU1@individual.net...
>
| |
| Richard 2006-08-01, 9:55 pm |
|
Clark F Morris wrote:
> There is Avenue of the Americas
In Yorkshire most of the streets don't have 'road' or 'street' appended
but have 'gate'* as part of the name in the manner of the viking
origins. Thus Warmgate, Stonegate, Swinegate are roads in York. They
also had streets called Parliment (talking place), Pavement, and
Shambles. The shortest street is 10 metres long and is called
Whip-ma-whop-ma-gate.
* gate has the meaning: 'place to walk' as in gait or gateway. The
construction that stops people is a bar, thus Warmgate Bar is the
building at the end of Warmgate which they can close.
| |
| James J. Gavan 2006-08-01, 9:55 pm |
| Richard wrote:
> Clark F Morris wrote:
>
>
>
>
> In Yorkshire most of the streets don't have 'road' or 'street' appended
> but have 'gate'* as part of the name in the manner of the viking
> origins. Thus Warmgate, Stonegate, Swinegate are roads in York. They
> also had streets called Parliment (talking place), Pavement, and
> Shambles. The shortest street is 10 metres long and is called
> Whip-ma-whop-ma-gate.
>
> * gate has the meaning: 'place to walk' as in gait or gateway. The
> construction that stops people is a bar, thus Warmgate Bar is the
> building at the end of Warmgate which they can close.
>
Just to add to the UK confusion second to last and last where we lived,
and after all this time I have no idea what the postal codes were :-
a) 44 Great Hinton
Near Trowbridge, Wilts.
Possibly a 1,000 or more residences now and a very desirable village for
buying property. Wins prizes now for Wiltshire's prettiest village.
b) 'Kimbles' Worthy Lane
Creech St. Michael
Near Taunton, Somerset
Real 'romantic' because 'Kimbles' was the dance-hall we met at in
Southsea. Problem was, my cousin pointed out it should have been spelled
correctly as 'Kimbells'.
First time a Canadian secretary typed to us at (b) above, the address
came out :-
Creech Street Michael !
Jimmy
|
|
|
|
|