IBM AS400 RPG IV Training Course(Course Code OL86)--3
-
Upload
ramana-varala -
Category
Documents
-
view
157 -
download
13
description
Transcript of IBM AS400 RPG IV Training Course(Course Code OL86)--3
Unit 2. Coding Specifications for RPG IV
Copyright IBM Corp. 1996, 2000 2-1
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-2
Unit Objectives - RPG IV Specifications
After completing this unit, you should be able to:
• Describe the use of each RPG IV Specification type
• Describe how to reference externally described database and printerfiles in RPG IV
• Write a simple listing programOL862000
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-3
OL862105
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-4
Symbolic Names
Symbolic names are used for:
• Fields
• Key field lists
• Labels
• Named constants
• Parameter lists
• Record names
And other RPG names!
Use RPG IV Style Guide suggestionsOL862110
Field Naming Rules
• First Character Must be Alphabetic
• Rest may be Alpha, numeric or $, #, @
• Name may be up to 4096 in length
− recommend 10 to 14 (based on RPG IV specification where used)
• Mixed case valid
− Use mixed case to create meaningful names− Must be unique - compiler converts all to upper case− LastName = lastname = LASTNAME
• If long name necessary, may continue using ...
�DN0N01Factor1+++++++Opcode(E)+Extended-factor2+++++++++D ExtraLongFieldNameToContainAlphaChars...D S 10 Inz
C EVAL ExtraLongFieldName...C ToContainAlphaChars = ′ Abcdef′
OL862112
Copyright IBM Corp. 1996, 2000 2-5
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-6
RPG Indicators
RPG Indicators
• ″Switches ″
• Indicate status of data (+ - 0 blank nonblank > <)
• Can be used to condition calculations and output
• Represented:
− 03 = *in03 = *IN03 = *IN(03)− *inxx can be a factor or result field in calculations
• Includes:
− 01 - 99 plus special purpose LR, OA - OG, OV− not necessary to declare− can also be externally defined in DDS or local variables
OL862115
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-7
H-Spec
�
HKeywords+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++H AltSeq(*EXT)H Aut(*LIBRCRTAUT)H CurSym(′ $′ )H Datedit(*MDY)H DatFmt(*MDY/)H Debug(*YES)H DecEdit(′ . ′ )H DftName(name)H Indent(′ | ′ )H TimFmt(*ISO)H Copyright(′ ( C) Copyright OL86V3 Programming - 2000′ )
• Free format
• Keyword Driven
• Style
− One keyword per line− Leave space after H
OL862120
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-8
OL862125
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-9
F-Specifications
�
.. 1....+....2....+....3....+....4....+....5....+....6....+....7....+FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++..FEmpMaster IF E DiskFEmpReport O E Printer OflInd(*IN73)
• Defines files to be processed by your program:
− Name of file− Type (input, output, update, combined)− Format (program-described or externally-described)− Device (Disk, Printer, Workstation)
• Keywords area to specify additional functions requiredOL862130
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-10
F-Spec Components
� *<---------- fixed format-----------><-------free format keywords------
* NAME RECORD ADD KEY PROCESSING * ==== ========== ============== * | | | * | | |FFilename++IPEASF.....L.....A.Device+.Keywords....................
FEmpMaster IF E Disk UsropnF Rename(FormatA:FormatB)F Ignore(FormatC) * | | | * | | | * USE EXT DEF DEVICE TYPE * === ======= ===========
FFilename++IPEASF.....L.....AIDevice+.Keywords....................
FEmpReport O E Printer Oflind(*In73)F Include(Detail)
FEmpDsply CF E Workstn Sfile(SflRec:Rrn)
FEmpHist IF A E K Disk
OL862135
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-11
Device Type / Processing
�
--------------- DEVICE TYPES -----------------------
USE DISK PRINTER WORKSTN=== ==== ======= =======
Input Y (+ Addition) - (Y)
Output Y Addition Y (Y)
Update Y (+ Addition) - -
Combined - - Y
OL862140
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-12
DB Processing Options
SEQUENTIAL -----(Consecutive)-------> by Relative Record| --------------> Number (RRN)| | - RAT = blank| || || || (Direct)| || || |---------|-------------> by Key Value
---------------- - RAT = ″K″RANDOM ----------------------------->
OL862145
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-13
F-Spec Comparisons
Externally Described Files:
�FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++.FEmpMaster IF E K DiskFEmpReport O E Printer OflInd(*IN73)
||
Externally Described====================
Program Described Files:
�FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++.FEmpMaster IF F 28 3PIDisk KeyLoc(1)FQsysPrt O F 132 Printer OflInd(*INOF)
||
Program Described=================
OL862150
H- and F-Specs - Employee PrintProgram
�FEmpMaster IP E K DiskFQprint O F 132 Printer OflInd(*inof)**DType S 8DCount S 3 0
IEmpRec 01** ** Record/field definitions from database follow; ** will be copied automatically by compiler. **C If not *InLRC If JOB = ′ MANAGER′C Eval Type = ′ MANAGER′C ElseC Eval Type = ′ REGULAR′C EndIfC Eval Count = Count + 1C EndIf **OQprint H 1P 2 2O OR OFO 5 ′ Page:′O PAGE Z 10O 50 ′ EMPLOYEE INFORMATION′O H 1P 2 1O OR OFO 12 ′ NAME′O 34 ′ SERIAL #′O 45 ′ DEPT′O 56 ′ TYPE′O D 1O LastName 20O Empno 32O WorkDept 45O TYPE 60O T LR 1O 20 ′ NUMBER OF EMPLOYEES′O Count L 27
OL862155
Copyright IBM Corp. 1996, 2000 2-14
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-15
OL86210L
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-16
D & I Specifications
• D-Spec defines program working variables
− Standalone fields
− Named constants
− Data structures and their subfields
− Arrays
− Named indicators
• I-Spec used to define program described input files
− Input records
− Field definitions / locationsOL862205
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-17
D-Spec to Define Data
Standalone fields:
�
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Keywords-cont+++Comments D Character S 8 D Number S 3 0 D D UpperCase C CONST(′ ABCDEFGHI- D JKLMNOPQRSTUVWXYZ′ ) D LowerCase C ′ abcdefghijklmnopqrs+ D tuvwxyz′ D BigNumber C 23456789 D D NegNumber C -1567
OL862210
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-18
OL862215
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-19
I-Spec for Input Data
Externally Described File:
�FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords....................FEmpMaster IF E DiskIFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC...................IRcdname+++....Ri........................................... ** There is no need in this program for an I-spec
Program Described File:
�FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords....................FEmpHist IF F 28 3PIDisk Keyloc(1)**
IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC...................IEmpHist NS 01I........................Fmt+SPFrom+To+++DcField+++++++++L1M1Fr..I P 1 3 0ENUMI A 4 23 ENAMEI A 24 24 ETYPEI P 25 26 0EDEPTI P 27 28 1ENHRS
OL862220
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-20
C Specifications
• Arithmetic functions
• Processing logic
− Read/write/update records
− Indicator control
• Conditional execution
• Data manipulation
• Iterative processingOL862305
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-21
C-Spec Structure
�DCount S 5 0 * �1� Test C/IND - should this operation be performed? * ==================================================== * | * | �2� Reset R/IND * | =============== * | | * | | * | | * | �3� Perform operation - F1/Op/F2 ==> Result | * | =========================================== | * | | | * | | �4� Turn on R/IND if appropriate * | | | * | | | * | | | * --------------------------------------------------------------------
C* N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
C 54 Add 1 Count 919293
OL862310
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-22
Typical Calculations
�
** Declare filesFEmpMaster IF E DiskFEmpReport O E Printer Oflind(*In73) ** Read next recordC Read EmpMaster ----40 ** Write current record to report as long as not EOFC If Not *In40C Write DetailC Endif ** End program if EOFC If *In40C Eval *InLR = *ONC Endif
OL862315
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-23
C-Specs (Extended Factor 2)
• Extended factor 2 format used by:
− Eval and EvalR
− DoW
− DoU
− For
− If
− When
− Return
− CallP
• Used to contain expressionsOL862320
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-24
OL862330
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-25
Output Specifications
• Program described files
− Data files / display files / printer files
− Describes program output records / formats / fields
• Externally described filesOL862405
O-Specs
�FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords....................**FEmpRept O F 132 Printer OflInd(*in73)**OFilename++DF..N01N02N03Excnam++++B++A++Sb+Sa+........................ * =========== Report Headings ================OEmpRept H 1P 2 2O OR 73O 5 ′ Page:′O PAGE Z 10O 50 ′ EMPLOYEE INFORMATION′O H 1P 2 1O OR 73O 12 ′ NAME′O 34 ′ SERIAL #′O 45 ′ DEPT′O 56 ′ TYPE′ * =========== Detail record output ============O N01N02N03Field+++++++++YB.End++PConstant/editword/DTfor **O D 1O LastName 20O Empno 32O WorkDept 45O TYPE 60 **=========== Final Total ====================O T LR 1O 20 ′ NUMBER OF EMPLOYEES′O Count L 27
OL862410
Copyright IBM Corp. 1996, 2000 2-26
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-27
OL86220L
C
op
yrigh
t IBM
Co
rp. 1
99
6, 2
00
02
-28
Unit Summary
Having completed this unit, you should be able to:
• Describe the use of each RPG IV Specification type
• Describe how to reference externally described database and printerfiles in RPG IV
• Write a simple listing programOL862ZZZ