Help with Data Selection in PIC Field



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Help with Data Selection in PIC Field

Postby crazycobol » Wed Jul 28, 2010 10:04 pm

Hello. I need help with something and maybe someone can help me out. I'll try and explain. I have a field called first_name that contain the person first name in that field. The field is 15 character in length.

Example:

first_name: John D

I am doing a data extraction that I only want JOHN and not the D. How would I go about doing that?

Another question as well. I have a field that is an address field. In that field, if the first letter is an "N", I would like to perform a statement to clear the address field to spaces. The address field is 20 character in length.

Any help is much appreciated. Thank you
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Help with Data Selection in PIC Field

Postby Robert Sample » Wed Jul 28, 2010 10:42 pm

Reference modification will do both of these.

Find the first space in the first name field and store the location of that space in WS-I.
MOVE FIRST-NAME (1 : WS-I) TO OUTPUT-VAR


For the second one:
IF  ADDR-FIELD (1 : 1) = 'N'
MOVE SPACES TO ADDR-FIELD.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Help with Data Selection in PIC Field

Postby dick scherrer » Thu Jul 29, 2010 1:10 am

Hello,

What if the first name is "JIM BOB "?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Help with Data Selection in PIC Field

Postby Robert Sample » Thu Jul 29, 2010 3:16 am

Hello, Jim?

:D

What Dick's example points out is that the rules are not comprehensive yet -- your cutting off at the first space won't always get good results (J K Rowling, for another example).
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Help with Data Selection in PIC Field

Postby crazycobol » Thu Jul 29, 2010 11:17 pm

Thanks Robert for responding. The address code worked great.

Can you explain to me the First Name issue. I'm not quite understanding.

I define WS-I first with

10 WS-I PIC X VALUE SPACE.

THEN IN THE PROGRAM, I PUT THIS STATEMENT:

MOVE FIRST-NAME (1:WS-I) TO OUTPUT-VAR.

The output-var is the data containing "JOHN"

Thanks again for your help. It is much appreciated.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Help with Data Selection in PIC Field

Postby crazycobol » Thu Jul 29, 2010 11:20 pm

You guys make a very valid point. As for now, I would like to get it to work so it only contain "JOHN" instead of "JOHN D"

Then when the issue arrise with the two name JIM BOB or J R Rowling, I would deal with it at that time. Thanks again.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Help with Data Selection in PIC Field

Postby Robert Sample » Fri Jul 30, 2010 12:01 am

77  WS-I PIC S9(08) COMP VALUE +0.


INSPECT FIRST-NAME TALLYING WS-I FOR CHARACTERS BEFORE INITIAL SPACE.
MOVE FIRST-NAME (1 : WS-I) TO <output variable>.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Help with Data Selection in PIC Field

Postby crazycobol » Fri Jul 30, 2010 12:18 am

Thanks Robert. Thats a quick response. It worked for the first record however it didn't continue down to the rest of the data.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Help with Data Selection in PIC Field

Postby Robert Sample » Fri Jul 30, 2010 4:21 am

Did you reset WS-I to zero before the second record?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Help with Data Selection in PIC Field

Postby crazycobol » Fri Jul 30, 2010 10:56 pm

i got it to work Robert with your suggestion with zero it out before the 2nd record. Its working as it should. Thank you very much for your help in this.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post