View previous topic :: View next topic |
Author |
Message |
kyrpt8198 Beginner
Joined: 16 Jul 2003 Posts: 2 Topics: 1
|
Posted: Wed Jul 16, 2003 10:27 am Post subject: Dynamically Read WS 01 Group |
|
|
Is it possible to read the lengths from a working storage group?
Example:
01 WS-Personal-Info.
05 Ws-Name PIC X(20) values spaces.
05 Ws-SSN PIC X(09) values spaces.
05 Ws-AGE PIC X(03) values spaces.
You get the idea. Can i loop thru the 05 levels and get their lengths without specificaly naming them. I hope i am getting my question accross. I guess can i say here is 01 'WS-Personal-Info' and then get what's listed under it or the lengths. |
|
Back to top |
|
 |
zatlas Beginner
Joined: 17 Dec 2002 Posts: 43 Topics: 4
|
Posted: Wed Jul 16, 2003 8:36 pm Post subject: |
|
|
Use special register length of, for example, using your code
WORKING-STORAGE SECTION.
77 WS-LEN PIC 9(4).
01 WS-Personal-Info.
05 Ws-Name PIC X(20) values spaces.
05 Ws-SSN PIC X(09) values spaces.
05 Ws-AGE PIC X(03) values spaces.
PROCEDURE DIVISION.
MOVE LENGTH OF WS-Personal-Info TO WS-LEN.
DISPALY "LENGTH OF WS-Personal-Info IS: " WS-LEN.
ZA |
|
Back to top |
|
 |
kyrpt8198 Beginner
Joined: 16 Jul 2003 Posts: 2 Topics: 1
|
Posted: Thu Jul 17, 2003 8:07 am Post subject: |
|
|
I need each individaul variables lenghts. I know how to get the overall length. |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sat Jul 19, 2003 1:14 am Post subject: |
|
|
Hi Krypt,
If your compiler supports it you can try this for each of your 05s:
Code: |
move zeros to ws-t-spaces
inspect reverse(ws-data) tallying ws-t-spaces
for leading spaces
compute ws-len-of-string = length of ws-data
- ws-t-spaces
|
I think that will work.
Regards, Jack. |
|
Back to top |
|
 |
jlmori Beginner
Joined: 20 Jun 2003 Posts: 9 Topics: 1
|
Posted: Tue Jul 22, 2003 5:12 am Post subject: |
|
|
Hi
You could try this:
Code: |
WORKING-STORAGE
05 WS-SUB-NAME PIC S9(9) COMP-3.
05 WS-SUB-SSN PIC S9(9) COMP-3.
05 WS-SUB-AGE PIC S9(9) COMP-3.
05 WS-END-OF-FIELD PIC X.
99 END-FOUND VALUE 'Y'.
99 SPACE-FOUND VALUE 'N'.
PROCEDURE DIVISION.
MOVE 'N' TO WS-END-OF-FIELD
PERFORM VARYING WS-SUB-NAME FROM 20 BY -1
UNTIL END-FOUND OR WS-SUB-NAME = 0
IF WS-NAME(WS-SUB-NAME:1) NOT EQUAL TO SPACE
MOVE 'Y' TO WS-END-OF-FIELD
END-IF
END-PERFORM
MOVE 'N' TO WS-END-OF-FIELD
PERFORM VARYING WS-SUB-SSN FROM 9 BY -1
UNTIL END-FOUND OR WS-SUB-SSN = 0
IF WS-SSN(WS-SUB-SSN:1) NOT EQUAL TO SPACE
MOVE 'Y' TO WS-END-OF-FIELD
END-IF
END-PERFORM
MOVE 'N' TO WS-END-OF-FIELD
PERFORM VARYING WS-SUB-AGE FROM 3 BY -1
UNTIL END-FOUND OR WS-SUB-AGE = 0
IF WS-AGE(WS-SUB-AGE:1) NOT EQUAL TO SPACE
MOVE 'Y' TO WS-END-OF-FIELD
END-IF
END-PERFORM
DISPLAY WS-SUB-NAME
DISPLAY WS-SUB-SSN
DISPLAY WS-SUB-AGE
|
|
|
Back to top |
|
 |
vp Beginner
Joined: 30 Jun 2003 Posts: 9 Topics: 0
|
Posted: Tue Jul 22, 2003 12:12 pm Post subject: |
|
|
You can also try this using UNSTRING function
WORKING STORAGE SECTION
Code: |
01 WS-PERSONAL-INFO.
05 WS-NAME PIC X(20).
05 WS-SSN PIC X(09).
05 WS-AGE PIC X(03).
01 WS-LENGTHS.
05 WS-NAME-LENGTH PIC S9(04) COMP.
05 WS-SSN-LENGTH PIC S9(04) COMP.
05 WS-AGE-LENGTH PIC S9(04) COMP.
01 WS-IN-REC PIC X(100).
PROCEDURE DIVISION.
MOVE 'MYNAME 111222333 21' TO WS-IN-REC
INITIALIZE WS-LENGTHS
WS-PERSONAL-INFO
UNSTRING
WS-IN-REC DELIMITED BY ALL SPACE
INTO
WS-NAME COUNT IN WS-NAME-LENGTH
WS-SSN COUNT IN WS-SSN-LENGTH
WS-AGE COUNT IN WS-AGE-LENGTH
END-UNSTRING
DISPLAY 'INPUT: ' WS-IN-REC
DISPLAY 'OUTPUT: WS-PERSONAL-INFO '
DISPLAY ' NAME IS ' WS-NAME
DISPLAY ' NAME LENGTH IS ' WS-NAME-LENGTH
DISPLAY ' SSN IS ' WS-SSN
DISPLAY ' SSN LENGTH IS ' WS-SSN-LENGTH
DISPLAY ' AGE IS ' WS-AGE
DISPLAY ' AGE LENGTH IS ' WS-AGE-LENGTH
INPUT: MYNAME 111222333 21
OUTPUT: WS-PERSONAL-INFO
NAME IS MYNAME
NAME LENGTH IS 0006
SSN IS 111222333
SSN LENGTH IS 0009
AGE IS 21
AGE LENGTH IS 0002
|
|
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Tue Jul 22, 2003 2:25 pm Post subject: |
|
|
vp,
I don't think your approach will work for a name like "john h smith jr'. Notice that jlmori performs from the end of each string to the beginning for just that reason.
Though, I'd use LENGTH OF WS-NAME instead of "20", etc. It's more flexible.
Regards, Jack. |
|
Back to top |
|
 |
vp Beginner
Joined: 30 Jun 2003 Posts: 9 Topics: 0
|
Posted: Tue Jul 22, 2003 2:51 pm Post subject: |
|
|
slade
Unstring statement is very powerfull you can use any delimiters you need.
If you have a Name-Field that has "firstname lastname, mi " you could use delimited by ' ' (double space). It will not work however, if the other fields only have one space in them.
What can be done is to use Unstring Statement on each field.
i.e.
05 ws-double-space pic x(02) value spaces.
05 some-string pic x(100) value spaces.
Unstring ws-name delimited by ws-double-space
into some-string count in ws-name-length
end-unstring
unstring ws-ssn delimited by space
into some-string count in ws-ssn-length
end-unstring
etc. |
|
Back to top |
|
 |
jlmori Beginner
Joined: 20 Jun 2003 Posts: 9 Topics: 1
|
Posted: Wed Jul 23, 2003 7:31 am Post subject: |
|
|
Hi there
I think vp's method is better than mine because my piece of code would not cater for the space(s) between first name and last name in computing the length of ws-name. My piece of code would require extra processing to cater for this, whereupon the code would become too complex, possibly involving nested perform varyings. So I think it's best for kyrpt8198 to go with the 'unstring' command.
Cheers |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Thu Jul 24, 2003 2:43 am Post subject: |
|
|
Sorry guys. I have to disagree. If you want to get the length of a field that contains embedded spaces, the safest way is to approach it from the back end, using the REVERSE function or a PERFORM VARYING ... BY -1.
Regards, Jack. |
|
Back to top |
|
 |
jlmori Beginner
Joined: 20 Jun 2003 Posts: 9 Topics: 1
|
Posted: Thu Jul 24, 2003 6:18 am Post subject: |
|
|
Hi there
In that case this piece of code may do the trick in getting the length of ws-name:
WORKING-STORAGE.
01 WS-COUNTERS.
05 WS-SPACE-COUNT PIC S9(5) COMP-3.
05 WS-SUB-NAME PIC S9(5) COMP-3.
05 WS-NAME-LENGTH PIC S9(5) COMP-3.
PROCEDURE.
INITIALIZE WS-COUNTERS
PERFORM VARYING WS-SUB-NAME FROM LENGTH-OF-WS-NAME BY -1
UNTIL WS-SUB-NAME = 0
IF WS-NAME(WS-SUB-NAME:1) EQUAL TO SPACE
ADD 1 TO WS-SPACE-COUNT
END-IF
END-PERFORM
COMPUTE WS-NAME-LENGTH = LENGTH-OF-WS-NAME - WS-SPACE-COUNT
DISPLAY 'LENGTH OF WS-NAME =' WS-NAME-LENGTH
The same method can be used in computing the length of ws-ssn and ws-age |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Thu Jul 24, 2003 1:12 pm Post subject: |
|
|
Now you're gettin' my drift. 8)
BTW, LENGTH-OF-WS-NAME should be "LENGTH OF WS-NAME".
Regards, Jack. |
|
Back to top |
|
 |
jlmori Beginner
Joined: 20 Jun 2003 Posts: 9 Topics: 1
|
Posted: Fri Jul 25, 2003 4:18 am Post subject: |
|
|
Hi there
Actually you dont necessarily have to approach it from the back end. You could code it as:
PERFORM VARYING WS-SUB-NAME FROM 1 BY 1
UNTIL WS-SUB-NAME = LENGTH OF WS-NAME +1
IF WS-NAME(WS-SUB-NAME:1) EQUAL TO SPACE
ADD 1 TO WS-SPACE-COUNT
END-IF
END-PERFORM |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sat Jul 26, 2003 1:10 pm Post subject: |
|
|
If you're looking for the number of spaces in a field or non-spaces your technique works. If you want the length of the string in the field you have to approach it from the back.
The only exception is if you know ABSOLUTELY the number of substrings in the string and the number of spaces separating the substrings.
Regards, Jack. |
|
Back to top |
|
 |
jlmori Beginner
Joined: 20 Jun 2003 Posts: 9 Topics: 1
|
Posted: Tue Sep 09, 2003 9:38 pm Post subject: |
|
|
Hi fellow programmers
It would be interesting to find out from kyrpt8198 whether any of the above techniques has helped with his initial problem. After reading his initial problem once again I think it would be virtually impossible to find the lengths of the variables, without reference to the name of the variables. As you can see, most of the above methods, name the variables. Eg, my piece of code
IF WS-NAME(SUB-1:1)
refers explicitly to the variable name WS-NAME.
If there is a method of finding the length of a variable without explicitly naming it, I also would be interested to know about it.
Thanks
Justin |
|
Back to top |
|
 |
|
|