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 Future consideration
Workspace IBM i
Categories Languages - RPG
Created by Guest
Created on Aug 31, 2023

Create a varying length field with the length from a fixed length field

It often happens that I have a field from a database og a screen that is fixed length and have to create a field that is varying length but having the same size as the fixed length.

unfortunately it is not possible to do this:
dcl-s fixedField char(40); // this field will normally come from a database or a screen
dcl-s varField varchar( %size(fixedField) );

or this
dcl-c fixedFieldSize %size(fixedField);
dcl-s varField varchar( fixedFieldSize );

So I have to hardcode it:
dcl-s fixedField char(40);
dcl-s varField varchar(40);
But it would be nice if it could be done so we don't have to hardcode it 
Idea priority Medium
  • Guest
    Reply
    |
    Dec 18, 2023

    Another way of doing it could be that it is possible to override the format like this

    dcl-s varField           like(fixedField) varchar;
    dcl-s packedField        like(zonedField) packed;
    The characteristics of the field is inherited but the format is overridden to varying or packed format.
  • Guest
    Reply
    |
    Oct 19, 2023
    IBM will use this Idea as input to planning, but no commitment is made or implied. This Idea will be updated in the future if IBM implements it. IBM will use votes and comments from others in the community to help prioritize this Idea.

    If this Idea is implemented, it would most likely involve new syntax for the LIKE keyword.

    - IBM Power Systems Development
  • Guest
    Reply
    |
    Sep 25, 2023

    That works for me, but FixedField must be defined in the same procedure, and it must be defined before the dcl-pi.

    ctl-opt nomain;
    dcl-proc p;
    dcl-s fixedfield char(10);
    dcl-pi *n varchar(%len(fixedfield));
    end-pi;
    return 'x';
    end-proc;

    If Fixedfield is a global field, you could define a named constant with the length, and use that named constant in the procedure.

    ctl-opt nomain;
    dcl-s FixedField char(10);
    dcl-c FixedFieldLen %LEN(FixedField);
    dcl-proc p;
    dcl-pi *n varchar(FixedFieldLen);
    end-pi;
    return 'x';
    end-proc;

    - Barbara Morris

  • Guest
    Reply
    |
    Sep 25, 2023

    But it's not working on parm definition:

    Dcl-pi *n varchar(%len(FixedField));

  • Guest
    Reply
    |
    Sep 6, 2023

    Thank you very much for the tip how to do it.

    I will suggest that it is included in the RPG manuals.


  • Guest
    Reply
    |
    Aug 31, 2023

    You can use %LEN to get the length of the fixed-length field.

    dcl-s fixedField char(40);
    dcl-s varField varchar(%len(fixedField));

    If you want the defined length of a varying field, you have to use %LEN(*MAX).

    dcl-s varField2 varchar(40);
    dcl-s fixedField2 char(%len(varField2 : *max));

    However ... To use %LEN like this in a definition, the field specified in the %LEN keyword has to already be defined. So if the %LEN field is coming from an externally-described file, you'd have to define a externally-described data structure and use the subfields for %LEN.

    dcl-f myDbFile;
    dcl-f myScreens workstn;

    dcl-ds myFileDefs extname('MYDBFILE') qualified template;
    end-ds;
    // might have to define several data structures for screen fields, one for each format
    dcl-ds screen1Defs extname('MYSCREENS' : 'SCREEN1' : *all) qualified template;
    end-ds;

    dcl-s varField varchar(%len(myFileDefs.someField));
    dcl-s varField2 varchar(%len(screen1Defs.someOtherField));

    - Barbara Morris