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.
Cobol Calculate the length of a string
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Cobol Calculate the length of a string
Hello,
Starting at the "right" side of the field and moving backwards by -1 may be your best bet.
Starting at the "right" side of the field and moving backwards by -1 may be your best bet.
Hope this helps,
d.sch.
d.sch.
-
- 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
Thank you Dick, that's what I am doing now.
Regards.
Ignacio.
Regards.
Ignacio.
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Cobol Calculate the length of a string
You're welcome - good luck
d

d
-
- 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
*
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.??
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.??
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Cobol Calculate the length of a string
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.
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.
d.sch.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Replace a string with another string with different length
by Devrana » Sun Jan 19, 2025 3:23 pm » in JCL - 1
- 1644
-
by sergeyken
View the latest post
Sun Jan 19, 2025 11:07 pm
-
-
- 1
- 2990
-
by oliver07
View the latest post
Sat Oct 30, 2021 2:32 pm
-
-
Finding duplicate in variable lenght string in cobol
by kanipriya2785 » Fri Jun 17, 2022 10:02 pm » in IBM Cobol - 8
- 3449
-
by sergeyken
View the latest post
Wed Jun 22, 2022 3:10 am
-
-
-
Convert fixed-length input records to variable-length output
by xcspg3 » Wed Oct 23, 2024 1:45 pm » in DFSORT/ICETOOL/ICEGENER - 5
- 1455
-
by sergeyken
View the latest post
Wed Oct 30, 2024 1:09 pm
-
-
-
Merge multiple fixed length files of different record length
by corvette1982 » Mon Mar 01, 2021 11:46 pm » in JCL - 8
- 5292
-
by willy jensen
View the latest post
Tue Mar 02, 2021 3:02 am
-