Cobol Calculate the length of a string

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS
ignacio
Posts: 5
Joined: Sun Mar 02, 2008 10:33 pm
Skillset: AS400 18 years as analyst, programmer and administration.
Referer: Google

Cobol Calculate the length of a string

Postby ignacio » Mon Mar 03, 2008 3:23 am

How can I calculate the length of a string if the corresponding intrinsec function is not avaliable?
Is there a better way, in terms of performance, than a PERFORM FROM LEN OF field STEP -1 UNTIL switch-found = True or field(n:1) not = SPACES. I have tried the INSPECT but in some cases does not give a correct result, and in any case is slower than the PERFORM loop option.

Regards.
Ignacio.

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: Cobol Calculate the length of a string

Postby dick scherrer » Mon Mar 03, 2008 6:04 am

Hello,

Starting at the "right" side of the field and moving backwards by -1 may be your best bet.
Hope this helps,
d.sch.

ignacio
Posts: 5
Joined: Sun Mar 02, 2008 10:33 pm
Skillset: AS400 18 years as analyst, programmer and administration.
Referer: Google

Re: Cobol Calculate the length of a string

Postby ignacio » Mon Mar 03, 2008 8:33 pm

Thank you Dick, that's what I am doing now.
Regards.
Ignacio.

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: Cobol Calculate the length of a string

Postby dick scherrer » Mon Mar 03, 2008 9:07 pm

You're welcome - good luck :)

d

mahi
Posts: 1
Joined: Thu Jul 03, 2008 2:52 pm
Skillset: Cobol, DB2, CICS, JCL & VSAM, EXPEDITOR,ENDEVOUR
Referer: through my friend

Re: Cobol Calculate the length of a string

Postby mahi » Thu Jul 03, 2008 3:01 pm

*
PERFORM VARYING IP-NAME-LEN FROM 56 BY -1
UNTIL (IP-NAME-LEN < 1)
OR (IP-NAME-TEXT(IP-NAME-LEN:1)
NOT = SPACE)
END-PERFORM.

Can u please brief out what is this functions.??

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: Cobol Calculate the length of a string

Postby dick scherrer » Thu Jul 03, 2008 10:25 pm

Hello mahi and welcome to the forums,

The code you posted will look at the text field and determine the length of the content. The rule for that code is that trailing blanks should not be included in the length.

If you make up some values, move them to the text field and execute that routine with a display of ip-name-len after the perform completes, you will see how it works.
Hope this helps,
d.sch.


  • Similar Topics
    Replies
    Views
    Last post