Sie sind auf Seite 1von 68

RPG IV Specification Types:

RPG IV source is coded on a variety of specifications. Each specification has a specific set of
functions.

There are three groups of source records that may be coded in an RPG IV program:

1. The main source section


2. The sub procedure section
3. The program data section.

The main source section consists of the first set of H, F, D, I, C, and O specifications in a module.
If the keyword NOMAIN is not specified, it corresponds to a standalone program or a main
procedure. If NOMAIN is specified, it does not contain a main procedure, and so it does not
contain any executable calculations. Every module requires a main source section
independently of whether subprocedures are coded.
Main Source Section Specifications
(H)
Control (Header) specifications provide information about program generation and
running of the compiled program.
(F)
File description specifications define all files in the program..
(D)
Definition specifications define items used in your program. Arrays, tables, data
structures, subfields, constants, standalone fields, prototypes and their parameters, and
procedure interfaces and their parameters are defined on this specification.
(I)
Input specifications describe records and fields in the input files and indicate how the
records and fields are used by the program.
(C)
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.
(O)
Output specifications describe the records and fields and indicate when they are to be
written by the program.

Subprocedure Specifications

(P)
Procedure specifications describe the procedure-interface definition of a prototyped
program or procedure
(D)
Definition specifications define items used in the prototyped procedure. Procedure-
interface definitions, entry parameters, and other local items are defined on this
specification.
(C)
Calculation specifications perform the logic of the prototyped procedure.
Program Data

Source records with program data follow all source specifications. The first line of the data
section must start with **.

If desired, you can indicate the type of program data that follows the **, by specifying this
keyword required: CTDATA, By associating the program data with the appropriate keyword, you
can place the groups of program data in any order after the source records.

The first entry for each input record must begin in position 1. The entire record need not be
filled with entries. Array elements associated with unused entries will be initialized with the
default value.
Control (Header) specifications

H SPEC

 H is the alphabetic code used for Control Specification. It is used to define the
controlling entity of the program e.g. date/ time format, default program name,
program as PEP, to define the decimal precision etc.
 It is also used to define the compiler options to be used while we are compiling the
program.
e.g. default activation group, authority, compiler source generation options etc.

To prompt H SPEC given the line command: IPH

Prompt type . . . H Sequence number . . . '''''''

Keywords

___________________________________>>>>> multiple keywords can be


written here

Comment

___________________
 H SPEC Keywords

o DEBUG (*Yes)

Use this keyword to indicate whether or not to perform DUMP operations in your RPG
program. The default is *NO, which means DUMP operations will not be performed. If you
have an error handler that uses the DUMP op-code, you should specify DEBUG (*YES) in
your H-spec.

o DATEDIT (*DMY)

o OPTION(*{NO}XREF *{NO}GEN *{NO}SECLVL *{NO}SHOWCPY *{NO}EXPDDS


*{NO}EXT *{NO}SHOWSKP) *{NO}SRCSTMT) *{NO}DEBUGIO)

As of V4R5, below are the options available:

*{NO}XREF: Determines whether or not to create a cross-reference listing when the


module is compiled.

*{NO}GEN: Determines whether or not to generate a compiled object.

*{NO}SECLVL: Sets the level of message displayed on compile listing.

*{NO}SHOWCPY: If *NOSHOWCPY is specified, /copy members are not expanded in the


compile listing.
This may be useful if you have a large copy member that defines many
procedure prototypes.

The two most useable options however are still probably *{NO}SRCSTMT and
*{NO}DEBUGIO.

*{NO}SRCSTMT: If *NOSRCSTMT is coded or this statement is excluded (*NOSRCSTMT


is the default), statements will be re-numbered when compiling the
program. If your program gets a run-time error, the statement indicated
will be virtually useless unless you have a copy of compile.
*SRCSTMT will prevent the compiler from renumbering the program's
statements.

*{NO}DEBUGIO: If you use the interactive source debugger to step through a program,
you'll notice that the debugger will break many times on every I/O
statement. This is because a separate breakpoint is inserted for every
field returned from the I/O buffer. This is not a major problem, and very
inconvenient. Coding *NODEBUGIO will break only once for each I/O
statement.

o DATFMT (FMT)

Specify this keyword to define the default format for date fields within the program.

Choose one of the following date formats:

*MDY (mm/dd/yy)

*DMY (dd/mm/yy)

*YMD (yy/mm/dd)

*ISO (yyyy-mm-dd)

*USA (mm/dd/yyyy)

*EUR (dd.mm.yyyy)

e.g. H datfmt(*MDY)

By default FMT will be *ISO.


o TIMFMT (FMT)
Choose one of the following time formats:

*HMS (hh:mm:ss)

*ISO (hh.mm.ss)

*USA (hh:mm AM or hh:mm PM)

*EUR (hh.mm.ss)

By default FMT will be *ISO.

o ACTGRP (*NEW | *CALLER | 'activation-group-name')

If ACTGRP (*NEW) is specified, then the program is activated into a new activation group. If
ACTGRP(*CALLER) is specified, then the program is activated into the caller's activation group. If an
activation-group-name is specified, then that name is used when this program is called.

H datedit(*YMD) datfmt(*ISO) option(*SRCSTMT *NODEBUGIO)

o NOMAIN

Specify this keyword to indicate that this module does not contain a main (program-entry) procedure.

o AUT (*LIBRCRTAUT | *ALL | *CHANGE | *USE | *EXCLUDE |


'authorization-list-name')

The AUT keyword specifies the authority given to users who do not have specific authority to the
object.
o BNDDIR ('library-name/binding-directory-name')

We can mention the bind directory name here that is to be used at the time of compilation.

File Description Specifications

F is the alphabetic code used for File Description specifications.


To prompt F SPEC given the line command: IPF

Prompt type . . . F Sequence number . . . '''''''

File File End of File

Filename Type Designation File Addition


Sequence

________ _ _ _ _ _

File Record Limits Length of Record

Format Length Processing Key Field Address Type

_ ____ _ ____ _

File

Organization Device Keywords

_ ______ __________________________

Comment

_______________
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.

FCZGD02A0 IF E K DISK INCLUDE(CZTD02A2)

F PREFIX(D20:3)

Fcmgq08a0 if e k disk ignore(cmtq08a1:cmtq08a3)

FSSG043A0 IF A E K Disk RENAME(SSH04310:SSH04310A)


 F SPEC continuation line

The prompt used for this is IPFK in RPG-400

o In order to refer the named record format as a subfile record format in the program.

o In order to rename the record format of a database file in a program.

o In order to define a named data structure as a file information data structure.

In RPGLE these keywords are defined in the keywords option.

 F SPEC Keywords

o COMMIT{(rpg_name)}

The COMMIT keyword allows the processing files under commitment control. By specifying
the optional parameter, you can control at run time whether to enable commitment control. If
the parameter contains a '1', the file will be opened with the COMMIT indication on, otherwise
the file will be opened without COMMIT.

o IGNORE(recformat{:recformat...})

The IGNORE keyword allows a record format from an externally described file to be ignored.
The external name of the record format to be ignored is specified as the parameter recformat.
One or more record formats can be specified, separated by colons (:).

Example:

FACCLG01 IF E K DISK IGNORE(Rec_format_2: Rec_format_3)

Suppose ACCLG01 has 3 record formats Rec_format_1, Rec_format_2 and Rec_format_3.

Now if we need only Rec_format_1 in our program, then we can IGNORE rest of the two
record formats Rec_format_2 and Rec_format_3.
o INCLUDE(recformat{:recformat...})

The INCLUDE keyword specifies those record format names that are to be included; all other
record formats contained in the file will be ignored.

Example:

FACCLG01 IF E K DISK INCLUDE(Rec_format_1)

Suppose ACCLG01 has 3 record formats Rec_format_1, Rec_format_2 and Rec_format_3.

Now if we need only Rec_format_1 in our program, then we can INCLUDE this record format
and rest of the record formats will be ignored.

o PREFIX(prefix{:nbr_of_char_replaced})

The PREFIX keyword is used to partially rename the fields in an externally described file.
PREFIX(YE:3) would change the field name 'YTDTOTAL' to 'YETOTAL'.

Example:

FACCLG01 UF A E K Disk

F Prefix(A01:3)

FACCLG02 UF A E K Disk

F Prefix(A02:3)

Here above logical files ACCLOG1 and ACCLOG2 both are based on same physical file and
only difference is their key fields. But they do have same field names. If we are using both file
at the same time, we cannot distinguish the field name of the two. Hence, to overcome this
problem we use PREFIX that partially renames the fields of the file.
Here ACCLG01 file will have its field’s first 3 character replaced with A01 and ACCLG02 file
will have its field’s first 3 character replaced with A02.

o RENAME(Ext_format:Int_format)

The RENAME keyword allows you to rename record formats in an externally described file.

Example:

FACCLG01 UF A E K Disk

F Rename(format1:format_xxx)

FACCLG02 UF A E K Disk

F Rename(format1:format_yyy)

Suppose we are using two files ACCLG01 and ACCLG02 both having the same record format
name format1, In such a case to distinguish the two files on the basis of their record format
name, we can use the RENAME keyword to rename the record format of one file to make it
different than the other one.

Here the new record format name for the two file will be format_xxx and format_yyy.

o SFILE(recformat:rrnfield)

Type the name of the record format and the field to contain the relative record number for the
entry field to be processed as a subfile. This keyword is valid only for externally described
files.

FSFLMSGDSP CF E WORKSTN SFILE(ACCSFL:RRN)

If we compile the program, we can see in the compiler report that all the formats related to the
subfile will get included in the program by using subfile.
Compiler report

FSFLMSGDSP CF E WORKSTN SFILE(ACCSFL:RRN)

*---------------------------------------------------------------------

* RPG name External name

* File name. . . . . . . . . : SFLMSGDSP AMIT/SFLMSGDSP

* Record format(s) . . . . . : ACCSFL ACCSFL

* ACCCTL ACCCTL

* MSGSFL MSGSFL

* MSGCTL MSGCTL

*---------------------------------------------------------------------

o USROPN

Specify this keyword to indicate that the file must be explicitly opened with the OPEN operation and
should be

closed with CLOSE operation.

* The printer file is opened in the calculation specifications

FFILE1 O F 132 DISK USROPN

/FREE

// Open the file if it is not already open

if not %open (FILE1);

open FILE1;
endif;

/END-FREE

o EXTMBR('member name') EXTMBR('*ALL')


Using EXTMBR ('member name’), we can use the member that we want to access of the file
mentioned here in F-Spec.
If instead of any member name, we mention EXTMBR ('*ALL'), then all the members are
accessed one by one.

Example: Used in example of INFDS.

o INFDS(data structure name)

FILE INFORMATION DATASTRUCTURE

A file information data structure (INFDS) can be defined for each file to make file
exception/error and file feedback information available to the program.
Example: Using INFDS & EXTMBR

>>>> To read all members of a PF

Columns . . . : 1 71 Browse AMIT/QRPGLESRC

SEU==> MBR_READ

FMT FX .....FFilename++IPEASF.....L.....A.Device+.Keywords++++++++++++++++++++

*************** Beginning of data *************************************

0001.00 FCUST IF E DISK EXTMBR('*ALL')

0001.01 F INFDS(FILEDS)

0001.02 *

0001.03 DFILEDS DS

0001.04 DRECORD *RECORD

0001.05 DMEMBER 129 138

0001.06 DDB_RRN 397 400I 0

0001.07 *

0001.08 *

0001.09 DDATA1 DS

0001.10 DFLD1 10

0001.11 DFILLER1 2 INZ('--')

0001.12 DFLD2 10

0001.13 DFILLER2 2 INZ('--')

0001.14 DFLD3 4 0

0001.15 DFILLER3 2 INZ('--')

0001.16 *

0001.17 *

0001.18 DDATA2 DS

0001.19 DFLD4 6

0001.20 DFILLER4 2 INZ('--')

0001.21 DFLD5 10

0001.22 DFILLER5 2 INZ('--')


0001.23 DFLD6 5 0

0001.24 DFILLER6 2 INZ('--')

0001.25 DFLD7 10 0

0001.26 *

0001.27 *

0001.28 *

0002.00 C READ CUST

0003.00 C DOW NOT %EOF(CUST) AND *IN90=*OFF

0003.02 C EVAL FLD1=MEMBER

0003.03 C EVAL FLD2=RECORD

0003.04 C EVAL FLD3=DB_RRN

0003.05 C EVAL FLD4=CSNBR

0003.06 C EVAL FLD5=CSNAME

0003.07 C EVAL FLD6=CS#OPN

0003.08 C EVAL FLD7=CS$OPN

0003.09 C DATA1 DSPLY

0003.10 C DATA2 DSPLY

0003.11 C READ CUST

0004.00 C ENDDO

0005.00 C SETON LR

****************** End of data ****************************************

Work with Members Using PDM USALID09

File . . . . . . CUST

Library . . . . AMIT Position to . . . . .

Type options, press Enter.


3=Copy 4=Delete 5=Display 7=Rename 8=Display description

9=Save 13=Change text 18=Change using DFU 25=Find string ...

Opt Member Date Text

CUST 07/27/12

MBR2 07/23/12

MBR3 07/23/12

Bottom

Parameters or command

===>

F3=Exit F4=Prompt F5=Refresh F6=Create

F9=Retrieve F10=Command entry F23=More options F24=More keys

File’s member Data

CUST data

CSNBR CSNAME CS#OPN CS$OPN

000001 000001 AMI 0 .00

000002 000002 upi 0 .00

000003 000003 KUM 0 .00

000004 000004 RAHIN 12,256 454,654.51


000005 000005 HARISH 980 798,789.00

MBR2 data

CSNBR CSNAME CS#OPN CS$OPN

000001 100002 upi 0 .00

000002 100003 KUM 0 .00

MBR3 data

CSNBR CSNAME CS#OPN CS$OPN

100003 KUM 0 .00

Output

Display Program Messages

CUST --CUSTR --0001--

000001--AMI --00000--0000000000

CUST --CUSTR --0002--

000002--upi --00000--0000000000

CUST --CUSTR --0003--

000003--KUM --00000--0000000000

CUST --CUSTR --0004--

000004--RAHIN --12256--0000454654

CUST --CUSTR --0005--


000005--HARISH --00980--0000798789

MBR2 --CUSTR --0001--

100002--upi --00000--0000000000

MBR2 --CUSTR --0002--

100003--KUM --00000--0000000000

MBR3 --CUSTR --0001--

100003--KUM --00000--0000000000

Example 2: INFDS using 369 position of display file to handle PAGEUP, PAGEDOWN, ENTER KEY…

f MyScreen c f e workstn INFDS (ScnDS)

d ScnDS ds

* Attention Indicator Byte

d PressKey 369 369

d EnterKey c const(x'F1')

d RollUp c const(x'F5')

d RollDown c const(x'F4')

select;

when PressKey = EnterKey; // Enter Key pressed

- - - - - - - - - - // Do programming for Enter Key

when PressKey = RollUp;

- - - - - - - - - - // Do programming for RollUp

when PressKey = RollDown;


- - - - - - - - - - // Do programming for RollDown

Endsl;

Seton lr;

o INFSR(subroutine_name)

FILE ERROR SUBROUTINE

Type the name of the subroutine that will get control when an exception/error condition occurs.

 The file error subroutine can only be coded in the main source section. You cannot code an
INFSR for a file that is used in subprocedure.

 Specifying INFSR (*PSSR) means that you want the "standard" *PSSR subroutine to
handle the file exception which it would do by default - that's the reason why *PSSR is
handling the exceptions for your files.

 If you only want exceptions handled for the specific file then give the subroutine a name
other than *PSSR, for example "FileErrSr" and assign that with INFSR(FileErrSr).
o OFLIND(indicator)

Indicator value from *INOA to *INOG or *INOV, is used to specify the overflow condition
for the program described printer files.

Indicator value from *IN01 to *IN99 is used to specify the overflow condition for the
externally described printer files.

Example:

Externally described printer file PRINT4

Columns . . . : 1 80 Browse
AMIT/QRPGLESRC

SEU==>
PRINT4

FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7


...+... 8

*************** Beginning of data


***********************************************************

0000.01
A*%%***********************************************************************

0000.02 A*%%TS RD 20 085008 ARUN REL-V5R4M0 5722-WDS

0000.03 A*%%FI+10660100000000000000000000000000000000000000000000000000

0000.04 A*%%FI 0000000000000000000000000000000000000000000000000

0000.05
A*%%***********************************************************************

0000.06 A R RCD001

0000.07
A*%%***********************************************************************

0000.08 A*%%RI 00000

0000.09
A*%%***********************************************************************

0000.10 A 80 2

0000.11 A 'PARTY ACCOUNT INFOR'


0000.12 A UNDERLINE

0000.13 A FLD001 2S 0O +2

0000.14 A EDTCDE(L)

0000.15 A UNDERLINE

0000.16
A*%%***********************************************************************

0000.17 A*%%SS

0000.18
A*%%***********************************************************************

0000.19 A R HEADER

0000.20
A*%%***********************************************************************

0000.21 A*%%RI 00000

0000.22 A*%%FS 001

0000.23
A*%%***********************************************************************

0000.24 A SPACEB(002)

0000.25 A 9

0000.26 A 'ORG'

0000.27 A HIGHLIGHT

0000.28 A +9

0000.29 A 'ACCOUNT NO'

0000.30 A +9

0000.31 A 'CCY'

0000.32 A +9

0000.33 A 'PARTY NO'

0000.34
A*%%***********************************************************************

0000.35 A*%%SS

0000.36
A*%%***********************************************************************

0000.37 A R DETAIL
0000.38
A*%%***********************************************************************

0000.39 A*%%RI 00005

0000.40
A*%%***********************************************************************

0000.41 A SPACEB(001)

0000.42 A ORG R O 9

0000.43 A REFFLD(REC1/ORG AMIT/MASTER)

0000.44 A ACC R O +8

0000.45 A REFFLD(REC1/ACC AMIT/MASTER)

0000.46 A CCY R O +8

0000.47 A REFFLD(REC1/CCY AMIT/MASTER)

0000.48 A PARTY R O +8

0000.49 A REFFLD(REC1/PARTY AMIT/MASTER)

0000.50
A*%%***********************************************************************

0000.51 A*%%SS

0000.52 A*%%SS

0000.53 A*%%SS

0000.54 A*%%SS

0000.55 A*%%SS

0000.56 A*%%SS

0000.57
A*%%***********************************************************************

0000.58 A R FOOTER

0000.59
A*%%***********************************************************************

0000.60 A*%%RI 00000

0000.61 A*%%FS 001

0000.62
A*%%***********************************************************************

0000.63 A SPACEB(002)

0000.64 A 13
0000.65 A 'TOTAL CUSTOMER FOUND = '

0000.66 A TOTAL 2S 0O +0

0000.67
A*%%***********************************************************************

0000.68 A*%%SS

0000.69 A*%%CP+999CRTPRTF

0000.70 A*%%CP+ FILE(AMIT/PRINT4)

0000.71 A*%%CP+ DEVTYPE(*SCS)

0000.72 A*%%CP PAGESIZE(*N 071 *N )

0000.73 A*%%CS+999CRTPRTF

0000.74 A*%%CS+ FILE(QTEMP/QPRDRPT )

0000.75 A*%%CS+ DEVTYPE(*SCS)

0000.76 A*%%CS PAGESIZE(*N 132 *N )

0000.77
A*%%***********************************************************************

****************** End of data ***************************************************

Print program using OFLIND

Columns . . . : 6 80 Browse
AMIT/QRPGLESRC

SEU==>
PRINT4PGMC

FMT * *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8

*************** Beginning of data


*******************************************************

0001.00

0002.00 FMASTER IF E K DISK

0003.00 FPRINT4 O E PRINTER OFLIND(*IN99)


0004.00 C Z-ADD 0 COUNT 2 0

0005.00 C WRITE HEADER

0006.00 C READ REC1 80

0007.00 C *IN80 DOWEQ *OFF

0008.00 C 99 WRITE HEADER

0009.00 C WRITE DETAIL

0010.00 C ADD 1 COUNT

0011.00 C READ REC1 80

0012.00 C IF COUNT=5 >>>> Here overflow condition will occur


after 5

are printed.

0013.00 C SETON 99

0014.00 C ELSE

0015.00 C SETOFF 99

0016.00 C ENDIF

0017.00 C ENDDO

0018.00 C MOVEL COUNT TOTAL

0019.00 C WRITE FOOTER

0020.00 C SETON LR

****************** End of data


**********************************************************

Output

ORG ACCOUNT NO CCY PARTY NO

190 A00000000001 EUR P00000000001

190 A00000000006 USD P00000000006

190 A00000000009 TRY P00000000009


191 A00000000002 USD P00000000002

191 A00000000004 EUR P00000000004

ORG ACCOUNT NO CCY PARTY NO

191 A00000000005 USD P00000000005

191 A00000000007 EUR P00000000007

191 A00000000008 USD P00000000008

TOTAL CUSTOMER FOUND = 08

Access particular member of a file

A. If you want to do this inside of the RPG then have at least V5R1, you can use EXTFILE and
EXTMBR.

FFile1 if e Disk Extfile(FilNam) ExtMbr(Member Name)

o Creating logical file for member 5 of MYFILELF physical file

CRTLF FILE(KCS/MYFILELF) SRCFILE(KCS/KC1) DTAMBRS((KCS/MYFILEPF (MBR5)))

Or,

ADDLFM FILE(KCS/MYFILELF) MBR(MYFILEBR) DTAMBRS((KCS/MYFILEPF (MBR5)))

o For accounting purpose each month data can be stored as 12 different members so that we
can easily access one month data or 12 months together. Easy to maintain 12 members in
one PF file instead of 12 PF Files. Hence, in such a case the members will be JANUARY,
FEBRUARY, MARCH and so on.

o To maintain the same data but for different system id.


 How to access all the member of a file

Columns . . . : 6 76 Browse
AMIT/QRPGLESRC

SEU==>
MBR_READ

FMT FX
FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++

*************** Beginning of data


*************************************

0001.00 FCUST IF E DISK EXTMBR('*ALL')

0001.01 F INFDS(FILEDS)

0001.02 *

0001.03 DFILEDS DS

0001.04 DRECORD *RECORD

0001.05 DMEMBER 129 138

0001.06 DDB_RRN 397 400I 0

0001.07 *

0001.08 *

0001.09 DDATA1 DS

0001.10 DFLD1 10

0001.11 DFILLER1 2 INZ('--')

0001.12 DFLD2 10

0001.13 DFILLER2 2 INZ('--')

0001.14 DFLD3 4 0

0001.15 DFILLER3 2 INZ('--')

0001.16 *

0001.17 *

0001.18 DDATA2 DS
0001.19 DFLD4 6

0001.20 DFILLER4 2 INZ('--')

0001.21 DFLD5 10

0001.22 DFILLER5 2 INZ('--')

0001.23 DFLD6 5 0

0001.24 DFILLER6 2 INZ('--')

0001.25 DFLD7 10 0

0001.26 *

0001.27 *

0001.28 *

0002.00 C READ CUST


90

0003.00 C DOW NOT %EOF(CUST) AND *IN90=*OFF

0003.02 C EVAL FLD1=MEMBER

0003.03 C EVAL FLD2=RECORD

0003.04 C EVAL FLD3=DB_RRN

0003.05 C EVAL FLD4=CSNBR

0003.06 C EVAL FLD5=CSNAME

0003.07 C EVAL FLD6=CS#OPN

0003.08 C EVAL FLD7=CS$OPN

0003.09 C DATA1 DSPLY

0003.10 C DATA2 DSPLY

0003.11 C READ CUST


90

0004.00 C ENDDO

0005.00 C SETON LR

****************** End of data


****************************************
CUST

CSNBR CSNAME CS#OPN CS$OPN

000001 AMI 0 .00

000002 upi 0 .00

000003 KUM 0 .00

000004 RAHIN 12,256 454,654.51

000005 HARISH 980 798,789.00

000006 RAJESH 560 754,555.00

000007 RONYSH 888 755,555.00

000008 KUNINA 447 755,555.00

000009 SHIUNA 222 744,444.00

000010 OINUJI 555 666,666.00

000011 FOSSIL 575 999,999.00

000012 BEKULL 5,858 4,545,645.00

000013 ROBIN 1,111 2,525,255.00

000014 SONIK 2,222 8,484,848.00

000015 KEVIN 7,552 8,484,848.00

000016 SAKIN 7,777 7,777,777.00

000017 TURNI 9,877 9,879,877.00

000018 SUPPI 2,227 4,564,567.00

000019 KHUSI 7,777 4,564,567.00

000020 SAHIL 8,888 8,888,888.00

000021 KAPIL 3,333 3,333,333.00

000022 RONIK 4,444 4,444,444.00

000023 KWNIK 5,555 4,555,555.00

******** End of data ********


OUTPUT

Display Program Messages

DSPLY CUST --CUSTR --0001--

DSPLY 000001--AMI --00000--0000000000

DSPLY CUST --CUSTR --0002--

DSPLY 000002--upi --00000--0000000000

DSPLY CUST --CUSTR --0003--

DSPLY 000003--KUM --00000--0000000000

DSPLY CUST --CUSTR --0004--

DSPLY 000004--RAHIN --12256--0000454654

DSPLY CUST --CUSTR --0005--

DSPLY 000005--HARISH --00980--0000798789

DSPLY CUST --CUSTR --0006--

DSPLY 000006--RAJESH --00560--0000754555

DSPLY CUST --CUSTR --0007--

DSPLY 000007--RONYSH --00888--0000755555

DSPLY CUST --CUSTR --0008--

DSPLY 000008--KUNINA --00447--0000755555

DSPLY CUST --CUSTR --0009--

DSPLY 000009--SHIUNA --00222--0000744444

DSPLY CUST --CUSTR --0010--

DSPLY 000010--OINUJI --00555--0000666666

DSPLY CUST --CUSTR --0011--

DSPLY 000011--FOSSIL --00575--0000999999

DSPLY CUST --CUSTR --0012--

DSPLY 000012--BEKULL --05858--0004545645


DSPLY CUST --CUSTR --0013--

DSPLY 000013--ROBIN --01111--0002525255

DSPLY CUST --CUSTR --0014--

DSPLY 000014--SONIK --02222--0008484848

DSPLY CUST --CUSTR --0015--

DSPLY 000015--KEVIN --07552--0008484848

DSPLY 000016--SAKIN --07777--0007777777

DSPLY CUST --CUSTR --0017--

DSPLY 000017--TURNI --09877--0009879877

DSPLY CUST --CUSTR --0018--

DSPLY 000018--SUPPI --02227--0004564567

DSPLY CUST --CUSTR --0019--

DSPLY 000019--KHUSI --07777--0004564567

DSPLY CUST --CUSTR --0020--

DSPLY 000020--SAHIL --08888--0008888888

DSPLY CUST --CUSTR --0021--

DSPLY 000021--KAPIL --03333--0003333333

DSPLY CUST --CUSTR --0022--

DSPLY 000022--RONIK --04444--0004444444

DSPLY CUST --CUSTR --0023--

DSPLY 000023--KWNIK --05555--0004555555

DSPLY MBR2 --CUSTR --0001--

DSPLY 100002--upi --00000--0000000000

DSPLY MBR2 --CUSTR --0002--

DSPLY 100003--KUM --00000--0000000000

DSPLY MBR3 --CUSTR --0001--

DSPLY 100003--KUM --00000--0000000000

DSPLY CUST --CUSTR --0001--


D SPEC

 D is the alphabetic code used for Definition specifications.

To prompt D SPEC give the line command: IPD

Prompt type . . . D Sequence number . . . '''''''

Declaration To /

Name E S/U Type From Length

_____________ _ _ __ _____ ______

Internal Decimal

Data Type Positions Keywords

_ __ _____________________________

Comment

________________

 D SPEC Keywords

o VARYING

D varstr s 50A VARYING


C eval varstr = 'Amit Jaiswal'

Here, the maximum length of the variable varstr will be 50, but the actual length can vary as
per the value assigned to this variable. Here the current size of variable will be the size of
string “Amit Jaiswal”.

o *VARSIZE
*VARSIZE has nothing to do with the data type of the variable. All it does is disable the
compiler's validity checking of the length.

o EXPORT & IMPORT

Export indicates that the variable has been defined (stored) in this module and will be used by some
other module which is importing this variable using Import keyword.

Import indicates that the variable has been defined (stored) in some other module and will be used
here.

Example:

Columns . . . : 6 76 Edit AMIT/QRPGLESRC

SEU==> MODULE1

FMT H HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*************** Beginning of data *************************************

0001.00 HOPTION(*NODEBUGIO)

0002.00 DVAR1 S 5 0 EXPORT INZ(11111)

0003.00 DVAR2 S 5 0 IMPORT

0003.03 C CALLB 'MODULE2'

0003.04 C EVAL VAR1=VAR2 +33333 >>>>>>>>>>>>>>>


VAR2=55555

0005.00 C VAR1 DSPLY


0006.00 C SETON LR

****************** End of data ****************************************

Columns . . . : 6 76 Edit AMIT/QRPGLESRC

SEU==> MODULE2

FMT D DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++

*************** Beginning of data *************************************

0002.00 DVAR1 S 5 0 IMPORT

0003.00 DVAR3 S 5 0 IMPORT

0003.07 DVAR2 S 5 0 EXPORT

0003.08 C CALLB 'MODULE3'

0004.00 C EVAL VAR2=VAR1+VAR3 >>>>>>>>>>>>>>> VAR2=22222

0005.00 C RETURN

****************** End of data ****************************************

Columns . . . : 6 76 Browse AMIT/QRPGLESRC

SEU==> MODULE3

FMT D DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++

*************** Beginning of data *************************************

0002.00 DVAR3 S 5 0 EXPORT

0004.00 C EVAL VAR3=11111 >>>>>>>>>> VAR3=11111

0004.01 C RETURN
****************** End of data ****************************************

CRTPGM PGM(AMIT/PGM1) MODULE(AMIT/MODULE1 AMIT/MODULE2 AMIT/MODULE3)

Below picture depicts the data flow due to import/export:

o EXTPGM

This keyword is used in case of prototyping. So first of all we will go through the concept of prototyping.

 Prototyping
 A prototype tells the compiler how the parameters of a called program or procedure are
defined.

 Prototyping makes the compiler to verify that whatever parameters that will be passed to a
called program or procedure appropriately defined.

 Prototyping benefit us by showing the error at compile time rather than at run time.

 Case1: Program without prototyping


Here, there is one rpgle program SENDPGM which calls a CL program ‘MSGSFLCL’ with parameters
MSGID(7), MSGF(10) and MSGOPT(1).

Calling Program SENDPGM

Columns . . . : 1 71 Browse
AMIT/QRPGLESRC

SEU==>
SENDPGM

FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6


...+... 7

*************** Beginning of data *************************************

* SEND MSG0001 FROM MESSAGE FILE CPF9898 TO PROGRAM MESSAGE QUEUE

C MOVEL 'MSG0001' MSGID

C MOVEL 'AM_MSGF' MSGF

C MOVE 'I' MSGOPT

C EXSR SEND

C SEND BEGSR

C CALL 'MSGSFLCL'

C PARM MSGID 7

C PARM MSGF 10

C PARM MSGOPT 1

C ENDSR

Message ID . . . . . . . . . : MSG0001

Message file . . . . . . . . : AM_MSGF

Library . . . . . . . . . : AMIT
Message text . . . . . . . . : THE ACCOUNT NUMBER CAN NOT BE BLANK

Called program MSGSFLCL

Columns . . . : 1 71 Browse
AMIT/QRPGLESRC

SEU==>
MSGSFLCL

FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6


...+... 7

*************** Beginning of data *************************************

0001.01 PGM PARM(&MSGID &MSGF &MSGOPT)

0002.00 DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)

0003.00 DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)

0004.00 DCL VAR(&MSGOPT) TYPE(*CHAR) LEN(1)

0006.00

0007.00

0008.00 IF COND(&MSGOPT *EQ 'I') THEN(SNDPGMMSG +

0009.00 MSGID(&MSGID) MSGF(&MSGF))

0010.00

0011.00 IF COND(&MSGOPT *EQ 'C') THEN(RMVMSG PGMQ(*PRV +

0012.00 (*)) CLEAR(*ALL))

0013.00 ENDPGM

****************** End of data ****************************************

When we run the program SENDPGM then at runtime it checks if the parameters are appropriately
passed or not. If we change PARM “MSGID” to some other data type or change its length, we will get
the error but not at compile time. We will get the error at run time and our program cannot continue
further.

To make sure that the program doesn’t crash at run time, we detect the error at compile time itself by
using prototyping. This is depicted in Case2 below.

 Case2: Program with prototyping


To use prototyping, we do the following modifications in the calling program SENDPFM.

Here we have changed the Parameter MSGID’s length from 7 TO 3.

Columns . . . : 1 71 Browse AMIT/QRPGLESRC

SEU==> SENDPGM

FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7

DMSGID S 3 >>>> Parm MSGID’s length changed from 7 to 3

DMSGF S 10

DMSGOPT S 1

DMSGSFLCL PR EXTPGM('MSGSFLCL')

DMSGID 7

DMSGF 10

DMSGOPT 1

* SEND MSG0001 FROM MESSAGE FILE CPF9898 TO PROGRAM MESSAGE QUEUE

C MOVEL 'MSG0001' MSGID

C MOVEL 'AM_MSGF' MSGF

C MOVE 'I' MSGOPT

C EXSR SEND

C SEND BEGSR

C CALLP MSGSFLCL(MSGID:MSGF:MSGOPT)
C ENDSR

Now when we compile the program, we get the below error at compile time.

**Error: The type and attributes of the parameter do not match those of the prototype.

But the error that we have got here is at compile time that is what we wanted.

o EXTPROC

If you've built modules with commands like CRTRPGMOD, CRTCLMOD, CRTCBLMOD, and CRTCMOD,
you're accustomed to calling them with the CALLB op code. Just as you can with CALL, you can replace
CALLB with CALLP.

 Case1: Program without prototyping


Calling Program SENDPGM

Columns . . . : 1 71 Browse
AMIT/QRPGLESRC

SEU==>
SENDPGM

FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6


...+... 7

*************** Beginning of data *************************************

* SEND MSG0001 FROM MESSAGE FILE CPF9898 TO PROGRAM MESSAGE QUEUE

C MOVEL 'MSG0001' MSGID

C MOVEL 'AM_MSGF' MSGF

C MOVE 'I' MSGOPT


C EXSR SEND

C SEND BEGSR

C CALLB 'MSGSFLCL'

C PARM MSGID 7

C PARM MSGF 10

C PARM MSGOPT 1

C ENDSR

**Here we have compiled the same CL using CRTCLMOD to make it a module.

Called module MSGSFLCL

Columns . . . : 1 71 Browse
AMIT/QRPGLESRC

SEU==>
MSGSFLCL

FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6


...+... 7

*************** Beginning of data *************************************

0001.01 PGM PARM(&MSGID &MSGF &MSGOPT)

0002.00 DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)

0003.00 DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)

0004.00 DCL VAR(&MSGOPT) TYPE(*CHAR) LEN(1)

0006.00

0007.00

0008.00 IF COND(&MSGOPT *EQ 'I') THEN(SNDPGMMSG +

0009.00 MSGID(&MSGID) MSGF(&MSGF))

0010.00

0011.00 IF COND(&MSGOPT *EQ 'C') THEN(RMVMSG PGMQ(*PRV +

0012.00 (*)) CLEAR(*ALL))

0013.00 ENDPGM
****************** End of data ****************************************

Now when we run the program we get the same run time error. To avoid this we will go for prototyping.

 Case2: Program with prototyping


Columns . . . : 1 71 Browse
AMIT/QRPGLESRC

SEU==>
SENDPGM

FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6


...+... 7

DMSGID S 3 >>> Parm MSGID’s length changed from


7 to 3

DMSGF S 10

DMSGOPT S 1

DMSGSFLCL PR EXTPROC('MSGSFLCL')

DMSGID 7

DMSGF 10

DMSGOPT 1

* SEND MSG0001 FROM MESSAGE FILE CPF9898 TO PROGRAM MESSAGE QUEUE

C MOVEL 'MSG0001' MSGID

C MOVEL 'AM_MSGF' MSGF

C MOVE 'I' MSGOPT

C EXSR SEND

C SEND BEGSR

C CALLP MSGSFLCL(MSGID:MSGF:MSGOPT)

C ENDSR
Using this we get the error at compile that we can correct and can easily avoid the situation of any run
time error due to parameters wrong definition.

o EXTNAME(file-name{:format-name}{:*ALL| *INPUT|*OUTPUT|*KEY})

The EXTNAME keyword is used to specify the name of the file which contains the field descriptions used
as the subfield description for the data structure being defined.

The file-name parameter is required. Optionally a format name may be specified to direct the compiler
to a specific format within a file.

The last parameter specifies which fields in the external record to extract:

 *ALL extracts all fields.


 *INPUT extracts just input capable fields.
 *OUTPUT extracts just output capable fields.
 *KEY extracts just key fields.

D Fileds1 E DS Export
D EXTNAME(file1)

Structure of the externally described data structure:

 Subfield name : Same as the external file’s fields name, unless it id renamed by
keyword EXTFLD
or the PREFIX keyword on a definition specification is used to apply a
prefix).
 Subfield length
 Subfield internal data type

All data structure keywords except LIKEDS and LIKEREC are allowed with the EXTNAME keyword.
D D0220NEW E DS PREFIX(D21:3)

D EXTNAME(CZGD02H0:CZTD02H2)

D D0220OLD E DS PREFIX(D@@:3)

D EXTNAME(CZGD02H0:CZTD02H2)

o CONST(value)

* Constant variables

D INTRO C CONST('Introduction')

D PNDINT C CONST('Pending Introduction')

D PNDCHG C CONST('Pending Change')

The keyword CONST(value) is used to identify the value of the constant.

o LIKE(RPG_name)

The LIKE keyword allows us to define a data element of same data type and length as another field. This
keyword may be used in place of the *LIKE DEFINE op-code.

* Variables

D SAVORGCOD S LIKE(D02ORGCOD) Inz

D SAVACNTNO S LIKE(D02ACNTNO) Inz

o OVERLAY(name{:pos | *NEXT})
The OVERLAY keyword allows us to define a field name on the basis of overlaying a data structure or a
data structure subfield.

D DataStruct DS

D MainField 10

D Field1 5 overlay(MainField)

D Field2 5 overlay(MainField:*next)

o OCCURS

* Below DS1 is multiple occurrence data structures with 10 occurrences.

Columns . . . : 6 80 Browse
AMITCC/QRPGLESRC

SEU==>
MULTDS

FMT D DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data


****************************************************

0001.00 D DS1 DS OCCURS(10) >>>>

0002.00 D FLDA 1 5

0003.00 D FLDB 6 10

0004.00 DX S 2 0 INZ(1)

0005.00

0006.00 C X DO 10

0007.00 C X OCCUR DS1 >>> OCCUR op-code sets the occurrence


to X

0008.00 C EVAL FLDA=%char(X)

0009.00 C EVAL FLDB=%char(X)

0010.00 C EVAL X=X+1

0011.00 C DS1 DSPLY


0012.00 C ENDDO

0013.00 C SETON LR

****************** End of data


*******************************************************

OUTPUT

DSPLY 1 1

DSPLY 2 2

DSPLY 3 3

DSPLY 4 4

DSPLY 5 5

DSPLY 6 6

DSPLY 7 7

DSPLY 8 8

DSPLY 9 9

DSPLY 10 10

o DTAARA{(data_area_name)}
Specifies the name of the external data that is associated with a field, data structure, data structure
subfield or data area data structure.

Dtime_is S z

Dtime_isO S 20

DMATCHNF S 1 0 INZ (0)

DRBSPRTYM S 1 INZ ('N')

DACCCONVF S 1 INZ('N')

DLDA UDS DTAARA(*LDA)

DLdadateY 1 4 0

DLdadateM 5 6 0

DLdadateD 7 8 0

**Data structure for GETTING CURRENT DATE AND TIME

DCURTIMDAT DS

DCURTIMDATE 1 16S 0

DCURRYEAR 1 4S 0

DCURRMONTH 5 6S 0

DCURRDAY 7 8S 0

DCURRHRS 9 10S 0

DCURRMINS 11 12S 0

DCURRSECS 13 16S 0

C TIMECAL BEGSR

C EVAL TIME_IS=%TIMESTAMP()

C EVAL TIME_ISO=%char(TIME_IS:*iso0)
C EVAL CURRYEAR=%dec(%SUBST(TIMe_ISo:1:4):4:0)

C EVAL CURRMONTH=%dec(%SUBST(TIMe_ISo:5:2):2:0)

C EVAL CURRDAY=%dec(%SUBST(TIMe_ISo:7:2):2:0)

C EVAL CURRHRS=%dec(%SUBST(TIMe_ISo:9:2):2:0)

C EVAL CURRMINS=%dec(%SUBST(TIMe_ISo:11:2):2:0)

C EVAL CURRSECS=%dec(%SUBST(TIMe_ISo:13:4):4:0)

C ENDSR

OUTPUT

TIME_IS = '2012-05-18-07.11.00.926000'

TIME_ISO = '20120518071100926000'

o CTDATA

Specifies that the array is a compile-time array.

Example is given after PERRCD definition.

o DIM(numeric_constant)

Specifies the number of elements of an array or table.

Example is given after PERRCD definition.

o PERRCD(numeric_constant)
Specifies the number of elements per record for a compile-time or a prerun-time array or table.

Example
Columns . . . : 1 100 Browse

SEU==>

FMT D .....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++

*************** Beginning of data **************************************

0001.00 darr1 s 3P 0 dim(5) ctdata perrcd(1)

0002.00 darr2 s 3P 0 dim(5) ctdata perrcd(1)

0003.00 dS s 3p 0 inz(0)

0004.00 dn s 2p 0 inz(1)

0005.00 c n do 5

0006.00 c eval s=arr2(n)-arr1(n)

0007.00 c s dsply

0008.00 c add 1 n

0009.00 c enddo

0010.00 c seton lr

0011.00 ** CTDATA arr1

0012.00 101

0013.00 102

0014.00 103

0015.00 104

0016.00 105

0017.00 ** CTDATA arr2

0018.00 201

0019.00 202

0020.00 203
0021.00 204

0022.00 205

****************** End of data


********************************************

O/P
DSPLY 100
DSPLY 100
DSPLY 100
DSPLY 100
DSPLY 100

o STATIC

Type this keyword in the D specifications of sub-procedures to indicate that a standalone field or data
structure is stored in static storage.

Automatic Storage

 By default, whatever stand-alone fields, data structures, arrays, etc. fields are defined inside a
sub-procedure use automatic storage.
 The scope of these sub-procedure’s fields will be till the sub-procedure runs. After that it will be
reset to default value(0 or blank).
 It has no effect of SETON LR. It really doesn’t matter if LR is SETON or SETOFF, its value will be
reinitialized each time the procedure is called.
Static Storage

 Static storage has its life cycle from the time the program is called until the activation group
where it is running ends, or until the job or group job ends.
 Static fields defined inside P specs has no effect of SETON LR, its values remain the same
between multiple calls to the program.
 Global variable is the one that is defined outside P-spec. Its values remain the same between
multiple calls to the program. But it is affected by SETON LR i.e. SETON LR resets the global
variable.

Columns . . . : 1 80 Browse
AMITCC/QRPGLESRC

SEU==>
STATICPGM

FMT D
.....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data


*****************************************************

0001.00 D Checkcount PR

0002.00 D n S 2 0 inz(1)

0003.00

0004.00 DDS1 DS

0005.00 DFiller1 12 inz(' Autocount=')

0006.00 DAuto 1 0

0007.00 DFiller2 14 inz(' Staticcount=')

0008.00 DStatic 1 0

0009.00 DFiller3 14 inz(' Globalcount=')

0010.00 DGlobalcount 1 0 inz(*zeros)

0011.00 C n DO 3

0012.00 C CALLP CHECKCOUNT

0013.00 C ENDDO

0014.00 C*** RETURN

0015.00 C SETON LR

0016.00

0017.00 P Checkcount B

0018.00 D PI

0019.00

0020.00 D AutoCount S 3 0
0021.00 D StaticCount S 3 0 STATIC

0022.00 C EVAL AutoCount=Autocount+1

0023.00 C EVAL StaticCount=StaticCount+1

0024.00 C EVAL Globalcount= Globalcount+1

0025.00

0026.00 C EVAL Auto=Autocount

0027.00 C EVAL Static=Staticcount

0028.00

0029.00 C DS1 DSPLY

0030.00

0031.00 P Checkcount E

0032.00

****************** End of data


**************************************************************************************
****

Condition based OUTPUT :

Case1: 1ST CALL without RETURN op-code

Autocount=1 Staticcount=1 Globalcount=1

Autocount=1 Staticcount=2 Globalcount=2

Autocount=1 Staticcount=3 Globalcount=3

Case2: 2ND CALL without RETURN op-code

Autocount=1 Staticcount=4 Globalcount=1

Autocount=1 Staticcount=5 Globalcount=2


Autocount=1 Staticcount=6 Globalcount=3

Case3: 1ST CALL with RETURN op-code

Autocount=1 Staticcount=1 Globalcount=1

Autocount=1 Staticcount=2 Globalcount=2

Autocount=1 Staticcount=3 Globalcount=3

Case4: 2ND CALL with RETURN op-code

Autocount=1 Staticcount=4 Globalcount=4

Autocount=1 Staticcount=5 Globalcount=5

Autocount=1 Staticcount=6 Globalcount=6

Case5: 3RD CALL with RETURN op-code after RCLRSC or SIGNOFF or RCLACTGRP (if used in
the program)

Autocount=1 Staticcount=1 Globalcount=1

Autocount=1 Staticcount=2 Globalcount=2

Autocount=1 Staticcount=3 Globalcount=3

o INZ
Columns . . . : 6 100 Browse

SEU==>

FMT D
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++

*************** Beginning of data


***********************************

0001.00 Da S 10A inz(*ALL'Z')

0002.00 Db S 10A inz(*blanks)

0003.00 Dc S 10 0 inz(*zeros)

0004.00 Dd S 10A inz

0005.00 De S 10 0 inz

0006.00 C a DSPLY

0007.00 C b DSPLY

0008.00 C c DSPLY

0009.00 C d DSPLY

0010.00 C e DSPLY

0011.00 C SETON
LR

****************** End of data


**************************************

O/P

DSPLY ZZZZZZZZZZ

DSPLY

DSPLY 0

DSPLY

DSPLY 0
C Specification
 C is the alphabetic code used for Calculation specifications.

To prompt C SPEC given the line command: IPC


Prompt type . . . C Sequence number . . . '''''''

Level N01 Factor 1 Operation Factor 2 Result

__ __ __________ _________ _________ _________

Decimal

Length Positions HI LO EQ Comment

____ __ __ __ __ _________________

The prompt elements are described below:

o N01 (Conditioning Indicator)

Position: 09

 This is condition indicator to decide if the calculation operation is to be performed or not.

 If we put N at position 9 then it means that the operation will be done only if the indicator at
position 10 is off.

Position: 10-11

 Blank
The position can be left blank if we don’t want to put any condition for the calculation
operation.

 01-99
Type a value from 01 to 99 to represent a general indicator.

 KA-KN or KP-KY
Type a value from KA to KN or KP to KY to represent a function key indicator.

 OA-OG or OV
Type a value from OA to OG or OV to represent an overflow indicator.

o Factor 1

Factor1 represents the name or literal on which the actual operation is to be performed.

o Op-Code ( Operation and Extender code)

Type an operation code to specify the operation to be performed.

For each operation there are certain op-codes defined that we can write in this section.

Below are the operation codes:

 ADD {(H)} (Add)


 ADDDUR {(E)} (Add Duration)
 ANDxx (And)
 BEGSR (Beginning of Subroutine)
 CABxx (Compare and Branch)
 CALL {(E)} (Call a Program)
 CALLB {(D | E)} (Call a Bound Procedure)
 CALLP {(M | R | E)} (Call a Program or Procedure)
 CASxx (Conditionally Invoke Subroutine)
 CAT {(P)} (Concatenate Two Character Strings)
 CHAIN {(N | E)} (Random Retrieval from a File)
 CHECK {(E)} (Check Characters)
 CHECKR {(E)} (Check Reverse)
 CLEAR (Clear)
 CLOSE {(E)} (Close Files)
 COMP (Compare)
 DEFINE (Field Definition)
 DELETE {(E)} (Delete Record)
 DIV {(H)} (Divide)
 DO (Do)
 DOU {(M | R)} (Do Until)
 DOUxx (Do Until)
 DOW {(M | R)} (Do While)
 DOWxx (Do While)
 DSPLY {(E)} (Display Function)
 DUMP (Program Dump)
 ELSE (Else)
 ELSEIF {(M | R)} (Else/If)
 ENDyy (End a Structured Group)
 ENDSR (End of Subroutine)
 EVAL {(H | M | R)} (Evaluation)
 EVAL {(M | R)} (Evaluation Right Adjust)
 EXCEPT (Calculation Time Output)
 EXFMT {(E)} (Write/Then Read Format)
 EXSR (Invoke Subroutine)
 EXTRCT {(E)}(Extract Date/Time)
 FEOD {(E)} (Force End of Data)
 FOR (For)
 GOTO (Go To)
 IF {(M | R)} (If)
 IFxx (If)
 IN {(E)} (Retrieve a Data Area)
 ITER (Iterate)
 KFLD (Define Parts of a Key)
 KLIST (Define a Composite Key)
 LEAVE (Leave a Do Group)
 LOOKUP (Look Up a Table or Array Element)
 MOVE (Move)
 MOVEA {(P)} (Move Array)
 MOVEL {(P)} (Move Left)
 MULT {(H)} (Multiply)
 MVR (Move Remainder)
 NEXT {(E)} (Next)
 ON-ERROR (On-Error)
 OPEN {(E)} (Open File for Processing)
 ORxx (Or)
 OTHER (Otherwise Select)
 OUT {(E)} (Write a Data Area)
 PARM (Identify Parameters)
 PLIST (Identify a Parameter List)
 POST {(E)} (Post)
 READ {(N | E)} (Read a Record)
 READC {(E)} (Read Next Changed Record)
 READE {(N | E)} (Read Equal Key)
 READP {(N | E)} (Read Prior Record)
 READPE {(N | E)} (Read Prior Equal)
 RETURN {(H | M | R)} (Return to Caller)
 SCAN {(E)} (Scan Character String)
 SELECT (Begin a Select Group)
 SETGT {(E)} (Set Greater Than)
 SETLL {(E)} (Set Lower Limit)
 SETOFF (Set Indicator Off)
 SETON (Set Indicator On)
 SORTA (Sort an Array)
 SUB {(H)} (Subtract)
 SUBDUR {(E)} (Subtract Duration)
 SUBST {(P | E)} (Substring)
 TAG (Tag)
 TEST {(D | T | Z | E)} (Test Date/Time/Timestamp)
 TESTB (Test Bit)
 TESTN (Test Numeric)
 TESTZ (Test Zone)
 TIME (Time of Day)
 UNLOCK {(E)} (Unlock a Data Area or Release a Record)
 UPDATE (Modify Existing Record)
 WHEN {(M | R)} (When)
 WHENxx (When True Then Select)
 WRITE (Create New Records)
 XFOOT {(H)} (Sum the Elements of an Array)
 XLATE {(P | E)} (Translate)
 Z-ADD {(H)} (Zero and Add)
 Z-SUB {(H)} (Zero and Subtract)

*** All the listed op-codes are explained in the next chapter.

Operator Extender:
Operation extender is used along with the op-codes to customize the op-code e.g. to half adjust the
decimal value, to read file without lock, to make the value padded with blank etc.

Possible values:

 Blank
It can be left blank if we don’t want any kind of extender with the op-code.

 (E)
Type (E) for error handling to occur. An error indicator is not allowed if the E extender is
specified.

 (H)
Type (H) if half adjust is to be performed.

 (N)
Type (N) if to read a file without lock.

 (P)
Type (P) if the result field is to be padded with blanks.

o Factor 2

Factor1 represents the name or literal on which the actual operation is to be performed.

o Result

Result field is used to hold the result of the calculation operation in a name or literal.
o Field Length

Possible values:

 Blank
Leave the field blank if the result field is already defined.

 1-30
Type a value from 1 to 30 to specify the length for a numeric field.

 1-32767
Type a value from 1 to 32767 to specify the length for a character field.

o Decimal Positions

Choose from the following:

 Blank
Leave the field blank if the result field is already defined or if it is not decimal.

 0-30
Type a value from 0 to 30 to indicate the number of decimal positions of the result field.

o HI
This resulting indicator representing a condition found for greater than, high or no record found
condition.

Possible values:

 Blank
Leave the field blank if no indicator is to be set on.

 01-99
Type any two-digit number to indicate general indicators.

 KA-KN or KP-KY
Type a value from KA to KN or from KP to KY to indicate a function key indicator.

 LR
Type LR to indicate a last record indicator.

 OA-OG or OV
Type a value from OA to OG or OV to indicate any overflow indicator.

o LO

This resulting indicator representing a condition found for less than or an error condition

Possible values:

 Blank
Leave the field blank if no indicator is to be set on.

 01-99
Type any two-digit number.

 KA-KN or KP-KY
Type a value from KA to KN or from KP to KY to indicate a function key indicator.

 OA-OG or OV
Type a value from OA to OG or OV to indicate an overflow indicator.

o EQ

This resulting indicator representing a condition found for equal, beginning-of-file, an end-of-file, or a
search string-found condition.

Possible values:

 Blank
Leave the field blank if no indicator is to be set on.

 01-99
Type any two-digit number.

 KA-KN or KP-KY
Type a value from KA to KN or from KP to KY to indicate a function key indicator.

 OA-OG or OV
Type a value from OA to OG or OV to indicate an overflow indicator.
o Comment

Type comments to describe any calculation.

 C SPEC another prompt type: IPCX

This prompt gives Extended Factor 2 specifications for calculation.

Prompt type . . . CX Sequence number . . . '''''''

Level N01 Factor 1 Operation

__ ___ ___________ __________

Extended

Factor 2 Comment

_______________________________________________ ________________
O Specs:
Output Specification describe the record and the format of fields, in a program described file
and when the record is to be written

Output specifications are optional for externally described files

O-SPECS can be divided into two categories

Record identification and control entries (Record Line)


Field description and control entries (Field Line)

O Specs - Record line:

ä Column 7-14

ä should have File name for program described files

ä Same file name that appears in the F-Spec for the output file

ä Valid record format name for the externally described files

ä Column 15-16

ä Logical relationship AND/OR indicates a relationship between the lines of output


indicators

ä Column 15 - Type of record

ä H , D - Detail record

ä T - Total Record

ä E - Exception record

ä Column 16 - 18 Record addition/Deletion field

ä ADD - ADD a record to the file or subfile

ä DEL - Delete a record from a file

ä Column 16 Fetch Overflow Specifier

ä Blank - Overflow for printer file is not fetched

ä F - Fetch overflow specified for printer file

O Specs - Field line:

ä Column 23-31 Field output indicators

ä Used to indicate whether fields within the record are printed/ written to
file
Procedure Specifications

Procedure specifications are used to define prototyped procedures that are specified after the main
source section, otherwise known as subprocedures.

1. A Begin-Procedure specification (B in position 24 of a procedure specification)


2. A Procedure-Interface definition, which specifies the return value and parameters, if any.
The procedure-interface definition is optional if the subprocedure does not return a value
and does not have any parameters that are passed to it. The procedure interface must
match the corresponding prototype.
3. Other definition specifications of variables, constants and prototypes needed by the
subprocedure. These definitions are local definitions.
4. Any calculation specifications needed to perform the task of the procedure. Any
subroutines included within the subprocedure are local. They cannot be used outside of
the subprocedure. If the subprocedure returns a value, then a RETURN operation must be
coded within the subprocedure. You should ensure that a RETURN operation is
performed before reaching the end of the procedure.
5. An End-Procedure specification (E in position 24 of a procedure specification)

Positions 7-21 (Name)

Entry
Explanation
Name
The name of the subprocedure to be defined.

Use positions 7-21 to specify the name of the subprocedure being defined. If the name is longer
than 15 characters, a name is specified in positions 7 - 80 of the continued name lines. The
normal rules for RPG IV symbolic names apply;
Position 24 (Begin/End Procedure)

Entry
Explanation
B
The specification marks the beginning of the subprocedure being defined.
E
The specification marks the end of the subprocedure being defined.

Positions 44-80 (Keywords)

Positions 44 to 80 are provided for procedure specification keywords. Only a Begin-Procedure


specification (B in position 24) can have a keyword entry.

Procedure-Specification Keywords

EXPORT

The specification of the EXPORT keyword allows the procedure to be called by another module
in the program. The name in positions 7-21 is exported in uppercase form.

Das könnte Ihnen auch gefallen