What's New since 7.2?

This section describes the enhancements made to ILE RPG after 7.2.

New operation code DATA-INTO
DATA-INTO reads data from a structured document, such as JSON, into an RPG variable. It requires a parser to parse the document. The DATA-INTO operation calls the parser, and the parser passes the information in the document back to the DATA-INTO operation, which places the information into the RPG variable.

DCL-DS product QUALIFIED;
   name VARCHAR(25);
   id CHAR(10);
   price PACKED(9 : 2);
END-DS product;

DATA-INTO product %DATA('ProductInfo.JSON' : 'doc=file')
                  %PARSER('MYLIB/MYJSONPARS');
See DATA-INTO (Parse a Document into a Variable), %DATA (document {:options}), %PARSER (parser {: options}).
Built-in function %PROC()
%PROC() returns the external name of the current procedure. See %PROC (Return Name of Current Procedure).
More places that complex qualified names can be used
Complex qualified names are now allowed in the following places:
Support for PCML version 7.0
With PCML version 7.0, the restriction against varying-length arrays and subfields is removed. The value '7.0' is now supported for the QIBM_RPG_PCML_VERSION environment variable, and parameters *V6 and *V7 are supported for the Control specification PGMINFO keyword. See PGMINFO(*PCML | *NO | *DCLCASE { : *MODULE | *V6 | *V7 ... } ).
Nested data structure subfields
When a qualified data structure is defined using free-form syntax, a subfield can be directly defined as a nested data structure subfield. The street subfield in the following data structure is referred to as product.manufacturer.address.street.

DCL-DS product QUALIFIED;
   name VARCHAR(25);
   id CHAR(10);
   DCL-DS manufacturer;
      name VARCHAR(10);
      DCL-DS address;
         street VARCHAR(50);
         city VARCHAR(25);
      END-DS address;
      active IND;
   END-DS manufacturer;
   price PACKED(9 : 2);
END-DS product;
See Nested data structure subfield.
New built-in functions %MAX and %MIN
%MAX returns the maximum value of its operands. %MIN returns the minimum value of its operands. There must be at least two operands, but there is no upper limit on the number of operands when %MAX or %MIN are used in calculations. When %MAX or %MIN are used in Declaration statements, there must be exactly two numeric operands.

In the following example, after the assignment operations, maxval has the value 'Zorro' and minval has the value 'Batman'.


   DCL-S maxval VARCHAR(10);
   DCL-S minval VARCHAR(10);
   DCL-S name1 VARCHAR(20) INZ('Robin');
   DCL-S name2 VARCHAR(10) INZ('Batman');

   maxval = %MAX(name1 : name2 : 'Zorro');
   minval = %MIN(name1 : name2 : 'Zorro');
See %MAX and %MIN (Maximum or Minimum Value).
ALIGN(*FULL) to define the length of a data structure as a multiple of its alignment
When *FULL is specified for the ALIGN keyword, the length of the data structure is a multiple of the alignment size. Without *FULL, the length of the data structure is determined by highest end position of the subfields. Specify the *FULL parameter when defining an aligned data structure to be passed as a parameter to a function or API, or if you use %SIZE to determine the distance between the elements in an array of aligned data structures.

For example, the following two data structures have a float subfield followed by a character subfield with length 1. The alignment size for both data structures is 8. The size of data structure DS_ALIGN_FULL is 16, while the size of data structure DS_ALIGN is 9.


DCL-DS ds_align_full ALIGN(*FULL) QUALIFIED;
    sub1 FLOAT(8);
    sub2 CHAR(1);
END-DS;

DCL-DS ds_align ALIGN QUALIFIED;
    sub1 FLOAT(8);
    sub2 CHAR(1);
END-DS;
See ALIGN{(*FULL)}.
ON-EXIT section
The ON-EXIT section runs every time that a procedure ends, whether the procedure ends normally or abnormally.

In the following example, the procedure allocates heap storage. The code that follows the ON-EXIT operation is always run, so the heap storage is always deallocated. The ON-EXIT section is run whether the procedure ends suddenly due to an unhandled exception, or the procedure is canceled due to the job ending, or the procedure returns normally due to reaching the end of the main part of the procedure or due to reaching a RETURN operation.


dcl-proc myproc;
   p = %alloc(100);

   ...
on-exit;
   dealloc(n) p;
end-proc;

See ON-EXIT (On Exit)

Support for fully free-form source
RPG source with the special directive **FREE in the first line contains only free-form code. The code can begin in column 1 and extend to the end of the line.

There is no practical limit on the length of a source line in fully free-form source.

Fixed-form code is not allowed in fully free-form source, but column-limited source that uses only columns 6-80 can be included by using the /COPY or /INCLUDE directive.

See Fully free-form statements

Extended ALIAS support for files
The ALIAS keyword can now be specified for any externally-described file.

If the ALIAS keyword is specified for a global file that is not qualified, the alternate names of the fields are available for use in the RPG program.

In the following example, the field REQALC in the file MYFILE has the alternate name REQUIRED_ALLOCATION. The ALIAS keyword indicates that the name for this field within the RPG program is REQUIRED_ALLOCATION. See ALIAS


     dcl-f myfile ALIAS;

     read myfile;
     if required_allocation <> 0
     and size > 0;
       ...
Relaxed rules for data structures for I/O operations
  • An externally-described data structure or LIKEREC data structure defined with type *ALL can be used as the result data structure for any I/O operation. See File Operations
    
         dcl-f myfile usage(*input : *output : *update);
         dcl-ds ds extname('MYFILE' : *ALL);
    
         read myfile ds;
         update myfmt ds;
         write myfmt ds;
    
  • When a data structure is defined for a record format of a DISK file using LIKEREC without the second parameter, and the output buffer layout is identical to the input buffer layout, the data structure can be used as the result data structure for any I/O operation.
    
         dcl-f myfile usage(*input : *output : *update);
         dcl-ds ds likerec(fmt);
    
         read myfile ds;
         update myfmt ds;
         write myfmt ds;
    
PCML enhancements
  • Specify the *DCLCASE parameter for the PGMINFO Control specification keyword to have the names in the program-interface information generated in the same case as the names are defined in the RPG source file. See PGMINFO(*PCML | *NO | *DCLCASE { : *MODULE | *V6 | *V7 ... } )
  • Specify PGMINFO(*YES) in the Procedure specification keywords for the procedure that should be included in the program-interface information when a module is being created, or specify PGMINFO(*NO) for the procedures that should not be included. See PGMINFO(*YES | *NO)
DCLOPT(*NOCHGDSLEN)
Specify DCLOPT(*NOCHGDSLEN) to prevent changing the length of a data structure on an Input, Output, or Calculation specification. Specifying DCLOPT(*NOCHGDSLEN) allows %SIZE(data-structure) to be used in more free-form declarations. See DCLOPT(*NOCHGDSLEN
New parameter TGTCCSID for CRTBNDRPG and CRTRPGMOD to support compiling from Unicode source
The ILE RPG compiler normally reads the source files for a compile in the CCSID of the primary source file. Since the compiler supports reading the source only in an EBCDIC CCSID, this means that the compile fails when the primary source file has a Unicode CCSID such as UTF-8 or UTF-16.

The TGTCCSID parameter for the CRTBNDRPG and CRTRPGMOD allows the RPG programmer to specify the CCSID with which the compiler reads the source files for the compile. Specify TGTCCSID(*JOB) or specify a specific EBCDIC CCSID such as TGTCCSID(37) or TGTCCSID(5035).

The default is TGTCCSID(*SRC).

Table 1. Changed Language Elements Since 7.2: Control specification keywords
Element Description
PGMINFO keyword *DCLCASE parameter to generate the names in the program-interface information in the same case as the names are coded in the RPG source file. See PGMINFO(*PCML | *NO | *DCLCASE { : *MODULE | *V6 | *V7 ... } ).
Table 2. Changed Language Elements Since 7.2: File specification keywords
Element Description
ALIAS keyword Allowed for all externally-described files See ALIAS.
Table 3. Changed Language Elements Since 7.2: Definitions
Element Description
DCL-DS operation code DCL-DS can be nested within a qualified data structure. See Nested data structure subfield.
ALIGN(*FULL) The ALIGN keyword can have parameter *FULL causing the length of a data structure to be a multiple of its alignment. See ALIGN{(*FULL)}.
Table 4. New Language Elements Since 7.2: Directives
Element Description
Special directive **FREE **FREE indicates that the source is fully free-form, with RPG code from column 1 to the end of the source line. See Fully free-form statements.
Table 5. New Language Elements Since 7.2: Control specification keywords
Element Description
DCLOPT (*NOCHGDSLEN) keyword Disallow changing the size of a data structure on an Input, Output, or Calculation specification. See DCLOPT(*NOCHGDSLEN.
Table 6. New Language Elements Since 7.2: Built-in functions
Element Description
%DATA Specifies the document to be parsed by the DATA-INTO operation code See %DATA (document {:options}).
%MAX Returns the maximum value of its operands See %MAX (Maximum Value).
%MIN Returns the minimum value of its operands See %MIN (Minimum Value).
%PARSER Specifies the parser for the DATA-INTO operation code See %PARSER (parser {: options}).
%PROC Returns the external name of the current procedure See %PROC (Return Name of Current Procedure).
Table 7. New Language Elements Since 7.2: Control specification keywords
Element Description
DCLOPT (*NOCHGDSLEN) keyword Disallow changing the size of a data structure on an Input, Output, or Calculation specification. See DCLOPT(*NOCHGDSLEN.
Table 8. New Language Elements Since 7.2: Operation codes
Element Description
DATA-INTO Import data from a structured document into an RPG variable. See DATA-INTO (Parse a Document into a Variable).
ON-EXIT Begin the ON-EXIT section. See ON-EXIT (On Exit).