RPG IV Specifications

1161 Views


RPG code is written on a variety of specification forms, each with a specific set of functions.

There are seven types of RPG IV specifications. Each specification type is optional. Specifications must be entered into your source program in the order shown below.

Main source section:

1. Control specifications provide the compiler with information about generating and running programs, such as the program name, date format, and use of alternate collating sequence or file translation.

2. File description specifications describe all the files that your program uses.

3. Definition specifications describe the data used by the program.

4. Input specifications describe the input records and fields used by the program.

5. Calculation specifications describe the calculations done on the data and the order of the calculations. Calculation specifications also control certain input and output operations.

6. Output specifications describe the output records and fields used by the program.

 

Subprocedure section:

1. Procedure specifications mark the beginning and end of the subprocedure, indicate the subprocedure name, and whether it is exported.

2. Definition specifications describe the local data used by the subprocedure.

3. Calculation specifications describe the calculations done on both the global and local data and the order of the calculations.

 

In the move to RPG all free the following specifications have been replaced:

  • Control (header) specifications with ctl-opt
  • File specifications with dcl-f
  • Definition specifications with dcl-s and dcl-ds
  • Procedure specifications with dcl-prdcl-pidcl-procend-proc
  • Input and Output specifications remain in fixed format, I think this is a big hint from IBM that we should no longer be using these specifications.

The following are the declaration operation codes:

DCL-C
Define a named constant
DCL-DS
Define a data structure
END-DS
End a data structure
{DCL-PARM}
Define a parameter
DCL-PI
Define a procedure interface
END-PI
End a procedure interface
DCL-PR
Define a prototype
END-PR
End a prototype
DCL-S
Define a standalone field
{DCL-SUBF}
Define a subfield

1.      File name: Mention here name of the file that you are going to use in your program.

2.      File Type: Mention the file type as I,O,U,C where I= INPUT, O=OUTPUT,U=UPDATE,C=COMBINED.

                  These are the modes in which we are going to use the file. C is used for display file.

3.      File Designation: Mention the File Designation as P,S,F where P=PRIMARY,S=SECONDARY,F=FULL PROCEDURAL.

Primary File = Record will be processed in the order; from start to end by rpg program cycle i.e. OPEN, READ, PROCESS, CLOSE. User can't change this order. There can be only one primary file in the program.

Secondary Files = Secondary files apply to programs that do multifile processing. All of the files involved in multifile processing, except the primary file, are secondary files.

Full Procedural file = User can control any order by rpg program opcode. User can change any order by rpg opcode. With full procedural files the programmer determines which record or a block of records to be read by way of the value of the key field used.

4.      File Addition: Mention ‘A’ if you want to add record to the DISK FILE. In update mode of file, use ‘A’ file designation.

5.      File Format: Mention if the file is program described or externally described.

6.      Record Address Type: Mention this field entry as ‘K’ if the file is a keyed file, blank if the file is a sequential access file or based on RRN.

7.      Device: Mention the device as DISK, PRINTER or WORKSTN.

Reference from Go4AS400:RPG Specifications

Dcl-F FileName Disk ( *Ext )                          
               ExtDesc('FileName')                    
               ExtFile(*ExtDesc)                      
               Usage(  *Input)                        
               Qualified                              
               UsrOpn                                 
               Rename( FILEREC  : R01_Rec )            
               Keyed                                  
               ;                                      
Dcl-F FileName Disk Usage(*Input:*Update:*Output:*Delete)        
               Rename(RECFORMAT:NEWRECFORM) Keyed Prefix(R3); 
Dcl-F FILENAME Disk ( *Ext )                       
               Usage( *Input )                     
               Qualified                           
               UsrOpn                              
               Rename( RCDFMT: FIL_Record )      
               Keyed ;                             

The USAGE keyword is optional, but if it is specified, it must have at least one parameter.

*INPUT
input
*OUTPUT
output
*UPDATE
input and update
*DELETE
input, update, and delete

 

 For example, *UPDATE implies both input and update. The following USAGE keywords have the same meaning:

USAGE(*INPUT : *UPDATE)
USAGE(*UPDATE)

The default usage for a file depends on the device-type of the file.

  • For a file with device-type DISK, SEQ, or SPECIAL, the default usage is *INPUT.
  • For a file with device-type PRINTER, the default usage is *OUTPUT.
  • For a file with device-type WORKSTN, the default usage is *INPUT and *OUTPUT.

IBM: USAGE(*INPUT *OUTPUT *UPDATE *DELETE)

RPPGM: File Specification

AS400 Tricks: F Spec

IBM: Specifications

Post Comments