TexAS400 Tutorial



RPG Program to Change Database Records Using a Display File

Finally, we get to the fun stuff! Hold on tight because things are about to get a lot more complicated.

Up to now, you have learned about the Control Language of the AS/400. You have also been introduced to DDS. In fact, you have seen how to use DDS to define a Physical File, a Logical File and a Print File. You have also seen some simple RPG programs.

Now, we will use DDS to create a Display File. Then, we will write a program to look up a Customer# record and change it. In the next topic, we will add the ability to enter new records and to delete records. Then, we will modify the program search by customer name.

Rather than talk you through all of the details, I am showing you the source code with lots of comments. There are so many comments that it looks harder than it is. So, I have also provided source code without the comments.

First, you must create a display file. This is often thought of as a screen map. It maps fields and characters on the screen. Each record in the display file is a different screen.

You can copy the display file from the USER000 library or key it in yourself.

Before you get started, try using SDA to view the screens that I have created in USER000. First, start SDA with the command STRSDA. Use selection 3 to TEST DISPLAY FILES. For the display file, use TUTD010. For library, use USER000. For RECORD TO BE TESTED, put the cursor in the field and hit F4. SDA will list all records defined. Select a record and hit ENTER a few times to see the screen.

To use SDA this way, the display file must already be created. That is, the source code must have been entered and it must have been compiled successfully.

Now that you can see what you want to create, try keying in the source code.

To key it in, STRPDM. Use option 3. Fill in file QDDSSRC, in your library for *ALL member names. Use F6 to add the member TUTD010. Make sure the TYPE is DSPF (for DISPLAY FILE).

When entering source code lines, try using F4 to prompt the fields. To turn off prompting, hit F12.

Click here to see the source code with all the comments. This is TUTD010 in QDDSSRC in USER000.

Click here to see the source code without all the comments. This is TUTD011 in QDDSSRC in USER000.

When you are finished, compile the source code with option 14. This is running the command CRTDSPF (Create Display File). When you are done, try using SDA again to test your display file.

If you have gotten this far, pat yourself on the back.

Now, we need to write the RPG program.

The program will display the first screen, SCRN1. The user will enter an A to add, C to CHANGE or D to DELETE. But for this portion, we will only program the CHANGE logic. In the next topice, we will add the ADD and DELETE logic.

The user also must enter a Customer #.

The program will first check to make sure that a C for CHANGE was entered. It then looks in the CUST database file for the Customer #. If either of these conditions is not met, the program moves an error message to the field DSPMSG and shows SCRN1 again.

If a Customer # is found, the program shows SCRN2. This screen shows the values in the record. If the user changes any values and hits ENTER, the program will rewrite the changes to the database.

Click here to see the RPG III source code with all the comments. This is TUTR010 in QRPGSRC in USER000.

Click here to see the RPG III source code without the comments. This is TUTR010NC.

Click here to see the RPG IV source code with all the comments. This is TUTR011 in QRPGLESRC in USER000.

Click here to see the RPG IV source code without the comments. This is TUTR011NC.

As before, try using F4 to prompt the fields. To turn off prompting, hit F12.

Also, as with all programs, compile the source code with option 14.

View your compile listing with the Work With Spool File command, WRKSPLF. Look for errors at the bottom of the listing.

To run the program, key CALL TUTR010 or CALL TUTR011.

Use any valid Customer #. 1002 is a valid #.

If you completed this topic, you are well on your way to becoming an RPG programmer.

 

 

Back to Table of Contents   |   Main Page