IBM Support

Have you heard of the /SET and /RESTORE directives?

General Page

You are in: RPG Cafe > /SET and /RESTORE directives?

Short URL:


Have you heard of the /SET and /RESTORE directives?

In 7.2, two new directives were added for ILE RPG

The /SET directive temporarily changes the defaults for some D spec keywords from the defaults set by the H spec. The /RESTORE directive undoes the effects of the active /SET directive.

If you code /SET in a /COPY file, there is an implicit /RESTORE at the end of the copy file.

The keywords allowed for /SET and /RESTORE are CCSID, DATFMT, and TIMFMT. For /SET, the keywords are the same as for the H spec. For /RESTORE, the second parameter of the CCSID keyword is not coded, and for DATFMT and TIMFMT, there is no parameter.

Make your /COPY files more robust

If you code a character, UCS-2, or graphic item without coding the CCSID keyword, or you code a date or time field without coding the format, then the CCSID or format defaults to whatever is coded in the H spec. If the definition is in a copy file, then it might be coded with a different CCSID or format in different modules. For example, if you have a prototype with a date field without specifying the format, then a calling module might have a different date format from the module containing the procedure.

You can ensure that every module has the same CCSID or format for the definitions in your copy file by coding the /SET directive at the beginning of your copy file. The /SET directive at the beginning of a /COPY file sets the defaults for all the Character, UCS2, Graphic, Date, and Time items defined in the /COPY file. Of course, you can explicitly specify the CCSID, date format, or time format individual definitions.

      /set ccsid(*char : *utf8) ccsid(*ucs2 : *utf16) datfmt(*iso) timfmt(*iso)
       dcl-pr getData;
          data varchar(100000);                // use the /SET default

       dcl-ds info_t qualified template;
           duedate date;                       // use the /SET default
           name varchar(100) ccsid(*jobrun);   // specify the CCSID explicitly

Define several items with the same CCSID or format

If you want to define several items with the same CCSID or format, you can code the /SET directive, code the field definitions without specifying the CCSID or format, and then code the /RESTORE directive when you want to undo the effect of /SET.

        /set ccsid(*char : *utf8)
           dcl-s firstName varchar(25);
           dcl-s lastName varchar(25);
        /restore ccsid(*char)

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SS69QP","label":"Rational Development Studio for i"},"Component":"ILE RPG Compiler","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
16 December 2019