MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

cobol string size

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
vihv
Beginner


Joined: 16 Apr 2007
Posts: 11
Topics: 4

PostPosted: Wed Oct 03, 2007 11:34 am    Post subject: cobol string size Reply with quote

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
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Wed Oct 03, 2007 11:41 am    Post subject: Reply with quote

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
View user's profile Send private message
CICS Guy
Intermediate


Joined: 30 Apr 2007
Posts: 292
Topics: 3

PostPosted: Wed Oct 03, 2007 3:30 pm    Post subject: Re: cobol string size Reply with quote

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
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Wed Oct 03, 2007 5:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Thu Oct 04, 2007 8:45 am    Post subject: Reply with quote

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
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Oct 04, 2007 8:56 am    Post subject: Reply with quote

I use slade's method, but don't forget to initialize L before your inspect statement.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Thu Oct 04, 2007 9:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Oct 04, 2007 9:28 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Oct 04, 2007 9:34 am    Post subject: Reply with quote

I'd edit my post to correct the grammar, but can't find the "edit" referred to in FAQ. Sad
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Thu Oct 04, 2007 10:57 am    Post subject: Reply with quote

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
View user's profile Send private message
CICS Guy
Intermediate


Joined: 30 Apr 2007
Posts: 292
Topics: 3

PostPosted: Thu Oct 04, 2007 3:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Fri Oct 05, 2007 9:06 am    Post subject: Reply with quote

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." Smile
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
vihv
Beginner


Joined: 16 Apr 2007
Posts: 11
Topics: 4

PostPosted: Tue Nov 27, 2007 12:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Tue Nov 27, 2007 12:52 pm    Post subject: Reply with quote

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

Wink
Between the REVERSE function and the INSPECT verb that shouldn't use up too many CPU cycles.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Nov 27, 2007 2:00 pm    Post subject: Reply with quote

well - you were told it by slade on Oct 4thy
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group