Monday, September 25, 2017

Free Form RPG

Overview
All RPG specs have free-form support except I and O specs.

Each free-form statement begins with an operation code and ends with a semicolon. Here is a list of the new operation codes:


  • CTL-OPT for control specs (H)
  • DCL-F for file specs (F)
  • DCL-S, DCL-DS, DCL-SUBF, DCL-C, DCL-PR, DCL-PI, DCL-PARM for data specs (D)
  • DCL-PROC for procedure specs (P)

Advantages
  • Free-form RPG allows code to be specified as free-form statements rather than in specific fixed columns.
  • Free-form code is still restricted to columns 8 – 80.
  • The /FREE and /END-FREE compiler directives are tolerated, but are no longer required for free-form.
  • Multiple line definitions are easier to code, easier to maintain, and easier to understand.
  • Defining data items with long symbol names is no longer problematic.
  • Free-form definitions can have /IF, /ELSEIF, /ELSE, and /ENDIF within the statement.

Changes for control specifications (H spec)

This section describes the changes for a control specification (H spec). The free-form keyword is CTL-OPT (Control Option). The free-form control statement starts with CTL-OPT, followed by zero or more keywords, and ends with a semicolon. Allowed keywords are the same keywords as an H spec.

Example Additional control statements

CTL-OPT OPTION(*SRCSTMT:*NODEBUGIO)
        DFTACTGRP(*No);

    // intermixed free-form and fixed-form
    CTL-OPT DATFMT(*ISO);
H TIMFMT(*ISO)

Changes for declaration statements (D spec)

This section describes the changes for declaration statements (D spec). A free-form data definition statement starts with DCL-<x>, and is followed by the data item name (which can be *N if the data item is unnamed), then by an optional data type, and then by zero or more keywords, and finally ends with a semicolon.


Example Fixed-form and free-form keywords

D* fixed-form declarations
D string        S       50A VARYING
D date          S         D DATFMT(*MDY)
D obj           S         O CLASS(*JAVA:'MyClass')
D ptr           S         * PROCPTR
   
    // free-form declarations
    DCL-S string VARCHAR(50);
    DCL-S date DATE(*MDY);
    DCL-S obj OBJECT(*JAVA:'MyClass');
    DCL-S ptr POINTER(*PROC);


Named constants
A named constant declaration starts with DCL-C, and is then followed by the name, then by the optional keyword CONST, and then by the value and finally ends with a semicolon.

Example  Named constants

// without the optional CONST keyword
DCL-C lower_bound -50;
DCL-C max_count 200;
DCL-C start_letter 'A';

// with the optional CONST keyword
DCL-C upper_bound CONST(-50);
DCL-C min_count CONST(200);
DCL-C end_letter CONST('A');
Specifying the CONST keyword makes no difference in the meaning of the declaration.

Stand-alone fields
A stand-alone field declaration starts with DCL-S.

Example  Stand-alone fields

DCL-S first_name CHAR(10) INZ('John');
DCL-S last_name  VARCHAR(20);
DCL-S index PACKED(6);
DCL-S salary PACKED(8:2);

Example  Stand-alone fields with LIKE

// Define using the LIKE keyword
DCL-S cust_index LIKE(index);

//Specify length adjustment with LIKE keyword
DCL-S big_index LIKE(index : +6);

Example  Declarations using named constants

DCL-C name_len CONST(10);
DCL-S one CHAR(name_len);
DCL-S two VARCHAR(name_len);
DCL-C digits 10;
DCL-C positions 3;
DCL-S value PACKED(digits:positions);

Example  Data structures

// Program described data structure
DCL-DS data_str_1;
    emp_name CHAR(10);
    first_name CHAR(10);
    salary PACKED(8:2);
END-DS;

// Program described data structure
DCL-DS data_str_2;
    value VARCHAR(4);
    index INT(10);
END-DS data_str_2;

//Unnamed data structure
DCL-DS *N;
    item VARCHAR(40);
END-DS;

Example Data structure using LIKEREC

DCL-DS custoutput LIKEREC(custrec);

Example Data structure with END-DS

DCL-DS PRT_DS LEN(132) END-DS;

Example Two equivalent data structures (END-DS)

DCL-DS myrecord EXT;
END-DS;

DCL-DS myrecord EXT END-DS;

Example Data structure with the DCL-SUBF keyword

DCL-DS record_one;
    buffer CHAR(25);
    DCL-SUBF read INT(3);
END-DS;

Example Two equivalent data structures (OVERLAY)

D* fixed-form declaration
D myds          DS
D   subf1           11      15A
D   subf2                    5P 2   OVERLAY(myds)
D   subf3                   10A     OVERLAY(myds:100)
D   subf4                   15A     OVERLAY(myds:*NEXT)
   
    //free-form declaration
    DCL-DS myds;
        subf1 CHAR(5) POS(11);
        subf2 PACKED(5:2) POS(1);
        subf3 CHAR(10) POS(100);
        subf4 CHAR(15);
    END-DS;
The OVERLAY(dsname:*NEXT) keyword means the same as no OVERLAY keyword at all.


Procedure prototypes
A procedure prototype declaration starts with DCL-PR, and is followed by a name and then by zero or more keywords, and ends with a semicolon.

Example Cosine procedure prototype

DCL-PR cosine FLOAT(8) EXTPROC('cos');
    angle FLOAT(8) VALUE;
END-PR;

Example GetCurTotal procedure prototype

DCL-PR getCurTotal PACKED(31:3) END-PR;

Example Procedure prototype parameter with the DCL-PARM keyword

DCL-PR proc_one;
    buffer CHAR(25) CONST;
    DCL-PARM read INT(3) VALUE;
END-PR;

Example  Procedure interface without parameters

DCL-PI *N CHAR(10);
END-PI;

Example Procedure interface parameter with the DCL-PARM keyword

DCL-PI proc_one;
    buffer CHAR(25) CONST;
    DCL-PARM read INT(3) VALUE;
END-PI;

Changes for procedure specifications (P spec)
This section describes the changes for a procedure specification (P spec). The free-form procedure statement declaration starts with DCL-PROC, and is followed by a name, then by an optional return type, and then by zero or more keywords, and ends with a semicolon.

Example Procedure statement

DCL-PR SubProc1 VARCHAR(100) DIM(2);
    varchar1    VARCHAR(10) CONST;
    ucs1        UCS2(5) CONST;
    varucs1     VARUCS2(5) CONST;
    graph1      GRAPH(20) CONST;
    vgraph1     VARGRAPH(50) CONST;
    packed1     PACKED(10) CONST;
    binary1     BINDEC(2) CONST;
    uns1        UNS(3) CONST;
    float1      FLOAT(4) CONST;
END-PR;

Changes for file specifications (F spec)
This section describes the changes for a file specification (F spec). The free-form file definition statement starts with DCL-F, and is followed by a file name and then by zero or more keywords, and ends with a semicolon.

Example File definition statement

DCL-F dspf WORKSTN
            EXTDESC('TABF035001');

Example 23. File definition statement (with additional keywords)

DCL-F dspf WORKSTN(*EXT) USAGE(*INPUT:*OUTPUT)
            EXTDESC('TABF035001');


1 comment:

  1. Unlock the potential of Azure AZ-400 Dumps PDF with DumpsPass4Sure! The upcoming Christmas Offer of 20% off is the perfect gift for aspiring tech professionals. Elevate your skills and career with our comprehensive course. Don't miss out on this exclusive opportunity to master Azure at an unbeatable price! #Azure #AZ400 #ChristmasOffer

    ReplyDelete