RPG Ⅳ基础
Unit 2. Coding Specifications for RPG IV
Symbolic Names and Reserved Words
The valid character set for the RPG IV language consists of:
? The letters A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
? RPG IV accepts lowercase letters in symbolic names but translates them to
uppercase during compilation ? The numbers 0 1 2 3 4 5 6 7 8 9
? The characters + - * , . ' & / $ # : @ _ > < = ( ) % ? The blank character
Note: The $, #, and @ may appear as different symbols on some codepages. For more information, see the iSeries Information Center globalization topic.
Symbolic Names
A symbolic name is a name that uniquely identifies a specific entity in a program or procedure. In the RPG IV language, symbolic names are used for the following:
? Arrays
? Conditional compile names ? Data structure
? Exception output records ? Fields
? Key field lists ? Labels
? Named constants ? Parameter lists ? Prototype names ? Record names ? Subroutines ? Tables
The following rules apply to all symbolic names except for deviations noted in the description of each symbolic name:
? The first character of the name must be alphabetic. This includes the
characters $, #, and @.
? The remaining characters must be alphabetic or numeric. This includes the
underscore (_).
? The name must be left-adjusted in the entry on the specification form except
in fields which allow the name to float (definition specification, keyword fields, and the extended factor 2 field).
? A symbolic name cannot be an RPG IV reserved word.
? A symbolic name can be from 1 to 4096 characters. The practical limits are
determined by the size of the entry used for defining the name. A name that is up to 15 characters can be specified in the Name entry of the definition or procedure specification. For names longer than 15 characters, use a
RPG Ⅳ基础
continuation specification. For more information, see About Specifications. A symbolic name must be unique within the procedure in which it is defined.
?
Array Names
The following additional rule applies to array names:
? An array name in a standalone field cannot begin with the letters TAB. Array
names may begin with TAB if they are either prototyped parameters or data structures defined with the DIM keyword.
Conditional Compile Names
The symbolic names used for conditional compilation have no relationship to other symbolic names. For example, if you define a file called MYFILE, you may later use /DEFINE to define condition name MYFILE, and you may also use /UNDEFINE to remove condition name MYFILE. This has no effect on the file name MYFILE. Conditional compile names can be up to 50 characters long.
Data Structure Names
A data structure is an area in storage and is considered to be a character field.
EXCEPT Names
An EXCEPT name is a symbolic name assigned to an exception output record. The following additional rule applies to EXCEPT names:
? The same EXCEPT name can be assigned to more than one output record.
Field Names
The following additional rules apply to field names:
? A field name can be defined more than once if each definition using that name
has the same data type, the same length, and the same number of decimal positions. All definitions using the same name refer to a single field (that is, the same area in storage). However, it can be defined only once on the definition specification.
? A field can be defined as a data structure subfield only once unless the data
structure is qualified (defined with QUALIFIED or LIKEDS). In this case, when the subfield is used, it must be qualified (specified in the form dsname.subfieldname).
? A subfield name cannot be specified as the result field on an *ENTRY PLIST
parameter.
KLIST Names
A KLIST name is a symbolic name assigned to a list of key fields.
Labels
A label is a symbolic name that identifies a specific location in a program (for example, the name assigned to a TAG or ENDSR operation).
RPG Ⅳ基础
Named Constants
A named constant is a symbolic name assigned to a constant.
PLIST Names
A PLIST name is a symbolic name assigned to a list of parameters.
Prototype Names
A prototype name is a symbolic name assigned to a prototype definition. This name must be used when calling a prototyped procedure or program.
Record Names
A record name is a symbolic name assigned to a record format in an externally described file. The following additional rules apply to record names in an RPG IV program:
? A record name can exist in only one file in the program.
Note: See RENAME(Ext_format:Int_format) for information on how to overcome this limitation.
Subroutine Names
The name is defined in factor 1 of the BEGSR (begin subroutine) operation.
Table Names
The following additional rules apply to table names:
? A table name can contain from 3 to 10 characters. ? A table name must begin with the letters TAB. ? A table cannot be defined in a subprocedure.
RPG IV Words with Special Functions/Reserved Words
The RPG IV reserved words listed below have special functions within a program.
? The following reserved words allow you to access the job date, or a portion
of it, to be used in the program: UDATE *DATE UMONTH *MONTH UYEAR *YEAR UDAY *DAY
? The following reserved words can be used for numbering the pages of a report,
for record sequence numbering, or to sequentially number output fields: PAGE
PAGE1-PAGE7
RPG Ⅳ基础
?
?
?
?
?
?
Figurative constants are implied literals that allow specifications without referring to length: *BLANK/*BLANKS *ZERO/*ZEROS *HIVAL *LOVAL *NULL *ON *OFF
*ALLX'x1..' *ALLG'oK1K2i' *ALL'X..'
The following reserved words are used for positioning database files. *START positions to beginning of file and *END positions to end of file. *END *START
The following reserved words allow RPG IV indicators to be referred to as data: *IN *INxx
The following are special words used with date and time: *CDMY *CMDY *CYMD *DMY *EUR *HMS *ISO *JIS *JOB *JOBRUN *JUL *LONGJUL *MDY *SYS *USA *YMD
The following are special words used with translation: *ALTSEQ *EQUATE *FILE *FTRANS *PLACE allows repetitive placement of fields in an output record. (See *PLACE for more information.)
RPG Ⅳ基础
?
?
?
*ALL allows all fields that are defined for an externally described file to be written on output. (See Rules for Figurative Constants for more information on *ALL)
The following are special words used within expressions: AND NOT OR Note:
NOT can only be used within expressions. It cannot be used as a name anywhere in the source.
The following are special words used with parameter passing: *NOPASS *OMIT *RIGHTADJ *STRING *VARSIZE
User Date Special Words
The user date special words (UDATE, *DATE, UMONTH, *MONTH, UDAY, *DAY, UYEAR, *YEAR) allow the programmer to supply a date for the program at run time. The user date special words access the job date that is specified in the job description. The user dates can be written out at output time; UDATE and *DATE can be written out using the Y edit code in the format specified by the control specification. (For a description of the job date, see theWork Management manual.)
Rules for User Date
Remember the following rules when using the user date:
? UDATE, when specified in positions 30 through 43 of the output specifications,
prints a 6-character numeric date field. *DATE, when similarly specified, prints an 8-character (4-digit year portion) numeric date field. These special words can be used in three different date formats: Month/day/year Year/month/day Day/month/year
Use the DATEDIT keyword on the control specification to specify the date formats of UDATE and *DATE:
DATEDIT *MDY *DMY *YMD UDATE format *DATE format *MDY *DMY *YMD *USA (mmddyyyy) *EUR (ddmmyyyy) *ISO (yyyymmdd) ?
Note that the DATEDIT keyword also controls the format of the Y edit code. If this keyword is not specified, the default is *MDY.
For an interactive job or batch program, the user date special words are set