if we have a variable Picx(10),i want to pass a string "resh"into itwhich is of only 4 size.Then,how can we find out the actual length of the string when it contains spaces in cobol?
Printable View
if we have a variable Picx(10),i want to pass a string "resh"into itwhich is of only 4 size.Then,how can we find out the actual length of the string when it contains spaces in cobol?
[QUOTE=sdresh;17233]if we have a variable Picx(10),i want to pass a string "resh"into itwhich is of only 4 size.Then,how can we find out the actual length of the string when it contains spaces in cobol?[/QUOTE]
Hi resh,
you can use a counter to find the actual length:
declare variable count of pic 9(01).
then:
perform varying count from 1 by 1 until Variable(count) equals spaces
The length of variable will be = count - 1.
Cheers,
[QUOTE=mail_mathewsonyc;17305]Hi resh,
you can use a counter to find the actual length:
declare variable count of pic 9(01).
then:
perform varying count from 1 by 1 until Variable(count) equals spaces
The length of variable will be = count - 1.
Cheers,[/QUOTE]
i would like to make the question clear that how can we find the actual length of the string at runtime.pls clarify?
say a Variable has ws-name pic X(10)
and the text as "radi"
declare another variable with pic 9(2) or something
say ws-count pic 9(2)
then
INSPECT WS-NAME TALLYING WS-COUNT FOR CHRACTERS BEFORE INITIAL ' '.
WS-COUNT would have the actual length.
[QUOTE=radibioinfo;18801]say a Variable has ws-name pic X(10)
and the text as "radi"
declare another variable with pic 9(2) or something
say ws-count pic 9(2)
then
INSPECT WS-NAME TALLYING WS-COUNT FOR CHRACTERS BEFORE INITIAL ' '.
WS-COUNT would have the actual length.[/QUOTE]
That's right :)
and in addition, in order to increase performance, you should use signed packed decimal counter instead of edited format : for cobol, [B]S[/B]9(nn) [B]COMP-3[/B]
is really better than 9(nn)