View previous topic :: View next topic |
Author |
Message |
vihv Beginner
Joined: 16 Apr 2007 Posts: 11 Topics: 4
|
Posted: Wed Oct 03, 2007 11:34 am Post subject: cobol string size |
|
|
Hi guys, I have a variable pic x(1000), i'm trying to find how many bytes of that area are populated with data, the "length of" command gives me the length of the whole area, do you know any way of knowing the size of the data stored in that area.
I dont want to loop from 1000 to 0 to find out the actual length of the data.
any ideas....thanks
eg. ws-customer-name pic x(1000).
move "jhon" to ws-customer-name
In this example ws-customer-name size is 4. |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Wed Oct 03, 2007 11:41 am Post subject: |
|
|
If you're populating the field, use a STRING statement with the DELIMITED BY and WITH POINTER clauses. The pointer will tell you how many characters you're moving. If you're looking for the length of a field that's already populated, I think your best bet would be the loop. |
|
Back to top |
|
|
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Wed Oct 03, 2007 3:30 pm Post subject: Re: cobol string size |
|
|
vihv wrote: | I dont want to loop from 1000 to 0 to find out the actual length of the data. |
Quote: | In this example ws-customer-name size is 4. | Sorry, after the data is moved, the size is the whole thing....
After the move, you will have to subtract the number of trailing spaces...... |
|
Back to top |
|
|
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Wed Oct 03, 2007 5:42 pm Post subject: |
|
|
COBOL doesn't deal with strings, it deals with fields. If you don't like that then use C or some other language. |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Thu Oct 04, 2007 8:45 am Post subject: |
|
|
Hi Vhiv,
You might try something like this:
Code: | INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L |
where: TEXT1 contains your field and L is the number of spaces, then (after the COMPUTE) the resultion: actual length of text in TEXT1. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Oct 04, 2007 8:56 am Post subject: |
|
|
I use slade's method, but don't forget to initialize L before your inspect statement. _________________ ....Terry |
|
Back to top |
|
|
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Thu Oct 04, 2007 9:10 am Post subject: |
|
|
Terry_Heinze wrote: | I use slade's method, but don't forget to initialize L before your inspect statement. |
I would think that the combination of INSPECT, REVERSE, and COMPUTE would be worse then a simple loop starting at 1000 and decrementing until the first none blank character. |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Oct 04, 2007 9:28 am Post subject: |
|
|
Either method will work. I guess I prefer the inspect/compute option since it's fewer statements and gave me the opportunity to familiarize myself with a function. If this had to be done repeatedly throughout the execution of a program, I'd benchmark the two methods to see if there was any significant performance issues. _________________ ....Terry |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Oct 04, 2007 9:34 am Post subject: |
|
|
I'd edit my post to correct the grammar, but can't find the "edit" referred to in FAQ. _________________ ....Terry |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Thu Oct 04, 2007 10:57 am Post subject: |
|
|
CraigG,
Quote: | COBOL doesn't deal with strings, it deals with fields. |
Somebody should contact IBM to let them know. Chapter 6 in the Enterprise COBOL for z/OS and OS/390 Programming Guide is titled Handling Strings. |
|
Back to top |
|
|
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Thu Oct 04, 2007 3:22 pm Post subject: |
|
|
jsharon1248 wrote: | Chapter 6 in the Enterprise COBOL for z/OS and OS/390 Programming Guide is titled Handling Strings. | Cute....COBOL can handle strings, but the STRING/UNSTRING does not apply to this, INSPECT & intrinsic functions have been mentioned and reference modification (from 1000 to 0) has been refused...Null terminated hasn't been mentioned..... |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Fri Oct 05, 2007 9:06 am Post subject: |
|
|
A better choice of words might have been, "COBOL doesn't handle strings as nicely as some other languages. Reference modification was a big improvement in string handling." _________________ ....Terry |
|
Back to top |
|
|
vihv Beginner
Joined: 16 Apr 2007 Posts: 11 Topics: 4
|
Posted: Tue Nov 27, 2007 12:27 pm Post subject: |
|
|
well, I found a cobol function to do it: Code: |
2500-GET-SIZE-OF-SEQ-AREA.
INITIALIZE WS-TALLY
INSPECT FUNCTION REVERSE(WS-SEQUENTIAL-DATA)
TALLYING WS-TALLY
FOR LEADING SPACES
COMPUTE WS-DATA-LENGTH =
LENGTH OF WS-SEQUENTIAL-DATA - WS-TALLY
END OF PARA
.
2500-EXIT.
EXIt.
|
inspect function reverse will do the trick |
|
Back to top |
|
|
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Tue Nov 27, 2007 12:52 pm Post subject: |
|
|
vihv wrote: | well, I found a cobol function to do it: Code: |
2500-GET-SIZE-OF-SEQ-AREA.
INITIALIZE WS-TALLY
INSPECT FUNCTION REVERSE(WS-SEQUENTIAL-DATA)
TALLYING WS-TALLY
FOR LEADING SPACES
COMPUTE WS-DATA-LENGTH =
LENGTH OF WS-SEQUENTIAL-DATA - WS-TALLY
END OF PARA
.
2500-EXIT.
EXIt.
|
inspect function reverse will do the trick |
Between the REVERSE function and the INSPECT verb that shouldn't use up too many CPU cycles. |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Nov 27, 2007 2:00 pm Post subject: |
|
|
well - you were told it by slade on Oct 4thy _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
|
|