Skip to Main Content
IBM Power Ideas Portal


This portal is to open public enhancement requests against IBM Power Systems products, including IBM i. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


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:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your 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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    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
    Reply
    |
    Feb 13, 2022

    This request will break so many products