Vous êtes sur la page 1sur 74

Moving from RPG/400

to RPG IV

Student Exercises
Student Exercises

Exercise Description
You are given the opportunity to work through the exercises given
what was taught in lecture using your Student Notebook and the
reference materials.

In this class, you will be provided with working code that you must
update to include the version 5 features covered in the lecture unit
as well as features from previous units when they apply.

You will be assigned a user id and initial password that will be


used to sign on. A profile, library, and outq have already been
created for you:
USRPRF(OE85nnn)
PASSWRD(OE85)
CURLIB(OE85nnn)
OUTQ(OE85nnn/OUTQ)
Your student profile (OE85nnn) has authority to your own objects
but you do not have authority to other students' libraries.

Passwords
Your password, OE85, is set to expire at initial signon. Please
change your password to something that you can easily
remember.

You will be prompted to type STUDENT NAME when first signing


on to the iSeries system. This information is stored in the user
profile TEXT field with the date that the profile was first used. At
each signon, the user's name in the user profile is concatenated
with the user id and inserted in the job's PRTTXT environment to
help identify printed reports for the students.

All objects that you require to solve the problems are included in
your student library. Should any object be accidentally deleted or
corrupted, you may refresh the appropriate object by copying the
original master files from the Student Master Library, OE85XXX.

Exercise Description v
Student Exercises

Authority and Solving Lab Problems

You have authority to your student OE85nnn library objects.


You have *USE authority to objects in OE85XXX that you may
use to refresh your lab objects and members when required.

As you perform your labs, deliberately use as many features of


RPG IV as possible.

Should you have any problem that you cannot solve on your
own, please ask your instructor for assistance.

vi RPG/400 to RPG IV
Student Exercises

Exercise 1. APPVEND Record List

What This Exercise is About


This exercise provides an opportunity to create a simple RPG IV
program and get acquainted with the new specification layouts
supported in SEU.

The program will list all the records in a supplied database file
(APPVEND) using an externally described printer file (APPLIST),
calculating some additional fields for the report.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use RPG IV format prompts in SEU
Edit, compile and run a simple RPG IV program

Required Materials
Reference the record and file layouts in your appendix.

Exercise 1. APPVEND 1-1


Student Exercises

Exercise Instructions

1. Preparation
a. Verify that the source members APPFREF, APPVEND and APPLIST are in
QDDSSRC in your library. Review each of the source members, and
familiarize yourself with the field names used in APPVEND and APPLIST.
You will find the DDS in the appendix of this notebook.
APPLIST Printer File

A REF(APPFREF)
**
A R HEADFORMAT SKIPB(1) SPACEA(1)
A 5'Number'
A 12'Supplier Name'
A 39'Address'
A 67'Zip'
A 76'Purchases YTD'
A 97'Balance'
A 108'Monthly Amt'
**
A R LISTFORMAT SPACEB(1)
A VNDNBR R 5
A VNDNAM R +2
A VNDAD1 R +2
A VNDZIP R +2
A PCHYTD R +4EDTCDE(J)
A BALOWE R +2EDTCDE(J)
A MONTHLY R +2EDTCDE(J) REFFLD(BALOWE)
A LARGEBAL 2 +4

2. Code APPVENDPRT
a. Code a new RPG IV program APPVENDPRT in your QRPGLESRC source
file to produce a list of every record in APPVEND. Use the print formats
provided in APPLIST. Pay particular attention to the following:
1) The member type should be RPGLE.
2) the field MONTHLY which is to be calculated by dividing BALOWE by
the value 12
3) the field LARGEBAL which should contain two asterisks '**' if
BALOWE contains a value greater than 5000, (otherwise the field
should remain blank)
4) use SEU formatted prompting for the various specification types, and
review obvious changes

1-2 RPG/400 to RPG IV


Student Exercises

5) do not be concerend with coding the logic for page overflow of


APPVENDPRT in this program.
b. Compile your program using PDM option 14. Prompt this option and
review the compile command and its parameters, taking the defaults.
c. Once your program has compiled, review the compiler listing.
d. Run your program to produce the APPLIST report. Verify your results
with the sample that follows.

Exercise 1. APPVEND 1-3


Student Exercises

Sample listing of output of APPVENDPRT program

Number Supplier Name Address Zip Purchases YTD Balance Monthly Amt
00688 SHARON PHILIPS CORP. 3468 NETOWN RD. 01610 500,000.00 25,000.00 2,083.33 **
63218 ACE DISTRIBUTORS 461 DELMAR RD. N.E. 72183 20,000.00 .00 .00
13130 T.M.ELLIOT INC. 681 MAIN ST. 34216 25,000.00 17,500.00 1,458.33 **
00016 BRAND X BEER TALLMAN BLDG. 64538 70,000.00 30,000.00 2,500.00 **
01148 JOHNSON & SONS 45 PARKWAY SO. 94034 6,850,000.00 750,000.00 62,500.00 **
00021 MEMORIAL CARETAKERS LAWRENCEVILLE HWY. 20438 100,000.00 35,000.00 2,916.66 **
00221 GEORGE RUDOLPH INC. 3184 BLDG. 6 13645 2,500.00 500.00 41.66
05075 PETER VAN ROTH CORP. VAN ROTH BLDG. 71063 100,000.00 20,000.00 1,666.66 **
10504 THE DEANA AGENCY 280 PARK AVENUE 10017 5,000,000.00 750,000.00 62,500.00 **
11002 THE DISK RECORD SHOP 461 CONGRESS AVENUE 91462 20,000.00 5,000.00 416.66
00010 JOHN M. SMITH & SONS 2732 FOURTH AVENUE 10001 50,000.00 4,500.00 375.00
10502 HUGH WILLSON & SON 4583-10 LANDMARK TOWERS 32110 400,000.00 75,000.00 6,250.00 **
34681 THE BREAKERS INC. 41 MANSION DR. 02840 200,000.00 2,000.00 166.66
21178 THE FRAMING PLACE HUNTS RD. 02185 30,000.00 5,000.00 416.66
00145 T.H.BRAYTON JR. 3636 DEWEY AVENUE 56513 45,000.00 15,000.00 1,250.00 **
07733 SEAL PRODUCTS INC. 45 HARRIS AVE. 34840 150,000.00 50,000.00 4,166.66 **
00612 R.H.GROCERY STORE 34 COLLIER RD. 75021 3,000.00 250.00 20.83
00011 FETZNER & FETZNER 34 MILL BLUFF ROAD 17625 50,000.00 750.00 62.50

END OF LAB

1-4 RPG/400 to RPG IV


Student Exercises

Exercise 2. Discount Summary List

What This Exercise is About


This exercise provides an opportunity to create a simple RPG IV
program and get acquainted with new specification types and
operation codes.

The program will summarize the records in the APPVEND physical


file, using an externally described printer file (DISCSUMMRY) to
print a single-page analysis. You will need to calculate the totals
presented on this report.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use RPG IV format prompts in SEU
Edit, compile and run a simple RPG IV program

Exercise 2. DISCSUMMARY 2-1


Student Exercises

Exercise Instructions
1. Preparation
a. Verify that the source member DISCSUMMRY is in QDDSSRC in your
library. Review the source member, and familiarize yourself with the
format and field names that are used.
b. Compile DISCSUMMRY to produce a printer file in your library.

DISCSUMMRY Printer File

A R HEADERFMT SKIPB(2)
A USERID 10 3
A 29'DISCOUNT SUMMARY REPORT'
A UNDERLINE
A 73DATE EDTCDE(Y) SPACEA(2)
A 3'Discount'
A 14'Purchases'
A 27'Discounts'
A 42'Purchases'
A 57'Discounts'
A 74'Balance' SPACEA(1)
A 3'Percent'
A 17'MTD'
A 30'MTD'
A 45'YTD'
A 60'YTD'
A 76'Due' SPACEA(1)
**
A R PRINTREC SPACEB(1)
A PROMPTDISC 3 2 3EDTCDE(J)
A PURCHMTD 11 2 9EDTCDE(J)
A DISCMTD 9 2 24EDTCDE(J)
A PURCHYTD 11 2 37EDTCDE(J)
A DISCYTD 11 2 52EDTCDE(J)
A BALANCEDUE 11 2 67EDTCDE(J)

2. Code Program SUMMARY


a. Create a new RPG IV program SUMMARY in your QRPGLESRC source file
to produce an analysis of the records in APPVEND. Use the print formats
provided in DISCSUMMRY. Pay particular attention to the following:
1) your User Id should appear on the report (field USERID)
2) the records are to be summarized and printed by Discount
Percentage (VTRMPC); this field contains values in the range 0.01 to
0.20.

2-2 RPG/400 to RPG IV


Student Exercises

3) calculate totals for PCHMTD, DCTMTD, PCHYTD, DCTYTD, and


BALOWE for each Discount Percentage.
Hint
You will find arrays to be an effective way of calculating the totals.
The array index would be the discount percentage times 100.

4) As you code, try some of these features of RPG IV:


Indentation of field names on the D-spec.
Liberal use of mixed case when specifying field names to make
your code easier to read and maintain.
Use mixed case for opcodes and indicators also.

b. Compile your program using PDM option 14.


c. Once your program has compiled, review the compiler listing.
d. Run your program to produce the DISCSUMMRY report. Verify your
results with the sample that follows:
Sample listing of output of SUMMARY program

à ð
OE85000 DISCOUNT SUMMARY REPORT 9/11/01
Discount Purchases Discounts Purchases Discounts Balance
Per Cent MTD MTD YTD YTD Due
.04 25,000.00 .00 400,000.00 .00 5,500.00
.05 1,277,200.00 2,660.00 32,710,355.00 41,375.00 1,705,500.00
.08 10,000.00 100.00 100,000.00 10,000.00 20,000.00
.10 474,420.00 1,145.00 7,324,000.00 24,335.00 1,830,750.00
.15 249,350.00 925.00 1,178,050.00 13,500.00 320,500.00
.20 450,000.00 400.00 6,850,000.00 40,000.00 750,000.00
á ñ

END OF LAB

Exercise 2. DISCSUMMARY 2-3


Student Exercises

Exercise 3. APPVEND Tax Display

What the Exercise is About


This exercise provides an opportunity to create an RPG IV program and become
familiar with the new free-format operation codes.

The program will list all the records in the APPVEND physical file, using an externally
described display file (APPVENDSFL). You will also need to calculate the Sales Tax
and Net Balance owed.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Employ some of the new operation codes available on the C-Spec
Edit, compile and run a simple RPG IV program

Exercise 3. APPVEND 3-1


Student Exercises

Exercise Instructions

1. Preparation
a. Verify that the source member APPVENDSFL is in QDDSSRC in your
library. Review the source member, and familiarize yourself with the
format/field names used. Note, you will be using subfile processing.

APPVENDSFL Display File


A REF(*LIBL/APPFREF)
A CA03(03)
**
A R FMTREC SFL
A VNDNBR R O 5 5
A VNDNAM R O 5 12
A BALOWE R O 5 39EDTCDE(J)
A NETAMOUNT 9Y 2O 5 54EDTCDE(J)
A VATAMOUNT 7Y 0O 5 69EDTCDE(1)
**
A R FMTCTL SFLCTL(FMTREC)
A SFLSIZ(0016)
A SFLPAG(0015)
A OVERLAY
A SFLDSP
A SFLDSPCTL
A 90 SFLEND(*MORE)
A 2 5DATE
A EDTCDE(Y)
A 2 30'SUPPLIER LIST NET TAX'
A DSPATR(HI)
A 2 68USER
A 4 5'Number'
A DSPATR(HI)
A 4 12'Supplier Name'
A DSPATR(HI)
A 4 44'Balance'
A DSPATR(HI)
A 4 56'Net Amount'
A DSPATR(HI)
A 4 75'VAT'
A DSPATR(HI)
**
A R FMTFTR
A 21 4'Press Enter to continue'
A 22 4'F3=Exit'
b. Compile APPVENDSFL to produce a display file in your library.

3-2 RPG/400 to RPG IV


Student Exercises

c. Update the Local Data Area (LDA) to contain the current tax rate in the
first four (4) positions. In our exercise, we will use 17.50 percent. Enter
1750 (as a character value) in the LDA.

2. Code APPENDDSP
a. Code a new RPG IV program APPVENDDSP in your QRPGLESRC source
file to list APPVEND records on the display. Use the display formats
provided in APPVENDSFL. Pay particular attention to the following:
1) the Tax Rate (VATRATE) is to be extracted from the LDA
2) the Tax Amount (VATAMOUNT) and Net Amount (NETAMOUNT) fields
are to be calculated in your program
The government has provided you with the following information to
enable you to accurately calculate the tax:
Tax Due = Taxable Amount x (Tax Rate / (100 + Tax Rate))
b. Compile your program using PDM option 14.
c. Once your program has compiled, review the compiler listing.
d. Run your program to display APPVEND. Verify your results with the
sample provided below.

APPVENDSFL Display
04/30/98 SUPPLIER LIST NET TAX OE85000

Number Supplier Name Balance Net Amount Tax


00688 SHARON PHILIPS CORP. 25,000.00 21,277.00 3,723
63218 ACE DISTRIBUTORS .00 .00 0
13130 T.M.ELLIOT INC. 17,500.00 14,894.00 2,606
00016 BRAND X BEER 30,000.00 25,532.00 4,468
01148 JOHNSON & SONS 750,000.00 638,298.00 111,702
00021 MEMORIAL CARETAKERS 35,000.00 29,787.00 5,213
00221 GEORGE RUDOLPH INC. 500.00 426.00 74
05075 PETER VAN ROTH CORP. 20,000.00 17,021.00 2,979
10504 THE DEANA AGENCY 750,000.00 638,298.00 111,702
11002 THE DISK RECORD SHOP 5,000.00 4,255.00 745
00010 JOHN M. SMITH & SONS 4,500.00 3,830.00 670
10502 HUGH WILLSON & SON 75,000.00 63,830.00 11,170
34681 THE BREAKERS INC. 2,000.00 1,702.00 298
21178 THE FRAMING PLACE 5,000.00 4,255.00 745
00145 T.H.BRAYTON JR. 15,000.00 12,766.00 2,234
More...
Press Enter to continue
F3=Exit

Exercise 3. APPVEND 3-3


Student Exercises

Exercise 4. Expressions and Functions

What This Exercise is About


This exercise provides an opportunity to use RPG IV's free form expressions and
string functions.

The RPG program in this example calculates the weekly pay for hourly employees,
calculates the tax to be withheld and the net pay resulting from subtracting the tax
from the earnings.

Your task is to replace the existing calculations for the earnings and the tax
calculations. The program prints a report so you can check the accuracy of your
calculations.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Code arithmetic, logical and string free-form expressions.

Exercise 4. Expressions/Functions 4-1


Student Exercises

Exercise Instructions

1. Preparation
a. Verify that the source member, RPGPAY, is in your source file.
b. Verify that the files PAYROLL and PRODFILE are in your library.

2. Compile and Test RPGPAY


a. Compile your source code using PDM option 14 (CRTBNDRPG command).
b. Test your program. It should produce printed output that looks similar to
this:
à ð
Pay and tax calculation 4/30/98
First and Last name Earned Pay tax Net pay
Jerry Anderson 1299.38 241.86 1057.52
Eddy Wheeler 816.90 197.41 619.49
Arthur Misner 820.31 111.66 708.65
Doris Hattenberger 950.25 195.07 755.18
Kevin Sachow 784.00 163.52 620.48

á ñ

Original Source Code for RPGPAY


F* RPGPAY - Pay check program
F*
FPAYROLL IF E DISK
FQPRINT O F 132 PRINTER OFLIND(*INOF)
C*
C EXCEPT HDG Prt HDG
C* Read a record
C *IN20 DOWEQ '0'
C READ PAYREC 20 EOF
C*
C *IN20 IFEQ '0' If not EOF
C***
C* Calculate pay and tax
C EXSR PAYC Calc pay
C EXSR TAXC Calc tax
C *LIKE DEFINE RATE NET + 2 Define Net
C PAY SUB TAX NET Net pay
C EXCEPT DETAIL Prt record
C OF EXCEPT HDG Prt HDG
C ENDIF EndIf EOF
C ENDDO Loop back
C***

4-2 RPG/400 to RPG IV


Student Exercises

C SETON LR Set LR
C RETURN Return
C PAYC BEGSR
C* Calculate payment - hours over 35 get additional 75%
C*
C HOURS IFLE 35 Hours <= 35
C HOURS MULT RATE PAY Total pay
C ELSE -else-
C RATE MULT 35 PAY 7 2 Full 35 hrs
C HOURS SUB 35 OTIME 3 0 Overtime hours
C RATE MULT 1.75 OTRATE 9 4 Find rate
C OTRATE MULT(H) OTIME OTPAY 7 2 Overtime pay
C ADD OTPAY PAY Total pay
C END
C ENDSR
C TAXC BEGSR
C* Calculate Tax - the first 200 dollars of earnings are tax free
C*
C PAY IFLE 200 Pay < 200
C Z-ADD 0 TAX 7 2 no tax
C ELSE -else-
C PAY SUB 200 TXABLE 7 2 200 tax free
C TXABLE MULT TAXD TXWRK 9 2 calc %
C TXWRK DIV(H) 100 TAX Tax to pay
C END
C ENDSR
OQPRINT E HDG 2 06
O 25 'Pay and tax calculation'
O UDATE Y 36
O E HDG 2
O 19 'First and Last name'
O 36 'Earned'
O 46 'Pay tax'
O 56 'Net pay'
O E DETAIL 1
O FNAME 10
O LNAME 26
O PAY 3 36
O TAX 3 46
O NET 3 56

3. Modify RPGPAY
a. Make the appropriate source code changes to rewrite the program to use
the following RPG IV features:
Define all variables on the D-spec rather than on the C-spec
Move the definition of the field Net to the D-spec
Make liberal use of mixed case to make your code more readable
Replace all arithmetic opcodes with Evals

Exercise 4. Expressions/Functions 4-3


Student Exercises

Replace DOWxx, IFxx with Dow, If and expressions


Use a named indicator for overflow; as well, you will need to use an If
to condition overflow rather than the conditioning indicator.
Replace any SETON/SETOFF opcodes.
Using the EVAL op code, code an expression using BIFs, create a new
field, FLName. This field should be defined as 25 characters and
should be created by concatenating the last name (LNAME) and first
name (FNAME) fields with a comma and one space between them. The
name should be of the form Lastname, Firstname like the results
below.
b. Compile your source code using option 14 (CRTBNDRPG).
c. Test your program. It should produce printed output that looks similar to
this:
à ð
Pay and tax calculation 9/13/01
First and Last name Earned Pay tax Net pay
Anderson, Jerry 1299.38 241.86 1057.52
Wheeler, Eddy 816.90 197.41 619.49
Misner, Arthur 820.31 111.66 708.65
Hattenberger, Doris 950.25 195.07 755.18
Sachow, Kevin 784.00 163.52 620.48

á ñ
END OF LAB

4-4 RPG/400 to RPG IV


Student Exercises

Exercise 5. Error Handling and BIFs

What This Exercise is About


This exercise provides an opportunity to try a few BIFs to replace indicators and to
add some error handling.

Your task is to replace all existing indicators with BIFs and to add limited error
handling.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use BIFs rather than indicators
Use BIFs for error handling

Exercise 5. Error Handling 5-1


Student Exercises

Exercise Instructions

1. Modify RPGPAY
a. Make a copy of your RPGPAY solution from the previous exercise. and
name it RPGPAYE.
b. Remove the indicator on the READ statements and replace all instances of
the indicator with a Built-in-Function.
c. Compile and test your program to confirm that it produces the same
output as your original solution.

2. Add Error Handling


a. Force an error by closing the file, Payroll, immediately after the DoW line
of code and before the Read.
b. Compile your program and run it. You should see the following message:
I/O operation was applied to closed file PAYROLL (C G D F).
c. Next, handle this error gracefully in your program by adding Error
Handling logic that will end the program if a problem is encountered with
the Payroll file. You may add an error message to the printer output if
you like or simply end the program.
d. Compile and test your program to confirm that it produces the error
message in your spool file member.
END OF LAB

5-2 RPG/400 to RPG IV


Student Exercises

Exercise 6. Date Processing

What This Exercise is About


This exercise provides an opportunity to experiment with date
BIFs such as %Date, %Diff and %SubDt.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use the %Date BIF to convert from a character to a date data
type.
Use the %SubDt BIF to extract the year, month and day portion
from a date
Use the %Diff BIF to determine the duration between two dates
expressed in days, months or years.

Introduction
You are given the DSPF DDS and will write a date program that
will use date processing BIFs.

Exercise 6. Date Processing 6-1


Student Exercises

Exercise Instructions

1. Review the DDS, DATEDSPF


a. In your library, you will find the DDS for the display file. A copy follows:
A REF(*LIBL/ITEM_PF)
A INDARA
A CA03(03 'Exit')
**
A R HEADER
A 3 35'Date Exercise' COLOR(WHT)
A 3 55'Today''s Date'
A TODAY L O 3 70DATFMT(*ISO)
**
A R PROMPT OVERLAY
A 8 10'Enter any date as YYYY-MM-DD'
** Date entry field follows
A CHARDATE 10A B 8 45
A 40 ERRMSG('Invalid date entered' 40)
**
A R DETAIL OVERLAY
A 10 20'The year entered was. .:'
A YEAR 4 0O 10 46EDTCDE(L)
A 11 20'The month entered was .:'
A MONTH 2 0O 11 48EDTCDE(L)
A 12 20'The day entered was . .:'
A DAY 2 0O 12 48EDTCDE(L)
A 14 20'The date entered is . .:'
A DAYS 5 0O 14 45EDTCDE(Z)
A 50 14 51'days from now'
A N50 14 51'days ago'
**
A R FOOTER OVERLAY
A 20 7'Press Enter to continue'
A 21 7'F3=Exit'
A COLOR(BLU)
b. Notice that the fields to be entered and displayed are defined in the DDS.
c. Compile and create the Display File, DATEDSPF.

2. Study the Display Output


a. Review this sample output:

6-2 RPG/400 to RPG IV


Student Exercises

à ð
Date Exercise Today's Date 2001-07-10

Enter any date as YYYY-MM-DD: 2001-10-01


The year entered was. .: 2001
The month entered was .: 10
The day entered was . .: 1
The date entered is . .: 83 days from now

Press Enter to continue


F3=Exit
á ñ
b. The user can enter a date that, when it is valid, is separated into the year,
month, and day components. Also, the duration between the date entered
and the job date is calculated in days and displayed as in the future “days
from now” or in the past “days ago.”
If the date is invalid the message “Invalid date entered” is displayed.

3. Modify the Program, DATERPG


In your library, you will find a source member named DATERPG. Add statements
to the program at the points indicated by // Insert ... to perform the tasks
required. A copy of the program follows:
FDateDSPF CF E Workstn IndDS(WKIND)
D WkInd DS
D Exit 3 3N
D BadDate 40 40N
D Future 50 50N
// Insert code to determine the value of today

// End
C Write Header
C Write Footer
C Exfmt Prompt

Exercise 6. Date Processing 6-3


Student Exercises

C Dow NOT Exit


// Reset date indicator
C Eval Future = *off
// Insert the code to test for valid date entered (CharDate)
// Hint - add a second extender to your test, E (error)

// End
C If %error
C Eval BadDate = *On
C Else
// Display details
// Insert code to extract year, month, day from date entered

// End
// Insert code to
// determine number of days between job date and date entered

// End
// Is Days in the past or the future?
C If Days < 0
C Eval Future = *on
C Else
C Eval Future = *off
C EndIf

C Write Detail
C EndIf
// Display prompt
C Exfmt Prompt
C Enddo

C Eval *InLR = *On


Further explaantion of the program:
a. Notice the use of named indicators.
b. The program determines today's date based on the job date and assigns
the value to the field Today.
c. When the user enters a value for the field CharDate, the program checks
whether it is valid. If it is not, you should turn on the BadDate indicator.
d. If the date is valid, the program extracts the year, month and days
components and assigns the values to the appropriate display file fields.

6-4 RPG/400 to RPG IV


Student Exercises

e. The program determines the difference in days between the date entered
and the job date. If the date is in the future, it sets the indicator, Future,
on. The program also handles the opposite situation.

4. Compile and Test


a. Compile your program and correct and errors.
b. Once you have created a *PGM, test it using various valid as well as
invalid dates. If you get a size error for the field Days, you can make it
larger in the DSPF or try a different value for Days. Days in the DSPF that
you are given is 5 digits in size.

END OF LAB

Exercise 6. Date Processing 6-5


Student Exercises

Exercise 7. Coding in Free Format

What This Exercise is About


In this exercise, students will change all calculations of an existing fixed format
program to free format coding. The students are given a copy of both the existing
program as well as the DSPF it uses.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Convert an existing fixed format RPG IV program to free format

Exercise 7. Coding in Free Format 7-1


Student Exercises

Exercise Instructions

1. Familiarize yourself with the Legacy Program


a. Find a member named VNDSEARCH in your QDDSSRC source file and
browse it.
b. Compile your copy of VNDSEARCH in your library.
c. Find the member named VNRSEARCH in QRPGLESRC and compile it.
d. Test VNRSEARCH by running it and entering partial search strings to
position the subfile. You may position the subfile using any character
string. An example is ABC.
e. Now that you are familiar with the traditional code's purpose, you will
change the calculations to all free format.

2. Modify the Program


a. Make a copy of VNRSEARCH and call it VNRSFREE.
b. Referencing the rules of free format coding, the examples in the notebook,
and the RPG Reference manual as necessary, convert all calculations to
free format using:
indentation to improve readability
comments
any other features that you would like to try
c. Once you have modified your program, compile it.
d. Test your program. Assuming you have not changed the flow of the logic,
it should work the same as VNRSEARCH.

3. Remove all indicators (Optional but recommended)


a. Change all numbered indicators to named indicators.
b. You may use based variables or INDARA/IndDS depending on which
technique you prefer or know. If you use INDARA/IndDS, remember to
add the INDARA keyword in the DDS and the IndDS keyword for the
display file in your program.

END OF LAB

7-2 RPG/400 to RPG IV


Student Exercises

Exercise 8. ILE PDM Options

What This Exercise is About


This exercise will familiarize you with the PDM options that support the new
Integrated Language Environment.

What You Should Be Able to Do


At the end of the lab, students should be able to identify PDM options used to:
Create modules
Create programs
Create service programs

Exercise 8. ILE PDM Options 8-1


Student Exercises

Exercise Instructions

Step 1
a. Start PDM and work with the objects in your library.
b. Press Function key F23 and review the options available to you.
c. What option can be used to create a program ?

d. What option can be used to create a service program ?

e. Type a 12 (work with...) on your RPG source file.


f. Place option 14 on one of the source members and prompt with the F4 key.
What CL command is prompted?

g. How do you create a module?

h. Is there a PDM option to create a program while in the Work with Member
screen?

In the following exercises you will be asked to enter commands like, CRTRPGMOD
and CRTPGM. Both of these have PDM options and F4 can be used to prompt. F5 is
used to refresh the screen. Use this function after you have created an object to
verify that the object is placed in your library.

END OF LAB

8-2 RPG/400 to RPG IV


Student Exercises

Exercise 9. Binding by Copy

What This Exercise is About


This exercise provides an opportunity to use ILE's static binding.

This application prints the days since an object was last used.

The calculations for determining the difference between two dates are located in a
separate source member, DAYSSINCE. This procedure accepts as a parameter a date
and returns in a second parameter the number of days between that date and today.

A CL program has also been created to duplicate the QADSPOBJ file and populate it
with the object descriptions. This source is found in member DSPOBJMOD.

Lastly, the RPG mainline program which reads the DSPOBJ file and prints the report
(modified to call DAYSSINCE) is found in member PRTOBJILE.

Your task in this machine exercise is to create all the modules needed from the
source code provided to you and to bind the modules together using Bind by Copy.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Create RPG IV and CL modules.
Create a multi-module ILE program using bind by copy.

Exercise 9. ILE Bind by Copy 9-1


Student Exercises

Exercise Instructions

1. Create Modules
a. Find and display the source member for the CL module, DSPOBJMOD in
your QCLSRC file. Note the statement that calls the RPG module,
PRTOBJILE. Note that it is a CALLPRC statement rather than a CALL.
This will be a bound call and the DSPOBJMOD module must be bound
with the PRTOBJILE module for it to work.
b. Compile the DSPOBJMOD member using the option 15 from PDM or the
CRTCLMOD command. Take the defaults for the compile.
c. Find and display the source member for the RPG module, PRTOBJILE.
Note the statement that calls the RPG module, DAYSSINCE. Note that it is
also a bound call (CALLB, rather than CALL). Therefore, the DAYSSINCE
module must also be bound with the previous two.
d. Compile the PRTOBJILE module using option 15 from PDM or the
CRTRPGMOD command. Take the defaults for the compile.
e. Find and display the source member for DAYSSINCE in your QRPGLESRC
source file. Compile it using option 15 from PDM or CRTRPGMOD, taking
the defaults.
f. After all modules have compiled successfully, create a bound program
using bind by copy. Use the PDM options for this and name the program
PRTOBJPGM. Include in these modules to be bound: DSPOBJMOD,
PRTOBJILE, and DAYSSINCE. Your finished command should look like
this:
CRTPGM PGM(PRTOBJPGM) MODULE(DSPOBJMOD PRTOBJILE DAYSSINCE)
ENTMOD(DSPOBJMOD)
g. How do you include multiple modules in a program other than keying in
each module name?

h. Can you find a compiled listing for PRTOBJPGM?


i. CALL PGM(PRTOBJPGM) PARM(OE85V4LIB).
j. Review the spooled file member that is created.
k. You may want to display the format and field descriptions in the file to
help understand how some of the fields are used in the RPG program.
You may do this by issuing the Display File Field Description command:
DSPFFD FILE(DSPOBJ)
Note especially the input field format for ODUDAT, which contains the date
each object was last used.

9-2 RPG/400 to RPG IV


Student Exercises

Source Code for RPG Module PRTOBJILE


F* PRTOBJ - Print program modified to use a date field
F*
F*
FDspObj IF E Disk
FQPRINT O F 132 Printer OflInd(OverFlow)
D LstUsd S D DATFMT(*YMD)
D CurDate S D
D NoDays S 5 0
C****************************************************************
C EXCEPT HDG
C****************************************************************
C* Read a record
C* QLIDOBJD is the format name of the QADSPOBJ file
C Read QLIDOBJD
C* Continue reading until EOF
C DoW Not %Eof(DspObj)
C****************************************************************
C*
C *MDY0 Test(DE) OduDat
C If Not %Error
C Eval *in10 = *off
C Eval LstUsd = %Date(OduDat:*MDY0)
C Else
C Eval *in10 = *on
C EndIf
C CallB 'DAYSSINCE'
C PARM LstUsd
C PARM NoDays
C If NoDays <> 99999
C EXCEPT DETAIL
** Overflow?
C If OverFlow
C EXCEPT HDG
C Eval Overflow = *Off
C EndIf
C EndIf
C Read QLIDOBJD
C EndDo
C* End the program
C Eval *inLR = *on
OQPRINT E HDG 2 06
O 25 'Objects '
O 'in Library'
O E HDG 2
O 6 'Object'
O 18 'Obj type'
O 30 'Attribute'
O 42 'Last used'
* +++++ Add the heading
O 60 'Days Since Used'
O E DETAIL 1
O ODOBNM 10
O ODOBTP 19
O ODOBAT 33
O N10 LSTUSD 42
O 10 42 'Not used'
O N10 NoDays L 56
O 10 56 'Not used'

Exercise 9. ILE Bind by Copy 9-3


Student Exercises

Source Code for RPG Module DAYSSINCE

HDATEDIT(*YMD) DATFMT(*YMD)
DCurDate S D
DDateIn S D
DNoDays S 5 0
DError C 99999
C *Entry PList
C Parm DateIn
C Parm NoDays
C Test (E) DateIn
C If Not %Error
C Eval CurDate = %Date(*date)
C Eval NoDays = %Diff(CurDate:DateIn:*D)
C Else
C Eval NoDays = Error
C EndIf
C Return

Source Code for CL Module DSPOBJMOD

PGM PARM(&LIB)
DCL VAR(&LIB) TYPE(*CHAR) LEN(10)
MONMSG MSGID(CPD2104 CPF2130)
DSPOBJD OBJ(&LIB/*ALL) OBJTYPE(*PGM) DETAIL(*BASIC) +
OUTPUT(*OUTFILE) +
OUTFILE(*CURLIB/DSPOBJ) /* CL Command +
to put all program objects from requested +
library into DSPOBJ for input to PRTOBJILE */
CALLPRC PRC(PRTOBJILE)
endpgm

2. Analyze Programs and Modules


a. Now display the external information of program PRTOBJPGM. Use the
DSPPGM command and prompt. Specify *ALL for the DETAIL parameter.
b. What is the program attribute? _____________________________
c. What is the number of modules? _______
d. How many service programs are there? ________
e. Is the object compressed? ________
f. Press ENTER until module information is displayed.
g. The list of modules only reflects copied modules. Press Enter.
h. The service programs are listed next. You can continue pressing the
ENTER key and explore the additional information stored or you can press
F3 to exit.

9-4 RPG/400 to RPG IV


Student Exercises

Exercise 10. Binding by Reference

What This Exercise is About


This exercise provides an opportunity to use bind by reference and create a Service
Program. The DAYSSINCE module is used in several programs, including
PRTOBJPGM. You will place the DAYSSINCE module into a Service Program and
then bind by reference to the program PRTOBJPGM.

What You Should be Able to do:


At the end of the lab, you should be able to:
Create a Service Program
Bind by reference

Exercise 10. ILE Bind by Reference 10-1


Student Exercises

Exercise Instructions
The DAYSSINCE module is called by the PRTOBJPGM module. You will create a
Service Program containing this module and re-create the programs to use this new
service program and a static bind by reference.

1. Create Service Program


a. Use PDM to create the service program. Specify the module DAYSSINCE
to be included and specify *ALL for the EXPORT parameter. This
indicates that all procedures in the service program can be called by
other procedures. If keyed on the command line, the command would
look like this:
CRTSRVPGM SRVPGM(MYSRVPGM) MODULE(DAYSSINCE) EXPORT(*ALL)
Note that service programs will typically have multiple modules. For
simplicity in this exercise, we are using a service program with only one
module.
b. Now you will create a new PRTOBJPGM program that will use the the
DAYSSINCE procedure from the service program. PRTOBJPGM is the
program you created in the binding exercise that included modules
DSPOBJMOD, PRTOBJILE, and DAYSSINCE. Use PDM to issue the
CRTPGM command. Name this new program PRTOBJPGM2. The
command on the command line should look like this:
CRTPGM PGM(PRTOBJPGM2) MODULE(DSPOBJMOD PRTOBJILE)
BNDSRVPGM(MYSRVPGM) ENTMOD(*FIRST)
c. Call PRTOBJPGM2 with the parameter OE85V4LIB. You should have a
spooled file report in the output queue. DAYSSINCE was used to calculate
the number of days but it was referenced and not copied into
PRTOBJPGM2.
DAYSSINCE, as a module in the service program, could be modified and
only the service program would have to be re-created. Of course, if the
modifications were no longer compatible with the programs and modules
that used DAYSSINCE there would be errors.

2. Modify DAYSSINCE
You will modify DAYSSINCE to EXPORT data item CURDATE and then recreate
the service program. This will cause errors in the programs using MYSRVPGM.
Re-binding of those programs will be required.
Defining CURDATE as an EXPORT data item from DAYSSINCE will prepare for the
following exercise.
a. Modify the source for DAYSSINCE so that CURDATE is EXPORTed and
recreate the module. To do this, add the EXPORT keyword in the D-spec
for CURDATE. Specifying EXPORT will make this variable available to be
used as a parameter to modules that call the DAYSSINCE procedure.
A source listing of DAYSSINCE is included.

10-2 RPG/400 to RPG IV


Student Exercises

b. Re-create the service program:


CRTSRVPGM SRVPGM(MYSRVPGM) MODULE(DAYSSINCE) EXPORT(*ALL)
c. Once you get the completion message that the service program has been
created,
CALL PRTOBJPGM2 PARM('OE85V4LIB')
d. Did the application run? Analyze the message in the 'joblog' and correct
any problems.
e. Re-create the program PRTOBJPGM2. Refer to the previous step if you
need help.
f. Run the application again when the problem is corrected.
g. Use the DSPSRVPGM command to display MYSRVPGM. Press the ENTER
key several times until you reach the Procedure Exports and Data Exports
screens.
END OF LAB

Exercise 10. ILE Bind by Reference 10-3


Student Exercises

Exercise 11. ILE Source Debugger

What This Exercise is About


This exercise gives you experience in using the Source View Debugger.

The Debug data is created when a DBGVIEW option other than *NONE on the
CRTRPGMOD command is used. You will first re-create modules with parameter
DBGVIEW *ALL for program PRTOBJPGM2.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Create modules that give the Source View Debugger access to source.
Start the Source View Debugger.
Select a module for debug.
Set conditional breakpoints.
Display variables

Exercise 11. Debugger 11-1


Student Exercises

Exercise Instructions

1. Using the Source Debugger


First, re-create modules with source debug data included. Then, use the source
debugger.
a. Create modules for each of these source members specifying the compile
option DBGVIEW(*ALL):
DSPOBJMOD (CLLE)
PRTOBJILE (RPGLE)
DAYSSINCE (RPGLE)
Recreate program PRTOBJPGM2, (a Bind by Copy will suffice):
CRTPGM PGM(PRTOBJPGM2) MODULE(DSPOBJMOD PRTOBJILE DAYSSINCE)
ENTMOD(DSPOBJMOD)
b. Enter STRDBG command and prompt with F4.
c. Enter the following in the prompt:
Program = PRTOBJPGM2 <===
Library = OE85nnn <===
Default program = *PGM
Max Trace stmt = 200
Trace full = *STOPTRC
Update prod files = *YES <===
d. Press F10 and review the other parameters. Look specifically at the
OPMSRC and DSPMODSRC parameters.
e. The source displayed is for module DSPOJBMOD, which is the first
module in the program.
f. Use F24 to view all the command key functions.
g. Use F14 to view the module list.
h. Select module PRTOBJILE with option 5, and press ENTER to display
source for PRTOBJILE.
i. Find the line of code:
C *MDY0 Test(DE) OduDat
j. Set a breakpoint using F6.
k. After setting the breakpoint, how can you tell that the breakpoint has been
set?

l. At what line number did you set the breakpoint? Make any necessary
corrections.

11-2 RPG/400 to RPG IV


Student Exercises

m. Exit the debugger using F12. Your breakpoints are not removed.
n. CALL PGM(PRTOBJPGM2) PARM(OE85V4LIB).
When the conditional breakpoint is reached, the program will stop and the
module source will display.
o. Move the cursor to variable ODUDAT and press F11. The value for
ODUDAT should be ' ' which explains why *IN10 is set on.
p. Move the cursor to the line number with the conditional breakpoint and
use F6 to clear (remove) it.
q. Exit the debugger using F12.
r. Enter ENDDBG to exit the debug session.

2. Using the Source Debugger Watch Feature


We will do a similar exercise as we did in the first step but this time, we will
watch the value of the indicator and a variable.
a. STRDBG as you did in the previous step.
b. Set a breakpoint at the first c-spec in the PRTOBJILE procedure.
c. CALL PRTOBJPGM2. When you reach the breakpoint, set a watch of the
*in10 indicator as well as NODAYS.
d. Continue execution and review the messages as the values of the two
variables changes.
e. Notice that as NODAYS changes, the module where is was changed is
automatically displayed.
f. Do you remember how you can avoid having the debugger process the
I-specs?

END OF LAB

Exercise 11. Debugger 11-3


Student Exercises

Exercise 12. Converting RPG III Source to RPG IV

What This Exercise is About


In this exercise, you will use the RPG IV conversion tool to convert existing RPG/400
(RPG III) code to RPG IV. The file you convert has DDS and CL source members along
with the RPG members. The conversion tool will not convert the DDS or CL members.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Convert RPG source code into RPG IV code.
Create a conversion log and report.

Exercise 12. Conversion 12-1


Student Exercises

Exercise Instructions

1. Conversion
a. The RPG source code to be converted is in OE85nnn/RPG400SRC. There
is no need to copy this source into your library.
b. You will need a log file. Use the CPYF command. You have been given
the authority to access the log file during this lab. Notice the name of the
object and the new object name are different below:
CPYF FROMFILE(QRPGLE/QARNCVTLG)
TOFILE(OE85nnn/QRNCVTLG)
CRTFILE(*YES)
c. Convert all members in the source file RPG400SRC into your QRPGLESRC
source file. Submit the CVTRPGSRC command with CVTRPT *YES to
batch. Use the CVTRPT *YES parameter to print a conversion report.
d. Use PDM to browse some of the converted members. Use F15 to split the
screen and browse the corresponding source member from
OE85nnn/RPG400SRC. Can you detect the changes made?

e. Notice that non-RPG members were not converted. Review your job log
for further details.
f. Look at the conversion report in your output queue.
g. Review the Log File using the RUNQRY command. List audit information
paying particular attention to Convert Status Data.
END OF LAB

12-2 RPG/400 to RPG IV


Student Exercises

Appendix A. Exercise Files and DDS

APPFREF Field Reference File

A*
A** FIELD REFERENCE FILE FOR ACCOUNTS PAYABLE
A** STUDENT EXERCISES
A*
A R REFFMT TEXT('FIELD REFERENCE FILE')
A*
A** FIELDS USED IN MULTIPLE RECORDS
A*
A VNDNBR 5 0 TEXT('VENDOR ID NUMBER')
A COLHDG('VENDOR' 'NUMBER')
A DEPTNO 3 0 TEXT('DEPARTMENT CHARGED')
A COLHDG('DEPARTMENT' 'NUMBER')
A ACTCD 1 TEXT('A=ACTIVE D=DELETE S=SUSPEND')
A COLHDG('ACTIVE' 'RECORD' 'CODE')
A*
A** FIELDS IN VENDOR MASTER RECORD
A*
A VNDNAM 25 TEXT('VENDOR NAME')
A COLHDG('VENDOR' 'NAME')
A VNDAD1 25 TEXT('ADDRESS LINE 1')
A COLHDG('ADDRESS LINE 1')
A VNDAD2 25 TEXT('ADDRESS LINE 2')
A COLHDG('ADDRESS LINE 2')
A VNDAD3 25 TEXT('ADDRESS LINE 3')
A COLHDG('ADDRESS LINE 3')
A VNDZIP 5 0 TEXT('ZIP CODE')
A COLHDG('ZIP' 'CODE')
A VNDACD 3 0 TEXT('AREA CODE')
A COLHDG('AREA' 'CODE')
A VNDPHN 7 0 TEXT('PHONE NUMBER')
A COLHDG('PHONE')
A VTRMPC 3 3 TEXT('NORMAL PROMPT PAY DISCOUNT%')
A COLHDG('TERMS' '%')
A VTRMDA 2 0 TEXT('NORMAL NO. OF DAYS FOR TERMS')
A COLHDG('TERMS' 'DAYS')
A VNDCLS 2 0 TEXT('VENDOR CLASS')
A COLHDG('CLASS')
A VNDSLS 25 TEXT('VENDOR SALESMAN')
A COLHDG('SALESPERSON')

Appendix A. Exercise Files and DDS A-1


Student Exercises

A DCTMTD 7 2 TEXT('DISCOUNT TAKEN THIS MONTH')


A COLHDG('DISCOUNT' 'TAKEN' 'MTD')
A DCTYTD 9 2 TEXT('DISCOUNT TAKEN THIS YEAR ')
A COLHDG('DISCOUNT' 'TAKEN' 'YTD')
A PCHMTD 9 2 TEXT('PURCHASES THIS MONTH')
A COLHDG('PURCHASES' 'YTD')
A PCHYTD 11 2 TEXT('PURCHASES THIS YEAR')
A COLHDG('PURCHASES' 'YTD')
A BALOWE 9 2 TEXT('BALANCE OWED')
A COLHDG('BALANCE' 'OWED')
A SRVRTG 1 TEXT('SERVICE RATING')
A COLHDG('SERVICE' 'RATING')
A DELRTG 1 TEXT('DELIVERY RATING')
A COLHDG('DELIVERY' 'RATING')
A SCHCOD 10A TEXT('SEARCH CODE')
A COLHDG('SEARCH' 'CODE')
A CHECK(ME)
A COMNTS 25 TEXT('COMMENTS ABOUT THIS VENDOR')
A COLHDG('COMMENTS ABOUT' 'VENDOR')
A*
A** FIELDS USED IN TRANSACTION RECORD
A*
A INVNBR 8 TEXT('VENDORS INVOICE AMOUNT')
A COLHDG('VENDOR' 'INVOICE' 'NUMBER')
A DATREC 6 0 TEXT('DATE RECEIVED')
A COLHDG('DATE' 'RECEIVED')
A MERCH 7 2 TEXT('MERCHANDISE AMOUNT')
A COLHDG('MERCHANDISE' 'AMOUNT')
A NET 7 2 TEXT('NET AMOUNT PAID')
A COLHDG('NET' 'AMOUNT' 'PAID')
A STATUS 1 TEXT('E=ENTERED T=TO PAY D=DELETE +
A P=PAID')
A COLHDG('STATUS' 'OF' 'RECORD')
A DTPAID 6 0 TEXT('DATE PAID')
A COLHDG('DATE' 'PAID')
A CHECK# 6 0 TEXT('CHECK NUMBER')
A COLHDG('CHECK' 'NUMBER')
A*
A** FIELDS USED IN DEPARTMENT MASTER
A*
A DNAME 15 TEXT('DEPARTMENT NAME')
A COLHDG('DEPARTMENT' 'NAME')
A BUDMTD 9 2 TEXT('AMOUNT BUDGETED THIS MONTH')
A COLHDG('BUDGET' 'AMOUNT' 'MTD')
A BUDYTD 11 2 TEXT('AMOUNT BUDGETED THIS YEAR')
A COLHDG('BUDGET' 'AMOUNT' 'YTD')
A DISMTD 9 2 TEXT('AMOUNT DISPERSED THIS MONTH')

A-2 RPG/400 to RPG IV


Student Exercises

A COLHDG('DISPERSED' 'MTD')
A DISYTD 11 2 TEXT('AMOUNT DISPERSED THIS YEAR')
A COLHDG('DISPERSED' 'YTD')
A GLACT 6 0 TEXT('GENERAL LEDGER ACCOUNT NBR')
A COLHDG('G/L' 'ACCOUNT' 'NUMBER')
A*
A** FIELDS USED IN ITEM MASTER FILE
A*
A ITMNBR 5 0 TEXT('ITEM NUMBER')
A COLHDG('ITEM' 'NUMBER')
A ITMDSC 25 TEXT('ITEM DESCRIPTION')
A COLHDG('ITEM' 'DESCRIPTION')
A ITMQOH 7 0 TEXT('QUANTITY ON HAND')
A COLHDG('QUANTITY' 'ON HAND')
A ITMQOO 7 0 TEXT('QUANTITY ON ORDER')
A COLHDG('QUANTITY' 'ON ORDER')
A ITMCST 5 2 TEXT('ITEM UNIT COST')
A COLHDG('ITEM' 'UNIT' 'COST')
A ITMPRC 5 2 TEXT('ITEM UNIT PRICE')
A COLHDG('ITEM' 'UNIT' 'PRICE')
A CATNBR 7 TEXT('VENDOR CATALOG NUMBER')
A COLHDG('VENDOR' 'CATALOG' 'NUMBER')
A*
A** FIELDS USED FOR PURCHASE ORDERS
A*
A PORNBR 6 0 TEXT('PURCHASE ORDER NUMBER')
A COLHDG('PURCHASE' 'ORDER' 'NUMBER')
A DATORD 6 0 TEXT('DATE ORDERED')
A COLHDG('DATE' 'ORDERED')
A ITMAMT 7 2 TEXT('ITEM EXTENDED AMOUNT')
A COLHDG('ITEM' 'EXTENDED' 'AMOUNT')
A QTYORD 5 0 TEXT('ITEM ORDERED QUANTITY')
A COLHDG('ITEM' 'ORDERED' 'QUANTITY')
A QTYREC 5 0 TEXT('ITEM QUANTITY RECEIVED')
A COLHDG('ITEM' 'QUANTITY' 'RECEIVED')
A DATDUE 6 0 TEXT('INVOICE DUE DATE')
A COLHDG('INVOICE' 'DUE' 'DATE')
A*
A** ADDITIONAL FIELDS
A*
A DUYR 2 0 TEXT('VENDOR INVOICE DUE DATE +
A - YEAR')
A COLHDG('INVOICE' 'DUE' 'DATE')
A DUMODY 4 0 TEXT('VENDOR INVOICE DUE DATE +
A - MONTH DAY')
A COLHDG('INVOICE' 'DUE' 'MONTH-DAY')
A DCTAVL 5 2 TEXT('VENDOR INVOICE DISCOUNT +

Appendix A. Exercise Files and DDS A-3


Student Exercises

A AVAILABLE')
A EDTCDE(3)
A COLHDG('INVOICE' 'DISCOUNT' +
A 'AVAILABLE')
A DUDATE 6 0 TEXT('VENDOR INVOICE DUE DATE: +
A MONTH-DAY-YEAR')
A EDTCDE(Y)
A COLHDG('DISPLAY' 'DUE DATE' 'MO-DAY+
A -YR')

A-4 RPG/400 to RPG IV


Student Exercises

APPVEND Physical File

A REF(APPFREF)
A R VENDMAST
A VNDNBR R
A VNDNAM R
A VNDAD1 R
A VNDAD2 R
A VNDAD3 R
A VNDZIP R
A VNDACD R
A VNDPHN R
A VTRMPC R
A VTRMDA R
A VNDCLS R
A ACTCD R
A VNDSLS R
A DCTMTD R
A DCTYTD R
A PCHMTD R
A PCHYTD R
A BALOWE R
A SRVRTG R
A DELRTG R
A COMNTS R
A SCHCOD R

Appendix A. Exercise Files and DDS A-5


Student Exercises

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')
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-6 RPG/400 to RPG IV


Student Exercises

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 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 +

Appendix A. Exercise Files and DDS A-7


Student Exercises

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')

A-8 RPG/400 to RPG IV


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

Appendix A. Exercise Files and DDS A-9


Student Exercises

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-10 RPG/400 to RPG IV


Student Exercises

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

Appendix A. Exercise Files and DDS A-11


Student Exercises

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')

A-12 RPG/400 to RPG IV


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

Appendix A. Exercise Files and DDS A-13


Student Exercises

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

A-14 RPG/400 to RPG IV


Student Exercises

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

Appendix A. Exercise Files and DDS A-15


Student Exercises

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

A-16 RPG/400 to RPG IV


Student Exercises

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

Appendix A. Exercise Files and DDS A-17


Student Exercises

Appendix B. Exercise Solutions and Answers


The solutions for the exercises are included for your reference. You may use them to
validate your solutions and answers to questions in the exercises.

Our solutions represent only one way to solve the problem. You may develop a
different solution that produces the desired result. Our solutions were written to show
you various features of RPG IV. You will notice liberal use of expressions and upper /
lower case coding.

Appendix B. Exercise Solutions and Answers B-1


Student Exercises

Exercise - APPVEND Record List


Program APPVENDPRT

FAppVend IF E Disk
FAppList O E Printer
** Read first record
C Read AppVend LR LR
C Write HeadFormat
C *InLR DoWNE *on
** Set flag for BALOWE > 5000
C BalOwe IfGT 5000
C Move '**' LargeBal
C Else
C Move *blanks LargeBal
C EndIf
** Calculate monthly repayment
C Balowe Div (H) 12 Monthly
C Write ListFormat
C Read AppVend LR LR
C EndDo
** End of program

B-2 RPG/400 to RPG IV


Student Exercises

Exercise - DISCSUMMARY Discount Summary List


Program SUMMARY

FAppVend IF E Disk
FDiscSummryO E Printer
** Arrays for summary totals
D PurchMtdAr S Dim(20) LIKE(PurchMtd)
D DiscMtdAr S Dim(20) LIKE(DiscMtd)
D PurchYtdAr S Dim(20) LIKE(PurchYtd)
D DiscYtdAr S Dim(20) LIKE(DiscYtd)
D BalanceAr S Dim(20) LIKE(BalanceDue)
D NoRecsAr S 3 0 Dim(20)
D Idx S 3 0
** Print Page Heading and Read first record
C Eval UserId = 'OE85000'
C Write HeaderFmt
C Read AppVend LR
** Read rest of file
C DoW *InLR = *Off
** Derive array index
C Eval Idx = VtrmPC * 100
C Eval PurchMtdAr(Idx) = PurchMtdAr(Idx) + PchMT
C Eval DiscMtdAr(Idx) = DiscMtdAr(Idx) + DctMTD
C Eval PurchYtdAr(Idx) = PurchYtdAr(Idx) + PchYT
C Eval DiscYtdAr(Idx) = DiscYtdAr(Idx) + DctYTD
C Eval BalanceAr(Idx) = BalanceAr(Idx) + BalOwe
C Eval NoRecsAr(Idx) = NoRecsAr(Idx) + 1
** Read next record
C Read Appvend LR
C EndDo
** Now print summary lines if all totals zero
C Do 20 Idx
C If NoRecsAr(Idx) > 0
C Eval PromptDisc = Idx / 100
C Eval PurchMtd = PurchMtdAr(Idx)
C Eval DiscMtd = DiscMtdAr(Idx)
C Eval PurchYtd = PurchYtdAr(Idx)
C Eval DiscYtd = DiscYtdAr(Idx)
C Eval BalanceDue = BalanceAr(Idx)
C Write PrintRec
C EndIf

Appendix B. Exercise Solutions and Answers B-3


Student Exercises

C EndDo

B-4 RPG/400 to RPG IV


Student Exercises

Exercise - APPVEND Tax Display


Program APPVENDDSP

H ExprOpts(*ResDecPos)
FAppVend IF E Disk
FAppVendSFLCF E WorkStn Sfile(FmtRec:RecNo)
** Define VAT rate; fetch from LDA
D UDS
D VatRate 4 2
** Define Subfile RRN; initialize to 1
D RecNo S 4 0 Inz(1)
C Read AppVend 90
C DoW Not *in90
** Calculate VAT amount and Net amount
C Eval(H) VatAmount = BalOwe * (VatRate /
C (100 + VatRate))
C Eval NetAmount = BalOwe - VatAmount
** Write Subfile record format
C Write FmtRec
C Read AppVend 90
C Eval RecNo = RecNo + 1
C EndDo
** Display Subfile
C Write FmtFtr
C ExFmt FmtCtl
** End program if F3 or ENTER pressed
C Eval *InLr = *On
C Return

Appendix B. Exercise Solutions and Answers B-5


Student Exercises

Exercise - Expressions and Functions


Payroll Program - RPGPAY

H ExPrOpts(*ResDecPos)
F* RPGPAY - Pay check program
F*
FPayroll IF E Disk
** Define overflow named indicator
FQprint O F 132 Printer Oflind(Overflow)
* +++++ Define the Tax and Pay fields based on the database
D Pay S +2 Like(Rate)
D Tax S +2 Like(Rate)
D Net S +2 Like(Rate)
D FLname S 25
C*
C Except Hdg
C* Read a record
C DoW not(*in20)
C Read Payrec 20
C*
C If not(*in20)
C***
C* Calculate pay and tax
C ExSR PAYC
C ExSR TAXC
C Eval Net = Pay -Tax
C* +++++ Concatenate first and last name
C Eval FLName = %Trimr(LName) + ', '
C + %Trimr(FName)
C Except DETAIL
** Test for overflow
C If Overflow
C Except HDG
C Eval Overflow = *off
C Endif
C EndIf
C EndDo
C***
C Eval *InLR = *on
C Return
C********* Insert Payment calculation here ***********
C PayC BegSR
C*
C If Hours <= 35
C Eval Pay = Hours * Rate
C Else
C Eval(H) Pay = (35 * Rate)
C + ((Hours - 35) * (Rate * 1.75))
C EndIf
C EndSR
C********* Insert Tax calculation here *************
C TAXC BegSR

B-6 RPG/400 to RPG IV


Student Exercises

C*
C Eval Tax = 0
C If Pay > 200
C Eval(H) Tax = (Pay - 200) * (Taxd / 100)
C EndIf
C EndSR
OQPRINT E HDG 2 06
O 25 'Pay and tax calculation '
O UDATE Y 36
O E HDG 2
O 19 'First and Last name'
O 36 'Earned'
O 46 'Pay tax'
O 56 'Net pay'
O E DETAIL 1
O* FNAME 10
O* LNAME 26
* +++++ Delete the FNAME field and write FLname instead of LNAME
O FLname 26
O PAY 3 36
O TAX 3 46
O NET 3 56

Appendix B. Exercise Solutions and Answers B-7


Student Exercises

Exercise - Error Handling BIFs


Payroll Program - RPGPAYE

H ExPrOpts(*ResDecPos)
F* RPGPAY - Pay check program
F*
FPayroll IF E Disk
** Define overflow named indicator
FQprint O F 132 Printer Oflind(Overflow)
* +++++ Define the Tax and Pay fields based on the database
D Pay S +2 Like(Rate)
D Tax S +2 Like(Rate)
D Net S +2 Like(Rate)
D FLname S 25
C*
C Except Hdg
C* Read a record
C DoW not %eof(Payroll)
** Force an error by closing file
C Close Payroll
**
C Read (E) Payrec
** Check for any problem and abort
C If %error
C Except Error
C Leave
C EndIf
C* Do we have EOF - checking all reads
C If not %eof(Payroll)
C***
C* Calculate pay and tax
C ExSR PAYC
C ExSR TAXC
C Eval Net = Pay -Tax
C* +++++ Concatenate first and last name
C Eval FLName = %Trimr(LName) + ', '
C + %Trimr(FName)
C Except DETAIL
** Test for overflow
C If Overflow
C Except HDG
C Eval Overflow = *off
C Endif
C EndIf
C EndDo
C***
C Eval *InLR = *on
C Return
C********* Insert Payment calculation here ***********
C PayC BegSR
C*
C If Hours <= 35

B-8 RPG/400 to RPG IV


Student Exercises

C Eval Pay = Hours * Rate


C Else
C Eval(H) Pay = (35 * Rate)
C + ((Hours - 35) * (Rate * 1.75))
C EndIf
C EndSR
C********* Insert Tax calculation here *************
C TAXC BegSR
C*
C Eval Tax = 0
C If Pay > 200
C Eval(H) Tax = (Pay - 200) * (Taxd / 100)
C EndIf
C EndSR
OQPRINT E HDG 2 06
O 25 'Pay and tax calculation '
O UDATE Y 36
O E HDG 2
O 19 'First and Last name'
O 36 'Earned'
O 46 'Pay tax'
O 56 'Net pay'
O E DETAIL 1
O* FNAME 10
O* LNAME 26
* +++++ Delete the FNAME field and write FLname instead of LNAME
O FLname 26
O PAY 3 36
O TAX 3 46
O NET 3 56
O E ERROR 1
O 26 'File Error - Program Ended'

Appendix B. Exercise Solutions and Answers B-9


Student Exercises

Exercise - Date and Time


Program DATERPG

FDateDSPF CF E Workstn IndDS(WKIND)


D WkInd DS
D Exit 3 3N
D BadDate 40 40N
D Future 50 50N
// Insert code to determine the value of today
C Eval Today = %date(*date)
// End
C Write Header
C Write Footer
C Exfmt Prompt
C Dow NOT Exit
// Reset date indicator
C Eval Future = *off
// Insert the code to test for valid date entered (CharDate)
// Hint - add a second extender to your test, E (error)
C Test(DE) CharDate
// End
C If %error
C Eval BadDate = *On
C Else
// Display details
// Insert code to extract year, month, day from date entered
C Eval Year = %subdt(%date(CharDate):*years)
C Eval Month = %subdt(%date(CharDate):*months)
C Eval Day = %subdt(%date(CharDate):*days)
// End
// Insert code to
// determine number of days between job date and date entered
C Eval Days = %Diff(today
C :%date(CharDate)
C :*days)
// End
// Is Days in the past or the future?
C If Days < 0
C Eval Future = *on
C Else
C Eval Future = *off
C EndIf
C Write Detail
C EndIf
// Display prompt
C Exfmt Prompt
C Enddo
C Eval *InLR = *On

B-10 RPG/400 to RPG IV


Student Exercises

Exercise - Coding in Free Format


Program VNRFREE

fVndnam_lf if e k disk
fVndsearch cf e workstn Sfile(VSearchDta:RRN)
f IndDS(SfileInd)
d RRN s 3 0 INZ
d SfileInd DS
d Exit 03 03N
d SflEnd 40 40N
d SflClr 75 75N
d SflDspCtl 85 85N
d SflDsp 95 95N
d NotFound 96 96N
**
/free
DoW not Exit;
// Setup search key and position file cursor
Search = %TrimL(Search);
SetLL Search VndNam_lf;
Read VndNam_lf ;
Rrn = 1;
// Load Subfile and read rest of records unless at End of File
DoW Not %Eof(VndNam_LF);
Write VsearchDta;
Read VndNam_lf;
Rrn = Rrn+1;
EndDo;
// Display Subfile - do we have any records to display?
If Rrn <= 1;
NotFound = *on;
Else;
SflDsp = *on;
EndIf;
// Display records in subfile
Write Header_Fmt;
SflDspCtl = *on;
Write VsearchCtl;
SflDsp = *off;
SflDspCtl = *off;
Exfmt Prompt_fmt;
NotFound = *off;
// Start a new search - clear subfile and reset RRN
SflClr = *on;
Write VSearchCtl;
SflClr = *off;
Rrn = 0;
EndDo;

Appendix B. Exercise Solutions and Answers B-11


Student Exercises

// Eoj
*inlr=*on;
Return;
// Perform once when program loaded
BegSR *inzSr;
Write FKey_Fmt;
Exfmt Prompt_fmt;
// Set SFLEND indicator
SflEnd = *on;
Endsr;
/end-free

B-12 RPG/400 to RPG IV


Student Exercises

Exercise - ILE PDM Options

What option can be used to create a program ?


Option 26; it can be placed beside multiple modules and service programs.
What option can be used to create a service program ?
Option 27.
Place option 14 on one of the source members and prompt with the F4 key. What
CL command is prompted?
CRTBNDRPG.
How do you create a module?
Option 15.
Is there a PDM option to create a program while in the Work with Member screen?
No, you must be working with objects.

Appendix B. Exercise Solutions and Answers B-13


Student Exercises

Exercise - Binding by Copy

How do you include multiple modules in a program other than keying in each
module name?
Use option 26 on multiple modules.
What is the program attribute?
CLLE
What is the number of modules?
3
How many service programs are there?
6
Is the object compressed?
NO

B-14 RPG/400 to RPG IV


Student Exercises

Exercise - Binding by Reference


DAYSSINCE to EXPORT CurDate

H DatEdit(*YMD) DatFmt(*YMD)
DCurDate S D Export
DDateIn S D
DNoDays S 5 0
DError C 99999
C *Entry PList
C Parm DateIn
C Parm NoDays
C Test (E) DateIn
C If Not %Error
C Eval CurDate = %Date(*date)
C Eval NoDays = %Diff(CurDate:DateIn:*D)
C Else
C Eval NoDays = Error
C EndIf
C Return

Appendix B. Exercise Solutions and Answers B-15


Student Exercises

Exercise - ILE Source Debugger


After setting the breakpoint, how can you tell that the breakpoint has been set?
The line number where you set the breakpoint is highlighted or displayed in a
different color.
At what line number did you set the breakpoint? Make any necessary corrections.
Be careful to set the breakpoint at the program line number in the first column.

B-16 RPG/400 to RPG IV


Student Exercises

Exercise - Converting RPG III Source to RPG IV


Conversion Report Excerpt You should get information like this for each program.
This excerpt involves only two of the programs being converted. For all programs,
the aid will convert:
Defintions in calculations to D-specs
Reformat all RPG II specs to RPG IV specs
Convert all RPG III to RPG IV opcodes that are supported
Flag all non supported opcodes

When you browse your converted members, you will see this.

OE85000 BOB
5716RG1 V3R7M0 961108 RN IBM ILE RPG/400
From file . . . . . . . . . . . : OE85000/RPG400SRC(RPG05)
To file. . . . . . . . . . . . . : OE85000/QRPGLESRC(RPG05)
Log file . . . . . . . . . . . . : *LIBL/QRNCVTLG(QARNCVTLG)
C o n v e r s i o n R e p o r t
Sequence <----------------------- Source Specifications ----------------
Number ....1....+....2....+....3....+....4....+....5....+....6....+...
002000 C CALL 'RPG05S' DLTPRM
*RNM0511 00 CALL operation code found.
004100 C DEBUG
*RNM0517 30 DEBUG operation code is not supported in RPG IV.
004700 C CALL 'RPG05S' DLTPRM
*RNM0511 00 CALL operation code found.
5716RG1 V3R7M0 961108 RN IBM ILE RPG/400
From file . . . . . . . . . . . : OE85000/RPG400SRC(RPG10)
To file. . . . . . . . . . . . . : OE85000/QRPGLESRC(RPG10)
Log file . . . . . . . . . . . . : *LIBL/QRNCVTLG(QARNCVTLG)
:
:
OE85000 BOB
5716RG1 V3R7M0 961108 RN IBM ILE RPG/400
From file . . . . . . . . . . . : OE85000/RPG400SRC(RPG10)
To file. . . . . . . . . . . . . : OE85000/QRPGLESRC(RPG10)
Log file . . . . . . . . . . . . : *LIBL/QRNCVTLG(QARNCVTLG)
C o n v e r s i o n R e p o r t
Sequence <----------------------- Source Specifications ----------------
Number ....1....+....2....+....3....+....4....+....5....+....6....+...
002500 C CALL 'RPG10S' DLTPRM
*RNM0511 00 CALL operation code found.
005100 C CALL 'RPG10S' DLTPRM
*RNM0511 00 CALL operation code found.
:
:

Appendix B. Exercise Solutions and Answers B-17

Vous aimerez peut-être aussi