Skip to main content

IBM i Feature Requests and Requirements

 Last exported on by

Qualified data structures in CLID: 215

    Click to rate
Currently CL variables whose storage is defined inside another variable (known in RPG as a data structure) cannot be qualified to that variable. CL modules are getting more and more complex given the expanded features IBM has introduced. The number of variables are getting larger and so are the number of data structure sub-fields and they must have unique names within the module. It is getting harder and harder to devise self-documenting field names with only 10 characters to work with, which was the problem that RPG had for many years before IBM allowed for qualified data structures.
It will make the programmer's job much easier and saves time in writing code. Therefore they will be able to write more self-documenting code and finish faster to be able to work on more useful endeavors.
There is no work-around. Unique sub-field names have to be devised and heavily documented so that other programmers will know what is going on.
I propose changing the DEFVAR parameter in the DCL command to have a 3rd element. It would have a default of *UNQUAL (for an unqualified sub-field) and it would allow a 2nd value of *QUAL (for a qualified sub-field).

DCL VAR(&QUALNAME) TYPE(*CHAR) LEN(20)
DCL VAR(&NAME) TYPE(*CHAR) STG(*DEFINED) LEN(10) +
    DEFVAR(&QUALNAME 1 *QUAL)
DCL VAR(&LIB) TYPE(*CHAR) STG(*DEFINED) LEN(10) +
    DEFVAR(&QUALNAME 11 *QUAL)

Variables declared this way can only be referenced with the qualifying name they're defined in, like so:

CHGVAR VAR(&QUALNAME:&NAME) VALUE('MYOBJ')
CHGVAR VAR(&QUALNAME:&LIB) VALUE('*LIBL')

This way other CL data structures can be defined with the same sub-fields:

DCL VAR(&OUTQ) TYPE(*CHAR) LEN(20)
DCL VAR(&NAME) TYPE(*CHAR) STG(*DEFINED) LEN(10) +
    DEFVAR(&OUTQ 1 *QUAL)
DCL VAR(&LIB) TYPE(*CHAR) STG(*DEFINED) LEN(10) +
    DEFVAR(&OUTQ 11 *QUAL)

CHGVAR VAR(&OUTQ:&NAME) VALUE('MYOUTQ')
CHGVAR VAR(&OUTQ:&LIB) VALUE('MYLIB')

(In RPG the separator character is a period(.) but in CL it's a valid character in variable names, so another character was needed. The best fit for this seemed to be the colon(:) character.)

Of course, if need be the entire data structure can also be referenced as:

CHGVAR VAR(&QUALNAME) VALUE('MYOBJ *LIBL')

Responsibility Contacts

Originator

As a member of COMMON, you can search our database of requirement requests.

If you cannot find an answer to your questions, click here to send us an email.