You are on page 1of 24

Unit 1.

RPG IV Introduction

Copyright IBM Corp. 1996, 2000

1-1

Unit Objectives - RPG IV Introduction


After completing this unit, you should be able to:
Describe the evolution of RPG as a high level language Explain the general purpose of each RPG IV specification type List the order of RPG IV specification entries in a program Describe the steps to code and test an RPG IV program List several unique features of the RPG language and discuss RPGs

strengths and weaknesses


OL861000

Copyright IBM Corp. 1996, 2000 1-2

RPG in the Sixties


1960 High Level Language Fixed-Logic Cycle Indicators Batch Oriented Card based machines
OL861105

Copyright IBM Corp. 1996, 2000 1-3

RPG II - RPG III


1970 Mid-range Systems

System/3 System/32 System/34 System/36

Interactive applications

Disk processing support Workstation support


Copyright IBM Corp. 1996, 2000 1-4

Structured program design for efficiency DBMS grew in sophistication System/38


OL861110

RPG/400
1990 AS/400 Enhancements

New operation codes Named constants Initialization subroutines Source code indentation
OL861115

Embed SQL statements in RPG code


Copyright IBM Corp. 1996, 2000 1-5

What is RPG IV?


Available beginning with V3R1 Component of ILE RPG for AS/400 Program Product Expanded or eliminated language limits Fulfill RPG programmers requirements Longer field names Free form expressions Date/time calculations supported Positioned for future growth ILE Part of OS/400 beginning with V2R3 More modularity
OL861120

Copyright IBM Corp. 1996, 2000 1-6

Development Cycle
Define the problem Design the solution Write the program Test and debug the program Document the program Maintain the program
OL861125

Copyright IBM Corp. 1996, 2000 1-7

Copyright IBM Corp. 1996, 2000

1-8

OL86110L

Describing a Programming Solution


Print headings Read an employee record Do While more records exist:

Count each employee record read Write detail employee information Read an employee record
Print total number of employees End program
OL861130

Copyright IBM Corp. 1996, 2000 1-9

Copyright IBM Corp. 1996, 2000

1-10

OL861135

RPG IV Specifications
Seven types of Specifications:

(H) (F) (D) (I) (C) (O) (P)


Optional

Control Specifications File description Specifications Definition Specifications Input Specifications Calculation Specifications Output Specifications Procedure Specifications

Specific functions
Copyright IBM Corp. 1996, 2000 1-11

Fixed-position / free-form
OL861140

Print Program
FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords.................... ** ** Define the files ** FEmp_Mast IF E Disk FEmp_ReportO E Printer DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments ** ** Define program work fields ** D Count S 3 0 CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** ** Process data records ** C Read Emp_Mast ----40 ** ** Have we read a record? ** C If NOT (*in40) C Eval Count = Count + 1 C Write Detail C Endif ** ** At EOF, write total and terminate program by setting on LR ** C If *In40 C Write Total C Eval *InLR = *ON C Endif

OL861145

Copyright IBM Corp. 1996, 2000

1-12

Copyright IBM Corp. 1996, 2000

1-13

OL861150

Copyright IBM Corp. 1996, 2000

1-14

OL861155

Copyright IBM Corp. 1996, 2000

1-15

OL861160

CRTBNDRPG Compile Options


GENLVL(10) OPTION()

*XREF/*NOXREF *GEN/*NOGEN *SHOWCPY/*NOSHOWCPY *NOSECLVL/*SECLVL *EXPDDS/*NOEXPDDS *EXT/*NOEXT

DBGVIEW(*STMT) OUTPUT(*PRINT/*NONE) INDENT(*NONE) REPLACE(*YES) TRUNCNBR(*YES) TGTRLS(*CURRENT)


OL861165

Copyright IBM Corp. 1996, 2000 1-16

Copyright IBM Corp. 1996, 2000

1-17

OL861170

Compiler Directives
Format the listing

/TITLE /EJECT /SPACE


Include other members in the compilation

/COPY
Conditionally include / exclude code

/DEFINE /UNDEFINE
Documentation / readability

Copyright IBM Corp. 1996, 2000 1-18

*
OL861175

Copyright IBM Corp. 1996, 2000

1-19

OL861205

Output Report
Page: 1 NAME Haas Thompson Kwan Geyer Stern Pulaski Henderson Spenser Lucchesi O Connell Quintana Nicholls Adamson Pianka Yoshimura Scoutten Walker Brown Jones Lutz Jefferson Marino Smith Johnson Perez Schneider Parker Smith Setrignt Mehta Lee Gounot NUMBER OF EMPLOYEES EMPLOYEE INFORMATION SERIAL # 000010 000020 000030 000050 000060 000070 000090 000100 000110 000120 000130 000140 000150 000160 000170 000180 000190 000200 000210 000220 000230 000240 000250 000260 000270 000280 000290 000300 000310 000320 000330 000340 32
OL861210

DEPT A00 B01 C01 E01 D11 D21 E11 E21 A00 A00 C01 C01 D11 D11 D11 D11 D11 D11 D11 D11 D21 D21 D21 D21 D21 E11 E11 E11 E11 E21 E21 E21

TYPE REGULAR MANAGER MANAGER MANAGER MANAGER MANAGER MANAGER MANAGER REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR REGULAR

Copyright IBM Corp. 1996, 2000

1-20

Using the RPG Logic Cycle


FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++ FEmpMaster IP E K DISK FQprint O F 132 PRINTER OFLIND(*in73) DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments DType S 8 DCount S 3 0 CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C Eval *in73 = *off C If *InLR = *off C If JOB = MANAGER C Eval Type = MANAGER C Else C Eval Type = REGULAR C EndIf C Eval Count = Count + 1 C EndIf OFilename++DF..N01N02N03Excnam++++B++A++Sb+Sa+........................ OQprint H 1P 2 2 O OR 73 O 5 Page: O PAGE Z 10 O 50 EMPLOYEE INFORMATION O H 1P 2 1 O OR 73 O 12 NAME O 34 SERIAL # O 45 DEPT O 56 TYPE O D 1 O LastName 20 O Empno 32 O WorkDept 45 O TYPE 60 O T LR 1 O 20 NUMBER OF EMPLOYEES O COUNT L 27
OL861215

Copyright IBM Corp. 1996, 2000

1-21

Using Full Procedural - Non-Cycle


FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++ FEmpMaster IF E Disk FEmpReport O E Printer OflInd(*IN73) ** CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** 1 Write report heading and read first record C Write Heading C Read Employee ----40 ** 2 Read the file and process until EOF using a loop C DoW *in40 = *OFF C Eval Count=Count + 1 C Eval Name = %trimr(Lastname) ** C IF Job = MANAGER C Eval Type = MANAGER C ELSE C Eval Type = REGULAR C EndIf ** 3 Check if overflow C If *in73 = *ON C Write Heading C Eval *in73 = *off C EndIf ** 4 Write record to report and read next record C Write Detail C Read Employee ----40 C EndDo ** 5 Perform EOJ C Write Total C Eval *inlr = *on
OL861215

Copyright IBM Corp. 1996, 2000

1-22

Copyright IBM Corp. 1996, 2000

1-23

OL86120L

Unit Summary
Having completed this unit, you should be able to:
Describe the evolution of RPG as a high level language Explain the general purpose of each RPG IV specification type List the order of RPG IV specification entries in a program Describe the steps to code and test an RPG IV program List several unique features of the RPG language and discuss RPGs

strengths and weaknesses


OL861ZZZ

Copyright IBM Corp. 1996, 2000 1-24

You might also like