Many programmers that have come to the AS/400 via S/36s and S/34s have retained old programming habits that, although solid, could be easily replaced with new techniques. Everyone knows this, but it is a task that is far easier said than done. You may read about UIM, windows for DDS, REXX, etc....But let's face it, a lot of this stuff is not what we do every day for a living. What about the not-so-glamorous stuff that's going to help right now, today?
For example, my old style of coding a simple interactive maintenance program was to begin all screen field names with a '$' sign. Then in my RPG program I would perform the following steps:
1. CHAIN and release my database record. To release the record, I place an N in position 53 of the C-spec containing the CHAIN operation. 2. Move the appropriate database fields to my screen fields. 3. Display the screen. 4. Read the screen looking for changes and, if changes had been made, I would CHAIN again to my database record. 5. Move the appropriate screen fields to my database fields. 6. Finally, update my record.
Whew! What a chore! I would think to myself, "What a pain in the butt-with all this new external &*%$, you would think this could be easier!"
Well, I found out it can be easier! I discovered the DDS keyword Return Data (RTNDTA). This keyword can eliminate the need to create separate variable names in display files used for database file updates. The display file can reference the database fields instead. No need to worry about field attributes matching between the database file and the display file. I don't have to code any MOVEs or Z-ADDs, and my program size is smaller as there are not as many variables.
Here's how it's done.
DDS coding:
Place the RTNDTA keyword at the record level on the appropriate record of the display file. Use the database field names and reference the database file. This will bring the database fields into the display file automatically when you retrieve the database record.
RPG coding:
1. CHAIN and release the database record.
2. Display the screen.
3. Read the screen looking for changes and, if changes have been made, CHAIN
again to the database record.
4. Reread the display format using the READ operation. This is what makes this
technique work. Since I CHAINed again to the database record, the internal
representation of the display file record is overlaid and any changes to
the display record are lost. But by reading the display record again (with
the RTNDTA keyword), you can retrieve the original values of the screen.
5. Update the database record.
Although this is not a mind-boggling, high-glam tip, I found it to be quite helpful. To be honest, I felt silly that I didn't know of this timesaving keyword; but as I talked to others, I found quite a few who weren't aware of it either. Maybe it can help you as well.
The DDS manual is a good reference where this keyword is concerned.
Editor's Note: This technique is meant for RPG programmers only. If you code in any other language you don't have a problem since you can always qualify variable names. COBOL, for example, can distinguish between CUSTOMER-NAME in the display file and CUSTOMER-NAME in the database file by qualifying it with OF or IN, such as CUSTOMER-NAME IN CUSTOMER-RECORD.
LATEST COMMENTS
MC Press Online