100% found this document useful (1 vote)
914 views167 pages

BAC - Training Programme

This document provides an agenda for a one-day training on RPG/400 programming. It will cover an introduction to RPG/400 including its history and structure, symbolic names, specifications like file descriptions and calculation specifications, and how to code, compile and run an RPG/400 program. Key topics include the logic cycle, operation codes, data types, and using the source entry utility and compiler to create executable objects from RPG source code.

Uploaded by

neethusany
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
914 views167 pages

BAC - Training Programme

This document provides an agenda for a one-day training on RPG/400 programming. It will cover an introduction to RPG/400 including its history and structure, symbolic names, specifications like file descriptions and calculation specifications, and how to code, compile and run an RPG/400 program. Key topics include the logic cycle, operation codes, data types, and using the source entry utility and compiler to create executable objects from RPG source code.

Uploaded by

neethusany
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 167

BAC - Training Programme

RPG/400
RPG/400 - Agenda for Day 1
• Introduction • F Specifications
• C specifications
• Brief History
• Data types
• Structure of RPG • Operation codes
• Symbolic names – OPEN/CLOSE
• Overview of Specifications – READ/WRITE
– LR
• How to Code/Compile/ Run
– DO WHILE/ENDDO
RPG program – RETRN
• RPG Indicators – SETON/SETOF
• Introduction to Logic Cycle • Simple examples
Introduction to RPG
• Invented by IBM in early 1960s
• RPG is a high-level programming language
• Most popular programming tool on AS/400
• Procedural language
• Highly position dependent
RPG History
• RPG (Report Program Generator) introduced by IBM in
early 1960s
• Began as a language to produce commonly needed business
reports
• Originally started with fixed-logic cycle and built in
indicators
• IBM started enhancing RPG by adding more functionality as
the usage became widespread
• Programmers started using for complex business processing
RPG History (Cont.)
• Versions of RPG
– RPG (1960s)
– RPG II (released on System/3 during early 1970s)
– RPG III (released on System/3 in 1979)
– RPG/400 (released on Sys./38 & AS/400 in 1988)
– RPG IV (recent introduction)
– ILE RPG ( “ )
Structure of RPG
• An RPG Program comprises a series of
Specifications
• Each specifications is used for a particular
purpose and has specific set of functions
• 7 specifications are available in RPG
• The RPG/400 source program must be entered
into the system in the order shown (except for E
& L which can be interchanged)
Structure of RPG
• Control Specifications (Header) - H Specs
• File description Specifications - F Specs
• Extension Specifications - E Specs
• Line counter Specifications - L Specs
• Input Specifications - I Specs
• Calculation Specifications - C Specs
• Output Specifications - O Specs
Structure of RPG
• Any of the specification types can be absent, but at
least one must be present
• The following entries are common to all RPG
specifications:
• Page (positions 1-2) and Line (positions 3-5). These are the
equivalent of source line number -used for comments
• Specification type (position 6). The following letter codes can
be used ( H F E L I C O)
• Program Identification (positions 75-80). Must be blank or
program name on the Control specs
• Comment Statements (* in position 7). On a comment statement
or a compiler directive, position 6 may be blank.
Symbolic Names
• A symbolic name is a name that uniquely identifies a
specific entity in a program. Its purpose is to allow
you to access that entity. In the RPG/400 language,
symbolic names are used for the following entities:

– Arrays – Named constants


– Data structures – PLISTs
– Fields – Record names
– Files – Subfields
– KLISTs – Subroutines
– Labels – Tables.
Symbolic Names
• 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 and
part of the RPG/400 character set.
• 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
• The numbers 0 1 2 3 4 5 6 7 8 9
• The characters + - * , . ' & / $ # : @
• The blank character
Symbolic Names
– The name must be left-adjusted in the entry on the
specification form.
– Blanks can fill out the entry but must not be
embedded in the name.
– A symbolic name cannot be an RPG/400 reserved
word.
– A symbolic name can be 1 to 6 characters.
– A symbolic name must be unique.
Symbolic Names
• Array Names
– An array name is a symbolic name assigned to an array.
The following additional rule applies to array names:
• An array name cannot begin with the letters TAB.
• Data Structure Names
– Data structure name is a symbolic name assigned to a
data structure. A data structure is an area in storage and
is considered to be a character field. The following
additional rule applies to DS names:
• A field can be defined as a data structure only once.
Symbolic Names
• Field Names
– A field name is a symbolic name assigned to a field
in a program. The following additional rules apply
to field names:
• A field name can appear on more than one field definition
statement if each definition using that name has the same
data type (character or numeric), 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).
• A field can be defined in a data structure only once.
Symbolic Names
• File Names
– A file name is a symbolic name assigned to a file. The
following additional rules apply to file names:
• A file name can contain from 1 to 8 characters.
• 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 destination point of
a GOTO or CABxx operation).
Symbolic Names
• 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.
• 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 :
• A record name can contain from 1 to 8 characters.
• A record name can exist in only one file in the program.
Symbolic Names
• Subfield Names
– A subfield name is a symbolic name assigned to a data
structure subfield. The following additional rules apply
to subfield names:
• A subfield name cannot be specified as the result field on an
*ENTRY PLIST parameter.
• A field or an array can appear only once as a subfield name.
• Subroutine Names
– A subroutine name is a symbolic name assigned to a
subroutine. The name is defined in factor 1 of the
BEGSR (begin subroutine) operation.
Symbolic Names
• Table Names
– A table name is a symbolic name assigned to a table.
The following additional rules apply to table names:
• A table name can contain from 3 to 6 characters.
• A table name must begin with the letters TAB.
Overview of
Specifications
Control Specification
• Also known as program ‘Header’
• It provides the RPG/400 compiler with
information about your program and your
system.
• This includes: Name of the program, Date
format for the program, Currency symbol
• This corresponds to the Configuration Section
in Cobol
File description Specifications
• File description specifications define all files used
in the program
– It has details like Filename , File type, File format,
Record length, Device, etc
– Each of the above entry should begin in a particular
position in F specification line - like Filename should
be in position 7-14, File format to be in position 19 etc.
• This corresponds to the Input-output Section in
Cobol
Extension Specifications
• Extension specifications describe all arrays
and tables and indicate how they are
initialised.
• This corresponds to the OCCURS and
VALUE clauses in Cobol or the DIM
statement in BASIC
Line Counter Specifications
• Line counter specifications indicate the
length of the overflow lines and the forms
length to be printed on each page for each
printer file in the program
• This is similar to Lineage clause in Cobol
Input Specifications
• Input specifications describe data structures,
named constants, records, and fields in the
input files and indicate how the records
and fields are used by the program.
Calculation Specifications
• Calculation specifications describe calculations
to be done by the program and indicate the
order in which they are done.
• Calculation specifications can control certain
input and output operations.
• All the arithmetic operations etc are done here
• This is similar to procedure division in COBOL
Output Specifications
• Output specifications describe the records
and fields and indicate when they are to be
written by the program.
• Every program described output file
necessarily to have an output specs entry
(optional for external described files)
• This corresponds to the Data Division in
Cobol which describe output records
How to Code/Compile/Run
an RPG/400 Program
How to Code & Compile RPG
• Program statements ‘Source code’ are generally
entered using SEU(source entry utility), pressing key
F6 will take you to SEU
• SEU has special features like line prompting and
syntax checking depending upon the specification
• Source programs are stored as members of a
source file, like all RPG programs in QRPGSRC
with member type RPG
How to Code & Compile RPG
• RPG source can be compiled by entering 14
in the opt column. (in PDM menu)
• This creates executable object(with the same
source name) which can be used to run
• It can be also compiled using CRTRPGPGM
command at the AS/400 prompt
How to Code & Compile RPG
• CRTRPGPGM PGM(TEST1)
» SRCFILE(*LIBL/QRPGSRC)
» SRCMBR(*PGM)
» GENLVL(9)
» TEXT(‘My Test program - 1’)
How to Code & Compile RPG
• An RPG compilation will fail if the source program
contains errors that are equal or greater than the error
level set on the GENLVL option of the CRTRPGPGM.
The default is 9 but it can set within 0 to 50
• The compiler grades errors into levels of severity
– 00 is an information message
– 10 a warning that an error was detected
– 20 an error was detected and compiler took action
– 30 a severe error was detected
– 40 abnormal termination of compilation
– 50 an error forces cancellation of the compiler job
How to Run a RPG Program
• In the PDM menu screen enter ‘C’ followed
by an Enter key against the RPG member
(program) you want to run
• Alternately you call from the command line
by issuing command
CALL (Library Name/Program Name)
How to View/Print Output
• Type ‘SP’ in any option column/Command
line on any of PDM’s screens to obtain a list
of your spooled files
• All spooled files will be displayed to you
• Enter ‘5’ adjacent to the file to look at the
spool
• All the warnings, errors, program exception
etc will be available in the spool file
RPG Compiler directives
• There are certain compiler directives
(instructions embedded in source program
that cause compiler to take certain action)
that are specified in the column 7. E.g.
– /TITLE (Positions 7-12)
– /EJECT (Positions 7-12)
– /SPACE (Positions 7-12)
– /COPY (Positions 7-11)
RPG Compiler directives
• /TITLE instructs the compiler to skip to new page
in the program listing and print the program title
• /EJECT tells the compiler to skip to a new page in
the program listing.
• /SPACE nnn directs compiler to insert nnn blank
lines on the program listing
• /COPY allows you to insert records from other file
members during a compile.
Summary
• RPG is relatively easy to use and after a short
learning curve programmers become productive
• Like all other languages its has its peculiarities,
strengths and weakness but a good tool for
developing business applications on AS/400
• Its file handling and display handling facilities with
a excellent report writing capabilities make it ideal
for development of commercial applications
Indicators
Indicators
• An indicator is a two-character entry that is set on
(1) or off (0) as the result of an operation or is
used to condition (or control) the processing of an
operation.
• Indicators are defined either by an entry on the
specification or by the RPG/400 program itself.
• The positions on the specification in which you
define an indicator determine how the indicator is
used.
Indicators
• An indicator that has been defined can then be
used to condition calculation and output
operations.
• The RPG/400 program sets and resets certain
indicators at specific times during the program
cycle.
• Most indicators can be changed by the SETON
and SETOF operation codes or moving *ON or
*OFF
Indicators
• Types of Indicator
– Overflow Indicators
– Record Identifying Indicators
– Control Level Indicators
– Field Indicators
– Resulting Indicators
Indicators - Rules
• Moving a character '0' (zero) or *OFF to any of
these fields sets the corresponding indicator off.
• Moving a character '1' (one) or *ON to any of
these fields sets the corresponding indicator on.
• Do not move any value, other than '0' (zero) or
'1' (one), to *INxx. Any subsequent normal
RPG/400 indicator tests may yield undesirable
results.
Indicators - Overflow
• An overflow indicator is defined by an entry in
positions 33 and 34 of the file description
specifications.
• It is set on when the last line on a page has been
printed or passed.
• Valid indicators are OA through OG, OV, and 01
through 99.
• A defined overflow indicator can then be used to
condition calculation and output operations.
Indicators - Record Identifying
• A record identifying indicator is defined by an
entry in positions 19 and 20 of the input specs and
is set on when the corresponding record type is
selected for processing.
• Valid indicators are 01-99, H1-H9, L1-L9, LR
U1-U8, RT
Indicators - Control Level
• A control level indicator is defined by an entry in
positions 59 and 60 of the input specifications,
designating an input field as a control field.
• It can then be used to condition calculation and
output operations.
• Valid control level indicator are L1 through L9.
Indicators - Field
• A field indicator is defined by an entry in positions 65
and 66, 67 and 68, or 69 and 70 of the input
specifications.
• You can use a field indicator to determine if the
specified field or array element is greater than zero,
less than zero, zero, or blank. You can then use the
field indicator to condition calculation or output
operations.
• Valid field indicators are 01-99, H1-H9, U1-U8 RT
Indicators - Resulting
• A resulting indicator is defined by an entry in positions
54-55,56-57,58- 59 of the calculation specs.
• The purpose of the resulting indicators depends on the
operation code specified in positions 28-32.
• Resulting indicators can be used
– to test the result field after an arithmetic operation
– to identify a record-not-found condition
– to indicate an exception/error condition for a file operation
– to indicate an end-of-file condition.
Indicators - Resulting (cont.)

• Valid resulting indicators are 01-99, H1-H9,


OA-OG, OV, L1-L9, LR, U1-U8, KA-KN,
KP-KY (valid only with SETOF), RT
Indicators - Other types
• It is not necessary to define all the Indicators in
the RPG/400 Specifications
• Some of the indicators are defined externally
and some of the them internally
• There are two types
– External indicators
– Internal indicators
Indicators - External
• The external indicators are U1 through U8.
• These indicators can be set in a CL program or in
an RPG/400 program.
– In a CL program, they can be set by the SWS
(switch-setting) parameter on the CL commands
CHGJOB (Change Job) or CRTJOBD (Create Job
Description).
– In an RPG/400 program, they can be set as a
resulting indicator or field indicator.
Indicators - Internal
• Internal indicators include:
– First page indicator (1P)
– Last record indicator (LR)
– Matching record indicator (MR)
– Return Indicator (RT)
Using Indicators

• Indicators defined, in previous slides, can be


used to condition files, calculation operations,
or output operations.
Using Indicators
• Using for File Conditioning
– The file conditioning indicators are specified in
positions 71 and 72 of the file description
specifications.
– Only the external indicators U1-U8 are valid for file
conditioning
Using Indicators
• Function Key Indicators
– You can use function key indicators in a program
that contains a WORKSTN device if the associated
function keys are specified in data description
specifications (DDS). Function keys are specified in
DDS with the CFxx or CAxx keyword.
– Function key indicators can be set off by the SETOF
operation.
Using Indicators
• Indicators Conditioning Calculations
– Indicators to condition calculations can be specified in
positions 7 and 8 and/or in positions 9 through 17.
• You can specify control level indicators (L1 through L9 and LR)
in positions 7 and 8 of the calculation specs
• You can use positions 9 through 17 of the calculation
specifications to specify indicators that control the conditions
under which an operation is processed.
– Indicators that are used to specify the conditions under
which a calculation is done are to be defined elsewhere in
the program.
Introduction to Logic Cycle
Program
RPG - Logic Cycle Program
You may wonder,

‘Why bother with logic cycle


program ?
RPG - Logic Cycle program
• The primary reason why you should be
familiar is that you often will be asked to
maintain programs written using this
concept
• If you don’t understand how this feature
work, you will have little chance of
modifying these programs
RPG - Logic Cycle program
• The RPG/400 compiler supplies part of the
logic for an RPG/400 program.
• Primary (identified by a P in position 16 of
the file description specifications) and
secondary (identified by an S in position 16
of the file description specifications) files
indicate input is controlled by the program
cycle.
RPG - Logic Cycle program
• A program can consist of One primary file
and, optionally, one or more secondary files
or full procedural files
• Set of C spec are executed for each record in
the primary file
RPG - Logic Cycle program
Pseudocode of RPG’s Fixed Logic cycle
Turn on 1P indicator
WHILE LR if off
Print detail output(H and D lines)
Turn off 1P,record identifying & level indicators
Read record from primary file
IF end of file
Turn on LR and all level indicators
ELSE
Turn on record identifying indicators
IF change in control filed
Turn on level indicator(s)
ENDIF
ENDIF
RPG - Logic Cycle program
Perform total calculation
Perform total output (T lines)
IF LR is not on
IF overflow indicator is on
Print lines conditioned by overflow
ENDIF
Move data into input fields
Perform detail calculations
ENDIF
ENDWHILE
RPG Training

Day 5
RPG/400 - Agenda for Day 5
• E Specifications • Special Keywords
– *DATE , * YEAR
• Arrays/Tables – CALL
• Error handling in – PLIST/ PARM/ ENTRY
RPG/400 • Operators
– LOKUP
• String handling
– CLEAR/RESET
• Data Area / Data – COMP
Structure – DSPLY
– XLATE
– COMIT/ROLBK
E Specifications
• Extension specifications describe all record
address files, tables and arrays.
• A maximum of 200 arrays and tables can be
used in a program
• This corresponds to the OCCURS and
VALUE clauses in Cobol or the DIM
statement in BASIC
E Specifications
• Record Address File
– A record-address file is a sequentially organised file
used to select records from another file.
– Only one file in a program can be specified as a
record-address file.
– This file is described on the file-description and
extension specifications
– The file processed by the record-address file must
also be specified on the extension specifications
Tables
• A table is a collection of data organized into
columns and rows
• Similar kinds of data are stored within a
column and the data within a row of a table is
related or ‘belongs’ together
• Typically, the data in the first column of a
table is organised in ascending order to
facilitate finding an item
Tables
• A typical 3 column table is shown below
State Code State Name Tax Rate
AK Alaska 1000
AL Alabama 1200
AZ Arizona 1300
CA California 1400
NY New York 900
….. …….. ….
.
Tables
• Data elements within table need to have
same length, same data type and same
number of decimal positions(for numeric)
• The table is defined in the E specifications
of the RPG program
• An RPG table name must begin with TAB
followed by up to 3 additional characters
Tables
• A simple table of 50 state code is coded in E specs as follows

State Code
AK
AL 6 27-32 36-39 40-42 44 45
AZ
CA Form Type Table Name No. of elements Length of element Decimel Sequencing(A/D)
NY
…..
WA E TABCOD 50 2 0A
Tables
• This table definition allocates memory so that
entire table full of data can remain in memory
through out the program execution
• The data values into the table can be put in two
different methods
– Having the data hard coded in program. This is called
as compile time tables
– Having the data obtained from a separate disk file. This
is called as pre-runtime or pre-execution table.
Tables - Compile time
• Here the data is hard coded in the program
source
• This table data is to be entered at the very
end of the program
• The source line should start with ‘**’ and
blank in the position 1-3 in source code and
must precede the table values
Tables - Compile time
• For example the state codes are to coded as
following
1 2 3
* *
A K
A
A
L
R
6 27-32 36-39 40-42 44 45
A Z Form Type Table Name No. of elements Length of element Decimel Sequencing(A/D)
C A
..
W
..
A
E TABCOD 50 2 0A
Tables - Compile time
• On more way coding the same example is shown
below
1 2 3 4 5 6 7 8
* *
A K A L A R A Z
C A C O C T D E

6 27-32 33-35 36-39 40-42 44 45


Form Type Table Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E TABCOD 4 50 2 0A
Tables - Compile time -Summary
• Compile time tables are useful for relatively small
tables
• And whose data are not likely to change over time
• Any change in the data means you have to modify
the source program, change the table data at the
end of program and recompile it
Tables - Pre-Runtime
• Here the data from a database file is read into the
table
• The RPG program automatically retrieves all the
table data from the file before the processing
begins
• Hence the name Pre-runtime table
Tables - Pre-Runtime
• The E specs requires an additional entry in the
position 19-26 i.e. the name of the file containing
the table data
• The entry in the E specs will is shown below

6 19-26 27-32 33-35 36-39 40-42 44 45


Form Type From filename Table Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E STATDATTABCOD 4 50 2 0A
Tables - Pre-Runtime
• Since the program is using a database file , a
definition of that file must find an entry in F Specs

• A typical entries in the F specs for this file will be

6 7-14 15 16 19 24-27 39 40-46


Form Type Filename I/O/U/C/D P/S/C/R/T/D File format Record Length E/L code Device

F STATDAT I T F 8 E DISK
Tables - Pre-Runtime-Summary
• This is used more for volatile (frequently changing)
type of data
• The contents of the table can be changed in the run
time tables
• This is done by having the following extra entries in
the F and E specs
– The file designate in the F specs should be Combined file,
rather than an Input file
– And a filename in position 19-28 (To file) has to be
mentioned in the E Specs
LOKUP (Look up)
• The LOKUP operation causes a search to be made for a particular element in an
array or table.
• Factor 1 is the search argument (data for which you want to find a match in the
array or table named).
• It can be: a character or numeric literal, a field name, an array element, a table
name, a named constant, or a figurative constant.
• The array or table to be searched is specified in factor 2.
Operator - LOKUP
• For a table LOKUP, the result field can contain the name
of a second table from which an element (corresponding
positionally with that of the first table) can be retrieved.
• Resulting indicators specify the search condition for
LOKUP. That is specified in positions 54-59.

6 18-27 28-32 33-42 43-48 54-55 56-57 58-59


Type Factor 1 Operation Factor 2 Result HI LOW EQ
C Search Argument LOKUP Table Name Table Name
C
C Search Argument LOKUP Array Name
C
Operator - LOKUP
• When you use the LOKUP operation, remember:
– The search argument and array element or table element must have
the same length and the same format (character or numeric).
– A search can be made for high, low, high and equal, or low and
equal only if a sequence is specified for the array or table in the
extension specifications.
– No resulting indicator is set on if the search is not successful.
– If only an equal indicator (positions 58-59) is used, the LOKUP
operation will search the entire array or table.
– The LOKUP operation can produce unexpected results when the
array is not strictly in ascending or descending sequence.
Tables - Look-Ups
• Tables are used for one primary purpose:to look up data
values
• This is done using LOKUP operation code and this is
coded in C specs
• The code for a simple table look-up

6 18-27 28-32 33-42 54-55 56-57 58-59


Type Factor 1 Operation Factor 2 HI LOW EQ
C CODEIN LOKUP TABCOD 50
C *IN50 IFEQ *ON
C EXSR FOUND
C ELSE
C EXSR NOTFOUND
C ENDIF
Tables - Two related Tables
• An example of related table data is shown below
• And this for table is called as alternating table

1 2 3 4 5 6 7 8 9 10
* *
A K A L A S K A
A L A L A B A M A
A Z A R I Z O N A
Tables - Two related Tables
• To reflect this data organization, the two tables are defined on the same line of E Specs
• The second table’s name, entry length are coded in the position 46-57 (decimals in Col
56, Sequencing in 57)

6 27-32 33-35 36-39 40-42 45 46-51 52-54


Form Type Table Name No of entries /record No. of elements Length of element Sequencing(A/D) Table(Alt.Format) Length

E TABCOD 1 50 2A TABNAM 10
Tables - Two related Tables
• The RPG code to get the information of the State
name looks like

6 18-27 28-32 33-42 43-48 49-51 54-55 56-57 58-59


Type Factor 1 Operation Factor 2 Result field Length HI LOW EQ
C CODEIN LOKUP TABCOD 50
C *IN50 IFEQ *ON
C MOVEL TABNAM NAME 10
C ELSE
C EXSR NOTFOUND
C ENDIF
Arrays
• An array is a data structure similar to a table, in that
it contains multiple elements, all defined with a
common name
• Each element within array must be the same data
type, same length and number of decimals positions
• Arrays are defined on E specs
• Like tables, you can load data into arrays at
compile time or pre run-time
Arrays - Definition
E Specs definition for compile time array
6 27-32 33-35 36-39 40-42 44 45
Form Type Array Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E ARS 1 50 2 0

E Specs definition for pre-runtime array


6 19-26 27-32 33-35 36-39 40-42 44 45
Form Type From filename Array name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E STATDATARS 4 50 2 0A
• Array names cannot begin with TAB
Array Vs Tables
• The first major difference is that unlike tables, arrays
can be loaded with values during the course of
program execution. This is called as runtime array
The data for runtime array can come from fields of
an input file of a program or from results of
calculations
• Secondly, unlike tables elements, individual
elements of an array can be directly referenced and
manipulated using index or pointer
Array - Run time
A normal runtime array is coded as follows
6 27-32 33-35 36-39 40-42 44 45
Form Type Array Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E QTY 12 5 0

• The positions 33-35 must be blank for a run-time array and this
identifies as runtime array
• The above example is an array ‘QTY’ with 12 elements and of
size 5 numeric
• You can refer to any of the element directly using the index
Array - Run time (Cont.)

6 27-32 33-35 36-39 40-42 44 45


Form Type Array Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E QTY 12 5 0

• RPG indexing notation requires a comma between


array name and index
• Thus QTY,3 refers to the third element of QTY
array, QTY,10 refers to tenth and so on
Array - Run time (Cont..)

6 27-32 33-35 36-39 40-42 44 45


Form Type Array Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E QTY 12 5 0

• The index used does not have to be a numeric literal, it


can be a numeric field with 0 decimal position
• For e.g. if N has a value 3, QTY,N refers to element 3
of QTY array.
• This is called as indirect referencing.
Run time arrays and input data
• The initial values for a run-time array can be
assigned through input or calculation specifications.
• You can use MOVE operation in C specs to put data
in each element of an array (or in selected elements)
• Using the input specifications (program described
file), you may fill an array with the data from a file.
• For. E.g. if you have a file of sales records
containing the salesman code and the sales for each
month - 12 sales figures in all
Run time arrays and input data
The sales figures can be defined as array elements
6 27-32 33-35 36-39 40-42 44 45
Form Type Array Name No of entries /record No. of elements Length of element Decimel Sequencing(A/D)

E SAL 12 5 0

The I specs entries will be like this


6 7-13 15 16 44-47 48-51 53-58
Type Array Name N/R D From To Field name
I SALES N S
1 4 SLMCD
5 64 SAL
Run time arrays and input data
• Thus, when a record is read from sales file, the
system will correctly subdivide the values into
appropriate elements of SAL on the E specs.
• The data value in position 5-9 of input record
will be stored in SAL,1; the value in position
10-14 in SAL,2 etc
• Then, you can directly refer to the array
element to the data
Calculations with Arrays
• All the arithmetic operations like- ADD, SUB, MULT, DIV,
SQRT or assignment operations like Z-ADD, Z-SUB,
MOVE, MOVEL can be used with arrays or their elements
• Lets look a following examples

6 18-27 28-32 33-42 43-48 40-51 54-55 56-57 58-59


Type Factor 1 Operation Factor 2 Result Length HI LOW EQ
C
C Z-ADD 100 QTY,5
C
C 5 MULT QTY,1 QTY,2
C
C QTY,1 ADD QTY,2 QTY,3
C
C MOVE 200 QTY,10
Calculations with Arrays
• In additions to the standard commands, three more
commands are available exclusively to array
operations.
– XFOOT
– SORTA
– MOVEA
XFOOT
• XFOOT, called ‘crossfoot’ sums the elements of an
array.
• Factor 2 contains the name of the array whose
elements are to added together
• The result field contains the field where the answer
is to be stored
XFOOT
6 18-27 28-32 33-42 43-48 40-51 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result Length HI LOW EQ
C
C XFOOT QTY TOTQTY 7 0
C

• In the above example the values of the element from


QTY,1 .. QTY,12 are summed up and the total is
stored in TOTQTY
SORTA
• SORTA is a simple but useful operation that
rearranges the values of the element of an
array in ascending or descending sequence.
• The sequence depend upon the entry in
position 45 of E specs (either A or D)
• If position 45 is blank, SORTA assumes as
ascending
SORTA
• Usage
6 18-27 28-32 33-42 43-48 40-51 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result Length HI LOW EQ
C
C SORTA QTY
C

• For example, if you have quantities of


12,24,11,7,16,31 in array of 6
• After SORTA operation on QTY, the result will be
in sorted order i.e.. 7,11,12,16,24,31
MOVEA (Move array)
• The MOVEA operation transfers values from factor
2 to the result field of the operation
• At least one of these entries should be an array
• You can use MOVEA operation for
– moving an array to another array
– moving an array to a field
– moving a field to an array
• The data movement is from left to right
6 18-27 28-32 33-42 43-48 40-51 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result Length HI LOW EQ
C MOVEA ARA ARB
C
C MOVEA ARA FIELDA 12
COMP (Compare)
• The COMP operation compares factor 1 with
factor 2.
• Factor 1 and factor 2 can contain a literal, a named
constant, a field name, a table name, an array
element, a data structure, or a figurative constant.
• Factor 1 and factor 2 must be either both character
or both numeric.
COMP (Compare)
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C Comparand COMP Comparand
C
C

• The indicators are set on as follows:


– High: (54-55) Factor 1 is greater than factor 2.
– Low: (56-57) Factor 1 is less than factor 2.
– Equal: (58-59) Factor 1 equals factor 2.
• At least one resulting indicator in positions 54 through 59 must be
specified.
COMP (Compare)
• For example, if we have 3 fields and initial field values
– FLDA = 100 , FLDB = 105.00 , FLDC = 100.00
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C FLDA COMP FLDB 11 12 13
C
C FLDB COMP FLDC 14 15 16
C
C FLDA COMP FLDC 17 18 19

• Indicator 12 is set on; indicators 11 and 13 are set off.


• Indicator 14 is set on; indicators 15 and 16 are set off.
• Indicator 19 is set on; indicators 17 and 18 are set off.
RPG/400

Special keywords in RPG/400


Date Special words
• There are few date special words that can be
used inside RPG/400 like
– UDATE *DATE
– UMONTH *MONTH,
– UDAY *DAY
– UYEAR *YEAR
• These special words allow the programmer to
supply a date for the program at run time.
Date Special words
• UDATE, is a 6-character numeric date field
whereas *DATE is an 8-character (4-digit year
portion) numeric date field.
• Both special words can produce three different date
formats:
– Month/day/year
– Year/month/day
– Day/month/year
• Positions 19 and 20 of the H specs is used to
specify the date format and the editing to be done.
Date Special words
• UDATE and *DATE can be used in O specs
• And they can be edited when they are written if
the Y edit code is specified in position 38 of the O
specs.
• The H specs entry in position 20 determines the
separator character to be inserted; for example,
12/31/88, 31.12.88., 12/31/1988
Date Special words
• Similarly other date special keywords can be used
in C specs or O specs
• UYEAR is a 2-position numeric date field where
as *YEAR is a 4-position numeric date field and
are used to move/print the year.
• UMONTH or *MONTH is used to move/print the
month, UDAY or *DAY to move/print the day.
RPG/400

Inter program Communications


Call Operations
• The main keyword used fir inter program
communications in RPG/400 are:
– CALL (Call a Program)
– FREE (Deactivate a Program)
– PARM (Identify Parameters)
– PLIST (Identify a Parameter List)
– RETRN (Return to Caller)
– *ENTRY
CALL - Flow of controls
PGM2
PGM 1

PGM4
RETRN
CALL PGM2
PGM3
CALL PGM3

RETRN
CALL PGM4

RETRN
CALL
• The CALL operation passes control to the
program specified in factor 2
• You can specify the library name and it must be
immediately followed by a slash and then the
program name (for example, 'LIB/PROG'.)
• The total length of a literal, including the slash,
cannot exceed 8 characters. The total length of a
field or named constant, including the slash,
cannot exceed 21 characters.
CALL
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C CALL Program name PLIST name ER LR
C
C CALL 'PGM1'
C
C CALL 'LIB/PGM2'
C
C MOVE 'LIB/PGM2' CALLX
C CALL CALLX

• Positions 56 and 57 to be set on for an error


returned from the called program and the positions
58 and 59 to be set on if the called program is an
RPG/400 program that returns with the LR on.
FREE
• The FREE operation removes a program from the list
of activated programs, frees static storage, and ensures
program initialisation the next time the program is
called.
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C FREE Program name ER
C
C CALL 'PGM1'
C FREE 'PGM1' 90

• Indicator 90 is set on if the FREE operation is not


completed successfully.
PARM
• PARM operation is used to indicate which field
values are to be shared between programs.
• A list of PARMs in the calling program must have
a list of corresponding PARMs in the called
program.
• PARM requires an entry in the result field of C
Specs and it can be a field, data structure or array
• PARMs can appear only immediately after a
CALL operation or following a PLIST operation.
PARM
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C CALL 'PGM1' ER
C PARM FLDA
C PARM FLDB
C PARM FLDC
C
C CALL 'PGM2' PLSTA
C
C PLSTA PLIST
C PARM FLDA
C PARM FLDB
C PARM FLDC

• PLSTA is the parameter list defined in the


program.
PLIST
• PLIST is a declarative operation that
identifies a list of parameters to be shared
between programs
• PLIST requires an entry in factor 1:
– This may be a PLIST name, if the PLIST is
within a calling program
– This may be reserved word *ENTRY, if the
PLIST is within a called program.
*ENTRY
• *ENTRY is the reserved keyword used in
the called program
• This is always linked with PLIST and
PARMS
• A called program can contain only one
*ENTRY PLIST
PLIST/*ENTRY
PLIST in calling program
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C CALL 'PGM2' PLSTA
C
C PLSTA PLIST
C PARM FLDA
C PARM FLDB
C PARM FLDC

PLIST in called program


6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C *ENTRY PLIST
C PARM FLDA
C PARM FLDB
C PARM FLDC
RETRN (Return)
• The RETRN operation returns control to the
calling program
• When the called program executes the RETRN
and if the LR is ON, the system’s resources
tied up with called programs are all released
• In case if LR is not ON within the called
program, it remains activated even if it
encounters RETRN
Data Areas
• We have seen PARMS allow data to be
shared between calling and called programs.
• Data Areas are AS/400 objects used to
communicate between programs with a job
or between jobs
• Data areas can be used to store information
of limited size , 1024 bytes long, that are
frequently used by several programs or same
program each time it is run.
E.g. Tax rates, discounts, last invoice number etc
Data Area Data Structures
• Data areas can be declared to RPG as Data
area Data structures
• This is done by putting a ‘U’ in position 18
• During program initialisation the data area
named in data structure is retrieved and
loaded into data structure sub fields and the
data area is implicitly locked
• If no name is specified for data area, the
local data area (LDA) is loaded
Data Area Data Structures
• When the program ends, the system writes back the contents
of data structure back to data area and releases the lock
• Typical entries in an I specs for a data area is shown below

6 7-13 1819-20 21-38 44-47 48-51 52 53-58


Type Filename O RI Record Identification From To dec Field Name
I U DS
I 1 8 0 INVNO
I
I TAXRAT U DS
I 1 6 2 PERTAX
I 7 12 2 EMPTAX
I 13 18 2 SURCHG
Data areas using *NAMVAR DEFN
• The contents of data area can be accessed through
*NAMVAR DEFN operation
• This operation requires *NAMVAR in factor 1
and a field to receive the data area’s contents in
the result field. The result field can be a field, a
data structure field or data structure
• Factor 2 contains the external name of data area.
• If blank, the result field represents both the
external data area name and the name field name
to receive data area contents
Data areas using *NAMVAR DEFN
• Let’s look how we code
6 18-27 28-32 33-42 43-48 49-51 53 54-55 56-57
Type Factor 1 Operation Factor 2 Result Length P/N/H HI LOW
C *NAMVAR DEFN CHKNO 5
C
C *NAMVAR DEFN INVOICE INVNO 6
C
C *NAMVAR DEFN *LDA LOCAL

• In 1st, the data area name CHKNO to be used as


field name
• In 2nd , the data area INVOICE is associated with
field INVNO
• In 3rd, local data area is associated with LOCAL
RPG/400

String handling in RPG/400


SUBST(Substring)
• The SUBST operation copies a portion of a
character string into a different field
• Factor 1 represents the length of the string to be
copied. It can be a field, array element, literal etc
• Factor 2 contains the base character string to be
copied. It can be a field, array element, literal etc
• The copying begins from left to right, unless the
base string is followed by colon(:) followed by a
start location
SUBST(Substring)
• Let’s look at the following examples with values of
FLDA = ‘ABCDE’ and FLDB = ‘12345’
6 18-27 28-32 33-42 43-48 49-51 53 54-55 56-57
Type Factor 1 Operation Factor 2 Result Length P/N/H HI LOW
C 3 SUBST FLDA FLDB 5 90
C
C 3 SUBST FLDA:3 FLDB 5 90
C
C 3 SUBST FLDA FLDB 5 P 90

• The result of 1st SUBST will be ‘ABC45 ’


• The result of 2nd SUBST will be ‘CDE45’
• The result of 3rd SUBST will be ‘ABC ‘
– Since position 53 contain a code P (pad), the unused
portion is padded with trailing blanks
CAT (Concatenate)
• The CAT operation is useful for concatenating the
values of two strings to form third string
• The two character data items are specified in factor 1
and factor2, the result field entry contains the results
• Usage

Type Factor 1 Operation Factor 2 Result HI LOW EQ


C
C Field A CAT Field B Field C
C
C
CAT (Concatenate)
• In CAT operation, you have a option of specifying
number of blanks you want to appear between the
concatenated fields by appending a colon(:) to
factor 2 item, followed by the number
• Consider two fields of size 8 having values FNAME
= ‘BILL ‘ , LNAME = ‘SMITH ’
6 18-27 28-32 33-42 43-48 49-51 54-55 56-57
Type Factor 1 Operation Factor 2 Result Length HI LOW
C FNAME CAT LNAME NAME 12
C
C FNAME CAT LNAME:1 NAME 12
C
SCAN
• The SCAN operation allows you to look for
a character or string of characters within a
character field
• The direction of SCAN is from left to right
• Usage
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C Compare string SCAN Base string
C
C 'MY' SCAN 'MY NAME IS' ON
C
SCAN
• Factor 1 contains the string you are looking for,
called as Compare string.. This may be a
character field, array element, named constant,
data structure name, literal, or table name.
• The number of characters of the factor 1 to be
compared , starting from left, can be specified
by putting ‘:’ followed by integer length
SCAN
• Factor 2 contains the string to be scanned,
called as Base string.. This may be a character
field, array element, named constant, data
structure name, literal, or table name.
• In factor 2 , you can specify the starting
location for SCAN to begin. This is done by
putting ‘:’ followed by the integer literal, field,
named constant or array element.
SCAN
• The SCAN operation uses the result field to put a number
which represents the starting position of compare string
within the base string
• Indicator in position 58-59 comes on if the SCAN is
successful, indicator 56-57 comes on if an error occurs
• The SCAN is case sensitive
• The SCAN operation is useful for inspecting text data (e.g.
to scan addresses of customers residing in same street etc.)
SCAN
• To get a feeling how SCAN works, we will look at this example where FLDA is ‘abcde’
and FLDB is ‘mabcdeabczab’

6 18-27 28-32 33-42 43-48 54-55 56-57 58-59


Type Factor 1 Operation Factor 2 Result HI LOW EQ
C FLDA SCAN FLDB FLDC 50
C
C FLDA:3 SCAN FLDB FLDC 50
C
C FLDA:3 SCAN FLDB:8 FLDC 50

• In Ist case, compare value is ‘abcde’, so FLDC is 2 and 50 is ON


• In IInd case, compare value is ‘abc’, so FLDC is 2 and 50 is ON
• In IIIrd case, FLDC is 0 and 50 is OFF, because scan starts at 8th byte of FLDB
XLATE
• XLATE is an operation that allows you to
convert within a string to other characters
• Factor 1 must contain the From string, followed
by a colon, followed by the To string.
• Factor 2 contains the source string to be
converted
• Result field has the results of the translation; this
can be the same as the source filed
XLATE
Usage
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C From:To XLATE String:start Target string ER
C

• You can use a colon (:) and value to designate the


position where translation is to begin
• An indicator in positions 56-57 turns on if an error
occurs on the operation.
XLATE
• Lets us look how XLATE works. This example translates the blank in field NUMBER to
‘-’

6 18-27 28-32 33-42 43-48 40-51 54-55 56-57 58-59


Type Factor 1 Operation Factor 2 Result Length HI LOW EQ
C
C MOVE '999 9999' NUMBER 8
C ' ':'-' XLATE NUMBER RESULT 8
C
C

• The result in RESULT will be '999-9999'.


XLATE
• Lets us take one more example, where uppercase letters are converted to lowercase and vice versa
• The From and To string of character set are defined through named constant UC & LC defined in I specs

6 7-20 21-38 43 53-58


Type Name/Seq Record Identification P/B/L/R Field Name
I
I 'ABCDEFGHIJKLMNOP- C UC
I QRSTUVWXYZ'
I 'abcdefghijklmnop- C LC
I qrstuvwxyz'

• This serves as our translation table


XLATE
6 18-27 28-32 33-42 43-48 40-51 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result Length HI LOW EQ
C MOVE 'Csd DepT' DEPTNAME 8
C LC:UC XLATE DEPTNAME RESULT 8
C
C MOVE 'CsD DepT' DEPTNAME 8
C UC:LC XLATE DEPTNAME RESULT 8
C
C MOVE 'CSD DEPT' DEPTNAME 8
C UC:LC XLATE DEPTNAME:6 RESULT 8

• RESULT=’CSD DEPT’
• RESULT =‘csd dept’
• RESULT = ‘CSD Dept’
CLEAR
• CLEAR changes the value of the data item(s) to
‘0’ or blanks depending upon the field type
• You can CLEAR individual fields or structures
(data structures, arrays, tables, record formats)
• CLEAR operation requires a factor 2 entry that
specifies which data item is to be cleared
CLEAR
Usage
6 18-27 28-32 33-42 43-48 54-55 56-57
Type Factor 1 Operation Factor 2 Result HI LOW
C
C *NOKEY CLEAR Structure/Variable
C

• If specified on an array, it clear entire array


• If the data item is file record format, you can
specify *NOKEY in factor to signal all fields to
cleared except the record key
• If CLEAR is used on record format, only fields
that are output are affected (E.g.. fields with
usage ‘O’ or ‘B’ in display file record format)
RESET
• The RESET operation is similar to CLEAR
• Here instead of initialising to blank or zero,
RESET restores the elements to whatever value
they had at the end of the initialisation step at
the program’s start
• If you had initialised data structure fields to
specific value or assigned values to fields in
*INZSR, you can reassign them to the original
value in middle of program execution
RESET
Usage
6 18-27 28-32 33-42 43-48 54-55 56-57
Type Factor 1 Operation Factor 2 Result HI LOW
C
C *NOKEY RESET Structure/Variable
C

• The RESET operation can be used in record


format, data structure, array, or table, or a
variable (field, subfield, or indicator) to reset to
its initial value.
COMIT (Commit)
• The COMIT operation:
– Makes all the changes to your files that have been
specified in output operations since the previous
COMIT or "ROLBK (Roll Back)" operation (or since
the beginning of operations under commitment
control)
– It Releases all the record locks for files you have
under commitment control.
• The file changes and the record-lock releases
apply to all the files you have under commitment
control,
COMIT
Usage
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C COMIT ER
C

• Commitment control starts when the COMIT


operation is executed or when the CL command
STRCMTCTL is executed.
• The optional indicator in positions 56 and 57 is set
on if the operation is not completed successfully.
ROLBK (Roll back)
• The ROLBK operation:
– Eliminates all the changes to your files that have
been specified in output operations since the
previous COMIT or ROLBK operation (or since
the beginning of operations under commitment
control).
– Releases all the record locks for the files you have
under commitment control.
– Repositions the file to its position at the time of the
previous COMIT operation (or at the time of the file
OPEN, if there has been no previous COMIT
operation.)
ROLBK
Usage
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C ROLBK ER
C

• The optional indicator in positions 56 and 57 is


set on if the operation is not successfully
completed.
DSPLY (Display)
• The DSPLY operation allows the program
to communicate with the display work
station that requested the program.
• The operation can display a message and
accept a response.
DSPLY (Display)
Usage
6 18-27 28-32 33-42 43-48 54-55 56-57 58-59
Type Factor 1 Operation Factor 2 Result HI LOW EQ
C
C Message Identifier DSPLY Output Queue Response ER
C

• The value in factor 1 is used to create the


message to be displayed. it can contain a field
name, a literal, a named constant, a table name,
or an array element
• Factor 1 can also contain *M, followed by a
message identifier that identifies the message to
be retrieved from the message file, QUSERMSG
DSPLY (Display)
• The factor 2 contains the queue where the message
has to be placed. It can system Q like QSYSOPR
(operator’s Q) or *EXT (requester’s Q) or any Q
set in AS/400 system
• The result field is optional. If it is specified, the
response is placed in it.
• The maximum length of information that can be
displayed is 52 characters
RPG/400

Error Handling
RPG error handling
No
Exception Execute next
/error seq.instructions
Yes

Set up file info


or pgm status DS

Yes Set on indicator


Indicator in
& execute next
56-57
seq.instructions
Yes
INFSR or Control passes to
*PSSR? INZSR or *PSSR
INFDS
• A file information data structure is a special data
structure that can be for each file used in the program
• This data structure contains predefined subfields that
can provide information to the program about the file
and operations done on the file
• The subfields of data structure vary depending upon
the type of the file like PF/PRTF/DSPF etc
INFDS
• A file information data structure must be linked
to the file it is associated with by making some
entries in file’s F specs
• The F specs definition will be
6 7-14 15 16 19 40-46 53 54-59 60-65
Type File Name I/O/U/C P/S/F F/V/E Device K name Entry

F SAMPLE U F E DISK K INFDS SAMPDS


• SAMPDS is data structure for file SAMPLE
INFDS
• Each data structure is 528 positions long and is
subdivided into predefined subfields
6 7-13 1819-20 21-38 44-47 48-51 52 53-58
Type Filename O RI Record Identification From To dec Field Name
I SAMPDS DS
I 1 8 FILNAM
I 11 15 0 STATUS
I 16 21 OPCODE
I SAMPDS
I *FILE FILNAM
I *STATUS FSTAT
I *OPCODE OPCODE

• In the data structure you can either use the


position of subfields or the keywords provided
INFDS
• The subfield in position 1-8 contains the name of
filename (keyword *FILE)
• The subfield in position 11-15 (keyword
*STATUS) contain the status code recent I/O
operation
• The subfield in position 16-21 (keyword
*OPCODE) contain the name of recent done
operation on the file such as READ etc
INZSR
• INZSR - This a special subroutine which receives
control when a file exception/error occurs and
there are no indicators specified in positions 56/57
• The INFSR is coded like any other subroutine
with BEGSR and ENDSR operation codes
Program Exception/Errors
• Some examples of program exception/errors are: division by
zero, SQRT of a negative number, invalid array index, an error
on a CALL etc
• They can be handled in one of the following ways:
– An indicator can be specified in positions 56 and 57 of the C specs.
The optional program status data structure is updated with the
exception/error information.
– A program exception/error subroutine can be specified.
– If the indicator or the program exception/error subroutine is not
present, program exception/errors are handled by the RPG/400 default
error handler.
Program Status Data Structure
• The Program status data structure provides
information about the program and about
exceptions/errors that occur during execution of
program
• Like file information data structure, program status
data structure has predefined subfields that are
automatically given to the program during its
execution
Program Status Data Structure
• The program-status data structure can supply you
with name of the program, routine name where error
occurred, the job name, job number, the name of the
user who called the program, date, parms etc
• In data structure, you can either use the position of
subfields or the keywords provided
6 7-13 1819-20 21-38 44-47 48-51 52 53-58
Type Filename O RI Record Identification From To dec Field Name
I S DS
I 1 10 FILNAM
I 11 15 0 STATUS
I 244 253 JOBNAM
I 254 263 USRNAM
Program Exception/Error subroutine
• *PSSR - This a special subroutine which receives
control when a program exception/error occurs
• You can specify *PSSR in factor 1 of the
subroutine's BEGSR operation.

6 7-13 1819-20 21-38 44-47 48-51 52 53-58


Type Filename O RI Record Identification From To dec Field Name
I S DS
I 1 10 FILNAM
I 11 15 0 STATUS
I 244 253 JOBNAM
I 254 263 USRNAM
RPG/400

Day 6
RPG - Agenda for Day 6
• Summarise all Specifications
• More examples
• RPG debugger
• Tips & techniques
• Restrictions of RPG/400
• Introduction to RPG/4
• Exercises
Restrictions of RPG
• Maximum 200 array or tables per program
• Compile time array max input record Len is 80
• Max Character field Len is 256
• Data structure length is 9999
• Data structure occurrence is 9999
• Edit word max 24 for literal & 115 for constant
• Element in array or table max 9999
• File max 50
Restrictions of RPG (Cont..)
• Level of nesting in structured group is 100
• Constant 256 for char, 512 for hex, 30 digit
with 9 decimal for numeric
• Overflow indicator only one
• Parameter max 255
• Primary file only one
• Printer file max 8 per program
• Printing lines min 2 max 112
Restrictions of RPG (Cont..)
• Program status data structure only 1
• Record address file 1
• Record length of program described file is
9999
• Subroutines 254 per program

You might also like