Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageOn 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"?
Post Follow-up to this messageHoward 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?
Post Follow-up to this messageOn 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.
Post Follow-up to this messageHoward 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
Post Follow-up to this messageOn 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.
Post Follow-up to this messageHoward 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.
Post Follow-up to this messageHoward 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.
Post Follow-up to this messageOn 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.
Post Follow-up to this messagejeff@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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.