Results 1 to 5 of 5

Thread: Find out the actual length of string

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Answers
    9

    Arrow Find out the actual length of string

    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?


  2. #2

    Cool Re: cobol

    Quote Originally Posted by sdresh View Post
    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?
    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,


  3. #3
    Junior Member
    Join Date
    Aug 2007
    Answers
    9

    Re: cobol

    Quote Originally Posted by mail_mathewsonyc View Post
    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,
    i would like to make the question clear that how can we find the actual length of the string at runtime.pls clarify?


  4. #4
    Junior Member
    Join Date
    Feb 2006
    Answers
    1

    Post Re: Find out the actual length of string

    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.


  5. #5
    Junior Member
    Join Date
    Dec 2007
    Answers
    4

    Smile Re: Find out the actual length of string

    Quote Originally Posted by radibioinfo View Post
    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.
    That's right

    and in addition, in order to increase performance, you should use signed packed decimal counter instead of edited format : for cobol, S9(nn) COMP-3
    is really better than 9(nn)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact