Define D specs in fully free RPG AS400

Define D specs in fully free RPG AS400
Define D specs in fully free RPG AS400, d specs, fully free rpg, Declare definition specs in rpg all free, define named constant in rpg all free, define standalone field in rpg all free, define data structure in rpg all free, define prototype in rpg all free, define procedure interface in rpg all free, DCL-PARM, DCL-C, DCL-S, DCL-DS, END-DS,using free form rpg for D specs, ibmi, rpgle, as400
Define D specs in fully free RPG AS400

Defined D specs in Fixed RPG vs Free form RPG

Here we defined D specs Definition statements in RPG fixed format and their respective free format.

We D specs we define Standalone fields, Named constants, Data Structures and their subfields, Prototypes, Procedure Interface, and Prototyped parameters.

We can define Array and tables as either a data-structure subfield or a standalone field.

D specs can be defined in two places within a module or a program, in the main source section and within the subprocedure. In the main source section, we define global and within subprocedure, we define procedure interface and its parameters and local standalone variable, local named constants, local data structure, and its subfields. Local ones are not known to any other procedure or main source section i.e. cycle main procedure.

We use the following operation code for free form Definition statements, followed by the name or by *N if the name is not defined followed by keywords and ends with a semicolon.

  • DCL-C: To define a named constant.
  • DCL-DS: To define a data structure.
  • END-DS: To end a data structure.
  • DCL-PARM: To define a parameter.
  • DCL-PI: To define a procedure interface.
  • END-PI: To end a procedure interface.
  • DCL-PR: To define a prototype.
  • END-PR: To end a prototype.
  • DCL-S: To define a standalone field.
  • DCL-SUBF: To define a subfield.
  • Define a named constant

    A free form named constant definition starts with DCL-C followed by the name of the constant followed by the value either specified directly or using the CONST keyword and ends with a semicolon.

  • Fixed RPG
  •      D version1        C                   CONST('V7R1M0')
         D version2        C                   'V6R1M0'
         D One             C                   CONST(1)
         D Two             C                   2
    
  • Free RPG
  • DCL-C version1 CONST('V7R1M0');
    DCL-C version2 'V6R1M0'; 
    DCL-C One CONST(1);
    DCL-C Two 2; 
    

    Define a Standalone field

    A free-form standalone field definition starts with DCL-S followed by the name of the field followed by keywords and ends with a semicolon.

  • Fixed RPG
  •      D FLD1            S             20A
         D FLD2            S                   LIKE(FLD1)
         D FLD3            S              3P 0
         D FLD4            S              4P 2
         D FLD5            S              3S 0
         D FLD6            S              4S 2
         D FLD7            S              5I 0
         D FLD8            S              5U 0
         D FLD9            S              8F
         D FLD10           S               D   DATFMT(*ISO)
         D FLD10A          S               D   
         D FLD11           S               T   TIMFMT(*ISO)
         D FLD11A          S               T
         D FLD12           S               Z
         D FLD13           S               N
         D FLD14           S              9B 0
         D FLD15           S              9B 2
         D FLD16           S               *
         D FLD17           S              10   DIM(5)
         D FLD18           S              10   DIM(5) CTDATA
         D FLD19           S              10   DTAARA('DATAAREA1')
         D FLD20           S              10C  CCSID(1200)   
         D FLD21           S              10C  CCSID(1200) VARYING 
         D FLD22           S              10   VARYING
         D FLD23           S                ∗  PROCPTR 
         D FLD24           S                O  CLASS(∗JAVA:'CLASSNAME') 
         D FLD25           S              10   INZ('TEST')
    
  • Free RPG
  • DCL-S FLD1 CHAR(20);
    DCL-S FLD2 LIKE(FLD1);
    DCL-S FLD3 PACKED(3);
    DCL-S FLD4 PACKED(4:2);
    DCL-S FLD5 ZONED(3);
    DCL-S FLD6 ZONED(4:2);
    DCL-S FLD7 INT(5);
    DCL-S FLD8 UNS(5);
    DCL-S FLD9 FLOAT(8);
    DCL-S FLD10 DATE(*ISO);
    DCL-S FLD10A DATE;
    DCL-S FLD11 TIME(*ISO);
    DCL-S FLD11A TIME;
    DCL-S FLD12 TIMESTAMP;
    DCL-S FLD13 IND;
    DCL-S FLD14 BINDEC(9);
    DCL-S FLD15 BINDEC(9:2);
    DCL-S FLD16 POINTER;
    DCL-S FLD17 CHAR(10) DIM(5);
    DCL-S FLD18 CHAR(10) DIM(5) CTDATA;
    DCL-S FLD19 CHAR(10) DTAARA('DATAAREA1');
    DCL-S FLD20 UCS2(10) CCSID(1200);
    DCL-S FLD21 VARUCS2(10) CCSID(1200);
    DCL-S FLD22 VARCHAR(10);
    DCL‑S FLD23 POINTER(∗PROC);
    DCL‑S FLD24 OBJECT(∗JAVA:'CLASSNAME');
    DCL-S FLD25 CHAR(10) INZ('TEST');
    

    Define a Data Structure field and subfield

    A free form data structure field definition starts with DCL-DS followed by the name of the data structure and *N if the data structure name is not defined and then followed by zero or more keywords and ends with a semicolon.

    The externally described data structure must have the keyword EXT or EXTNAME.

    If the Data structure is program-described subfields an END-DS statement (optional) must be specified.

    DCL-SUBF keyword is optional to specify.

    END-DS is not specified for a data structure defined with the LIKEDS or LIKEREC keyword.

    END-DS may be followed by the name of the data structure.

    If the data structure does not have a name, END-DS must be specified without an operand.

    Using length and different data types with data structure subfields.

  • Fixed RPG
  •      D                 DS
         D FLD1                          10A
         D FLD2                           7P 0   
         D FLD3                           5A       
    
  • Free RPG
  • DCL-DS *N;
      DCL-SUBF FLD1 CHAR(10);
      DCL-SUBF FLD2 PACKED(7);
      DCL-SUBF FLD3 CHAR(5);
    END-DS;
    

    or

    DCL-DS *N;
      FLD1 CHAR(10);
      FLD2 PACKED(7);
      FLD3 CHAR(5);
    END-DS;
    

    Using specified starting and ending positions with data structure subfields.

  • Fixed RPG
  •      D                 DS      
         D FLD1                    1     10
         D FLD2                   11     20
    
  • Free RPG
  • DCL-DS *N;
      DCL-SUBF FLD1 CHAR(10) POS(1);
      DCL-SUBF FLD2 CHAR(10) POS(11);
    END-DS;
    

    or

    DCL-DS *N;
      FLD1 CHAR(10) POS(1);
      FLD2 CHAR(10) POS(11);
    END-DS;
    

    Using OVERLAY keyword with data structure subfields.

  • Fixed RPG
  •      D                 DS
         D FLD1                          10A 
         D FLD2                           5A   OVERLAY(FLD1:1)
         D FLD3                           5A   OVERLAY(FLD1:6)
    
  • Free RPG
  • DCL-DS *N;
      DCL-SUBF FLD1 CHAR(10);
      DCL-SUBF FLD2 CHAR(5) OVERLAY(FLD1:1);
      DCL-SUBF FLD3 CHAR(5) OVERLAY(FLD1:6);
    END-DS;
    

    or

    DCL-DS *N;
      FLD1 CHAR(10);
      FLD2 CHAR(5) OVERLAY(FLD1:1);
      FLD3 CHAR(5) OVERLAY(FLD1:6);
    END-DS;
    

    Using Qualified and LIKEDS and DIM with subfields.

  • Fixed RPG
  •      DDS1              DS                  QUALIFIED
         D FLD1                          10A 
         D FLD2                           5A   VARYING
         D FLD3                           3P 0
         D FLD4                                LIKEDS(DS2)
         D FLD5                                LIKEDS(DS3) DIM(5)
    
  • Free RPG
  • DCL-DS DS1 QUALIFIED;
      DCL-SUBF FLD1 CHAR(10);
      DCL-SUBF FLD2 VARCHAR(5);
      DCL-SUBF FLD3 PACKED(3);
      DCL-SUBF FLD4 LIKEDS(DS2);
      DCL-SUBF FLD5 LIKEDS(DS3) DIM(5);
    END-DS DS1;
    

    or

    DCL-DS DS1 QUALIFIED;
      FLD1 CHAR(10);
      FLD2 VARCHAR(5);
      FLD3 PACKED(3);
      FLD4 LIKEDS(DS2);
      FLD5 LIKEDS(DS3) DIM(5);
    END-DS DS1;
    

    If there are no subfields of a data structure.

  • Fixed RPG
  •      D DS1             DS           100
    
  • Free RPG
  • DCL-DS DS1 LEN(100) END-DS;
    

    Defining Externally described data structure using EXTNAME keyword.

    Specify either the EXT keyword or the EXTNAME keyword as the first keyword.

  • Fixed RPG
  •      D ds1           E DS                  EXTNAME(rpgle14pf)    
    
  • Free RPG
  • DCL-DS DS1 EXTNAME('RPGLE14PF') ;
    END-DS;
    

    Defining Externally described data structure Using LIKEREC keyword.

  • Fixed RPG
  • Defining Externally described data structure in Fixed and Free format.

    Specify either the EXT keyword or the EXTNAME keyword as the first keyword.

  • Fixed RPG
  •      D ds1             DS                  LIKEREC(Rcdfmt14:*ALL)    
    
  • Free RPG
  • DCL-DS ds1 LIKEREC(Rcdfmt14:*All);               
    
  • Free RPG
  • DCL-DS ds1 LIKEREC(Rcdfmt14:*All);      
    

    Other data structures such as File Information Data structure and Program status data structure Fixed and Free format definition can be referred from the following link.

    Working with Data Structures in RPG Fixed, /Free and Fully Free

    Define a Prototype Definition

    A free-form prototype definition starts with a DCL-PR statement followed by the name of the prototype, followed by keywords, and finally a semicolon.

    END-PR statement is used to end the prototype. If there are no parameters then END-PR may be specified as part of the DCL-PR statement.

    A prototype for a program with no parameter. The external name of the program is 'PGM1'.

  • Fixed RPG
  •      D PGM1            PR                  EXTPGM('PGM1')            
    
  • Free RPG
  • DCL-PR PGM1 EXTPGM; 
    END-PR;
    

    A prototype for a program with one parameter. The external name of the program is 'PGM1'.

  • Fixed RPG
  •      D PGM1            PR                  EXTPGM('PGM1')  
         D PARM1                         10A   CONST           
    
  • Free RPG
  • DCL-PR PGM1 EXTPGM; 
      PARM1 CHAR(10) CONST;
    END-PR;
    

    A prototype with a two-parameter.

  • Fixed RPG
  •      D ADD             PR                   
         D PARM1                         10A   CONST
         D PARM2                          3P 0 CONST
    
  • Free RPG
  • END-PR specified with or without a name.

    DCL-PR ADD; 
      PARM1 CHAR(10) CONST;
      PARM2 PACKED(3) CONST;
    END-PR;
    

    or

    DCL-PR ADD; 
      PARM1 CHAR(10) CONST;
      PARM2 PACKED(3) CONST;
    END-PR ADD;
    

    A prototype with no parameter and return value

  • Fixed RPG
  •      D ADD             PR            10A       
    
  • Free RPG
  • END-PR specified with or without a name.

    DCL-PR ADD CHAR(10) END-PR; 
    

    A prototype using DCL-PARM to define some of its subfields.

  • Fixed RPG
  •      D ADD             PR                   
         D SELECT                        10A   
         D PARM2                          3P 0  
    
  • Free RPG
  • DCL-PARM is required when the parameter name is the same as the operation code name.

    DCL-PR ADD;
      DCL-PARM SELECT CHAR(10); 
      PARM2 PACKED(3); 
    END-PR; 
    

    C prototype COS

  • Fixed RPG
  •      D ADD             PR             8F 0 EXTPROC('cos')                
         D angle                          8F 0 VALUE  
    
  • Free RPG
  • DCL‑PR COS FLOAT(8) EXTPROC('cos'); 
      angle FLOAT(8) VALUE;
    END‑PR;
    

    Define a Procedure Interface

    A free form procedure Interface definition starts with a DCL-PI statement followed by the name of the procedure or *N if you do not want to repeat the name of the procedure followed by keywords and at last a semicolon.

    END-PI statement is used to end the prototype. If there are no parameters then END-PI may be specified as part of the DCL-PI statement.

    If you do not specify a prototype for a cycle-main procedure, you may use *N as the name for the procedure interface.

    Please note that we will be using DCL-PROC and END-PROC which is for P specs free format in RPG AS400 since we are using *N with the procedure Interface name.

    A procedure Interface without parameters

  • Fixed RPG
  •      D                 PI            10A                           
    
  • Free RPG
  • DCL‑PI ∗N CHAR(10); 
    END‑PI;
    

    A procedure interface for a cycle-main procedure with one parameter. The procedure interface is having no name.

  • Fixed RPG
  •      D                 PI  
         D PARM1                         10A   CONST           
    
  • Free RPG
  • DCL-PI *N; 
      PARM1 CHAR(10) CONST;
    END-PI;
    

    A procedure Interface with two-parameter.

  • Fixed RPG
  •      D ADD             PI                   
         D PARM1                         10A   CONST
         D PARM2                          3P 0 CONST
    
  • Free RPG
  • END-PI specified with or without a name.

    DCL-PROC ADD;
    DCL-PI *N; 
      PARM1 CHAR(10) CONST;
      PARM2 PACKED(3) CONST;
    END-PI;
    END-PROC;
    

    or

    DCL-PROC ADD;
    DCL-PI *N; 
      PARM1 CHAR(10) CONST;
      PARM2 PACKED(3) CONST;
    END-PI ADD;
    END-PROC;
    

    A procedure Interface with no parameter and return value

  • Fixed RPG
  •      D ADD             PI            10A       
    
  • Free RPG
  • END-PR specified with or without a name.

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

    A procedure Interface using DCL-PARM to define some of its subfields.

  • Fixed RPG
  •      D ADD             PI                   
         D SELECT                        10A   
         D PARM2                          3P 0  
    
  • Free RPG
  • DCL-PARM is required when the parameter name is the same as the operation code name.

    DCL-PROC ADD;
    DCL-PI *N;
      DCL-PARM SELECT CHAR(10); 
      PARM2 PACKED(3); 
    END-PI; 
    END-PROC;
    

    Related Post

    Define F specs in Fully Free RPG
    Define H,F,D,P specs in fully free RPG AS400

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain