AS06 Student Exercise
AS06 Student Exercise
cover
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.
TOC Contents
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Exercises description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
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.
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.
EXempty
Exercise 1. Coding and compiling RPG IV
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.
__ 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.
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.
© 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.
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.
© 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.
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
© 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.
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.
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);
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.
End of exercise
EXempty
Exercise 2. Sequencing RPG IV specifications and
compiling
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.
EXempty
© 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
End of exercise
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
EXempty
Exercise 3. Coding a report program
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
Files used
All files are externally described:
• Physical file ITEM_PF (input) to be processed by key
• Printer file ITPCOST
© 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
EXempty
Exercise 4. Adding overflow
Introduction
Enhance the program that produced the listing of the records in the ITEM_PF
database file. You improve your listing program.
Files used
All files are externally described:
• Physical file ITEM_PF (input) to be processed by key
• Printer file ITPCOST
End of exercise
EXempty
Exercise 5. Data definition
Introduction
Using either the LPEX editor, modify an existing member, named PORLIST
adding appropriate File specs and Definition specs given the following
specifications.
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;
// Page overflow?
If PrtOver;
Write Heading;
PrtOver = *Off;
EndIf;
// Accumulate totals
TotQtyAvl = ItmQtyOH + ItmQtyOO;
// Set indicator for Low Available Quantity
*in43 = (TotQtyAvl < 15);
Item No Description Qty On Hand Qty On Order Tot Avail Avail Cost Avail List
__ 4. There are some fields used that you will define in your program to produce low stock count
and total stock count.
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.
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.
End of exercise
EXempty
Exercise 6. Adding arithmetic functions
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
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.
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.
End of exercise
EXempty
Exercise 7. Data manipulation
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
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.
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
__ 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.
__ 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.
End of exercise
EXempty
Exercise 8. Coding an inquiry program
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
© 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.
© 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
EXempty
Exercise 9. Procedures
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.
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.
EXempty Use the following display file to help you to define your fields correctly:
__ 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.
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.
__ 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
EXempty
Exercise 10.Data structures and data areas
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.
EXempty
© 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
End of exercise
EXempty
Exercise 11.Maintaining database files
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
Additions 4
Deletions 2
Changes 3
Invalid Trans 8
Total Transactions 17
EXempty __ 2. Currently, the add transactions are treated as invalid transactions as you can determine
from the current report:
Trans
Code P.O. # Item # Qty OO Unit Cost Qty Recd. Date Recd. Status Message
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)
© 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
© 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
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
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
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
AP
Appendix A. Physical and logical files DDS
© 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
© 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
© 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
© 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
EXempty
Appendix B. Exercise solutions
The field Sum was undefined because the D-spec was entered incorrectly and defined a field
named 'Sums'.
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
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
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;
// 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;
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;
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
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.
© 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
*****************************************************************
* 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 2 61DATE
A EDTCDE(Y)
A 2 71TIME
A 23 4'F3 = Exit'
A COLOR(BLU)
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 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)
*****************************************************************
* 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 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
EXempty **********************************************************************
C Move Udate TodaysDate
C ExFmt Prompt_Fmt
© 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
**********************************************************************
* 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
**********************************************************************
* 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
** 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)
C If %Eof(Item_PF)
C Eval *InLR = *ON
C Write Detail
C Endif
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 Endif
**********************************************************************
* 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
********************************************************************** ***
* 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
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)
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
© 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 PrvVndNbr = VndNbr
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
C Read PodLnq_LF
C Enddo
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
**********************************************************************
* 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
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
© 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
EXempty
Appendix D. Rational Developer for Power
Systems
__ 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.
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
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.
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
© 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
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.
© 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.
EXempty __ 31. Your RSE Workbench should now look similar to the one below.
© 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.
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);
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.
© 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
backpg
Back page