Highlighted
Absent Member.
Absent Member.
966 views

content size of a string

Good afternoon, please have a string type variable and it has a text of x characters, there is a function so that I can get the exact size of this content, I am joining 3 variables in a string and getting whitespace between them , example:
set variable to var1 & var2 & var3
So, what for?
text1                           text2                                      text3
and I need you to stay
text1 text2 text3
thank you
0 Likes
6 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: content size of a string

One way is to use the STRING statement:

string
   var1 delimited by space
   var2 delimited by space
   var3 delimited by space
   into variable

–Ғɑɳօ
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: content size of a string

thanks, this form I already used, but not right, as it is a text contains several spaces in this text, there I lost part of the text, I am using a class in .net visual cobol for the visual sudio
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: content size of a string

It's not clear to me from the question how var1 etc. are defined. Is it something like:
01 var1 string. *> var1 is a string object
...or more like:
01 var pic x(32). *> var1 is a conventional COBOL alphanumeric data item.

If the first, you could try using the Trim function, e.g.
set variable to var1::Trim & space & var2::Trim & space & var3::Trim.
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: content size of a string

In either way, it should work with the Trim or TrimEnd functions. The Trim will remove all leading and trailing spaces while TrimEnd will only remove the trailing spaces.
–Ғɑɳօ
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: content size of a string

You can create a user function that computes the trailing space trimmed length of a PIC x(length) data item and then use the trimmed length in reference modification such as stringvar(1: trimmedlength) to reference the trailing space trimmed string.

Here's a possible example of such a trimmed length user function:

identification division.
function-id. trimlength.

environment division.
configuration section.

data division.
working-storage section.
01 trim-length pic 9(9) binary.

linkage section.
01 string1 pic x any length.
01 length1 pic 9(9) binary.

procedure division using string1 returning length1.
000-start.

move 0 to trim-length
inspect function reverse(string1)
tallying trim-length for leading spaces
* inspect string1 tallying trim-length for trailing spaces
compute length1 = length of string1 - trim-length
exit function
.

end function trimlength.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: content size of a string

Thank you very much, it worked.
Cheers
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.