Skip to Main Content
IBM Power Ideas Portal

Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Post your ideas

Start by posting ideas and requests to this portal to enhance a Power product or service. Take a look at ideas others have posted and upvote them if they matter to you,

  1. Post an idea

  2. Upvote ideas and add comments to ideas that matter most to you

  3. Get feedback from the IBM team to refine your idea

Help IBM prioritize your ideas and requests

The IBM team may need your help to refine the ideas so they may ask for more information or feedback. The Power teams will then decide if they can begin working on your idea. If they can start during the next development cycle, they will put the idea on the priority list. Each team at IBM works on a different schedule, where some ideas can be implemented right away, others may be placed on a different schedule.

Receive notification on the decision

Some ideas can be implemented at IBM, while others may not fit within the development plans for the product. In either case, the team will let you know as soon as possible. In some cases, we may be able to find alternatives for ideas which cannot be implemented in a reasonable time.


Specific link you will want to bookmark for future use

IBM Unified Ideas Portal - https://ideas.ibm.com/ - Use this site to create or search for existing Ideas across all IBM products that are outside of Power, and track all of your personal interactions with all Ideas.

Status Not under consideration
Workspace IBM i
Categories Languages - RPG
Created by Guest
Created on Feb 13, 2022

Remove or Relaxe the error when %SUBST length exceeds length of data

The runtime for RPG currently blows up if %SUBST(var : START : LENGTH ) length value exceeds the length of the VAR or if it is 0.
Provide an option to ignore this issue for runtime purposes. OPTION(*NOLENCHK) (No Length Check) which would cause runtime to ignore this issue and not end with RNX0115.


Use Case:

A %SUBST( VAR : 1) runs fine for a VAR of any length.
However %SUBST(VAR : 3 : 15) will fail if VAR is less than 17 bytes in length. When Length exceeds the number of bytes available in VAR, then it should be treated as if it were unspecified and the length calculated to the end of the variable, except when the 3rd parameter is 0, then it should be treated as no bytes and return nothing or change nothing.


Idea priority High
  • Guest
    May 22, 2022

    Just omitting the length parameter doesn't solve all the cases, for example I have a field that returns the status of an HTTP operation, for example '200 OK' (but if the operation fails - for example the server was down - it returns an empty string). The problem is that not all servers respond with the same text so I only need to test the numeric part.

    In my code I would test If %SubSt(Status: 1: 3) = '200' .. but that fails if the string is empty. My work around now is to code If %SubSt(Status + ' ': 1: 3) = '200' but I consider it rather silly code.

    Another solution would be If %Split(Status: ' ') = '200' but %Split returns an array :-( Please vote IBMI-I-3265 for allowing an index on the %Split operation, ie. %Split(Status: ' ')(1)

  • Guest
    Mar 22, 2022

    Thank you for taking the time to submit your request, and thank you for providing additional information about the request.

    We understand the request, and agree with it in general. Although. we think that in many cases where the length operand for %SUBST is too long, it should have simply been omitted, allowing the %SUBST operation to return the remaining data following the start position. Note that the length operand for %SUBST has always been optional.

    After careful consideration, we know that we cannot deliver this enhancement soon, so it is being declined. However, we believe this request may have future value, so we will add it to an internal list for us to keep in mind for the future.

  • Guest
    Mar 4, 2022

    Ah, crap! Thanks.
    I get the various SST, SUBST, and SUBSTR (CL, RPG, SQL) substring features mixed up.
    In RPG I would like the option to have the LENGTH parameter not generate an error when it causes the SUBST to exceed the right-end of the value.
    If EVAL(e) would do it, fine, but it typically occurs on a conditional statement so that wouldn't apply.

    For the most part, this is "found bugs" in Legacy code that I come across where it fails "today" for the first time due to the original programmer not checking the LENGTH argument. Probably because it was written before %LEN worked like it does today.
    So rather than go in an change this logic in "27 places" I would prefer a Header spec option that simply says, "Keep going" in this context.
    Thanks.

  • Guest
    Mar 3, 2022

    Bob, it has always been possible to omit the length operand for %SUBST. If trhe length operand is omitted, the length defaults to the length remaining in the field starting at the start position.

    Please verify that this RFE can be closed, since it's easier to just omit the length operand than it would be to add a new keyword about ignoring length errors.

  • Guest
    Mar 2, 2022

    Omitting the Length would be preferred.
    But ignoring the length-too-long situation would be nice for existing code. But once we have the ability to omit the length, then that's good enough.

    Here's one scenario:

    dcl-s workField varchar(255);
    dcl-s company varchar(255);
    workField = %upper(company);

    eval X = %scan(WorkField, 'Q'); // Find first 'Q' in the field
    eval target = %SUBST( CompanyName : X+1 : 255); // Read from first 'Q' + 1 to end of field

  • Guest
    Mar 2, 2022

    Please provide a "real-life" scenario where just omitting the length operand wouldn't work just as well as ignoring the length-too-long situation.

  • Guest
    Feb 16, 2022

    Sean and Niels, if you note the detail I added, (a compiler CTL-OPT keyword) that turns it off, it won't break anyone's code.
    In fact, I don't see who even if it were just done without a switch to control it, it would break code. Well if you mean "break" by making it continue instead of ending, then yes, I agree, if your code depends on this happening (can't imagine a scenario where it would but so be it) then it would "break" that if you recompiled. Hence, the Switch/Option was asked for.

  • Guest
    Feb 15, 2022

    There has already been raised a RFE for %left() and %right() many years ago.
    https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=93115

    But Bobs suggestion to lax the check if the position or length exceeds the length of the string using an option like OPTION(*NOLENCHK) is OK.

  • Guest
    Feb 14, 2022

    This is a great RFE.
    It is however not only the length but also the position: it try to do a substring to take the first character of a zero length string aka. %SUBST ( '':1:1) then both the length and position causes the exception.

    But as @Sean Batson is noticing - if implemented in the the current SUBST it will cause a lot of issues. So may I suggest - perhaps at new set of build-in: %Left, %Right, %Mid

    For that reason we have our own strLeft(), strMid(), strRight() functions that implements that for RPG.

    https://github.com/sitemule/ILEstdlib/blob/master/src/string.c

  • Guest
    Feb 13, 2022

    This request will break so many products