Free-Form Data Structure Definition

A data structure begins with a DCL-DS statement.

If the LIKEDS or LIKEREC keyword is not specified for the DCL-DS statement, the DCL-DS statement is followed by zero or more subfields, followed by an END-DS statement.

DCL-DS statement

The first statement begins with DCL-DS, followed by the name of the data structure or *N if it does not have a name, followed by keywords, and finally a semicolon.

Subfields

Note: Subfields are not specified for a data structure defined with the LIKEDS or LIKEREC keyword.

See Free-Form Subfield Definition.

END-DS statement

  • 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.
    
       DCL-DS custInfo QUALIFIED;
          id INT(10);
          name VARCHAR(50);
          city VARCHAR(50);
          orders LIKEDS(order_t) DIM(100);
          numOrders INT(10);
       END-DS custInfo;
    
  • If the data structure does not have a name, END-DS must be specified without an operand.
  • If there are no subfields, END-DS may be specified as part of the DCL-DS statement, following the keywords and before the semicolon. In this case, END-DS cannot be followed by the name of the data structure.
    
      DCL-DS prtDs LEN(132) END-DS;
    

Externally-described data structure

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

  DCL-DS myfile EXT END-DS;
  DCL-DS extds1 EXTNAME('MYFILE') END-DS;
If you specify the EXT keyword, you can also specify the EXTNAME keyword as a later keyword.

  DCL-DS extds2 EXT INZ(*EXTDFT) EXTNAME('MYFILE') END-DS;

Program Status Data Structure (PSDS)

Specify the PSDS keyword to define the PSDS. For predefined subfields such as *STATUS, specify the reserved word in place of the data-type keyword.

  DCL-DS pgm_stat PSDS;
     status *STATUS;
     routine *ROUTINE;
     library CHAR(10) POS(81);
  END-DS;

See Program Status Data Structure for a list of all the predefined subfields for a PSDS.

File Information Data Structure (INFDS)

The name of an INFDS is specified as the parameter for the INFDS keyword of a file definition.

For predefined subfields such as *STATUS, specify the reserved word in place of the data-type keyword.

  DCL-F myfile DISK(*EXT) INFDS(myfileInfo);
  DCL-DS myfileInfo;
     status *STATUS;
     opcode *OPCODE;
     msgid CHAR(7) POS(46);
  END-DS;

See File Feedback Information for a list of all the predefined subfields for an INFDS.

File Information Data Structure

Specify the *AUTO parameter for the DTAARA keyword.

  DCL-DS dtaara_ds DTAARA(*AUTO) LEN(100);
     name CHAR(10);
  END-DS;

Examples of free-form data structures

  1. Data structures defined with LIKEDS and LIKEREC are coded as a single statement without END-DS.
    
       DCL-DS info LIKEDS(info_T);
       DCL-DS inputDs LIKEREC(custFmt : *INPUT);
    
  2. A data structure cust_info with three subfields. The END-DS statement is specified without a name.
    
      DCL-DS cust_info;
         id INT(10);
         name VARCHAR(25);
         startDate DATE(*ISO);
      END-DS;
    
  3. A data structure using DCL-SUBF to define some of its subfields.
    • Subfield select has the same name as an operation code allowed in free-form calculations. DCL-SUBF is required for this subfield. See Table 1.
    • Subfield name does not have the same name as an operation code, so DCL-SUBF is not required.
    • Subfield address does not have the same name as an operation code, so DCL-SUBF is not required, but it is valid.
    
      DCL-DS *N;
         DCL-SUBF select CHAR(10);
         name CHAR(10);
         DCL-SUBF address CHAR(25);
      END-DS;
    
  4. A data structure order_info. The END-DS statement is specified with a name.
    
      DCL-DS order_info QUALIFIED;
         part LIKEDS(part_info_T);
         quantity INT(10);
         unit_price PACKED(9 : 2);
         discount PACKED(7 : 2);
      END-DS order_info;
    
  5. An externally-described data structure with additional subfields.
    
      DCL-DS cust_info EXTNAME('CUSTFILE');
         num_orders INT(10);
         earliest_order DATE(*ISO);
         latest_order DATE(*ISO);
      END-DS;
    
  6. An externally-described data structure whose name is the same as the name of the external file, 'CUSTINFO'. The data structure has external subfields identified by the EXTFLD keyword. The EXTFLD keyword is specified without a parameter when the subfield name is the same as the external name.
    
      DCL-DS custInfo EXT;
         cust_name EXTFLD('CSTNAM');
         id_no EXTFLD INZ(0);
      END-DS;
    
  7. A data structure with a nested data structure subfield.
    
      DCL-DS employeeInfo QUALIFIED;
         id_no int(10);
         DCL-DS name;
            last VARCHAR(25);
            first VARCHAR(25);
            initial CHAR(1);
         END-DS;
         type VARCHAR(10);
      END-DS;
    
      employeeInfo.id_no = 12345;
      employeeInfo.name.first = 'Robin';
      employeeInfo.name.last = 'Hood';
    
  8. An unnamed data structure.
    
      DCL-DS *N;
         string CHAR(100);
         string_array CHAR(1) DIM(100) OVERLAY(string);
      END-DS;