0% found this document useful (0 votes)
74 views158 pages

AS06 Student Exercise

Uploaded by

sergio Avalos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views158 pages

AS06 Student Exercise

Uploaded by

sergio Avalos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 158

V10.

cover

IBM Training Front cover


Student Exercises

RPG IV Programming Fundamentals Workshop for IBM i


Course code AS06 ERC 8.0
Student Exercises

Trademarks
IBM® is a registered trademark of International Business Machines Corporation.
The following are trademarks of International Business Machines Corporation in the United States,
or other countries, or both:
AS/400® AS/400e™ DB™
DB2® Integrated Language Iterations®
Environment®
i5/OS™ Language Environment® OS/400®
PartnerWorld® Power Systems™ Power Systems Software™
Power® Rational® Redbooks®
RPG/400® System i® Worklight®
400®
Adobe is either a registered trademark or a trademark of Adobe Systems Incorporated in the United
States, and/or other countries.
Pentium is a trademark or registered trademark of Intel Corporation or its subsidiaries in the United
States and other countries.
Windows is a trademark of Microsoft Corporation in the United States, other countries, or both.
Java™ and all Java-based trademarks and logos are trademarks or registered trademarks of
Oracle and/or its affiliates.
VMware and the VMware “boxes” logo and design, Virtual SMP and VMotion are registered
trademarks or trademarks (the “Marks”) of VMware, Inc. in the United States and/or other
jurisdictions.
Other product and service names might be trademarks of IBM or other companies.

December 2014 edition


The information contained in this document has not been submitted to any formal IBM test and is distributed on an “as is” basis without
any warranty either express or implied. The use of this information or the implementation of any of these techniques is a customer
responsibility and depends on the customer’s ability to evaluate and integrate them into the customer’s operational environment. While
each item may have been reviewed by IBM for accuracy in a specific situation, there is no guarantee that the same or similar results will
result elsewhere. Customers attempting to adapt these techniques to their own environments do so at their own risk.

© Copyright International Business Machines Corporation 2002, 2014.


This document may not be reproduced in whole or in part without the prior written permission of IBM.
US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
V10.0
Student Exercises

TOC Contents
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii

Exercises description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Exercise 1. Coding and compiling RPG IV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Part 1: Start Remote Systems Explorer (RSE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Part 2: Opening the Remote System Explorer perspective . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Part 3: Start the LPEX editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Part 4: Compile your RPG IV program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Part 5: Run your RPG IV program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

Exercise 2. Sequencing RPG IV specifications and compiling . . . . . . . . . . . . . . . . . . . . . . . 2-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Part 1: Log on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Part 2: Edit the source member . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Part 3: Sequence the RPG IV specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Part 4: Compile the source member . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Part 5: Find and view the compiler listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Part 6: Run your new program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

Exercise 3. Coding a report program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Part 1: Create the PRTF ITPCOST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Part 2: Write your RPG IV program ITRCOST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3

Exercise 4. Adding overflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Part 1: Modify your program ITRCOST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Part 2: Enhance your ITRCOSTE program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3

Exercise 5. Data definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Part 1: Examine the existing RPG IV source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Part 2: Add file definitions to PORLIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Part 3: Review total field definitions in POPLIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Part 4: Compile and test your program PORLIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4

Exercise 6. Adding arithmetic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Part 1: Cost of inventory on hand report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Part 2: Copy your source program ITRCOSTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Part 3: Compile and test your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4

Exercise 7. Data manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Part 1: Run the %SCAN and %SUBST demonstration programs . . . . . . . . . . . . . . . . . . . 7-3

© Copyright IBM Corp. 2002, 2014 Contents iii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Part 2: Review the sample report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3


Part 3: Review and compile PRTF VNPADR03 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Part 4: Write the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5
Part 5: Test and execute your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5

Exercise 8. Coding an inquiry program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Part 1: Understanding the requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Part 2: Create the display file VNDINQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Part 3: Understanding the program logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
Part 4: Create the program VNRINQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
Part 5: Test your program VNRINQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4

Exercise 9. Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Part 1: Write a procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Part 2: Code a procedure prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4
Part 3: Code another subprocedure and prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4
Part 4: Include prototypes in a main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
Part 5: Create a service program and main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5

Exercise 10. Data structures and data areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Part 1: Display output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Part 2: Copy existing members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3
Part 3: Create a data area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3
Part 4: Modify your DSPF VNDINQDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4
Part 5: Modify your RPG member VNRINQDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4
Part 6: Compile and test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4

Exercise 11. Maintaining database files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-1


Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Part 1: Analyze the output report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Part 2: Analyze the purchase orders open line item file . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
Part 3: Analyze the purchase order transaction file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6
Part 4: Program description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6
Part 5: Modify the PORMNT02 program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Part 6: Compile and test your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13
Part 7: Modify your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13

Appendix A. Physical and logical files DDS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1

Appendix B. Exercise solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1


Exercise 1: Coding and compiling RPG IV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2
Exercise 2: Sequencing RPG IV specifications and compiling . . . . . . . . . . . . . . . . . . . . . . . . . . B-3
Exercise 3: Coding a report program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
Exercise 4: Adding overflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7
Exercise 5: Data definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-8
Exercise 6: Adding arithmetic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-9
Exercise 7: Data manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-10
Exercise 8: Coding an inquiry program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-11

iv RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

TOC Exercise 9: Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-14


Exercise 10: Data structures and data areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Exercise 11: Maintaining database files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-19

Appendix C. Sample legacy programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-1

Appendix D. Rational Developer for Power Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1


Part 1: Start Remote Systems Explorer (RSE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1
Part 2: Opening the Remote System Explorer perspective . . . . . . . . . . . . . . . . . . . . . . . . D-4
Part 3: Start the LPEX editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-13
Part 4: Compile your RPG IV program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-15
Part 5: Run your RPG IV program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-15

© Copyright IBM Corp. 2002, 2014 Contents v


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

vi RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

TMK
Trademarks
The reader should recognize that the following terms, which appear in the content of this training
document, are official trademarks of IBM or other companies:
IBM® is a registered trademark of International Business Machines Corporation.
The following are trademarks of International Business Machines Corporation in the United States,
or other countries, or both:
AS/400® AS/400e™ DB™
DB2® Integrated Language Iterations®
Environment®
i5/OS™ Language Environment® OS/400®
PartnerWorld® Power Systems™ Power Systems Software™
Power® Rational® Redbooks®
RPG/400® System i® Worklight®
400®
Adobe is either a registered trademark or a trademark of Adobe Systems Incorporated in the United
States, and/or other countries.
Pentium is a trademark or registered trademark of Intel Corporation or its subsidiaries in the United
States and other countries.
Windows is a trademark of Microsoft Corporation in the United States, other countries, or both.
Java™ and all Java-based trademarks and logos are trademarks or registered trademarks of
Oracle and/or its affiliates.
VMware and the VMware “boxes” logo and design, Virtual SMP and VMotion are registered
trademarks or trademarks (the “Marks”) of VMware, Inc. in the United States and/or other
jurisdictions.
Other product and service names might be trademarks of IBM or other companies.

© Copyright IBM Corp. 2002, 2014 Trademarks vii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

viii RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

pref
Exercises description
Exercise instructions: The instructions describe what you are to accomplish. There are no
definitive details on how to perform the tasks. You are given the opportunity to work through the
exercise given what you learned in the unit presentation.

General instructions for all machine exercises


Each exercise begins with a statement of objectives, followed by detailed steps that describe the
exercise.
Students should read through the complete exercise before starting the exercise and then read
each step completely before performing that step.
When instructions refer to the name of a library, object, or source member, such as AS06nnn,
replace the lower case nnn with the team number assigned to you by the instructor.
Use AS06nnn for your user profile name and AS06 as your initial password. Your password is set
to expire at first signon. When prompted, change it to something you can remember easily.
You work with your own library, AS06nnn.
Complete each exercise step and resolve any problems before you proceed to the next step.
Which editor to use: You can use the PC-based LPEX editor of RD for I or you can use SEU as
your editor. LPEX is the recommended editor. It is straightforward and easy to use.
You can open the LPEX editor by Start > All Programs > IBM Software Development Platform >
IBM Rational Developer for Power Systems Software > IBM Rational Developer for Power
Systems Software.
Your instructor can help you with any questions you have regarding the use of LPEX or SEU.

© Copyright IBM Corp. 2002, 2014 Exercises description ix


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

x RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 1. Coding and compiling RPG IV

What this exercise is about


In this exercise, you create a new RPGLE source member using the editor in
RSE/RD for IBM i.
After having created the member, you compile it and, if necessary, correct
any compilation errors.
You also have the opportunity to review a compilation listing and correct the
cause of any diagnostic messages.

What you should be able to do


At the end of the exercise, you should be able to:
• Implement a simple example of the development process on the i
• Review a compiler listing to determine any compilation errors
• Correct any compilation errors

Introduction
Create a source member named DEVPGM01 in your AS06nnn/QRPGLESRC
source file, where nnn is your team number as assigned by the instructor.
DEVPGM01 displays the sum of 2 + 2 in your user message queue.
Compile the RPG IV code and review your compilation listing to correct any
problems.

Requirements
• Student Notebook
• Userid (AS06nnn) and password AS06.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
You perform this exercise using the editor in RSE. Instructions are written assuming the LPEX
editor.

Part 1: Start Remote Systems Explorer (RSE)


RSE allows you to connect to an IBM i server and define a collection of filters (lists of items that you
define). You can then access and operate on whatever items are of interest you.
First you must start the product. Follow these steps to start the product.
__ 1. Click Start on the task bar of your Desktop.
__ 2. Select Programs or All Programs, depending on your system.
__ 3. Select IBM Software Delivery Platform > IBM Rational Developer for Power Systems
Software > IBM Rational Developer for Power Systems Software.
__ 4. A dialog appears. Here you specify the directory of the workspace where your projects and
other resources, such as folders, subfolders, and files that you are developing in the
workbench, reside.

__ 5. Change the field in this dialog and use a unique directory name, for example, AS06nnn
(where nnn is your team number, such as AS06001).
Ensure the Use this as the default and do not ask again check box is not selected.
__ 6. Click OK to open the Workbench.

1-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 7. Click the icon in the top, middle of the Welcome page to go to the Workbench.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 8. Click the maximize button to maximize or the restore button to return the Workbench to its
original size.

__ 9. Click the X in the IBM i RSE Getting Started tab. This display is always available by
choosing the Help > IBM i RSE Getting Started menu option.
A workbench is a desktop development environment. The workbench aims to achieve
seamless tool integration and controlled openness by providing a common paradigm
for the creation, management, and navigation of workbench resources. Each workbench
window contains one or more views and an editor.

1-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Part 2: Opening the Remote System Explorer perspective


__ 10. Check for the name of the perspective.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 11. If you see a different perspective (not the Remote System Explorer) in the Workbench, or no
perspective, click Window > Open Perspective > Remote System Explorer from the
Workbench menu.
The Remote System Explorer perspective opens.

You work in the Remote System Explorer perspective in the Workbench. This perspective allows an
IBM i programmer to display the connections that she has already configured, create a new
connection, connect to and disconnect from the connections that she has defined, and work with
IBM i files, commands, jobs, and integrated file system files.
When you first open the Remote System Explorer, you are not connected to any System except
your local hard drive on your workstation. To connect to a remote IBM i system, you need to define
a connection. When you define a connection, you specify the name or IP address of the remote
system and you give your connection a unique name that acts as a label in your workspace so that
you can easily connect and disconnect. When you connect to the IBM i system, the workbench
prompts you for your user ID and password on that host.
The first time you connect to an IBM i system, you need to specify a profile. All connections, filters,
and filter pools belong to profiles.

1-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 12. In the Remote Systems view, New Connection is automatically expanded to show the
various remote systems types you can connect to through the Remote System Explorer.

__ 13. Double-click the IBM i icon to configure a connection to an i system.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 14. The profile defaults to the name of the workstation. The Remote IBM i System Connection
page opens.
On this page, you specify the information for your connection. The cursor on this page is
positioned in the Host name field.
In the Host name field, type <i_server> (Check with your instructor, if you do not remember
the system name or IP address to enter).

__ 15. Keep the default value for Parent profile as is. You do not need to change it.
__ 16. Keep the Verify host name check box selected.
__ 17. Click Finish to define your system. You have configured a connection.
__ 18. In the Remote Systems view, your new connection is expanded to reveal your subsystems.
The Objects subsystem is the subsystem you will use most often. It is very similar to PDM
in that it allows you to access objects in the QSYS file system and to perform actions on
those objects.
__ 19. Once expanded, the first three entries under the Objects subsystem are named after the
PDM options because they have similar capabilities:
• Work with libraries is similar to WRKLIBPDM.
• Work with objects is similar to WRKOBJPDM.
• Work with members is similar to WRKMBRPDM.

1-8 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty • In addition, there are entries for working with library lists and user libraries:
- Library list is similar to WRKLIBPDM in PDM. You can start with the predefined
library list filter that, when expanded, lists all libraries in your library list.
- User libraries allow you to work with all user libraries you can access on that i server.
You also have more entries to work with under the connection itself, and you can see from
these entries that Remote System Explorer goes well beyond PDM. It allows you to explore
i jobs and commands and the integrated file system.
__ 20. Work with a library in your library list, and add the library that you will be using in this
exercise:
Right-click Objects and select Properties on the menu.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 21. Select Initial Library List on the left pane.


__ 22. Type the name of <your library> in the Library field, and click Add.

__ 23. Click OK.


This will add the library to your library list every time you use this connection.

1-10 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 24. Expand the Library list folder.


Now, the connection will be activated, and you will be prompted for a user ID and password.
__ 25. Enter <i_userid> and <i_password>.
__ a. Ensure that the Save user ID check box is not selected.
__ b. Ensure that the Save password check box is not selected.
__ c. Click OK.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

As you know, you can use the properties of any of the subsystems to set connection
information such as adding a library to a library list. Back in the Workbench in the Remote
Systems view, when you click the Refresh icon, you will see the libraries in your job's
library list.

__ 26. Click the + beside Work with members.


__ 27. In the Library entry field, type AS06nnn.
__ 28. In the File entry field, type QRPGLESRC.

1-12 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 29. Click the Next button, and on the subsequent filter name display, type QRPGLESRC as the
name of this new filter. Click Finish.

__ 30. Repeat the above steps to add a filter for your QDDSSRC source file in your library.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 31. Your RSE Workbench should now look similar to the one below.

Part 3: Start the LPEX editor


__ 32. Right-click your QRPGLESRC filter icon and select New > member.

1-14 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 33. On the IBM i Source Member display, verify that your library AS06nnn and source file
QRPGLESRC are already completed. For member name, type DEVPGM01R. For member
type, use the scroll bar to select RPGLE. For the text prompt, type the following:
Lab Exercise 1B Compile of an RPG IV program
Click Finish.

© Copyright IBM Corp. 2002, 2014 Exercise 1. Coding and compiling RPG IV 1-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 34. Once the editor window opens, enter the code that follows into your source member.
__ 35. Here is the code that you enter into your QRPGLESRC file, member DEVPGM01. The lines
should start in column 8:
dcl-s Message char(30) inz('The sum of 2 plus 2 is');
Dcl-s Sums packed(3) inz;

sum = 2 + 2;
message = %trimr(Message) + ' ' + %char(sum);

Dsply message '*REQUESTER';

return;
__ 36. Save the file as it is to your QRPGLESRC file on the i by selecting File > Save. The member is
then written to your QRPGLESRC source file with a member name of DEVPGM01R. Do not
close the member. In the next step, you will create (compile) the program.

Part 4: Compile your RPG IV program


__ 37. Open the source member DEVPGM01R in QRPGLESRC in your library AS06nnn (by clicking
that item in the RSE workspace) if you have previously closed it. Your RPGLE program for
this source file member is now ready to compile. Click Compile > Compile > CRTBNDRPG
(without prompting). There is an error window (tab named Error List) if your program has
any warnings or errors. The Command Log tab will display the status of your compile.
__ 38. Make any necessary corrections and recompile your program.
__ 39. Repeat this process until the *PGM member is successfully created.

Part 5: Run your RPG IV program


__ 40. Sign on to a 5250 session on the IBM i server. Issue the command DSPLIB AS06nnn and
check that your program DEVPGM01R exists as a *PGM. Assuming it does, on the
command line, enter CALL DEVPGM01R. You should see the message from your program.

End of exercise

1-16 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 2. Sequencing RPG IV specifications and
compiling

What this exercise is about


This exercise provides an opportunity to correctly sequence RPG IV code, to
compile your sequenced source member, and to view the compiled listing.

What you should be able to do


At the end of the exercise, you should be able to:
• Find a specific RPG IV source member in your QRPGLESRC file
• Edit an RPG IV source member
• Correctly sequence RPG IV code so that it will compile
• Create an executable RPG IV program
• Manipulate the compiler options
• Find and view a compiled source listing

Introduction
You are given a source member VNRADR018 in AS06nnn/QRPGLESRC
where nnn is your student number.
VNRADR018 is an inquiry program. It prompts the user for a vendor number.
If the number is valid, it displays a vendor's address on the screen. All
supporting objects needed for this exercise are provided.
The existing source file is not sequenced correctly. Put the specifications in
the correct order and then compile the corrected source member.
When it is successfully compiled, call and test the program.

© Copyright IBM Corp. 2002, 2014 Exercise 2. Sequencing RPG IV specifications and compiling 2-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
In the following instructions, we direct you on what to do without telling you explicitly how to do it. If
you need any assistance, please ask your instructor.

Part 1: Log on
__ 1. Sign on to an i 5250 session.

Part 2: Edit the source member


If you are using the LPEX editor and filters, expand your QRPGLESRC filter. Sign on when or if
prompted. Open the existing member in your QRPGLESRC file, VNRADR01, by double-clicking it.
__ 2. Edit the member VNRAR018.

Part 3: Sequence the RPG IV specifications


__ 3. Review the code in the member. The code is incorrectly sequenced and a compile would
end in error. A copy of this source code is provided for you as follows.
__ 4. Correctly sequence the source code using move commands.
__ 5. M moves a line of code. Before or After designates the target location. MM is used for moving
blocks of code. Type MM on the first and last block lines and then place an A or B on the
target line. The move is executed when the Enter key is pressed. Or, you can select a line
and press Ctrl+X to cut the line and Ctrl+V to paste it in the correct position.
• RPG specifications are ordered in control specification, file definition, data definition,
and calculation specifications sequence.
• Like specifications are grouped together.
• When you are satisfied with the sequence, save the member.
**********************************************************************
* VNRADR018
* Vendor Address Inquiry *
* This program prompts the user for a vendor number and displays *
* the vendor's address information on the screen. *
* *
* The user has options to exit the program and to print a vendor *
* record. *
* *
* INDICATORS: *
* Exit - the user requests to exit the program *
* PrintIt - the user requests to print vendor address *
* NotFound - no vendor found to match the input vendor number *
**********************************************************************

2-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty

Part 4: Compile the source member


__ 6. Compile the member VNRADR018.
__ 7. When the compile has ended, continue with the next step.

Part 5: Find and view the compiler listing


__ 8. If you are not actively running a 5250 session, start one.
__ 9. Use work with spooled files (WRKSPLF) to find the compiler listing.
__ 10. Display the file named VNRADR018. The listing file name is always the same as the
compiled member name.

© Copyright IBM Corp. 2002, 2014 Exercise 2. Sequencing RPG IV specifications and compiling 2-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Identify the field names copied in from the externally described files. They have specification
types of I and O. These specifications are generated automatically for you by the compiler.
Input (I) specifications define the format of incoming data from files (physical files, logical
files, display files for example).
Output (O) specifications define the format in which data will be written to a physical or
logical file in addition to a display or printer file.
__ 11. Notice the source specifications section.
__ 12. Notice the message summary section.
__ 13. Locate the cross reference section. Which named indicators are used?

Hint

Look for the data type (N) fields.

Can you guess which field definitions are indicators?


____________________________________________________________
__ 14. Check the last message in the listing. Was the program object (*PGM) placed in your
library? (Check your listing) ________.
If the program was not created, try to find the error and then compile again. If you need help,
ask the instructor.

Part 6: Run your new program


__ 15. Use the WRKOBJPDM command to look at the objects in your AS06nnn library.
__ 16. Look for a new object, named VNRADR018. What is the object type?
_____________________________________
__ 17. To run the new program, enter CALL VNRADR01 on the command line. You should see the
vendor address inquiry screen. Enter a few valid vendor numbers (10001 through 10050)
to test the application.

End of exercise

2-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Optional Exercise


Step 1. Compiler options
__ 1. Go back to LPEX and take the compile (prompt) option with the CRTBNDRPG command.
__ 2. Specify *SECLVL and *NOEXPDDS for the compiler options parameter.
__ 3. Press the Enter key.

Step 2. Review the changes


__ 4. Display the compiled listing again.
__ 5. Are external field names listed? ________
__ 6. Look at the message summary section. The text describes the messages in more detail.

End of exercise

© Copyright IBM Corp. 2002, 2014 Exercise 2. Sequencing RPG IV specifications and compiling 2-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

2-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 3. Coding a report program

What this exercise is about


This exercise provides an opportunity to practice entering and compiling an
RPG IV program.

What you should be able to do


At the end of the exercise, you should be able to:
• Code an RPG IV program using the LPEX editor
• Compile the RPG IV program
• Review the compiler listing and correct errors
• Run the program successfully

Introduction
Produce a listing of the records in the ITEM_PF database file.

© Copyright IBM Corp. 2002, 2014 Exercise 3. Coding a report program 3-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Sample report output follows:

PAGE 1 COST OF ON HAND INVENTORY

ITEM# DESCRIPTION COST QTY OH COST OH

20001 Telephone, one line 15.00 10


20002 Telephone, two line 89.00 5
20003 Speaker Telephone 85.00 6
20004 Telephone Extension Cord 1.10 25
20005 Dry Erase Marker Packs 2.25 428
20006 Executive Chairs 325.00 10
20007 Secretarial Chairs 55.00 13
20008 Desk Calendar Pads 5.00 56
20009 Diskette Mailers .20 128
20010 Address Books 6.00 1,680
20011 Desk lamp, brass 20.00 3
20012 Blue pens 20.00 7
20013 Red pens 100.00 14
20014 Black pens 150.00 25
More...

Files used
All files are externally described:
• Physical file ITEM_PF (input) to be processed by key
• Printer file ITPCOST

3-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Exercise instructions


Part 1: Create the PRTF ITPCOST
__ 1. Study the DDS source (also in your QDDSSRC file) for the printer file ITPCOST. Note the
different format names:
*****************************************************************
* ITPCOST *
* Cost of Inventory On Hand Report *
*****************************************************************
* This printer file is used to print the cost of on hand *
* inventory. This report is double spaced.
* *
* FORMATS: *
* HEADING: To be printed at the top of each page. *
* DETAIL: To print the information for one item. *
* TOTAL: To print the total value of all on hand items *
* at the end of the report. *
* *
*****************************************************************
A REF(DICTIONARY)
A R HEADING SKIPB(2) SPACEA(2)
A 1'PAGE'
A +1PAGNBR EDTCDE(Z)
A 26'COST OF ON HAND INVENTORY'
A 1'ITEM#' SPACEB(2)
A +2'DESCRIPTION'
A +19'COST'
A +6'QTY OH'
A +5'COST OH'
A R DETAIL SPACEA(2)
A ITMNBR R 1
A ITMDESCR R +2
A ITMCOST R +2EDTCDE(K)
A ITMQTYOH R +2EDTCDE(1)
A ITMCOSTOH R +2 +2REFFLD(ITMCOST) EDTCDE(K)
A R TOTAL SPACEB(1)
A 1'TOTAL COST OF INVENTORY ON HAND:'
A TOTCOSTOH R +4 53REFFLD(ITMCOST) EDTCDE(K)
__ 2. You use only the HEADING and DETAIL formats in this exercise.
__ 3. Create (compile) the printer file object from the DDS source provided.

Part 2: Write your RPG IV program ITRCOST


Use your lecture notebook to help you code this program. The sample program that we discussed
in lecture helps to guide you through the process. The logic you write for coding one report applies

© Copyright IBM Corp. 2002, 2014 Exercise 3. Coding a report program 3-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

to other report programs. What differs is how you manipulate the data. In this exercise, you do not
modify the data in any way. You do that in a later exercise.
__ 4. Write an RPG IV program to list all the records in ITEM_PF sequentially using the record
key. Use the sample report provided at the beginning of the exercise. Notice that we are
going to print only some of the fields described in the PRTF. We add more fields in
subsequent exercises and use the same PRTF again. Add a new member, ITRCOST, to your
QRPGLESRC in your AS06nnn library.
__ 5. You noted in the previous step that the PRTF contains three separate formats. How many
formats do you use in your program? ________
__ 6. Your program should reference and use only those formats that are required to produce a
report like the sample report.
You might INCLUDE those formats to be used or IGNORE those formats to be dropped on
the file specification.
__ 7. Enable page overflow in your program using the OflInd(PrtOver)keyword for your
ITPCOST printer file. List the detail of each item record that is read in the report.
__ 8. Compile and test the program, checking the printed results against the sample provided.

Note

Notice that when you display spooled reports in your OUTQ, you do not see all the spacing
and skipping that you specify in your printer file DDS. Spooled data is compressed to reduce
the storage required.

End of exercise

3-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 4. Adding overflow

What this exercise is about


In this exercise, you enhance the report program that you wrote in the
previous exercise.

What you should be able to do


At the end of the exercise, you should be able to:
• Modify an RPG IV report program
• Compile your RPG IV program
• Review the compiler listing and correct errors
• Run your program successfully

Introduction
Enhance the program that produced the listing of the records in the ITEM_PF
database file. You improve your listing program.

© Copyright IBM Corp. 2002, 2014 Exercise 4. Adding overflow 4-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Sample report output follows:


PAGE 1 COST OF ON HAND INVENTORY

ITEM# DESCRIPTION COST QTY OH COST OH

20001 Telephone, one line 15.00 10


20002 Telephone, two line 89.00 5
20003 Speaker Telephone 85.00 6
20004 Telephone Extension Cord 1.10 25
20005 Dry Erase Marker Packs 2.25 428
20006 Executive Chairs 325.00 10
20007 Secretarial Chairs 55.00 13
20008 Desk Calendar Pads 5.00 56
20009 Diskette Mailers .20 128
20010 Address Books 6.00 1,680
20011 Desk lamp, brass 20.00 3
20012 Blue pens 20.00 7
20013 Red pens 100.00 14
20014 Black pens 150.00 25
20015 Number 2 pencils 2.50 150
20016 Number 3 pencils 4.50 25
20017 Two Drawer File Cabinets 5.50 15
20018 Manilla folders 4.00 50
20019 Hanging file folders 3.00 150
20020 Metal desk 125.00 2
20021 Pink erasers .25 250
20022 Gum erasers .75 100
20023 Twelve inch rulers 1.25 15
20024 Eighteen inch rulers 1.00 65
20025 Staples 2.50 14
20026 Three Ring Binders 4.00 10
20027 Three hole punch 8.00 149

PAGE 2 COST OF ON HAND INVENTORY

ITEM# DESCRIPTION COST QTY OH COST OH

20028 Desk picture frame 5 X 7 3.50 47


20029 8 1/2 x 11 lined paper 1.00 1,500
20030 Headset 1.50 523
20031 Folding chair .50 127
20032 Digital desk clock 19.99 44
20033 Banquet table, 6 ft. 2.00 10,128
20034 Executive Oak Desk 500.00 1
: : : :

Files used
All files are externally described:
• Physical file ITEM_PF (input) to be processed by key
• Printer file ITPCOST

4-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Exercise instructions


Part 1: Modify your program ITRCOST
__ 1. Make a copy of your program, ITRCOST. In LPEX, you can edit your original program
ITRCOST, and then use Save as to create your new member, ITRCOSTE.

Part 2: Enhance your ITRCOSTE program


__ 2. Enhance your program to print headings on the page overflow condition using the
HEADING format of the ITPCOST PRTF.
__ 3. Test for overflow in your program. Overflow should be checked before you print a detail
format.
__ 4. Compile and test the program, checking the printed results against the sample provided.

End of exercise

© Copyright IBM Corp. 2002, 2014 Exercise 4. Adding overflow 4-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

4-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 5. Data definition

What this exercise is about


This exercise provides an opportunity to code RPG IV File specifications for
externally defined files as well as Data Definition specifications to define work
fields used in the program.

What you should be able to do


At the end of the exercise, you should be able to:
• Code File specifications
• Code Definition specifications

Introduction
Using either the LPEX editor, modify an existing member, named PORLIST
adding appropriate File specs and Definition specs given the following
specifications.

© Copyright IBM Corp. 2002, 2014 Exercise 5. Data definition 5-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
Part 1: Examine the existing RPG IV source
__ 1. Locate and edit your copy of PORLIST in your QRPGLESRC file. A copy follows:
// Headings on first page
Write Heading;

// Read first record of file


Read Item_PF;

DoW not %eof(Item_PF);

// Page overflow?
If PrtOver;
Write Heading;
PrtOver = *Off;
EndIf;

// Accumulate totals
TotQtyAvl = ItmQtyOH + ItmQtyOO;
// Set indicator for Low Available Quantity
*in43 = (TotQtyAvl < 15);

// Accumulate low quantity situations


If *in43;
Low = Low + 1;
EndIf;

// Calculate value (at cost) of available inventory


AvlCost = ItmCost * TotQtyAvl;

// Calulate value (at retail) of available inventory


AvlPrice = ItmPrice * TotQtyAvl;

// Accumulate the total number of records processed


Count = Count + 1;

// Print the detail format


Write Detail;
// Read second and subsequent records of file
Read Item_PF;
EndDo;

// End of file processing

// Move the program accumulators to the printer file fields


LowCountP = Low;
TotCountP = Count;
// Print the record format for totals
Write Footing;
*InLr = *on;
__ 2. Notice that there are no files defined yet. Defining the files is part of the exercise.

5-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 3. Review the following sample report:


6/24/03 Item Master Listing Page: 1

Item No Description Qty On Hand Qty On Order Tot Avail Avail Cost Avail List

20001 Telephone, one line 10 6 16 240.00 480.00


20002 Telephone, two line 5 12 17 1,513.00 2,125.00
20003 Speaker Telephone 6 8 14 Low 1,190.00 1,960.00
20004 Telephone Extension Cord 25 10 35 38.50 104.65
20005 Dry Erase Marker Packs 428 10 438 985.50 1,314.00
20006 Executive Chairs 10 2 12 Low 3,900.00 7,200.00
20007 Secretarial Chairs 13 5 18 990.00 1,890.00
20008 Desk Calendar Pads 56 10 66 330.00 528.00
20009 Diskette Mailers 128 200 328 65.60 278.80
: :::::::
: :::::::
20047 Yellow paper, 8 1/2 X 11 199 10 209 616.50 833.91
20048 3 hole white paper 35 10 45 150.70 314.55
20049 3 hole lined paper 10 4 14 Low 53.90 97.86
20050 Heavy duty stapler 5 0 5 Low 45.70 106.25
Low Stock Count 7
Total Stock Count 50
*** End of Listing ***

__ 4. There are some fields used that you will define in your program to produce low stock count
and total stock count.

Part 2: Add file definitions to PORLIST


__ 5. All files are externally described.
__ 6. Physical file, ITEM_PF, is to be processed sequentially by key as input only. It is a
procedural file. If you want to view the DDS for ITEM_PF, a copy can be found in your
QDDSSRC file. ITEM_PF references field reference file, DICTIONARY, which contains
specific field information. A copy is also in your QDDSSRC file. All database file descriptions
can also be found in the appendix.
__ 7. Printer file, POPLIST is an output file that is externally described. You have a copy in your
QDDSSRC file. Assign an indicator, PrtOver, as you have done earlier, for page overflow.

Note

You could name the overflow indicator anything you wanted. Also, notice that the definition
of the indicator is accomplished simply by referencing it on the printer file specification. It is
not necessary to define the indicator explicitly on a Data Definition specification. However,
many i installations make a practice of explicitly defining all indicators to make maintenance
more straightforward.

© Copyright IBM Corp. 2002, 2014 Exercise 5. Data definition 5-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Part 3: Review total field definitions in POPLIST


__ 8. Open your member, POPLIST. Identify the FOOTING format where the accumulators are
defined; note the names of these accumulators. You need to identify where these fields are
calculated in the program, to determine any other work variables which might need to be
declared.

Hint

You could try compiling the PORLIST program as follows. The compiler listing will provide
useful information in the cross reference section, detailing where every variable is defined
and used.

Part 4: Compile and test your program PORLIST


__ 9. Compile the printer file used by PORLIST, POPLIST in your QDDSSRC source file.
__ 10. Compile your program PORLIST.
__ 11. Review your compiler listing. Notice the external files, ITEM_PF and POPLIST that are
included in your compilation.
__ 12. Correct any errors based on the compilation listing.
__ 13. When your program has compiled, run the command, CALL PORLIST, to run your program.
__ 14. Check your output queue and see whether the report was produced. Check the sample
output above. If the report was produced, you have finished the exercise.

End of exercise

5-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 6. Adding arithmetic functions

What this exercise is about


This exercise provides an opportunity to enhance your ITRCOSTE program.

What you should be able to do


At the end of the exercise, you should be able to:
• Code arithmetic calculations to produce an extension and totaling of data
• Run the program

Introduction
In this exercise, you use the ITPCOST printer file and the ITRCOSTE RPG IV
program that you worked with in an earlier exercise.
You must have completed the ITRCOSTE program in the earlier exercise to
perform this exercise.
This exercise assumes that the student completed the earlier Coding a report
program exercise successfully. If you were unable to complete that exercise,
you should ask your instructor for assistance.

Introduction
Enhance the audit listing of the records in the ITEM_PF database file that
you wrote earlier.

© Copyright IBM Corp. 2002, 2014 Exercise 6. Adding arithmetic functions 6-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Sample report output follows:


PAGE 1 COST OF ON HAND INVENTORY

ITEM# DESCRIPTION COST QTY OH COST OH

20001 Telephone, one line 15.00 10 150.00


20002 Telephone, two line 89.00 5 445.00
20003 Speaker Telephone 85.00 6 510.00
20004 Telephone Extension Cord 1.10 25 27.50
20005 Dry Erase Marker Packs 2.25 428 963.00
20006 Executive Chairs 325.00 10 3,250.00
20007 Secretarial Chairs 55.00 13 715.00
20008 Desk Calendar Pads 5.00 56 280.00
20009 Diskette Mailers .20 128 25.60
20010 Address Books 6.00 1,680 10,080.00
20011 Desk lamp, brass 20.00 3 60.00
20012 Blue pens 20.00 7 140.00
20013 Red pens 100.00 14 1,400.00
20014 Black pens 150.00 25 3,750.00
20015 Number 2 pencils 2.50 150 375.00
20016 Number 3 pencils 4.50 25 112.50
20017 Two Drawer File Cabinets 5.50 15 82.50
20018 Manilla folders 4.00 50 200.00
20019 Hanging file folders 3.00 150 450.00
20020 Metal desk 125.00 2 250.00
20021 Pink erasers .25 250 62.50
20022 Gum erasers .75 100 75.00
20023 Twelve inch rulers 1.25 15 18.75
20024 Eighteen inch rulers 1.00 65 65.00
20025 Staples 2.50 14 35.00
20026 Three Ring Binders 4.00 10 40.00
20027 Three hole punch 8.00 149 1,192.00

PAGE 2 COST OF ON HAND INVENTORY

ITEM# DESCRIPTION COST QTY OH COST OH

20028 Desk picture frame 5 X 7 3.50 47 164.50


20029 8 1/2 x 11 lined paper 1.00 1,500 1,500.00
20030 Headset 1.50 523 784.50
20031 Folding chair .50 127 63.50
20032 Digital desk clock 19.99 44 879.56
20033 Banquet table, 6 ft. 2.00 10,128 20,256.00
20034 Executive Oak Desk 500.00 1 500.00
20035 Flourescent lamp 12.00 12 144.00
20036 India ink 2.05 96 196.80
20037 Pencil sharpener, manual 5.55 13 72.15
20038 Mouse pad .37 208 76.96
20039 2 ring binders 2.05 12 24.60
20040 Ergonomic mouse 4.40 12 52.80
20041 Printer ribbon 2.95 6 17.70
20042 White out .98 1 .98
20043 Office tool kit 24.00 12 288.00
20044 Pink paper, 8 1/2 X 11 2.95 166 489.70
20045 Blue paper, 8 1/2 X 11 2.95 75 221.25

6-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty 20046 Continuous 8,5 X 11 paper 20.00 24 480.00


20047 Yellow paper, 8 1/2 X 11 2.95 199 587.05
20048 3 hole white paper 3.35 35 117.25
20049 3 hole lined paper 3.85 10 38.50
20050 Heavy duty stapler 9.15 5 45.75

TOTAL COST OF INVENTORY ON HAND: 51,755.90

Files used
All files are externally described:
• Physical file ITEM_PF (input) to be processed by key
• Printer file ITPCOST (no changes are required to the copy that you used
in your previous exercise)

© Copyright IBM Corp. 2002, 2014 Exercise 6. Adding arithmetic functions 6-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
Part 1: Cost of inventory on hand report
__ 1. Study the Cost of inventory on hand report.

Part 2: Copy your source program ITRCOSTE


__ 2. Make a copy of your solution, ITRCOSTE, from the previous exercise and name it
ITRCOSTADD.
__ 3. Modify your new program, ITRCOSTADD, to:
i. Produce the cost on hand field as shown in the sample report.
ii. Produce the total line that you see in the sample output.

Hint

It is always a good idea to add new functions individually. This can make debugging
problems much easier than adding many new things at once. Code the first enhancement
above. Then, compile and test your program. When you are satisfied with the results, code
the logic to produce the total line. Remember to write the total line following the format of
the ITPCOST printer file.

Part 3: Compile and test your program


__ 4. Repeat this process until your program produces the report correctly.

End of exercise

6-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 7. Data manipulation

What this exercise is about


This exercise is an opportunity for you to use expressions and built-in
functions in your RPG IV programs.

What you should be able to do


At the end of the exercise, you should be able to code:
• Logical expressions
• Character expressions
• Arithmetic expressions

Introduction
You are given report layout information and a description of the function of
the program that you write. A PRTF (VNPADR03) is provided that you use to
produce output from your RPG program to produce the report.
You will write a program, VNRADR03, to produce the report.

Purpose
Produce a listing of active vendors from the VENDOR_PF file.

General considerations
Sample report output is provided. Also, several demonstration programs are
provided to show you the results of using several BIFs that you might elect to
use in your program. The first steps of the exercise encourage you to run and
browse these programs.

Files used
All files are externally described:
• VENDOR_PF (input) to be processed sequentially by key
• Printer file VNPADR03 PRTF

© Copyright IBM Corp. 2002, 2014 Exercise 7. Data manipulation 7-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Processing
Review the DDS source for the printer file and the PF in QDDSSRC in your
student library. Make a note of the format names that you need to use in this
program.

7-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Exercise instructions


Part 1: Run the %SCAN and %SUBST demonstration programs
Experiment by running the sample programs, BFRSCAN and BFRSUBST. This program is provided to
familiarize you with these built-in functions which you likely use as you code the program in this
exercise.
__ 1. Call the BFRSCAN program and follow the instructions to see the results of
using %SCAN. %SCAN searches a string using a search argument and returns a numeric
value The program asks you for your first and last name. Try the program different ways.
Enter your first name starting in the first position followed by a blank and then your last
name. Next, try it with a blank in front of your first name. Can you see how %SCAN works?
Now just fill all 20 characters with any non blank characters. What value does %SCAN
return now?
__ 2. Call the BFRSUBST program. Enter any string of three words. You can try great is RPGIV to
begin if you want. Rearrange and truncate the words in your input phrase by specifying start
and length values for the three %SUBST expressions.
__ 3. To do this, type three words of your choice into the input phrase area so that no word is in
the same relative position as you want in the output phrase. Next, using the three
substring functions, pick up the three words in the sequence you want them to appear in
the output phrase. With a little practice, you should be able to easily specify offsets and
lengths to help the program rearrange the words in your phrase.
__ 4. If you have a question, ask your instructor.

Part 2: Review the sample report


__ 5. Examine the output that follows:
Page 1 Active Vendors 01/29/2002 13:45:56
Vend Vendor
Vend VND Zip Area Tel Sales
Num Vendor Name Vendor Street Vendor City State Code Code No Person

10001 John M. Smith & Sons 2732 Fourth Ave. New York NY 10001 201 662-1000 Bill
10002 Hugh Wilson & Son 4583 Landmark Towers Summit CO 32110 303 454-1010 Jerry
10003 Paper and Pencil 280 Park Ave. New York NY 10017 212 658-5346 Ross
10004 The Desk Shop 461 Congress Ave. San Francisco CA 91462 415 329-3435 Joyce
10006 Andy Glover Corp. 100 Plainfield Rd. Montgomery AL 40612 205 600-7000 Carl
10007 The Chair Market 11 Rocking Horse Ct. Hardford CT 02185 203 458-3636 John
10008 Office Joe 5300 Bradfield Blvd. Horsham NY 78231 501 742-6565 Howard
10009 Reams of Paper 3 Manilla Ct. Oklahoma City OK 72143 405 616-2525 Cindy
10010 Clifford Distribution 3 Mountain View Rd. Las Vegas NV 63813 702 722-4585 Roy
.... ... .. .
.... ... .. .
.... ... .. .
.... ... .. .
10049 Susquehanna Supply 1122 Front St. Chenango Valley PA 74113 406 258-1257 Hector
10050 Genessee Office Products 1313 Koday Rd. Binghamton NY 34506 816 555-1313 Antonio

Number of active vendors: 46 *

__ 6. You should notice several things about this report. First, only the first name is shown for the
vendor sales person contact at the vendor's office. Second, since we are concerned only
about active vendors, we are showing a total count of active vendors. Both active as well as
inactive vendor records can be found in the Vendor_PF file.

© Copyright IBM Corp. 2002, 2014 Exercise 7. Data manipulation 7-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Part 3: Review and compile PRTF VNPADR03


__ 7. Review the source file, VNPADR03:
*****************************************************************
* VNPADR03 *
* VENDOR ADDRESS REPORT *
*****************************************************************
* THIS PRINTER FILE FORMATS THE VENDOR ADDRESS DATA. *
* INDICATORS: NONE *
*****************************************************************
* CHANGE LOG *
* DATE PROGRAMMER DESCRIPTION *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
* 8/27/96 RJSLANEY NEW FILE. *
*****************************************************************
A REF(VENDOR_PF)
A R HEADING
A SKIPB(001)
A TEXT('VENDOR_LISTING')
A 1'PAGE'
A +1PAGNBR EDTCDE(Z)
A 45'Active Vendors'
A 110DATE EDTCDE(Y)
A 122TIME
A
A 110'Vend' SPACEB(1)
A +2'Vendor'
A
A 1'Vend' SPACEB(1)
A 87'VND'
A +6'Zip Area'
A +6'Tel Sales'
A
A 1'Num' SPACEB(1)
A 8'Vendor Name'
A 35'Vendor Street'
A 62'Vendor City'
A 87'State'
A +3'Code Code'
A +6'No Person' SPACEA(2)
A
A R DETAIL SPACEB(1)
A VNDNBR R 1EDTCDE(Z)
A VNDNAME R 8
A VNDSTREET R 35
A VNDCITY R 62
A VNDSTATE R 87
A VNDZIPCODER +7
A VNDAREACD R +2
A VNDTELNO R +1EDTWRD('0 - ')
A VNDSALES1 16 +1
A
A R TOTAL SPACEB(1)
A 7'Number of active vendors:'
A COUNT 9 0 35EDTCDE(1)
A 50'*'

__ 8. Compile your source member VNPADR03 in your source file QDDSSRC. This creates your
PRTF that is used by the RPG program to produce the report.

7-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Part 4: Write the program


Here is an explanation of the steps to write your program, VNRADR03.
__ 9. Create a new source member, VNRADR03.
__ 10. Print the headings of the report for the first page.
__ 11. Read the first record of the VENDOR_PF file.
__ 12. You should process records until End of File is encountered. Write a DoW group as you
have done before to handle this.
__ 13. For each record read:
• Check to see if the record is active (VNDACTIVE = 'A'). If the record is active:
- Extract the first name from the sales person name field (VndSales) and place it in a
shorter field of 16 characters named VndSales1. This field is shorter than the name
field and all we want to print is the sales person's first name (the VNDSALES field
contains first and last name separated by a blank). The shorter field will be placed in
VNDSALES1 by your program. Use BiFs where possible.
For example, if the VndSales field contains the value, 'Jim Slonovski ‘
the field VndSales1 should contain 'Jim '.
- Print the detail line format of the PRTF.
- Increment the record counter (see the definition of COUNT in the PRTF). You will
print it at the bottom of the report as a total number of active records. You will not
need to define this field in your program.
• You are responsible for printing headings for both the first page and whenever an
overflow condition is encountered.
• When EOF for the VENDOR_PF is reached, you should print the TOTAL format of the
PRTF and end the program.

Part 5: Test and execute your program


__ 14. Your program should produce output similar to the report that follows.
__ 15. To view the data to validate your report, you may use SQL if you know it, or enter this
command:
RUNQRY *n Vendor_PF
You can start another 5250 session to view the data and your report at the same time.
__ 16. In this program, the field names used in the PRTF matched those in the VENDOR_PF file.
Unfortunately, this is not always the case. In many applications, the PRTF fields are defined
using different names than those in the associated data file. How would you code your
program to ensure that the data from the PF appears in the PRTF?
_________________________________________________________________
_________________________________________________________________

© Copyright IBM Corp. 2002, 2014 Exercise 7. Data manipulation 7-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

End of exercise

7-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty
Exercise 8. Coding an inquiry program

What this exercise is about


This exercise provides an opportunity to create and use a two-format display
file in an interactive program.

What you should be able to do


At the end of the exercise, you should be able to:
• Create a display file using DDS
• Write an RPG program that uses a display file for a simple inquiry
application

Introduction
Company documents frequently lack complete vendor information. A
program to display a vendor's entire record would be helpful.
You are given screen design information and a program description.
You create a display file and program to display a vendor's record on the
screen.

© Copyright IBM Corp. 2002, 2014 Exercise 8. Coding an inquiry program 8-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
Part 1: Understanding the requirements
__ 1. When the program is initially called, the user is prompted for a vendor number. There is an
option to exit. See the following prompt screen format:
...+....1....+....2....+....3....+....4....+....5....+....6....+....7..
-AS06999 Vendor Inquiry DIRTCITY
- 6/01/11 08:15:58
- Vendor number. . . . : _____
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
- Please press enter to continue
- F3 = Exit
-Invalid vendor number - press reset and re-enter

8-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 2. For a valid vendor number, display the results as below:


...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+...
-AS06999 Vendor Inquiry DIRTCITY
- 2/01/02 08:15:58
-
-
+
-
- Vendor number . .: 10035
- Name . . . . . . : Thomas Corley
- Address . . . . : 285 Avenue B
+ Lockport IL 11014
- Telephone. . . . : ( 212 ) 348-5618
- Sales Person . . : James Milburn
- Purchases YTD . : 23,000.00
- Balance Owed . . : 5,000.00
+
-
-
-
-
+
-
-
- F3 = Exit F12 = Return to previous Display
-
__ 3. If a valid vendor number is entered, the entire vendor record is displayed. See the previous
figure. Note the use of function keys. F3 ends the program and F12 returns to the prompt
display.

Part 2: Create the display file VNDINQ


__ 4. If you know how to use Screen Designer to create display files, please use it. Otherwise,
use the LPEX editor to code the DDS for each of the two formats above.
__ 5. Name the DDS source member, VNDINQ (type DSPF), in file AS06nnn/QDDSSRC.
__ 6. Create two formats:
__ a. The prompt format
__ b. The detail format
__ 7. Name your formats PROMPT_FMT and DSPLY_FMT.
__ 8. Include the user ID, system name, date, and time in your formats.
__ 9. Use keyword CA03(03) to enable the function key for both formats and to support the text
F3 = Exit.

© Copyright IBM Corp. 2002, 2014 Exercise 8. Coding an inquiry program 8-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 10. Include Purchases YTD and Balance Owed, with appropriate editing. If the Balance Owed
is greater than 5000.00, display it using reverse image and the color red. This condition
should be based on indicator 60 being set by the program.

Note

Currency symbol

Students should use their local currency symbol. No currency symbol is shown in the sample
solution to avoid CCSID issues in countries where the currency symbol is not a dollar sign.
__ 11. Use keyword ERRMSG ('Invalid vendor number - press Reset and re-enter' nn) to display an
error message on line 24 if the vendor number entered is invalid.
__ 12. The nn is your program's error indicator if the vendor number is invalid. Remember to
condition the keyword with indicator nn.
__ 13. Consult the Appendix in this Exercise Guide for the Vendor_PF file and DICTIONARY file to
review field names and their characteristics.

Part 3: Understanding the program logic


__ 14. In this program, you access the VENDOR_PF file using its key, VNDNBR, obtaining the value
of the key from the prompt format of your display file.
__ 15. Use the program description described previously as a guide for the logic you write to
interact with your display file. Note the use of indicator 60 to test the balance. If you reset the
indicator in your display file, there is no need to reset it in your program.

Part 4: Create the program VNRINQ


__ 16. Create a new member, VNRINQ, in file AS06nnn/QRPGLESRC.
__ 17. Use your sample inquiry program in your notebook to help guide you as you code this
inquiry program.
__ 18. Refer to your display file for indicator usage.
__ 19. Compile the program.

Part 5: Test your program VNRINQ


__ 20. Call VNRINQ.
__ 21. Enter a valid vendor number (10001-10050). You should see the vendor's information.
__ 22. Enter an invalid vendor number. You should see the error message you coded in the
ERRMSG keyword.
__ 23. Enter a valid vendor number (10001-10050) again. Verify the error message is not
displayed.
__ 24. Press F3 to end the program. Your program should end.

8-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty End of exercise

© Copyright IBM Corp. 2002, 2014 Exercise 8. Coding an inquiry program 8-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

8-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty
Exercise 9. Procedures

What this exercise is about


This exercise provides an opportunity to code a procedure that can be used
like an RPG IV built-in function (BIF). Your procedure receives input and then
returns a value to the caller.

What you should be able to do


At the end of the lab, you should be able to:
• Code a procedure that returns a value to the caller
• Code a prototype for a procedure
• Code a procedure interface for a procedure
• Code a local variable for a procedure

Introduction
Given a complete loan payment calculator application, your task is to modify
certain inline calculations to create procedures that return a value to the
caller.
You are not required to write any new logic. All that you are required to do is
to move existing calculations to procedures. Then, you modify the current
procedure so that it calls the procedures.

© Copyright IBM Corp. 2002, 2014 Exercise 9. Procedures 9-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
Part 1: Write a procedure
In this portion of the exercise, you modify an existing program by moving some inline calculations
into two procedures and writing the code necessary to call them. You code the procedure interfaces
to define the parameters that are passed to the procedures.
__ 1. Create a new QRPGLESRC source member, RATPER. RATPER, a procedure, receives as
parameters the annual interest rate and number of payments per year, returning the periodic
interest rate.
__ 2. You do not have to code the prototype at this time. It is coded in a separate source member
in a later step.
__ 3. Code the procedure interface for RATPER on Definition specs. At some point your complete
procedure is an independent compile unit. The PI must precisely define all parameter
attributes in the expected sequence that they are passed from the caller.

9-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Use the following display file to help you to define your fields correctly:

© Copyright IBM Corp. 2002, 2014 Exercise 9. Procedures 9-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 4. Create the DSPF, LOANPAYD.


__ 5. Review LOANPAYSP as follows. A copy is in your library.

__ 6. Write code for the calculations of the RATPER procedure that calculate the periodic interest
rate for a loan. If you like, you can simply copy the calculation from your copy of
LOANPAYSP to RATPER.
__ 7. Write code for the procedure specifications of your RATPER procedure. Make it an
EXPORTable procedure. You may use the RDi procedure wizard if you know how to use it.
__ 8. Write code for the PI of your RATPER procedure.
__ 9. Write code for a RETURN operation in your RATPER procedure.
__ 10. Exit and add an appropriate text description to your new source member.

Part 2: Code a procedure prototype


__ 11. Create new QRPGLESRC source member RATPER_PR. The PR suffix is an abbreviation
for prototype. By writing code for a procedure prototype in a source member separate from
the rest of the procedure, you can /COPY the prototype into modules that call your
procedure, as well as modules that include it.
__ 12. Write code statements in this member for a prototype for the RATPER procedure. Be sure
that the PR statements match the requirements for the RATPER procedure. If necessary,
refer to the PI in RATPER for help.
__ 13. Exit and add appropriate descriptive text to your new source member.
__ 14. Enter the RATPER source member. Add a /COPY statement to include the RATPER_PR
source member.
__ 15. Create a module, RATPER, from the RATPER source member using the CRTRPGMOD
command. If errors are found, fix them and repeat until the member is created.

Part 3: Code another subprocedure and prototype


__ 16. Create another exportable procedure member PAYMNT in your source file QRPGLESRC.

9-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 17. This procedure receives the principal amount, rate per period, and total number of
payments. It returns the actual payment amount. See the above program LOANPAYSP for
the calculation of amount of the monthly payment. You can copy the calculation from your
LOANPAYSP to PAYMNT. You may use the RDi procedure wizard to create this procedure if
you know how.
__ 18. Exit and add an appropriate text description to your new source member.
__ 19. Now create another procedure prototype member PAYMNT_PR in your source file
QRPGLESRC. This prototype describes the input to your PAYMNT procedure. If necessary,
refer to the PI in PAYMNT for help.
Some programmers prefer to include all procedure prototypes in a single source member.
This approach is acceptable, but you might find including so many unused prototypes
unnecessarily cumbersome. Others prefer to reduce the number of unreferenced compiler
messages by including prototypes for only the procedures that are to be included in the
program. By coding each prototype in a separate source member, you can eliminate
unnecessary prototypes.
__ 20. Exit and add appropriate descriptive text to your new source member. You have created
code that can be used and reused to create local and exportable subprocedures.
__ 21. Enter your PAYMNT source member. Add a /COPY statement to include the PAYMNT_PR
prototype source member.
__ 22. Create a module from your PAYMNT source member using the CRTRPGMOD command. If
errors are found, fix them and repeat until the member is found.

Part 4: Include prototypes in a main program


__ 23. Modify your copy of LOANPAYSP. You might want to make a backup copy of the program.
__ 24. Code statements necessary to perform the loan payment calculation using your two new
subprocedures.
__ 25. Be sure that the rate and payment calculations are not performed within LOANPAYSP, but
rather in your subprocedures.
__ 26. Code the necessary /COPY statements to include the prototype source members at the
appropriate places in LOANPAYSP.
__ 27. Create a module from LOANPAYSP using the CRTRPGMOD command. If errors occur, fix
them and continue creating until a member is created.
__ 28. You should now have five new source members. LOANPAYSP is the member to be
compiled. Using the /COPY compiler directive, it directs the compiler to include the two
prototype source members at the appropriate points.

Part 5: Create a service program and main program


__ 29. Create a service program, RATES, using the CRTSRVPGM command that combines the
RATPER and PAYMNT modules. Use the EXPORT(*ALL) and ACTGRP(*CALLER)
parameters.

© Copyright IBM Corp. 2002, 2014 Exercise 9. Procedures 9-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 30. Create program LOANPAYSP using the CRTPGM command. Specify BNDSRVPGM(RATES)
and ACTGRP(*NEW).
__ 31. Test LOANPAYSP. You might experience an error if you do not enter a valid interest rate.
__ 32. If it operates correctly, you have created an RPG IV program using procedures.

End of exercise

9-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty
Exercise 10.Data structures and data areas

What this exercise is about


This exercise provides an opportunity to create a data area and retrieve its
contents from an RPG IV program.

What you should be able to do


At the end of the lab, you should be able to:
• Create a data area
• Retrieve the contents of a data area in an RPG IV program
• Modify and rewrite the contents of a data area from an RPG IV program

Introduction
In this lab, you start with a new program and display file. You modify the
display file VNDINQAR to include our company name and tax rate. You
modify the RPG program VNRINQAR to fetch the company name and tax
rate from a data area.

© Copyright IBM Corp. 2002, 2014 Exercise 10. Data structures and data areas 10-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
Part 1: Display output
__ 1. Review this sample display. Your output should be similar to it. Notice the company name in
the display.

Programming Supplies, International

RJSLANEY Vendor Inquiry AECAUX


March 29, 2002 11:55:54

Vendor number. . . . : 10050

Please press enter to continue


F3 = Exit

10-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty

Programming Supplies, International

RJSLANEY Vendor Inquiry AECAUX


March 29, 2002 11:55:54

Vendor number. . . . : 10050

Name . . . . . . : Genessee Office Products


Address . . . . : 1313 Koday Rd.
Binghamton NY 34506
Telephone. . . . : ( 816 ) 555-1313
Sales Person . . : Antonio Souchak
Purchases YTD . : 50,000.00
Balance Owed . . : 15,000.00

Tax Owed . . . . : 975.00

Please press enter to continue


F3 = Exit

Part 2: Copy existing members


__ 2. Make copies of the display file VNDINQAR and RPG IV member VNRINQAR member so
that you can modify them in this lab. Name your new members VNDINQDT and
VNRINQDT, respectively.

Part 3: Create a data area


Our company name was the RPG Supply Company. We are merging with another company
named Programming Supplies, International. We need to change all headings on our reports
and displays to reflect this new name. Management asked that you write our company name in
a data area so that we can access the company name without having to change and recompile
programs in the future.
In addition, the VP of Finance requested that we display the tax owed on any outstanding
balance. In speaking with the VP, we learn that the current tax rate is 6.5% and that the rate is
expected to change sometime this year.

© Copyright IBM Corp. 2002, 2014 Exercise 10. Data structures and data areas 10-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 3. Create a data area, COMPANY, of 50 characters in length and place Programming


Supplies, International in it as well as the 6.5% tax rate. The tax rate should be specified as
065 in the first three positions of the data area.
We are making the data area 50 bytes long just in case corporate decides to place more
information in it.
When you run CRTDTAARA, you need to use F4 to prompt. You should specify & in the
CRTDTAARA VALUE keyword (initial value) when prompting in order to extend the entry
area for complete input of the contents required.

Part 4: Modify your DSPF VNDINQDT


__ 4. Add the company name variable at the top of the existing display formats as shown in the
sample. If it is necessary, modify line numbers to avoid potential overlap.
__ 5. Define a new field, TAX (7,2), in the display file that holds the tax calculated based on the
balance owed.

Part 5: Modify your RPG member VNRINQDT


__ 6. Use a data structure to hold the information from your data area and to separate the
company name (character value) from the tax rate to be used in the program, which must be
numeric to be valid.
__ 7. Modify it so that the company name variable is retrieved from your data area and is
available to print at the top of the report.
__ 8. Also, retrieve the value of the tax rate from the data area.
__ 9. Calculate the tax to be displayed as the product of VNDBALANCE and the tax rate stored in
your data area.

Part 6: Compile and test


__ 10. If you have problems, check your compiler messages closely.

End of exercise

10-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty
Exercise 11.Maintaining database files

What this exercise is about


In this exercise, you update a database file based on transactions read from
another file.

What you should be able to do


At the end of the exercise, you should be able to:
• Use various opcodes to access database records
• Write a file maintenance program
• Use CPYF to populate a DB file with data

Introduction
Management has asked that you modify purchase order data with updates
that already have been entered into a transaction file. You are given the
transaction data file (POTRANS_PF) with several transactions already entered
into it. You are given a PRTF (POPMNT02) that produces a simple transaction
log.
The transactions update the data by using a logical view of the data. This LF
is also provided.
You are also given a program that does most of the job. You add the logic
that processes one type of transaction. Since you now know how to code
subroutines, write your code in a subroutine. Your responsibility is to:
• Review the purchase orders open line items file, POOPNLI_LF.
• Review the transaction file, POTRANS_PF.
• Review the PRTF that defines the audit report layout, POPMNT02.
• Modify the RPG IV program to process the transactions, update the
purchase orders line items file and produce the audit trail.

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise instructions
Part 1: Analyze the output report
__ 1. Review the following report that is the desired output that your program should produce.

...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...10....
16:08:04 Open Purchase Order File Maintenance Log 1/31/02

Trans
Code P.O. # Item # Qty OO Unit Cost Qty Recd. Date Recd. Status Message

A 300002 20023 5 100.00 5 2000/05/17 C Record Added


300005 20002 6 89.00 0 Before Transaction Processed
C 300005 20002 13 .00 0 Record Changed
D 300007 20028 0 .00 0 Record Deleted
300004 20013 3 100.00 3 1996/06/29 C Before Transaction Processed
C 300004 20013 7 .00 0 Record Changed
A 300002 20028 5 100.00 5 2000/05/17 C Record Added
D 300001 20070 0 .00 0 Record not found
C 300004 20071 25 .00 0 Record not found
300007 98877 0 .00 0 Invalid Transaction
A 300002 20023 5 100.00 5 2000/05/17 C Record already exists - not added
A 300002 20028 5 100.00 5 2000/05/17 C Record already exists - not added
d 300001 20007 0 .00 0 Invalid Transaction
c 300002 20015 8 85.00 0 2000/05/22 Invalid Transaction
D 300001 20007 0 .00 0 Record Deleted
300002 20015 10 2.50 0 Before Transaction Processed
C 300002 20015 8 85.00 0 2000/05/22 Record Changed
A 300002 20015 8 85.00 0 2000/05/22 Record already exists - not added
A 300009 20025 35 25.00 0 Record Added
A 300007 20035 25 25.00 0 Record Added

Additions 4
Deletions 2
Changes 3
Invalid Trans 8

Total Transactions 17

11-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty __ 2. Currently, the add transactions are treated as invalid transactions as you can determine
from the current report:

16:05:54 Open Purchase Order File Maintenance Log 1/31/02 Page 1

Trans
Code P.O. # Item # Qty OO Unit Cost Qty Recd. Date Recd. Status Message

A 300002 20023 5 100.00 5 2000/05/17 C Invalid Transaction


300005 20002 6 89.00 0 Before Transaction Processed
C 300005 20002 13 .00 0 Record Changed
D 300007 20028 0 .00 0 Record Deleted
300004 20013 3 100.00 3 1996/06/29 C Before Transaction Processed
C 300004 20013 7 .00 0 Record Changed
A 300002 20028 5 100.00 5 2000/05/17 C Invalid Transaction
D 300001 20070 0 .00 0 Record not found
C 300004 20071 25 .00 0 Record not found
300007 98877 0 .00 0 Invalid Transaction
A 300002 20023 5 100.00 5 2000/05/17 C Invalid Transaction
A 300002 20028 5 100.00 5 2000/05/17 C Invalid Transaction
d 300001 20007 0 .00 0 Invalid Transaction
c 300002 20015 8 85.00 0 2000/05/22 Invalid Transaction
D 300001 20007 0 .00 0 Record Deleted
300002 20015 10 2.50 0 Before Transaction Processed
C 300002 20015 8 85.00 0 2000/05/22 Record Changed
A 300002 20015 8 85.00 0 2000/05/22 Invalid Transaction
A 300009 20025 35 25.00 0 Invalid Transaction
A 300007 20035 25 25.00 0 Invalid Transaction

Additions
Deletions 2
Changes 3
Invalid Trans 12

Total Transactions 17

__ 3. The PRTF, which is provided to you, is named POPMNT02. Review the DDS and review the
sample report as you do so.

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 4. The POPMNT02 printer file should have been compiled in the previous exercise and should
exist in your library.

* POPMNT02 *

A REF(POTRANS_PF POLINE_PF)
A R HEADING SKIPB(2)
A 5TIME
A 22'Open Purchase Order File Maintenan-
A ce Log'
A 65DATE EDTCDE(Y)
A 80'Page'
A +1PAGNBR EDTCDE(J)
A SPACEA(2)
A**
A 1'Trans'
A 2'Code'
SPACEB(1)
A 8'P.O. #'
A 21'Item #'
A 30'Qty OO'
A 40'Unit Cost'
A 50'Qty Recd.'
A 60'Date Recd.'
A 71'Status'
A 78'Message'
A SPACEA(2)
A
A R TRNDETAIL SPACEA(1)
A TRNCODE R 3REFFLD(POTRAN_FMT/TRNCODE *LIBL/POT-
A RANS_PF)
A POTPONBR R 8REFFLD(POTRAN_FMT/POTPONBR *LIBL/PO-
A TRANS_PF)
A POTITMNBR R 20REFFLD(POTRAN_FMT/POTITMNBR *LIBL/P-
A OTRANS_PF)
A POTQTYOO R 30EDTCDE(J) REFFLD(POTRAN_FMT/POTQTYO-
A O *LIBL/POTRANS_PF)
A POTITMCOSTR 42REFFLD(POTRAN_FMT/POTITMCOST *LIBL/-
A POTRANS_PF) EDTCDE(J)
A POTQTYREC R 50EDTCDE(J) REFFLD(POTRAN_FMT/POTQTYR-
A EC *LIBL/POTRANS_PF)
A POTDATREC R 60REFFLD(POTRAN_FMT/POTDATREC *LIBL/P-
A OTRANS_PF) EDTWRD(' / / ')
A POTSTATUS R 74REFFLD(POTRAN_FMT/POTSTATUS *LIBL/P-
A OTRANS_PF)
A 10 78'Record not found'
A 11 78'Record already exists - not added'
A 12 78'Record Added'
A 13 78'Record Deleted'
A 14 78'Record Changed'
A 15 78'Invalid Transaction'
A
A R POORIG SPACEA(2)
A PONBR R 8REFFLD(POLINE_FMT/PONBR *LIBL/POLIN-
A E_PF)

11-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty A ITMNBR R 20REFFLD(POLINE_FMT/ITMNBR *LIBL/POLI-


A NE_PF)
A POLQTYOO R 30EDTCDE(J) REFFLD(POLINE_FMT/POLQTYO-
A O *LIBL/POLINE_PF)
A POLITMCOSTR 42REFFLD(POLINE_FMT/POLITMCOST *LIBL/-
A POLINE_PF) EDTCDE(J)
A POLQTYREC R 50EDTCDE(J) REFFLD(POLINE_FMT/POLQTYR-
A EC *LIBL/POLINE_PF)
A POLDATREC R 60REFFLD(POLINE_FMT/POLDATREC *LIBL/P-
A OLINE_PF) EDTWRD(' / / ')
A POLSTATUS R 74REFFLD(POLINE_FMT/POLSTATUS *LIBL/P-
A OLINE_PF)
A 78'Before Transaction Processed'
A
A R TOTAL SPACEB(3)
A 10'Additions'
A ADDCNT 5 0 40EDTCDE(Z) SPACEA(2)
A 10'Deletions'
A DELCNT 5 0 40EDTCDE(Z) SPACEA(2)
A 10'Changes'
A CHGCNT 5 0 40EDTCDE(Z) SPACEA(2)
A 10'Invalid Trans'
A ERRCNT 5 0 40EDTCDE(Z) SPACEA(3)
A 10'Total Transactions'
A TOTCNT 5 0 40EDTCDE(Z)

Part 2: Analyze the purchase orders open line item file


A*****************************************************************
A* PO Open Line Item LF: POOPNLI_LF
A*****************************************************************
A
A R POLINE_FMT TEXT('PO Line Item Record')
A PFILE(POLINE_PF)
A K PONBR
A K ITMNBR
__ 5. Browse the data in the POLINE_PF file. While you are processing the POOPNLI_LF logical
file, you need to understand the physical, POLINE_PF, on which it is based.
An SQL SELECT statement is provided to you in your QRPGLESRC file. It is named
LAB11SQL1. This statement displays the POLINE_PF data used in the program.
__ a. To run the SQL statement, you need to copy it. To do this, use the COPY facility of the
PC 5250 emulator (see the tool bar) to copy the text in your member.
__ b. Next, on a command line, enter STRSQL and press Enter.
__ c. You see a command screen with the heading Enter SQL Statements. Use the Page
Down key if the screen shows only a partial page of empty command lines.
__ d. Paste your SELECT statement to the right of the arrow (===>) and press Enter.
__ e. You see the results of your query. Once you understand the results, press Enter.
__ f. Then, use F3 to exit SQL.

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ g. When prompted to exit, press Enter.


If you have any problems, ask your instructor for assistance.

Part 3: Analyze the purchase order transaction file


__ 6. Review the DDS of the following transaction file. The transactions are already entered and
are provided to you in your library.
__ 7. Browse the data in the POTRANS_PF file.
Another SQL SELECT statement is provided to you in your QRPGLESRC file. It is named
LAB11SQL2.
This statement displays the POTRANS_PF data used in the program.
__ a. To run the SQL statement, you need to copy it as well. To do this, use the COPY facility
of the PC 5250 emulator (see the tool bar) to copy the text in your member.
__ b. Next, on a command line, enter STRSQL and press Enter.
__ c. You see a command screen with the heading Enter SQL Statements. Use the Page
Down key if the screen shows only a partial page of empty command lines.
__ d. Paste your SELECT statement to the right of the arrow (===>) and press Enter.
__ e. You see the results of your query. When you understand the results, press Enter.
__ f. Then, use F3 to exit SQL.
__ g. When prompted to exit, press Enter.
If you have any problems, ask your instructor for assistance.
A*****************************************************************
A* PO line Transaction PF: POTRANS_PF
A*****************************************************************
A REF(DICTIONARY)
A R POTRAN_FMT TEXT('PO Transaction Record')
A TRNCODE 1A TEXT('Transaction Code')
A COLHDG('Trans' 'Code')
A POTPONBR R REFFLD(PONBR)
A POTITMNBR R REFFLD(ITMNBR)
A POTQTYOO R REFFLD(POLQTYOO)
A POTITMCOSTR REFFLD(POLITMCOST)
A POTDATREC R REFFLD(POLDATREC)
A POTQTYREC R REFFLD(POLQTYREC)
A POTSTATUS R REFFLD(POLSTATUS)

Part 4: Program description


The program named PORMNT02 reads the POTRANS_PF file sequentially. Based upon the
transaction type, the current program changes an existing purchase order record or deletes an
existing record. All other transactions are considered to be invalid. You are responsible for
enhancing the existing program to handle an add transaction and for ensuring that the transaction
is processed correctly. See the sample report to understand the transactions that you process.

11-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Here is a more detailed description of the existing program:


__ 8. The PORMNT02 program handles page overflow, as your other programs do.
__ 9. For each transaction, PORMNT02 prints the POTRANS_PF transaction whether the
transaction is valid or invalid.
__ 10. For a delete transaction, PORMNT02 makes sure that the record to be deleted exists and
deletes it if found. The program prints the appropriate message and adds to the delete
counter for each valid delete transaction. If a record to be deleted is not found, the programs
print an error message and adds one to the error counter.
__ 11. For a change transaction, PORMNT02 checks first that the record exists. If it does, it prints
the POOPNLI_LF record before the POTRANS_PF update is applied; then, the program
updates the fields changed by the POTRANS_PF record, prints the change message and
adds one to the change counter.
If the change is invalid, PORMNT02 prints an error message and add to the error counter.
__ 12. When all transactions are processed, the program calculates the total number of
transactions processed, and prints not only the total of all transactions, but also the sum of
each type of transaction as shown on the report.

Part 5: Modify the PORMNT02 program


Your job is to add the logic to handle the add transaction, indicated by a transaction code of 'A'.
There are two places in the existing program that need your attention:
__ 13. In the SELECT group, check for an add transaction and execute the ADD subroutine, which
should be named AddSR.
__ 14. Code the subroutine to process a transaction with the code 'A':
__ a. Make sure that the record does not already exist. Use an I/O opcode that returns a
found or not found condition
__ b. If the add transaction is valid:
1) Print the appropriate message.
2) Add one to the add counter.
3) Build fields of the new record using the data from the POTRANS_PF.
4) Initialize any fields that are not referenced in the POTRANS_PF.
5) Write the new record to the file.
__ c. Handle an invalid addition by:
1) Printing an error message as shown on the report,
2) Adding one to the error count field.
__ 15. Review the code for the change and delete transactions. The process for much of your add
logic is similar.
__ 16. Review the current program and understand the logic. Notice the use of named indicators.

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Notice the modular coding style employing many subroutines:

11-8 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

11-10 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

11-12 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

EXempty Part 6: Compile and test your program


Because your program updates the POOPNLI_LF while you are testing, you might corrupt
the data. To refresh the data in the file, you should use the CPYF command. Copy the data
from the master copy that is in the AS06XXX library.
__ 17. When you are satisfied that the POOPNLI_LF file has been updated correctly and your
report is correct, you are finished.
__ 18. Otherwise, use your debugging skills as needed.

Part 7: Modify your program


__ 19. Notice that the key is constructed using KLIST/KFLD. Remove the KLIST/KFLD code.
__ 20. Construct the key to the POOPNLI_LF file using a parameter string.
__ 21. Compile and test your program. You need to refresh your POLINE_PF file before and after
the test.

End of exercise

© Copyright IBM Corp. 2002, 2014 Exercise 11. Maintaining database files 11-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

11-14 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

AP
Appendix A. Physical and logical files DDS

Field Reference PF: DICTIONARY


A*****************************************************************
A** Field Reference PF: DICTIONARY
A*****************************************************************
A R REFFMT TEXT('Field Reference File')
A*
A** Fields Used in Vendor Mastor File, VENDOR_PF
A*
A VNDNBR 5 0 TEXT('Vendor Number')
A COLHDG('Vend' 'Num')
A VNDNAME 25 TEXT('Vendor Name')
A COLHDG('Vendor' 'Name')
A VNDSTREET 25 TEXT('Vendor Street')
A COLHDG('Vendor Street')
A VNDCITY 23 TEXT('Vendor City')
A COLHDG('Vendor City')
A VNDSTATE 2 TEXT('Vendor State')
A COLHDG('Vnd' 'ST')
A VNDADDR3 25 TEXT('Address Line 3')
A COLHDG('Address Line 3')
A VNDZIPCODE 5 0 TEXT('Zip Code')
A COLHDG('Zip' 'Code')
A VNDAREACD 3 0 TEXT('Vendor Area Code')
A COLHDG('Vend' 'Area' 'Code')
A VNDTELNO 7 0 TEXT('Vendor Telephone Number')
A COLHDG('Vendor' 'Tel' 'No' )
A VNDDISCPCT 3 3 TEXT('Discount % For Prompt Pymt')
A COLHDG('Disc' 'Per' 'Cent')
A VNDDUEDAYS 2 0 TEXT('Days Until Payment is Due')
A COLHDG('Terms' 'Days')
A VNDCLASS 2 0 TEXT('Vendor Class')
A COLHDG('Vnd' 'Cls')
A VNDACTIVE 1 TEXT('A=Active D=Delete S=Suspend')
A COLHDG('Act' 'Rec' 'CD')
A VNDSALES 25 TEXT('Vendor Salesperson')
A COLHDG('Vendor' 'Sales' 'Person')
A VNDDISCMTD 7 2 TEXT('Discount Taken This Month')
A COLHDG('Vend' 'Disc' 'MTD')
A VNDDISCYTD 9 2 TEXT('Discount Taken This Year')
A COLHDG('Vend' 'Disc' 'YTD')
A VNDPRCHMTD 9 2 TEXT('Purchases This Month')
A COLHDG('Vend' 'Purch' 'MTD')
A VNDPRCHYTD 11 2 TEXT('Purchases This Year')

© Copyright IBM Corp. 2002, 2014 Appendix A. Physical and logical files DDS A-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

A COLHDG('Vend' 'Purch' 'YTD')


A VNDBALANCE 9 2 TEXT('Vendor Balance Owed')
A COLHDG('Vend' 'Balance' 'Owed')
A VNDSERVRTG 1 TEXT('Vendor Service Rating')
A COLHDG('Vnd' 'Srv' 'Rtg')
A VNDDLVRTG 1 TEXT('Vendor Delivery Rating')
A COLHDG('Vnd' 'Del' 'Rtg')
A VNDCOMMENT 25 TEXT('Comments About This Vendor')
A COLHDG('Comments')
A*
A* Fields Used In Item Master File, ITEM_PF
A*
A ITMNBR 5 0 TEXT('Item Number')
A COLHDG('Item' 'Num')
A ITMDESCR 25 TEXT('Item Description')
A COLHDG('Item' 'Description')
A ITMQTYOH 7 0 TEXT('Quantity on Hand')
A COLHDG('Qty' 'on' 'Hand')
A ITMQTYOO 7 0 TEXT('Quantity on Order')
A COLHDG('Qty' 'on' 'Order')
A ITMCOST 5 2 TEXT('Item Unit Cost')
A COLHDG('Item' 'Unit' 'Cost')
A ITMPRICE 5 2 TEXT('Item Unit Price')
A COLHDG('Item' 'Unit' 'Price')
A ITMVNDCAT# 7 TEXT('Vendor Catalog Number')
A COLHDG('Vendor' 'Catalog' 'Number')
A*
A** Fields Used For Purchase Order Summary File, POSUM_PF
A*
A PONBR 6 0 TEXT('Purchase Order Number')
A COLHDG('Purch' 'Order' 'Number')
A POTOTAMT 7 2 TEXT('Purchase Order Amount')
A EDTCDE(3)
A COLHDG('Purch' 'Order' 'Amount')
A PODATE 8 0 TEXT('PO Date: YYYYMMDD')
A COLHDG('PO' 'Date' 'YYYYMMD')
A POSTATUS 1 TEXT('O=On Order C=Complete +
A D=Delete')
A COLHDG('PO' 'Sts')
A VALUES(' ' 'O' 'C' 'D')
A*
A** Fields Used in Purchase Order Line Item File, POLINE_PF
A*
A POLQTYOO 5 0 TEXT('PO Item Quantity On Order')
A COLHDG('Qty' 'Ord')
A POLITMCOST 5 2 TEXT('Item Unit Cost')
A COLHDG('Item' 'Unit' 'Cost')
A POLDATREC 8 0 TEXT('Date Received')

A-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

AP A COLHDG('Date' 'Rec' 'YYYYMMDD')


A POLQTYREC 5 0 TEXT('Item Quantity Received')
A COLHDG('Qty' 'Rec')
A POLSTATUS 1 TEXT('Blank=On Order, C=Complete +
A D=Delete I=Incomplete')
A COLHDG('PO' 'Ln' 'Sts')
A VALUES(' ' 'C' 'D' 'I')
A*
A** Fields Used in Accounts Payable Open Invoice File, APINV_PF
A*
A APINVNBR 8 TEXT('Vendor Invoice Number')
A COLHDG('Vendor' 'Invoice' 'Number')
A APDATE 8 0 TEXT('Date Order Complete')
A COLHDG('Date' 'Compl' 'YYYYMMDD')
A APDISCOUNT 5 2 TEXT('Vendor Invoice Discount +
A Available')
A EDTCDE(3)
A COLHDG('Inv' 'Disc' 'Avail')
A APNETPAID 7 2 TEXT('Net Amount Paid')
A EDTCDE(3)
A COLHDG('Net' 'Amount' 'Paid')
A APSTATUS 1 TEXT('Blank=No Action D=Delete +
A T=To Pay P=Paid')
A COLHDG('AP' 'Sts')
A VALUES(' ' 'D' 'T' 'P')
A APDATEPAID 8 0 TEXT('Date Paid')
A COLHDG('Date' 'Paid' 'YYYYMMDD')
A APCHECK# 6 0 TEXT('Check Number')
A COLHDG('Check' 'Number')
A APDUEDATE 8 0 TEXT('Vendor Invoice Due Date +
A YYYYMMDD')
A COLHDG('Due' 'Date' 'YYYYMMDD')

© Copyright IBM Corp. 2002, 2014 Appendix A. Physical and logical files DDS A-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Accounts Payable Invoice PF: APINV_PF


A*****************************************************************
A* Accounts Payable Invoice PF: APINV_PF
A*****************************************************************
A REF(DICTIONARY)
A UNIQUE
A R APINV_FMT TEXT('Open Payables Record')
A PONBR R
A VNDNBR R
A APINVNBR R
A APDATE R
A POTOTAMT R
A APDISCOUNTR
A APNETPAID R
A APSTATUS R
A APDATEPAIDR
A APCHECK# R
A APDUEDATE R
A K PONBR

Item Master PF: ITEM_PF


A*****************************************************************
A* Item Master PF: ITEM_PF
A*****************************************************************
A REF(DICTIONARY)
A UNIQUE
A R ITEM_FMT TEXT('Item Master Record')
A ITMNBR R
A ITMDESCR R
A ITMQTYOH R
A ITMQTYOO R
A ITMCOST R
A ITMPRICE R
A VNDNBR R
A ITMVNDCAT#R
A K ITMNBR

A-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

AP Join LF for delinquency notices: PODLNQ_LF


A*****************************************************************
A* Join LF for delinquency notices: PODLNQ_LF
A*****************************************************************
A R PODLNQ_FMT JFILE(POSUM_PF POLINE_PF VENDOR_PF)
A J JOIN(1 2)
A JFLD(PONBR PONBR)
A JDUPSEQ(ITMNBR)
A J JOIN(1 3)
A JFLD(VNDNBR VNDNBR)
A* Fields from POSUM_PF:
A PONBR JREF(1)
A VNDNBR JREF(1)
A PODATE
A* Fields from POLINE_PF
A ITMNBR
A POLQTYOO
A POLITMCOST
A POLQTYREC
A* Fields from VENDOR_PF:
A VNDNAME
A VNDAREACD
A VNDTELNO
A VNDSALES
A*
A K VNDNBR
A K PONBR

PO line item LF: POITEM_LF


A*****************************************************************
A* PO line item LF: POITEM_LF
A*****************************************************************
A
A R POLINE_FMT TEXT('PO Line Item Record')
A PFILE(POLINE_PF)
A K ITMNBR
A O POLSTATUS CMP(EQ 'D')

© Copyright IBM Corp. 2002, 2014 Appendix A. Physical and logical files DDS A-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

PO line item PF: POLINE_PF


A*****************************************************************
A* PO line item PF: POLINE_PF
A*****************************************************************
A REF(DICTIONARY)
A UNIQUE
A R POLINE_FMT TEXT('PO Line Item Record')
A PONBR R
A ITMNBR R
A POLQTYOO R
A POLITMCOSTR
A POLDATREC R
A POLQTYREC R
A POLSTATUS R
A K PONBR
A K ITMNBR

PO Open Line Item LF: POOPNLI_LF


A*****************************************************************
A* PO Open Line Item LF: POOPNLI_LF
A*****************************************************************
A
A R POLINE_FMT TEXT('PO Line Item Record')
A PFILE(POLINE_PF)
A K PONBR
A K ITMNBR

PO Summary PF: POSUM_PF


A*****************************************************************
A* PO Summary PF: POSUM_PF
A*****************************************************************
A REF(DICTIONARY)
A UNIQUE
A R POSUM_FMT TEXT('PO Summary Record')
A PONBR R
A VNDNBR R
A POTOTAMT R
A PODATE R
A POSTATUS R
A K PONBR

A-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0
Student Exercises

AP Vendor master PF: VENDOR_PF


A*****************************************************************
A* Vendor master PF: VENDOR_PF
A*****************************************************************
A REF(DICTIONARY)
A UNIQUE
A R VENDOR_FMT TEXT('Vendor Master File Record')
A VNDNBR R
A VNDNAME R
A VNDSTREET R
A VNDCITY R
A VNDSTATE R
A VNDZIPCODER
A VNDAREACD R
A VNDTELNO R
A VNDDISCPCTR
A VNDDUEDAYSR
A VNDCLASS R
A VNDACTIVE R
A VNDSALES R
A VNDDISCMTDR
A VNDDISCYTDR
A VNDPRCHMTDR
A VNDPRCHYTDR
A VNDBALANCER
A VNDSERVRTGR
A VNDDLVRTG R
A VNDCOMMENTR
A K VNDNBR

Vendors by Name LF: VNDNAM_LF


A*****************************************************************
A* Vendors by Name LF: VNDNAM_LF
A*****************************************************************
A ALTSEQ(QSYSTRNTBL)
A R VENDOR_FMT PFILE(VENDOR_PF)
A K VNDNAME

© Copyright IBM Corp. 2002, 2014 Appendix A. Physical and logical files DDS A-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

A-8 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty
Appendix B. Exercise solutions

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 1: Coding and compiling RPG IV


dcl-s Message char(30) inz('The sum of 2 plus 2 is');
Dcl-s Sum packed(3) inz;
Sum = 2 + 2;
Message = %trimr(Message) + ' ' + %char(sum);
Dsply Message '*REQUESTER';
Return;

The field Sum was undefined because the D-spec was entered incorrectly and defined a field
named 'Sums'.

B-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Exercise 2: Sequencing RPG IV specifications and compiling


The CRTBNDRPG command is used to compile the program.

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exit, NotFound, and PrintIt are the indicators used in the program.
**********************************************************************
* VNRADR018 *
* Vendor Address Inquiry *
**********************************************************************
* This program prompts the user for a vendor number and displays *
* the vendor's address information on the screen. *
* *
* The user has options to exit the program and to print a vendor *
* record. *
* *
* INDICATORS: *
* Exit - the user requests to exit the program *
* PrintIt - the user requests to print vendor address *
* NotFound - no vendor found to match the input vendor number *
**********************************************************************
Ctl-opt DftActGrp(*yes) ExprOpts(*ResDecPos) DatFmt(*USA);
******************************************************************
// Vendor Display Formats
Dcl-f VndAdr01 workstn InDDS(WkStnInd);
// Vendor Data File
Dcl-F Vendor_PF disk(*ext) usage(*input) keyed;
// Report Formats
Dcl-F VnpAdr Printer(*ext) OflInd(PrtOver);
******************************************************************
Dcl-s ToDaysDate date;
// Named indicators used with display file
Dcl-ds WkStnInd;
Exit ind pos(3);
NotFound ind pos(99);
PrintIt ind pos(10);
end-ds;
******************************************************************
TodaysDate = %date(*date); // Get date from system
ExFmt Prompt_Fmt; // Prompt for vendor number
DoW Not Exit; // Do the following until user presses F3
(Exit)
NotFound= *off; // Initialize the record found indicator
Chain VndNbr Vendor_PF; // Find the vendor record
If %Found(Vendor_PF); // If we find a valid vendor record:
ExFmt Dsply_Fmt; // Disply the vendor record
If PrintIt; // If the user pressed F10,
Write Vnadd_Fmt; // print the vendor record
EndIf; // End if user pressed F10
Else; // We did not find a record
NotFound = *on; // Set the record found indicator on
EndIf; // End else no record found

B-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty ExFmt Prompt_Fmt; // Prompt for a new vendor number


EndDo; // End do while loop
Return; // End the program

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 3: Coding a report program


**********************************************************************
* ITRCOSTS *
* Cost of Inventory On Hand Report *
**********************************************************************
* *
* This program lists all the items in the ITEM_PF file. It computes *
* extended item cost by multiplying quantity on hand times item cost.*
* EXTENDED COST IS TOTALED FOR ALL ITEMS. *
* *
* INPUT FILE: ITEM_PF, externally described *
* Format: ITEM_FMT *
* *
* PRINTER FILE: ITPCOST, externally described. *
* Formats: HEADING, DETAIL, TOTAL *
* *
* INDICATORS: *
* LR - Close files, end program *
**********************************************************************
Dcl-f Item_PF disk(*ext) usage(*input) Keyed;
Dcl-f Itpcost Printer Include(Detail)
Include(Heading)
OflInd(PrtOver);
**
Write Heading; // Produce the heading
// Read first record to get started
Read Item_Pf;
DoW not %eof(Item_PF); // We have at least one record so
// enter loop to process remaining
// records.
Write Detail;
// Read subsequent records
Read Item_Pf;
EndDo;
Return;

B-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Exercise 4: Adding overflow


**********************************************************************
* ITRCOSTSE *
* Cost of Inventory On Hand Report *
**********************************************************************
* *
* This program lists all the items in the ITEM_PF file. It computes *
* extended item cost by multiplying quantity on hand times item cost.*
* EXTENDED COST IS TOTALED FOR ALL ITEMS. *
* *
* INPUT FILE: ITEM_PF, externally described *
* Format: ITEM_FMT *
* *
* PRINTER FILE: ITPCOST, externally described. *
* Formats: HEADING, DETAIL, TOTAL *
* *
* INDICATORS: *
* LR - Close files, end program *
**********************************************************************
Dcl-f Item_PF disk(*ext) usage(*input) Keyed;
Dcl-f Itpcost Printer Include(Detail)
Include(Heading)
OflInd(PrtOver);
// Headings on first page
Write Heading;
// Read first record to get started
Read Item_Pf;
Dow not %eof(Item_PF); // We have at least one record so
// enter loop to process remaining
// records.
// Headings on page overflow
If PrtOver; // check for overflow
Write Heading;
PrtOver = *Off;
Endif;
Write Detail; // Print detail record
Read Item_Pf; // read subsequent records
EndDo;
Return;

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 5: Data definition


Dcl-f Item_PF disk(*ext) usage(*input) Keyed;
Dcl-f POPList Printer OflInd(PrtOver);
Dcl-s Low zoned(3 : 0);
Dcl-s Count like(low : +2);
// Headings on first page
Write Heading;
// Read first record of file
Read Item_PF;
DoW not %eof(Item_PF);
// Page overflow?
If PrtOver;
Write Heading;
PrtOver = *Off;
EndIf;
// Accumulate totals
TotQtyAvl = ItmQtyOH + ItmQtyOO;
// Set indicator for Low Available Quantity
*in43 = (TotQtyAvl < 15);
// Accumulate low quantity situations
If *in43;
Low = Low + 1;
EndIf;
// Calculate value (at cost) of available inventory
AvlCost = ItmCost * TotQtyAvl;
// Calulate value (at retail) of available inventory
AvlPrice = ItmPrice * TotQtyAvl;
// Accumulate the total number of records processed
Count = Count + 1;
// Print the detail format
Write Detail;
// Read second and subsequent records of file
Read Item_PF;
EndDo;
// End of file processing
// Move the program accumulators to the printer file fields
LowCountP = Low;
TotCountP = Count;
// Print the record format for totals
Write Footing;
Return;

B-8 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Exercise 6: Adding arithmetic functions


// File Declarations
Dcl-f Item_PF Disk(*ext) usage(*input) keyed;
Dcl-f ItpCost Printer OflInd(PrtOver);
// Headings on first page
Write Heading;
// Read first record to get started
Read Item_Pf;
Dow not %eof(Item_PF); // We have at least one record so
// enter loop to process remaining
// records.
// Calculate cost on hand
ItmCostOH = ItmCost * ItmQtyOH;
// Calculate total cost on hand
TotCostOH = TotCostOH + ItmCostOH;
// Headings on page overflow
If PrtOver; // Check for overflow
Write Heading;
PrtOver = *Off;
Endif;
Write Detail; // Print detail record format
Read Item_Pf; // Read subsequent records
EndDo;
Write Total; // Print total record format
Return;

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 7: Data manipulation


//*************************************************************************
// VNRADR03S
// Active Vendor Report
//*************************************************************************
// Print listing of ACTIVE vendors from Vendor_PF file.
//
// INDICATORS:
// PrtOverFlow - Printer overflow
//
//*************************************************************************
Dcl-f Vendor_PF disk(*ext) usage(*input) Keyed; // Input database file
Dcl-f VnpAdr03 Printer OflInd(PrtOverFlow); // Output printer file
Write Heading; // Print page 1 heading
// Read first record
Read Vendor_Fmt; //Read input record
Dow not %eof (Vendor_PF); //While NOT EOF
// Include selection for only active records
If VndActive = 'A'; // For active rec only
// Put salesperson first name in smaller field on report
VndSales1 = %Subst(VndSales:1:
%scan(' ':VndSales));
// Check for overflow
If PrtOverFlow;
Write Heading;
PrtOverFlow = *off;
EndIf;
Write Detail; // Print detail record
// Increment counter of active records processed thus far
Count = Count + 1;
EndIf; // End if active record
Read Vendor_Fmt; // Read next record
EndDo;
// Total processing
// Check for overflow
If PrtOverFlow;
Write Heading;
EndIf;
Write Total; // Print record count
Return;

B-10 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Exercise 8: Coding an inquiry program

A**********************************************************************
A* VNDINQS *
A* Inquiry by Vendor Number Display File *
A**********************************************************************
A* THIS DISPLAY FILE CONTAINS THESE FORMATS: *
A* *
A* PROMPT_FMT - Prompts for Vendor Number *
A* DSPLY_FMT - Displays a vendor record *
A* *
A* INDICATORS: *
A* 03 - User requests to exit the program *
A* 12 - Cancel (Return to prompt screen) *
A* 60 - Balance due > 5000.00 *
A* 96 - Invalid vendor number *
A*****************************************************************
A REF(*LIBL/VENDOR_PF)
A INDARA
A CA03(03 'End Program')
A R PROMPT_FMT
A 1 2USER
A 1 30'Vendor Inquiry'
A COLOR(WHT)
A 1 71SYSNAME
A 2 61DATE
A EDTCDE(Y)
A 2 71TIME
A 3 3'Vendor number. . . . :'
A VNDNBR_INQR D I 3 28COLOR(WHT)
A REFFLD(VNDNBR DICTIONARY)
A 96 ERRMSG('Invalid vendor number - pre-
A ss reset and re-enter' 96)
A 22 3'Please press enter to continue'
A 23 4'F3 = Exit'
A COLOR(BLU)
A R DSPLY_FMT
A CA12(12 'Return to previous display-
A Display')
A 1 2USER
A 1 30'Vendor Inquiry'
A COLOR(WHT)
A 1 71SYSNAME
A 2 61DATE
A EDTCDE(Y)
A 2 71TIME

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-11


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

A 7 3'Vendor number . .:'


A VNDNBR R O 7 24
A 8 3'Name . . . . . . :'
A 9 3'Address . . . . :'
A VNDNAME R O 8 24
A VNDSTREET R O 9 24
A VNDCITY R O 10 24
A VNDSTATE R O 10 49
A VNDZIPCODER O 10 53
A 11 3'Telephone. . . . :'
A VNDAREACD R O 11 26
A 11 24'('
A 11 30')'
A VNDTELNO R O 11 33
A EDTWRD('0 - ')
A 12 3'Sales Person . . :'
A VNDSALES R O 12 24
A 13 3'Purchases YTD . :'
A VNDPRCHYTDR 13 24EDTCDE(J)
A 14 3'Balance Owed . . :'
A VNDBALANCER 14 26EDTCDE(J)
A 60 DSPATR(HI)
A 60 COLOR(RED)
A 23 4'F3 = Exit F12 = Return to previou-
A s Display'
A COLOR(BLU)
// Vendor master File
Dcl-f Vendor_PF Disk(*ext) usage(*input) keyed;
// Display File
Dcl-f Vndinqs Workstn IndDS(WkIndicators);
// Indicator Data Structure
Dcl-ds WkIndicators;
Exit ind pos(3);
Cancel ind pos(12);
HighBalance ind pos(60);
NotFound ind pos(96);
end-ds;
Exfmt Prompt_fmt; // Display Prompt_Fmt
Dow NOT Exit; // Continue process until user presses F3
Chain Vndnbr_inq Vendor_PF; // Read record; valid key?
If %found(Vendor_PF);
// Record found; display the Dsply_Fmt
DoW NOT Cancel;
// Check whether balance owed is greater than 5000.00
HighBalance = VndBalance > 5000.00;
// Display details
Exfmt Dsply_fmt;
IF Exit; // F3 pressed

B-12 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty *InLR = *ON;


Return; // exit program
Endif; // End if exit pressed
EndDo; // End while not canceled
Else; // Else vendor not found
NotFound = *on;
endif; // End else vendor not found
// No Item record found or F12 - display prompt
Cancel = *OFF; // Reset indicator
Exfmt Prompt_fmt; // Redisplay Prompt format
enddo; // end display loop
*InLR = *ON;
Return;

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-13


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 9: Procedures
Rate period prototype member
// RATPER - Calc dec periodic interest rate PROTOTYPE
Dcl-pr RatPer packed(13 : 11);
annualRate packed(5 : 3); // Annual % rate
payPerYear packed(2 : 0); // # payments per year
End-Pr;
Rate period procedure
ctl-opt nomain;
/Copy RatPer_PR
// RATPER - Calc dec periodic interest rate SUBPROCEDURE
Dcl-proc RatPer Export;
Dcl-PI RatPer packed(13 : 11);
annualRate packed(5 : 3); // Annual % rate
payPerYear packed(2 : 0); // # payments per year
End-pi;
Return ( annualRate * 0.01 ) / payPerYear;
End-proc RatPer;
Payment prototype member
** Calc loan payment PROTOTYPE
dcl-pr Paymnt packed(9 : 2);
Principal packed(9 : 2);
RatePeriod packed(13 : 11);
NbrPayTot packed(4 : 0);
End-Pr;
Payment procedure
ctl-opt nomain;
/Copy Paymnt_PR
Dcl-proc Paymnt Export;
// PAYMNT - Calc loan payment SUBPROCEDURE
dcl-pi Paymnt packed(9 : 2);
Principal packed(9 : 2);
RatePeriod packed(13 : 11);
NbrPayTot packed(4 : 0);
End-pi;
Return (Principal*RatePeriod) /
(1-(1/((1+RatePeriod)**NbrPayTot)));
End-proc Paymnt;

B-14 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Loan Payment main line


Dcl-f LoanPayD WorkStn IndDS(LoanPDS);
Dcl-ds LoanPDS;
Exit ind pos(3);
End-ds;
/Copy RatPer_PR
/Copy Paymnt_PR
ExFmt PayFmt;
DoW NOT Exit;
RatePeriod = Ratper(RatePCAnn :
NbrPayYr);
PaymentAmt = Paymnt(Principal :
RatePeriod :
NbrPayTot);
ExFmt PayFmt;
EndDo;
*InLR = *On;
Return;

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-15


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 10: Data structures and data areas


A**********************************************************************
A* VNDINQDTS *
A* Inquiry by Vendor Number Display File *
A**********************************************************************
A* THIS DISPLAY FILE CONTAINS THESE FORMATS: *
A* *
A* PROMPT_FMT - Prompts for Vendor Number *
A* DSPLY_FMT - Displays a vendor record *
A* HEADER_FMT - Displays header information *
A* FKEYS_FMT - Displays function key description *
A* *
A* INDICATORS: *
A* 01 - First time indicator *
A* 03 - User requests to exit the program *
A* 60 - Balance owed pver 5000.00 *
A* 96 - Invalid vendor number *
A*****************************************************************
A REF(*LIBL/VENDOR_PF)
A INDARA
A R HEADER_FMT
A CONAME 40 O 1 25
A 3 2USER
A 3 30'Vendor Inquiry'
A COLOR(WHT)
A 3 71SYSNAME
A TODAY 18 O 4 50
A* 4 61DATE
A* EDTCDE(Y)
A 4 71TIME
A R PROMPT_FMT PUTOVR
A OVERLAY
A CA03(03 'End Program')
A 6 3'Vendor number. . . . :'
A VNDNBR_INQR D B 6 28COLOR(WHT) OVRDTA
A REFFLD(VNDNBR DICTIONARY)
A 96 ERRMSG('Invalid vendor number' 96)
A R DSPLY_FMT PUTOVR
A OVERLAY
A 8 3'Name . . . . . . :'
A 9 3'Address . . . . :'
A VNDNAME R O 8 24OVRDTA
A VNDSTREET R O 9 24OVRDTA
A VNDCITY R O 10 24OVRDTA
A VNDSTATE R O 10 49OVRDTA
A VNDZIPCODER O 10 53OVRDTA

B-16 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty A 11 3'Telephone. . . . :'


A VNDAREACD R O 11 26OVRDTA
A 11 24'('
A 11 30')'
A VNDTELNO R O 11 33OVRDTA
A EDTWRD('0 - ')
A 12 3'Sales Person . . :'
A VNDSALES R O 12 24OVRDTA
A 13 3'Purchases YTD . :'
A VNDPRCHYTDR 13 24EDTCDE(J) OVRDTA
A 14 3'Balance Owed . . :'
A VNDBALANCER 14 26EDTCDE(J) OVRDTA
A 60 DSPATR(HI)
A 60 COLOR(RED)
A 16 3'Tax Owed . . . . :'
A TAX 7 2O 16 29EDTCDE(J) OVRDTA
A R FKEYS_FMT
A OVERLAY
A 22 3'Please press enter to continue'
A 23 4'F3 = Exit'
A COLOR(BLU)
H ExPrOpts(*ResDecpos)
// Vendor master File
Dcl-f Vendor_PF Disk(*ext) usage(*input) keyed;
// Display File
Dcl-f Vndinqdts Workstn IndDS(WkIndicators);
// Indicator Data Structure
Dcl-ds WkIndicators;
Exit ind pos(3);
Cancel ind pos(12);
HighBalance ind pos(60);
NotFound ind pos(96);
End-Ds;
Dcl-ds monthDS;
january char(9) inz('January');
february char(9) inz('February');
march char(9) inz('March');
april char(9) inz('April');
may char(9) inz('May');
june char(9) inz('June');
july char(9) inz('July');
august char(9) inz('August');
september char(9) inz('September');
october char(9) inz('October');
november char(9) inz('November');
december char(9) inz('December');
Months char(9) Dim(12) pos(1);
End-Ds;

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-17


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

// Data Structure to hold company name


Dcl-ds Company DTAARA;
TaxrateA char(3);
Taxrate zoned(3 : 3) OVERLAY(TaxRateA);
CoName char(40);
Empty char(7);
End-ds;
// get company name from Data area
// Write headings on first page of report
In Company;
// Convert month number to month name and format date
Today = %trimr(months(*month)) + ' '
+ %char(*day) + ', ' + %char(*year);
Write Header_Fmt;
Write Fkeys_Fmt;
Exfmt Prompt_fmt; // Display Prompt_Fmt
Dow NOT Exit; // Continue process until user presses F3
Chain Vndnbr_inq Vendor_PF; // Read record; valid key?
If %found(Vendor_PF);
// Record found; display the Dsply_Fmt
// Check whether balance owed is greater than 5000.00
HighBalance = VndBalance > 5000.00;
// Calcualte tax owed on balance
Tax = VndBalance * TaxRate;
// Display details
Write Dsply_fmt;
Else;
NotFound = *on;
endif;
// No Item record found or F12 - display prompt
Cancel = *OFF; // Reset indicator
Exfmt Prompt_fmt; // Redisplay Prompt format
enddo;
*InLR = *ON;
return;

B-18 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Exercise 11: Maintaining database files


ctl-opt actgrp(*caller) dftactgrp(*no) main(POMaintPgm);
//********************************************************************
// PORMNT02 *
// PO Maintenance - Open Line Items *
//********************************************************************
// *
// This program allows changes to the Open Line Items: *
// Additions *
// Deletions *
// Changes *
// *
// INDICATORS: *
// 10 - Record not found *
// 11 - Record exists (duplicate add) *
// 12 - Record added *
// 13 - Record deleted *
// 14 - Record changed *
// 15 - Invalid Transaction *
//********************************************************************
// PO Transaction File
Dcl-f POTRANS_PF DISK(*ext) usage(*input);
// Open Line Items File
Dcl-f POOPNLI_LF disk(*ext) usage(*UPDATE : *OUTPUT : *delete) Keyed;
// Maintenance Printer File
Dcl-f POPMNT02 PRINTER OFLIND(OverFlow) INDDS(Indicators);
Dcl-ds Indicators;
RecNotFound ind pos(10);
RecExists ind pos(11);
RecAdded ind pos(12);
RecDeleted ind pos(13);
RecChanged ind pos(14);
InvalidTrans ind pos(15);
End-Ds;
// Data structure for Line Item Key
dcl-ds LItmKey extname('POOPNLI_LF' : *key)
qualified;
End-Ds;
dcl-proc POMaintPgm;
dcl-pi POMaintPgm extpgm('PORMNT02S8');
End-Pi;
// Write headings on first page of report
Write Heading;
// Read first transaction record
Read POTrans_PF;
DoW not %eof(POTrans_PF);

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-19


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

// Reset Indicators
RecNotFound = *off;
RecExists = *off;
RecAdded = *off;
RecDeleted = *off;
RecChanged = *off;
InvalidTrans = *off;
// Set key values
LItmKey.PONBR = potponbr;
LItmKey.ITMNBR = potitmnbr;
// Process transactions
Select;
When Trncode = 'A';
AddSr();
When Trncode = 'D';
DelSr();
When Trncode = 'C';
ChgSr();
Other;
InvTrSr();
EndSl;
// Read next transaction record
Read POTrans_PF;
EndDo; //END DO while not end of file
// EOJ Processing
PrtTotals();
close POTRANS_PF;
close POOPNLI_LF;
close POPMNT02;
Return;
End-Proc;
// Additions
Dcl-proc ADDSR;
Dcl-pi Addsr;
End-Pi;
SetLL %kds(LItmKey) POOPNLI_LF;
If not %equal(POOPNLI_LF);
// If no record found (OK), add and set RecAdded
ponbr = potponbr;
ITMNBR = potitmnbr;
POLQTYOO = POTQTYOO;
POLITMCOST = POTITMCOST;
POLDATREC = POTDATREC;
POLQTYREC = POTQTYREC;
POLSTATUS = POTSTATUS;
WRITE POLINE_FMT;
RecAdded = *ON;
Addcnt = Addcnt + 1;

B-20 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty // If record exists, set RecExists


Else;
RecExists = *on;
ErrCnt = ErrCnt + 1;
EndIf; //END else record exists
// Print transaction
PrtDetail();
End-Proc;
// Deletions
dcl-proc DelSR;
dcl-pi DelSR;
End-Pi;
// Delete the record
// If no record found (Error), set RecNotFound
// If record exists (OK), delete and set RecDeleted
DELETE %kds(LItmKey) POOPNLI_LF;
If %found(POOPNLI_LF);
RecDeleted = *ON;
PONbr = PotPONbr;
Itmnbr = POTITMNBR;
Delcnt = Delcnt + 1;
Else;
RecnotFound = *on;
Errcnt = Errcnt + 1;
EndIf;
PrtDetail();
return;
End-Proc;
// Changes
dcl-proc ChgSr;
dcl-pi ChgSr;
End-Pi;
// Check for record
CHAIN %kds(LItmKey) POOPNLI_LF;
If %found(POOPNLI_LF);
// Print Original fields
PrtPOOrig();
// Update quantity
ponbr = potponbr;
ITMNBR = potitmnbr;
POLQTYOO = POTQTYOO;
POLITMCOST = POTITMCOST;
POLDATREC = POTDATREC;
POLQTYREC = POTQTYREC;
POLSTATUS = POTSTATUS;
// Change the record
UPDATE POLINE_FMT;
// If record exists, set RecChanged

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-21


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

RecChanged = *ON;
Chgcnt = Chgcnt + 1;
Else;
RecnotFound = *on; // Set if no record found
Errcnt = Errcnt + 1;
EndIf;
// Print transaction
PrtDetail();
return;
End-Proc;
// Invalid Transaction
dcl-proc InvTrSr;
dcl-pi InvTrSr;
End-Pi;
InvalidTrans = *on;
Errcnt = Errcnt + 1;
PrtDetail();
InvalidTrans = *off;
return;
End-Proc;
// Print Totals Subprocedure
Dcl-proc PrtTotals;
Dcl-pi PrtTotals;
End-Pi;
TotCnt = ChgCnt + DelCnt + ErrCnt + Addcnt;
CheckOV();
Write Total;
return;
End-Proc;
// Print original record fields, transaction and new fields
Dcl-proc PrtPOOrig;
Dcl-pi PrtPOOrig;
End-Pi;
CheckOV();
Write POOrig;
return;
End-Proc;
// Print transaction
Dcl-proc PrtDetail;
Dcl-pi PrtDetail;
End-Pi;
CheckOV();
Write TrnDetail;
return;
End-Proc;
// Check for Overflow
Dcl-proc CheckOV;
Dcl-pi CheckOV;

B-22 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty End-Pi;
If OverFlow;
Write Heading;
OverFlow = *off;
EndIf;
return;
End-Proc;
Another option for changing KLIST/KFLD to parameters:
1. Delete or comment out the KLIST/KFLD lines of code at the beginning of calculations.
2. Modify each opcode that uses the LitmKey to use a parameter string of (PotPONbr:
PotItmNbr). For example:
SetLL (PotPONbr : POItmNbr) POOPNLI_LF

© Copyright IBM Corp. 2002, 2014 Appendix B. Exercise solutions B-23


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

B-24 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty
Appendix C. Sample legacy programs
Included in this appendix are programs written before free-format calculations were available. The
purpose of providing these programs is to enable you to familiarize yourself with code that you will
encounter on the job.
Many of these programs are similar to the programs that you coded in the exercises.

Coding and compiling RPG IV

DMessage S 30 Inz('The sum of 2 plus 2 is')


DSum S 3 0 INZ
C Eval Sum = 2 + 2
C Eval Message = %trimr(Message) + ' ' +
C %char(sum)
C message dsply '*REQUESTER'
C Eval *inLr = *on
C return

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Sequencing RPG IV specifications and compiling

*****************************************************************
* VNDADR01 *
* Vendor Address Inquiry *
*****************************************************************
* This display file contains two record formats: *
* PROMPT_FMT - prompts the user for a vendor number *
* DSPLY_FMT - displays vendor address *
* *
* INDICATORS: *
* 03 - user requests to exit the program *
* 10 - user requests to print vendor address *
* 99 - invalid vendor number *
*****************************************************************
* CHANGE LOG *
* DATE PROGRAMMER DESCRIPTION *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
*01/22/96 R.P. Giv New File *
*****************************************************************
A DSPSIZ(24 80 *DS3)
A REF(*LIBL/VENDOR_PF)
A R PROMPT_FMT
A CA03(03)
A 1 2USER
A 1 71SYSNAME

A 1 30'Vendor Address Inquiry'


A DSPATR(HI)
A COLOR(WHT)

A 2 61DATE
A EDTCDE(Y)
A 2 71TIME

A 8 24'Enter Vendor Number . .'


A VNDNBR R B 8 50CHECK(RZ)
A 99 9 30'Invalid Vendor Number'
A COLOR(WHT)

A 12 29'Press Enter to Continue'


A COLOR(BLU)

A 23 4'F3 = Exit'
A COLOR(BLU)

C-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty A R DSPLY_FMT
A CA10(10 'Print Vendor Record')
A 1 2USER
A 1 30'Vendor Address Inquiry'
A DSPATR(HI)
A COLOR(WHT)
A 1 71SYSNAME

A 2 61DATE
A EDTCDE(Y)
A 2 71TIME

A 8 26'Vendor Number . . :'


A VNDNBR R O 8 48COLOR(WHT)

A VNDNAME R O 10 38COLOR(GRN)
A 10 19'Name . . . . . :'

A VNDSTREET R O 11 38COLOR(GRN)
A 11 19'Street . . . . :'

A 12 19'City/State/Zip :'
A VNDCITY R O 12 38COLOR(GRN)
A VNDSTATE R O 12 65COLOR(GRN)
A VNDZIPCODER O 12 70EDTCDE(Z)
A COLOR(GRN)
A 14 29'Press Enter to Continue'
A COLOR(BLU)

A 23 2'F10 = Print Vendor Address'


A COLOR(BLU)

*****************************************************************
* VNPADR *
* Vendor Address Report *
*****************************************************************
* This printer file formats the vendor address data. *
* INDICATORS: NONE *
*****************************************************************
* CHANGE LOG *
* DATE PROGRAMMER DESCRIPTION *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
* 1/22/96 SSSMITH New file. *
*****************************************************************
A REF(VENDOR_PF)
A R VNADD_FMT
A SKIPB(001)

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

A TEXT('VENDOR ADDRESS FORMAT')


A 30'VENDOR ADDRESS'
A SPACEA(1)
A 80DATE EDTCDE(Y)
A 90TIME SPACEA(1)
A
A 2'VENDOR #:'
A VNDNBR R 14
A VNDNAME R 30SPACEA(1)

A VNDSTREET R 30SPACEA(1)

A VNDCITY R 30
A VNDSTATE R 55
A VNDZIPCODER 60
A

**********************************************************************
* VNRADR01S *
* Vendor Address Inquiry *
**********************************************************************
* This program prompts the user for a vendor number and then displays*
* the vendor's address information on the screen. *
* *
* The user has options to exit the program and to print a report. *
* *
* INDICATORS: *
* 03 - EXIT - the user requests to exit the program *
* 10 - PRINT- the user requests to print vendor address *
* 99 - ERROR - no vendor found to match the input vendor number *
**********************************************************************
* *
* DATE PROGRAMMER DESCRIPTION *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
* 5/30/00 R.P. Giv New Program *
* *
******************************************************************
H Indent('| ')
******************************************************************
* Vendor Display Formats
FVndAdr01 CF E WorkStn
* Vendor Data File
FVendor_PF IF E K Disk
* Report Formats
FVnpAdr O E Printer
**********************************************************************
DToDaysDate s D

C-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty **********************************************************************
C Move Udate TodaysDate
C ExFmt Prompt_Fmt

C DoW Not *in03

C Eval *In99 = *OFF


C VndNbr Chain Vendor_PF
**
C If %Found(Vendor_PF)
C ExFmt Dsply_Fmt
**
C If *in10
C Write Vnadd_Fmt
C EndIf
C
C Else
C Eval *In99 = *ON
C EndIf
**
C ExFmt Prompt_Fmt
C EndDo
**
C Eval *inLr = *on

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Coding a report program

**********************************************************************
* ITRCOSTS *
* LIST OF INVENTORY ITEMS *
* *
* This program lists all the items in the ITEM_PF file. *
* *
* INPUT FILE: ITEM_PF, externally described *
* Format: ITEM_FMT *
* *
* PRINTER FILE: ITPCOST, externally described. *
* Formats: HEADING, DETAIL, TOTAL *
* *
* INDICATORS: *
* 73 - Printer overflow *
* LR - Close files, end program *
**********************************************************************
FItem_PF IF E K Disk
FItpcost O E Printer Oflind(*In73)
F Include(Detail)
**
C Read Item_Pf LR
C If not *InLR
C Write Detail
C Endif

C-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Adding overflow

**********************************************************************
* ITRCOSTOFS *
* Cost of Inventory On Hand Report *
**********************************************************************
* *
* This program lists all the items in the ITEM_PF file. It prints *
* headings on the first page and whenever overflow is encountered. *
* *
* INPUT FILE: ITEM_PF, externally described *
* Format: ITEM_FMT *
* *
* PRINTER FILE: ITPCOST, externally described. *
* Formats: HEADING, DETAIL, TOTAL *
* *
* INDICATORS: *
* 30 - first page processing complete *
* 73 - Printer overflow *
* LR - Close files, end program *
**********************************************************************
FItem_Pf IF E Disk
FItpcost O E Printer Oflind(*IN73)
F Ignore(Total)
** Write Headings on first page
C If Not *in30
C Write Heading
** Headings printed; bypass them next cycle
C Eval *In30 = *on
C EndIf
**
C Read Item_PF LR
C If not *InLR
** Check for overflow
C If *in73
C Write Heading
C Eval *in73 = *off
C EndIf
** Write detail line on report
C Write Detail
C Endif

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Alternate solution for adding overflow

** File Declarations
FItem_PF IF E K Disk
FItpCost O E Printer OfLind(*In73)
F Include(Detail)
F Include(Heading)

D FirstPage S N Inz(*On)

** Headings on first page


C If FirstPage
C Write Heading
C Eval FirstPage = *Off
C Endif

** Read next record


C Read Item_PF

C If %Eof(Item_PF)
C Eval *InLR = *ON

** Print if not yet EOF


C Else

** Headings on page overflow


C If *In73
C Write Heading
C Eval *In73 = *Off
C Endif

C Write Detail
C Endif

C-8 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Data definition

A REF(ITEM_PF)
** Page heading
A R HEADING SKIPB(6) SPACEA(1)
A 5DATE EDTCDE(Y)
A 30'Item Master Listing'
A 65'Page:'
A +1PAGNBR EDTCDE(Z)
A 5'Item No' SPACEB(2)
A 13'Description'
A 39'Qty On Hand'
A 52'Qty On Order'
A 66'Tot Avail'
A 78'Avail Cost'
A 90'Avail List'
** Item detail
A R DETAIL SPACEB(1)
A ITMNBR R 5
A ITMDESCR R 13
A ITMQTYOH R 41EDTCDE(J)
A ITMQTYOO R 55EDTCDE(J)
A TOTQTYAVL 8 0 65EDTCDE(J)
A 43 76'Low'
A AVLCOST R +2 80REFFLD(ITMCOST) EDTCDE(J)
A AVLPRICE R +2 90REFFLD(ITMPRICE) EDTCDE(J)
** Report ending
A R FOOTING SPACEB(2)
A 25'Low Stock Count'
A LOWCOUNTP 5 0 46EDTCDE(J) SPACEA(1)
A 25'Total Stock Count'
A TOTCOUNTP 8 0 42EDTCDE(J) SPACEA(1)
A
A 30'*** End of Listing ***'

FItem_PF IF E K Disk
FPOPList O E Printer Oflind(*In88)

D Low S 3 0
D Count S +2 Like(Low)

C If NOT *In99
** Headings on first page
C Write Heading
C Eval *In99 = *ON

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

C Endif

C Read Item_PF LR

C If *In88
** Page overflow
C Write Heading
C Eval *In88 = *Off
C Endif

C If *InLR
** End of file reached
C Eval LowCountP = Low
C Eval TotCountP = Count
C Write Footing
** Not EOF so process record
C Else

C Eval TotQtyAvl = ItmQtyOH + ItmQtyOO


C Eval *In43 = (TotQtyAvl < 15)
** Accumulate low quantity situations
C If *in43
C Eval Low = Low + 1
C EndIf
**
C Eval AvlCost = ItmCost * TotQtyAvl
C Eval AvlPrice = ItmPrice * TotQtyAvl
C Eval Count = Count + 1
C
C Write Detail

C Endif

C-10 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Adding arithmetic function

**********************************************************************
* ITRCOSTADS *
* Cost of Inventory On Hand Report *
**********************************************************************
* *
* This program lists all the items in the ITEM_PF file. It prints *
* headings on the first page and whenever overflow is encountered. *
* *
* INPUT FILE: ITEM_PF, externally described *
* Format: ITEM_FMT *
* *
* PRINTER FILE: ITPCOST, externally described. *
* Formats: HEADING, DETAIL, TOTAL *
* *
* INDICATORS: *
* 30 - first page processing complete *
* 73 - Printer overflow *
* LR - Close files, end program *
**********************************************************************
* CHANGE LOG *
* DATE PROGRAMMER DESCRIPTION *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
* 3/25/96 N. D. Cator New Program *
* *
**********************************************************************
FItem_Pf IF E Disk
FItpcost O E Printer Oflind(*IN73)
** Write Headings on first page
C If Not *in30
C Write Heading
** Headings printed; bypass them next cycle
C Eval *In30 = *on
C EndIf
**
C Read Item_PF LR
C If not *InLR
** Process each record as long as there are records (*inLR = EOF)
C Eval ItmCostOH = ItmCost * ItmQtyOH
C Eval TotCostOH = TotCostOH + ItmCostOH
** Check for overflow
C If *in73
C Write Heading
C Eval *in73 = *off
C EndIf

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

** Write detail line on report


C Write Detail
C EndIf
** End of file processing
C If *inLR
** Check for overflow
C IF *in73
C WRITE HEADING
C Eval *in73 = *off
C EndIf
** Print totals
C Write TOTAL
C EndIf

C-12 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Data manipulation

********************************************************************** ***
* VNRADR03S
* Active Vendor Report
**********************************************************************
* Print listing of ACTIVE vendors from Vendor_PF file.
*
* INDICATORS:
* 30 - first page processing complete *
* 88 - Printer overflow *
* LR - Close files, end program *
*
**********************************************************************
*
* DATE PROGRAMMER DESCRIPTION
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 5/17/2000 R. P. Gee New Program
*
**********************************************************************
FVendor_PF IF E K DISK
FVnpAdr03 O E Printer OflInd(*In88)
**********************************************************************
DVndSales1 S 16
**********************************************************************
C If Not *in30
C Write Heading
** Headings printed; bypass them next cycle
C Eval *In30 = *on
C EndIf
**
C Read Vendor_Fmt LR
C If not *InLR
** Include selection for only active records
C If VndActive = 'A'
** Move VENDOR_PF fields to VNPADR03 PRTF fields
C Eval VENDNAME = VndName
C Eval VENDSTREET = VndStreet
C Eval VENDCITY = VndCity
C Eval VENDSTATE = VndState
C Eval VENDZIPCD = VndZipCode
C Eval VENDAREACD = VndAreaCd
C Eval VENDPHONE = VndTelNo
** Put salesperson first name in smaller field on report
C Eval VndSales1 = %Subst(VndSales:1:
C %scan(' ':VndSales))
** Check for overflow

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

C If *in88
C Write Heading
C Eval *in88 = *off
C EndIf
**
C Write Detail
** Increment counter of active records processed thus far
C Eval Count = Count + 1
** End conditional logic for active records only
C EndIF
** EndIF for processing of records in file
C EndIf
** Total processing
C If *inLR
** Check for overflow
C If *in88
C Write Heading
C Eval *in88 = *off
C EndIf
**
C Write Total
C EndIf

C-14 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty Coding an inquiry program

A***************************************************************** ****
A* VNDINQS *
A* Inquiry by Vendor Number Display File *
A***************************************************************** ****
A* THIS DISPLAY FILE CONTAINS THESE FORMATS: *
A* *
A* PROMPT_FMT - Prompts for Vendor Number *
A* DSPLY_FMT - Displays a vendor record *
A* *
A* INDICATORS: *
A* 01 - First time indicator *
A* 03 - User requests to exit the program *
A* 96 - Invalid vendor number *
A*****************************************************************
A* CHANGE LOG *
A* DATE PROGRAMMER DESCRIPTION *
A* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
A* 8/01/96 N. D. Cator New Display File *
A*****************************************************************
A REF(*LIBL/VENDOR_PF)
A CA03(03 'End Program')
A R PROMPT_FMT
A 1 2USER
A 1 30'Vendor Inquiry'
A COLOR(WHT)
A 1 71SYSNAME
A 2 61DATE
A EDTCDE(Y)
A 2 71TIME
A 3 3'Vendor number. . . . :'
A VNDNBR_INQR D I 3 28COLOR(WHT)
A REFFLD(VNDNBR DICTIONARY)
A 96 ERRMSG('Invalid vendor number - pre-
A ss reset and re-enter' 96)
A 22 3'Please press enter to continue'
A 23 4'F3 = Exit'
A COLOR(BLU)
A R DSPLY_FMT
A CA12(12 'Return to previous display-
A Display')
A 1 2USER
A 1 30'Vendor Inquiry'
A COLOR(WHT)
A 1 71SYSNAME

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

A 2 61DATE
A EDTCDE(Y)
A 2 71TIME
A 7 3'Vendor number . .:'
A VNDNBR R O 7 24
A 8 3'Name . . . . . . :'
A 9 3'Address . . . . :'
A VNDNAME R O 8 24
A VNDSTREET R O 9 24
A VNDCITY R O 10 24
A VNDSTATE R O 10 49
A VNDZIPCODER O 10 53
A 11 3'Telephone. . . . :'
A VNDAREACD R O 11 26
A 11 24'('
A 11 30')'
A VNDTELNO R O 11 33
A EDTWRD('0 - ')
A 12 3'Sales Person . . :'
A VNDSALES R O 12 24
A 13 3'Purchases YTD . :'
A VNDPRCHYTDR 13 24EDTCDE(J)
A 14 3'Balance Owed . . :'
A VNDBALANCER 14 26EDTCDE(J)
A 60 DSPATR(HI)
A 60 COLOR(RED)
A 23 4'F3 = Exit F12 = Return to previou-
A s Display'
A COLOR(BLU)

** RPG program......: VNRINQS


** Vendor master File
FVendor_PF IF E K Disk
** Display File
FVndinqs CF E Workstn
**
C Dow NOT *In03
C Vndnbr_inq Chain Vendor_PF

C If %found(Vendor_PF)
C DoW NOT *In12
* Check whether balance owed is greater than 5000.00
C Eval *in60 = VndBalance > 5000.00
** Display details
C Exfmt Dsply_fmt

C IF *In03

C-16 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty C Eval *InLR = *ON


C Return
C Endif
c EndDo
c Else
C Eval *In96 = *on
c endif
** No Item record found or F12 - display prompt
C Eval *In12 = *OFF
C Exfmt Prompt_fmt
c enddo
C Eval *InLR = *ON
C Return
C IF *In03
C Eval *InLR = *ON
C Return
****************************************************************
C *Inzsr Begsr
C Exfmt Prompt_fmt
C Endsr

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Structured programming
This program uses CALLs; in this class, you used subprocedures and reworked a different
program.

** File declarations
FPodLnq_LF IF E K Disk

D Delinquent S 15P 5
D POCount S 2P 0
D BkOrdTotal S 7P 2
D StopCode S 1A Inz('N')

D PrvPONbr S Like(PONbr)
D PrvVndNbr S Like(VndNbr)
D PrvVndName S Like(VndName)
D PrvVndSales S Like(VndSales)
D PrvVndAreaCD S Like(VndAreaCD)
D PrvVndTelNo S Like(VndTelNo)

C *Entry Plist
C Parm Delinquent

C PorFaxParm Plist
C Parm Delinquent
C Parm BkOrdtotal
C Parm PrvVndName
C Parm PrvVndSales
C Parm PrvVndAreaCd
C Parm PrvVndTelNo
C Parm POCount
C Parm StopCode

C Read PodLnq_LF
C Exsr SaveDetail
C Dow Not %Eof(PodLnq_LF)

C If PoDate < Delinquent

C If PrvVndNbr = VndNbr

** New Purchase Order? If so, add to count


C If PrvPONbr <> PONbr
C Eval POCount = POCount + 1
C Eval PrvPONbr = PONbr
C Endif

C-18 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty C Else
** New Vendor - print/fax existing details before proceeding
C If POCount > 0
C Call 'PORFAX' PorFaxParm
C Endif
C Exsr SaveDetail
C Endif

** Accumulate totals regardless


C Eval BkOrdTotal = BkOrdTotal +
C ((PolQtyOO - PolQtyRec) * PolItmCost)
C Endif

C Read PodLnq_LF
C Enddo

C Eval StopCode = 'Y'


C Call 'PORFAX' PorFaxParm

C Eval *InLR = *ON


C Return

C SaveDetail Begsr
C Eval PrvVndNbr = VndNbr
C Eval PrvVndName = VndName
C Eval PrvVndSales = VndSales
C Eval PrvVndAreaCD = VndAreaCD
C Eval PrvVndTelNo = VndTelNo
C Eval POCount = 0
C Eval BkOrdTotal = 0
C Endsr

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Maintaining database files

**********************************************************************
* PORMNT02S *
* PO Maintenance - Open Line Items *
**********************************************************************
* *
* This program allows changes to the Open Line Items: *
* *
* INDICATORS: *
* 10 - Record not found *
* 11 - Record exists (duplicate add) *
* 12 - Record added *
* 13 - Record deleted *
* 14 - Record changed *
* 15 - Invalid Transaction *
* 88 - Printer Overflow *
**********************************************************************
** PO Transaction File
FPOTRANS_PFIF E DISK
** Open Line Items File
FPOOPNLI_LFUF A E K DISK
** Maintenance Printer File
FPOPMNT02 O E PRINTER OFLIND(*in88)
**
** Build the Line Item Key
C LItmKey KLIST
C KFLD POTPONBR
C KFLD POTITMNBR
** Write headings on first page of report
C Write Heading
** Read first transaction record
C Read POTrans_PF
C DoW not %eof(POTrans_PF)
** Reset Indicators
C Eval *in10 = *off
C Eval *in11 = *off
C Eval *in12 = *off
C Eval *in13 = *off
C Eval *in14 = *off
C Eval *in15 = *off
** Process transactions
C Select
*
C When Trncode = 'A'
C Exsr AddSr

C-20 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty *
C When Trncode = 'D'
C Exsr DelSr
*
C When Trncode = 'C'
C Exsr ChgSr
C Other
C Exsr InvTrSr
C EndSl
** Read next transaction record
C Read POTrans_PF

C EndDo
** EOJ Processing
C Exsr PrtTotals
C Eval *inlr = *on

** Additions
C ADDSR BEGSR
** Record already exists?
C LItmKey Chain POOPNLI_LF
C If not %found(POOPNLI_LF)
C Eval ponbr = potponbr
C Eval ITMNBR = potitmnbr
C EVAL POLQTYOO = POTQTYOO
C Eval POLITMCOST = POTITMCOST
C EVAL POLDATREC = POTDATREC
C EVAL POLQTYREC = POTQTYREC
C Eval POLSTATUS = POTSTATUS
** If no record found (OK), add and seton 12
C WRITE POLINE_FMT
C EVAL *IN12 = *ON
C Eval Addcnt = Addcnt + 1
** If record does exist (error), seton 11
C Else
C Eval *in11 = *on
C Eval ErrCnt = ErrCnt + 1
C EndIf
** Print transaction
C Exsr PrtDetail
C ENDSR
** Deletions
C DelSR BEGSR
** Delete the record
** If no record found (Error), seton 10
** If record exists (OK), delete and seton 13
C LItmKey DELETE POOPNLI_LF
C If %found(POOPNLI_LF)

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

C Eval *IN13 = *ON


C Eval Delcnt = Delcnt + 1
C Else
C Eval *in10 = *on
C Eval Errcnt = Errcnt + 1
C EndIf
C
C Exsr PrtDetail
C ENDSR
** Changes
C ChgSr BEGSR
** If no record, seton *IN10
C LItmKey CHAIN POOPNLI_LF
C If %found(POOPNLI_LF)
* Print Original fields
C Exsr PrtPOOrig
* Update quantity
C Eval ponbr = potponbr
C Eval ITMNBR = potitmnbr
C EVAL POLQTYOO = POTQTYOO
C Eval POLITMCOST = POTITMCOST
C EVAL POLDATREC = POTDATREC
C EVAL POLQTYREC = POTQTYREC
C Eval POLSTATUS = POTSTATUS
** Change the record
C UPDATE POLINE_FMT
** If record exists, seton 14
C EVAL *IN14 = *ON
C Eval Chgcnt = Chgcnt + 1
C Else
C Eval *in10 = *on
C Eval Errcnt = Errcnt + 1
C EndIf
** Print transaction
C Exsr PrtDetail
C ENDSR
C
** Invalid Transaction
C InvTrSr BegSr
C Eval *in15 = *on
C Eval Errcnt = Errcnt + 1
C Exsr PrtDetail
C Eval *in15 = *off
C EndSr
** Print Totals Subroutine
C PrtTotals Begsr
C Eval TotCnt = ChgCnt + DelCnt + ErrCnt + Addcn
C ExSr CheckOV

C-22 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty C Write Total


C EndSr
** Print original record fields, transaction and new fields
C PrtPOOrig BegSr
C ExSr CheckOV
C Write POOrig
C EndSr
**
C PrtDetail BegSr
C ExSr CheckOV
C Write TrnDetail
C EndSr
** Check for Overflow
C CheckOV BegSr
C If *in88
C Write Heading
C Eval *in88 = *off
C EndIf
C EndSr

© Copyright IBM Corp. 2002, 2014 Appendix C. Sample legacy programs C-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

C-24 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty
Appendix D. Rational Developer for Power
Systems

Sample startup and use example for Exercise 1


Part 1: Start Remote Systems Explorer (RSE)
RSE allows you to connect to an i server and define a collection of filters (lists of items that you
define). You can then access and operate on whatever items are of interest you.
First you must start the product. Follow these steps to start the product:
__ 1. Click Start on the task bar of your Desktop.
__ 2. Select Programs or All Programs, depending on your system.
__ 3. Select IBM Software Delivery Platform > IBM Rational Developer for I V9.1 > IBM
Rational Developer for i.
__ 4. A dialog will appear. Here you specify the directory of the workspace where your projects
and other resources, such as folders, subfolders, and files that you are developing in the
workbench, will reside.

__ 5. Change the field in this dialog and use a unique directory name, for example, AS06nnn
(where nnn is your team number, such as AS06001).
Ensure the Use this as the default and do not ask again checkbox is not selected.
__ 6. Click OK to open the Workbench.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 7. Click the icon in the top, middle of the Welcome page to go to the Workbench.

D-2 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 8. Click the maximize button to maximize or the restore button to return the Workbench to its
original size.

__ 9. Click the X in the IBM i RSE Getting Started tab. This display is always available by
choosing the Help > IBM i RSE Getting Started menu option.
A workbench is a desktop development environment. The workbench aims to achieve
seamless tool integration and controlled openness by providing a common paradigm for the
creation, management, and navigation of workbench resources. Each workbench window
contains one or more views and an editor.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Part 2: Opening the Remote System Explorer perspective


__ 10. Check for the name of the perspective.

D-4 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 11. If you see a different perspective (not the Remote System Explorer) in the Workbench, or no
perspective, click Window > Open Perspective > Remote System Explorer from the
Workbench menu.
The Remote System Explorer perspective opens.

You work in the Remote System Explorer perspective in the Workbench. This perspective
allows an IBM i programmer to display the connections that she has already configured,
create a new connection, connect to and disconnect from the connections that she has
defined, and work with IBM i files, commands, jobs, and integrated file system files.
When you first open the Remote System Explorer, you are not connected to any System
except your local hard drive on your workstation. To connect to a remote IBM i system, you
need to define a connection. When you define a connection, you specify the name or IP
address of the remote system and you give your connection a unique name that acts as a
label in your workspace so that you can easily connect and disconnect. When you connect
to the IBM i system, the workbench prompts you for your user ID and password on that host.
The first time you connect to an IBM i system, you need to specify a profile. All connections,
filters, and filter pools belong to profiles.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 12. In the Remote Systems view, New Connection is automatically expanded to show the
various remote systems types you can connect to through the Remote System Explorer.

__ 13. Double-click the IBM i icon to configure a connection to an i system.

D-6 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 14. The profile defaults to the name of the workstation. The Remote IBM i System Connection
page opens.
On this page, you specify the information for your connection. The cursor on this page is
positioned in the Host name field.
In the Host name field, type <i_server> (check with your instructor if you do not remember
the system name or IP address to enter).

__ 15. Leave the Parent profile default value. You do not need to change it.
__ 16. Leave the Verify host name checkbox selected.
__ 17. Click Finish to define your system.
You have configured a connection.
__ 18. In the Remote Systems view, your new connection is expanded to reveal your subsystems.
The Objects subsystem is the subsystem you will use most often. It is very similar to PDM
in that it allows you to access objects in the QSYS file system and to perform actions on
those objects.
__ 19. Once expended, the first three entries under the Objects subsystem are named after the
PDM options, because they have similar capabilities:
• Work with libraries is similar to WRKLIBPDM.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

• Work with objects is similar to WRKOBJPDM.


• Work with members is similar to WRKMBRPDM.
• In addition, there are entries for working with library lists and user libraries:
- Library list is similar to WRKLIBPDM in PDM. You can start with the predefined
library list filter that, when expanded, lists all libraries in your library list.
- User libraries allow you to work with all user libraries you can access on that i server.
You also have more entries to work with under the connection itself, and you can see from
these entries that Remote System Explorer goes well beyond PDM. It allows you to explore
i jobs and commands and the integrated file system.
__ 20. Work with a library in your library list, and add the library that you will be using in this
exercise:
Right-click Objects and select Properties on the menu.

D-8 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 21. Select Initial Library List on the left pane.


__ 22. Type the name of <your library> in the Library field, and click Add.

__ 23. Click OK.


This will add the library to your library list every time you use this connection.
__ 24. Expand the Library list folder.
Now, the connection will be activated, and you will be prompted for a user ID and password.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 25. Enter <i_userid> and <i_password>.


Make sure that the Save user ID checkbox is unchecked.
Make sure that the Save password checkbox is unchecked.
Click OK.

D-10 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty As you know, you can use the properties of any of the subsystems to set connection
information such as adding a library to a library list. Back in the Workbench in the Remote
Systems view when you click the Refresh icon, you will see the libraries in your job's
library list.

__ 26. Click the + beside Work with members...


__ 27. In the Library entry field, type AS06nnn.
__ 28. In the File entry field, type QRPGLESRC.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 29. Click the Next button, and on the subsequent filter name display, type QRPGLESRC as the
name of this new filter. Click Finish.

__ 30. Repeat the above steps to add a filter for your QDDSSRC source file in your library.

D-12 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 31. Your RSE Workbench should now look similar to the one below.

Part 3: Start the LPEX editor


__ 32. Right-click your QRPGLESRC filter icon and select New > member.
__ 33. On the IBM i Source Member display, verify that your library AS06nnn and source file
QRPGLESRC are already completed. For member name, type DEVPGM01R. For member type,
use the scroll bar to select RPGLE. For the text prompt, type the following:
Lab Exercise 1B Compile of an RPG IV program.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Click Finish.

__ 34. Once the editor window opens, enter the code that follows into your source member.

D-14 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V9.0
Student Exercises

EXempty __ 35. Here is the code that you enter into your QRPGLESRC file, member DEVPGM01. The lines
should start in column 8:
dcl-s Message char(30) inz('The sum of 2 plus 2 is');
Dcl-s Sums packed(3) inz;

sum = 2 + 2;
message = %trimr(Message) + ' ' + %char(sum);

Dsply message '*REQUESTER';

return;
__ 36. Save the file as it is to your QRPGLESRC file on the i by selecting File > Save. The member is
then written to your QRPGLESRC source file with a member name of DEVPGM01R. Do not
close the member. In The next step, you will create (compile) the program.

Part 4: Compile your RPG IV program


__ 37. Open the source member DEVPGM01R in QRPGLESRC in your library AS06nnn (by clicking
that item in the RSE workspace) if you have previously closed it. Your RPGLE program for
this source file member is now ready to compile. Click Compile > Compile > CRTBNDRPG
(without prompting). There is an error window (tab named Error List) if your program has
any warnings or errors. The Command Log tab will display the status of your compile.

Part 5: Run your RPG IV program


__ 38. Sign on to a 5250 session on the i server. Issue the command DSPLIB AS06nnn and check
that your program DEVPGM01R exists as a *PGM. Assuming it does, on the command line,
enter CALL DEVPGM01R. You should see the message.

© Copyright IBM Corp. 2002, 2014 Appendix D. Rational Developer for Power Systems D-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

D-16 RPG IV Programming Fundamentals © Copyright IBM Corp. 2002, 2014


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V10.0

backpg
Back page

You might also like