Skip to Main Content
IBM Z Software


This portal is to open public enhancement requests against IBM Z Software products. 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 Delivered
Workspace PL/I Compilers
Created by Guest
Created on Mar 19, 2018

SUBSTR Optional Parameter

Sometimes it's is easier to specify the ending position instead of the length in the third parameter, specifically when parsing a string for keywords and values.

Can an optional parameter be added to the SUBSTR built-in function that will indicate that the third parameter is an ending position, not a length?

I know my example below is not functional as coded, but I'm trying to be brief and show the benefit of using the ending position over the length in SUBSTR vs. showing an actual working module.

mystring = 'value1=abc,value2=def';

keyword_start = 1
do until(keyword_end = -1);

keyword_end = index(mystring,'=',keyword_start)-1;

keyword = substr(mystring,keyword_start,keyword_end,1);

/* keyword = substr(mystring,keyword_start,keyword_end-keyword_start+1); */

value_start = keyword_end+2;

value_end = index(mystring,',',keyword_end)-1;

value = substr(mystring,value_start,value_end,1);
/* value = substr(mystring,value_start,value_end-value_start+1); */

keyword_start = index(mystring,',',keyword_end+1)+1;

end;

In this case, this implementation is cleaner and briefer than specifying the length since it is calculated.

Idea priority Low
  • Guest
    Reply
    |
    Apr 29, 2020

    This has been delivered in a PTF to the 5.3 compiler via the new SUBTO built-in function

  • Guest
    Reply
    |
    Apr 24, 2018

    We will do this, probably as SUBTO

  • Guest
    Reply
    |
    Apr 23, 2018

    I was always wondering if the usage of builtin functions has relevant performance benefits over "selfwritten" funcs.
    And why there are no "c-standard-library-equivalents" are available for pl/i.
    Maybe someone can comment on that?

    Not knowing the above, i workarounded a situation similar to the thread-starter by writing my own function, any comments on that?

    substr_foo: proc(str, start, end) returns(char(100) var);
    dcl str char(*);
    dcl (start,end) bin fixed(15);
    return(substr(str, start, (end-start+1) ) );
    end substr_foo;

    br johann

  • Guest
    Reply
    |
    Apr 5, 2018

    I just thought of a slightly different use of the optional argument which might be more palatable. In my original example, I specified a '1' in a fourth argument to indicate the third argument was an ending position, not a length.

    A better approach would be to have the fourth argument be the ending position, not an indicator. So a user could call SUBSTR as it exists now to indicate length:
    MyNewString = substr(MyOldString,12,10)

    Or, they could call it with an optional argument to indicate the ending position:
    MyNewString = substr(MyOldString,12,,21)

    If the optional argument was present, it would take precedence over the third argument.

    Again, if IBM prefers a new function, that is fine with me.

  • Guest
    Reply
    |
    Apr 5, 2018

    It's perfectly fine to introduce a new function if that is preferred over an optional argument to SUBSTR, although there is precedence for an optional argument. INDEX started out with two arguments and grew to 3 arguments the last being the starting position which was added years later and is optional.

    If you want to introduce a new function, the name SUBTO works for me. It's a shorter name than SUBTHRU, less typing and more room on the line for code.

  • Guest
    Reply
    |
    Apr 4, 2018

    changing the status to "need more information" until my questions are answered

  • Guest
    Reply
    |
    Apr 4, 2018

    I think it would indeed be useful to have this ability, but I'm not a fan of providing it via an extra option. Would having an alternately named built-in function be ok? and if so, we're open to suggestions for names. Perhaps it could be SUBTHRU or SUBTO or ??