What's New in this Release

This section describes the enhancements made to ILE RPG in V7R1.

Sort and search data structure arrays

Data structure arrays can be sorted and searched using one of the subfields as a key.

     // Sort the custDs array by the amount_owing subfield
     SORTA custDs(*).amount_owing;

     // Search for an element in the custDs array where the
     // account_status subfield is "K"
     elem = %LOOKUP("K" : custDs(*).account_status);
Sort an array either ascending or descending

An array can be sorted ascending using SORTA(A) and descending using SORTA(D). The array cannot be a sequenced array (ASCEND or DESCEND keyword).

     // Sort the salary array in descending order
     SORTA(D) salary;
New built-in function %SCANRPL (scan and replace)

The %SCANRPL built-in function scans for all occurrences of a value within a string and replaces them with another value.

     // Replace NAME with 'Tom'
     string1 = 'See NAME. See NAME run. Run NAME run.';
     string2 = %ScanRpl('NAME' : 'Tom' : string1);
     // string2 = 'See Tom. See Tom run. Run Tom run.'
%LEN(varying : *MAX)

The %LEN builtin function can be used to obtain the maximum number of characters for a varying-length character, UCS-2 or Graphic field.

Use ALIAS names in externally-described data structures

Use the ALIAS keyword on a Definition specification to indicate that you want to use the alternate names for the subfields of externally-described data structures. Use the ALIAS keyword on a File specification to indicate that you want to use the alternate names for LIKEREC data structures defined from the records of the file.

     A          R CUSTREC
     A            CUSTNM        25A         ALIAS(CUSTOMER_NAME)
     A            CUSTAD        25A         ALIAS(CUSTOMER_ADDRESS)
     A            ID            10P 0

     D custDs        e ds                  ALIAS
     D                                     QUALIFIED EXTNAME(custFile)
      /free
        custDs.customer_name = 'John Smith';
        custDs.customer_address = '123 Mockingbird Lane';
        custDs.id = 12345;
Faster return values

A procedure defined with the RTNPARM keyword handles the return value as a hidden parameter. When a procedure is prototyped to return a very large value, especially a very large varying value, the performance for calling the procedure can be significantly improved by defining the procedure with the RTNPARM keyword.

     D getFileData     pr              a   varying len(1000000)
     D                                     rtnparm
     D   file                          a   const varying len(500)
     D data            S               a   varying len(1000)
      /free    
         data = getFileData ('/home/mydir/myfile.txt');
%PARMNUM built-in function

The %PARMNUM(parameter_name) built-in function returns the ordinal number of the parameter within the parameter list. It is especially important to use this built-in function when a procedure is coded with the RTNPARM keyword.

     D                 pi
     D   name                       100a   const varying
     D   id                          10i 0 value
     D   errorInfo                         likeds(errs_t)
     D                                     options(*nopass)
      /free
        // Check if the "errorInfo" parameter was passed
        if %parms >= %parmnum(errorInfo);
Optional prototypes

If a program or procedure is not called by another RPG module, it is optional to specify the prototype. The prototype may be omitted for the following types of programs and procedures:

Pass any type of string parameter
Implicit conversion will be done for string parameters passed by value or by read-only reference. For example, a procedure can be prototyped to have a CONST UCS-2 parameter, and character expression can be passed as a parameter on a call to the procedure. This enables you to write a single procedure with the parameters and return value prototyped with the UCS-2 type. To call that procedure, you can pass any type of string parameter, and assign the return value to any type of string variable.
     // The makeTitle procedure upper-cases the value
     // and centers it within the provided length
     alphaTitle = makeTitle(alphaValue : 50);
     ucs2Title = makeTitle(ucs2Value : 50);
     dbcsTitle = makeTitle(dbcsValue : 50);
Two new options for XML-INTO

These options are also available through a PTF for V6R1.

Teraspace storage model

RPG modules and programs can be created to use the teraspace storage model or to inherit the storage model of their caller. With the teraspace storage model, the system limits regarding automatic storage are significantly higher that for the single-level storage model. There are limits for the amount of automatic storage for a single procedure and for the total automatic storage of all the procedures on the call stack.

Use the storage model (STGMDL) parameter on the CRTRPGMOD or CRTBNDRPG command, or use the STGMDL keyword on the Control specification.

*TERASPACE
The program or module uses the teraspace storage model.
*SNGLVL
The program or module uses the single-level storage model.
*INHERIT
The program or module inherits the storage model of its caller.
Change to the ACTGRP parameter of the CRTBNDRPG command and the ACTGRP keyword on the Control specification

The default value of the ACTGRP parameter and keyword is changed from QILE to *STGMDL.

ACTGRP(*STGMDL) specifies that the activation group depends on the storage model of the program. When the storage model is *TERASPACE, ACTGRP(*STGMDL) is the same as ACTGRP(QILETS). Otherwise, ACTGRP(*STGMDL) is the same as ACTGRP(QILE).

Note:
The change to the ACTGRP parameter and keyword does not affect the default way the activation group is assigned to the program. The default value for the STGMDL parameter and keyword is *SNGLVL, so when the ACTGRP parameter or keyword is not specified, the activation group of the program will default to QILE as it did in prior releases.
Allocate teraspace storage

Use the ALLOC keyword on the Control specification to specify whether the RPG storage-management operations in the module will use teraspace storage or single-level storage. The maximum size of a teraspace storage allocation is significantly larger than the maximum size of a single-level storage allocation.

Encrypted listing debug view

When a module's listing debug view is encrypted, the listing view can only be viewed during a debug session when the person doing the debugging knows the encryption key. This enables you to send debuggable programs to your customers without enabling your customers to see your source code through the listing view. Use the DBGENCKEY parameter on the CRTRPGMOD, CRTBNDRPG, or CRTSQLRPGI command.

Table 1. Changed Language Elements Since V6R1
Language Unit Element Description
Control specification keywords ACTGRP(*STGMDL) *STGMDL is the new default for the ACTGRP keyword and command parameter. If the program uses the teraspace storage module, the activation group is QILETS. Otherwise it is QILE.
Built-in functions %LEN(varying-field : *MAX) Can now be used to obtain the maximum number of characters of a varying-length field.
Operation codes SORTA(A | D) The SORTA operation code now allows the A and D operation extenders indicating whether the array should be sorted ascending (A) or descending (D).
Table 2. New Language Elements Since V6R1
Language Unit Element Description
Control specification keywords STGMDL(*INHERIT | *TERASPACE | *SNGLVL) Controls the storage model of the module or program
ALLOC(*STGMDL | *TERASPACE | *SNGLVL) Controls the storage model for the storage-managent operations %ALLOC, %REALLOC, DEALLOC, ALLOC, REALLOC
File specification keywords ALIAS Use the alternate field names for the subfields of data structures defined with the LIKEREC keyword
Definition specification keywords ALIAS Use the alternate field names for the subfields of the externally-described data structure
RTNPARM Specifies that the return value for the procedure should be handled as a hidden parameter
Built-in functions %PARMNUM Returns the ordinal number of the parameter in the parameter list
%SCANRPL Scans for all occurrences of a value within a string and replaces them with another value
XML-INTO options datasubf Name a subfield that will receive the text data for an XML element that also has attributes
countprefix Specifies the prefix for the names of the additional subfields that receive the number of RPG array elements or non-array subfields set by the XML-INTO operation


[ Top of Page | Previous Page | Next Page | Contents | Index ]