Page 1 of 3
Help with Data Selection in PIC Field
Posted:
Wed Jul 28, 2010 10:04 pm
by crazycobol
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
Re: Help with Data Selection in PIC Field
Posted:
Wed Jul 28, 2010 10:42 pm
by Robert Sample
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.
Re: Help with Data Selection in PIC Field
Posted:
Thu Jul 29, 2010 1:10 am
by dick scherrer
Hello,
What if the first name is "JIM BOB "?
Re: Help with Data Selection in PIC Field
Posted:
Thu Jul 29, 2010 3:16 am
by Robert Sample
Hello, Jim?
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).
Re: Help with Data Selection in PIC Field
Posted:
Thu Jul 29, 2010 11:17 pm
by crazycobol
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.
Re: Help with Data Selection in PIC Field
Posted:
Thu Jul 29, 2010 11:20 pm
by crazycobol
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.
Re: Help with Data Selection in PIC Field
Posted:
Fri Jul 30, 2010 12:01 am
by Robert Sample
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>.
Re: Help with Data Selection in PIC Field
Posted:
Fri Jul 30, 2010 12:18 am
by crazycobol
Thanks Robert. Thats a quick response. It worked for the first record however it didn't continue down to the rest of the data.
Re: Help with Data Selection in PIC Field
Posted:
Fri Jul 30, 2010 4:21 am
by Robert Sample
Did you reset WS-I to zero before the second record?
Re: Help with Data Selection in PIC Field
Posted:
Fri Jul 30, 2010 10:56 pm
by crazycobol
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.