About SUBST function

335 pts.
Tags:
AS/400
AS/400 FUNCTIONS
I'm doing a SUBST on a string from a position where the character is space like this: eval str1 = %subst(str1:(wpos1+3)) Let us assume that the string is of 15 length and the string in this str1 as 'SURESH '. The value in wpos1 as '7' . Now if we try to extract the spaces according to the expression, is there a possibility of getting an error? If it results in error what is the error code and could you please help me. Thanks in advance.

Software/Hardware used:
iseries or as400 v7r1

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 13  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Why would there be an error? There's nothing wrong with what you've shown. If an error happens, it has nothing to do with that code, so we have no idea what the error might be. An example of an error that might happen could be that str1 is a parameter value. The error could be that the calling program only passed a 10-char variable, and putting a new value into a 15-char area could cause an error. But that's a simple random guess. No one knows what might happen in a program we can't see. . Tom
    125,585 pointsBadges:
    report
  • JSDHFKJHA
    RNQ0100 ' Message . . . . : Length or start position is out of range for the string operation (C G D F). ' i am getting this error when i am trying to extract a part from a string, from a position where there is no character could u please let me know how i can resolve this problem
    335 pointsBadges:
    report
  • TomLiotta
    You need to show the data definitions for str1 and wpos1. Also, show how you know that wpos1 has a value of (7) at the time of the error. If you have dump, the value of wpos1 will be shown in it. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    BTW, there are characters there, if the field is 15 characters long. They are all 'blank' characters, but those are characters. -- Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Unless STR1 is defined with the varying keyword.
    50,385 pointsBadges:
    report
  • Splat
    If you check, you will find the value of wpos1 + 3 exceeds the length of str1.  You might want to look into either validating wpos1 before the substring operation or utilising the Monitor function.
    7,395 pointsBadges:
    report
  • Splat
    If you check, you will find the value of wpos1 + 3 exceeds the length of str1.  You might want to look into either validating wpos1 before the substring operation or utilising the Monitor function.
    7,395 pointsBadges:
    report
  • Splat
    I have no earthly idea as to why that duplicated.
    7,395 pointsBadges:
    report
  • TomLiotta
    Yes, a VARYING field could be an issue, and that's why we need to see the actual definition. If it turns out to be VARYING, then we'd also need to see its current length. A dump would show its value and its current length. -- Tom
    125,585 pointsBadges:
    report
  • JSDHFKJHA
    Yes finally i think we are close to the solution it seems because the str1 variable in the program is defined with the keyword varying. now could u people please help me how can i resolve this issue without removing the keyword varying in the definition of the str1 Thanks in advance
    335 pointsBadges:
    report
  • TomLiotta
    You need to check your starting position against the current length of the field before trying to extract any characters. Since you always use (+ 3) in your expression, you might have something like this:
    if wpos1 > (%len(str1) - 3) ;
       // some default code...
    else ;
       str1 = %subst(str1:(wpos1+3)) ;
    endif ;
    Or you might use a MONITOR-block:
    monitor ;
       str1 = %subst(str1:(wpos1+3)) ;
    on-err ;
       // error code here...
    endmon ;
    The %LEN() function will tell you the current length in characters (or digits) of a variable or epression. You can use it to ensure that your functions stay within bounds of fields.
    .
    Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Your original question stated the assumption that the length was "15". Now it seems that that was a false assumption. That makes it hard to find solutions to problems, and it's why it helps to show definitions in the questions. -- Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Wrap-up D Str1 s 15A VARING Working length of Str1 is the length of the data put into the string. 15 is the maximum length. The working length is found with %len(str1) Addressing positions beyound this length will cause an error.
    50,385 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following