Creating DDS for subfiles can be a challenging task. In all, there are 26 DDS keywords that relate to subfiles. You have to figure out which ones you need, which record format to place them in and which parameters you specify. Fortunately, SDA does much of this work for you. SDA breaks down the task into logical steps, groups related keywords together and provides syntax checking and context-sensitive help along the way.
The subject of subfiles is an extensive topic. While I will discuss some basic subfile concepts, this article focuses on SDA. For an in-depth treatment of subfile concepts, refer to the four-part "AS/400 Subfile Programming" series published in MC from July 1992 through October 1992.
This article presents a tutorial which shows how to create subfiles with SDA. For those who want practice using SDA or just want to improve their subfile skills, this exercise should help. I have supplied figures for some of the screens I describe in the article. However, due to spatial constraints, I can't show all the screens. Therefore, it is to your advantage to perform these steps at your terminal as I describe them to you. So sign on to your workstation and get ready for a guided tour of the subfile capabilities of SDA.
The Practice Subfile
In this exercise, you'll create a subfile application to display the records in file QADBXREF in library QSYS. This file is automatically maintained on every AS/400 and contains a record for each file in your system. 1 shows what the final screen will look like from an SDA design session.
In this exercise, you'll create a subfile application to display the records in file QADBXREF in library QSYS. This file is automatically maintained on every AS/400 and contains a record for each file in your system. Figure 1 shows what the final screen will look like from an SDA design session.
The screen in 1 consists of three record formats, which is typical of most subfile panels. The top portion of the screen is a subfile control record, called CTLREC, which contains heading literals. The middle section is a series of subfile records, called SFLREC, containing database fields (one subfile record per database record). The bottom portion of the screen is a record called FKEYS, which contains a literal to display valid function keys.
The screen in Figure 1 consists of three record formats, which is typical of most subfile panels. The top portion of the screen is a subfile control record, called CTLREC, which contains heading literals. The middle section is a series of subfile records, called SFLREC, containing database fields (one subfile record per database record). The bottom portion of the screen is a record called FKEYS, which contains a literal to display valid function keys.
Creating this display file requires that you progress through a series of options within SDA. The flowchart in 2 shows an overview of the path I will lead you through. You may find it helpful to refer to this chart as you work through this exercise.
Creating this display file requires that you progress through a series of options within SDA. The flowchart in Figure 2 shows an overview of the path I will lead you through. You may find it helpful to refer to this chart as you work through this exercise.
Getting Started
To begin creating the display file, start SDA by entering the following command:
STRSDA OPTION(1) + SRCFILE(xxx/QDDSSRC) + SRCMBR(SFL005DF)
SDA presents you with the Work with Display Records panel. Initially, this screen does not contain any records. Before creating the records, define the valid function keys for the display file by pressing F14 to access the file- level keywords. On the Select File Keywords panel, place a Y in the Indicator keywords option and press Enter. SDA presents you with the Define Indicator Keywords panel. In the first row, type CA03 in the Keyword column and 03 in the Resp column. This activates indicator 03 whenever the user presses the F3 key. Press Enter twice to return to the Work with Display Records panel.
Creating the Records
Now you're ready to create the three record formats for the display file. SDA ensures that every subfile record has a corresponding subfile control record by always creating them in pairs. To see how this works, select option 1 and press Enter. SDA presents you with the Add New Record panel. Type the name SFLREC in the New Record prompt and SFL in the Type prompt and press Enter. When SDA prompts you for the name of the subfile control record, type CTLREC and press Enter. This creates two record formats: SFLREC and CTLREC.
When you create a subfile, SDA automatically prompts you for both the subfile and subfile control keywords and assigns them to the appropriate record format. The first screen is the Select Subfile Keywords panel. Bypass this screen by pressing Enter, since this application doesn't require any subfile keywords. The next screen is the Select Subfile Control Keywords panel. On this screen are three groups of keywords you need to use. Place a Y next to "General keywords," "Subfile display layout" and "Select record keywords," and then press Enter.
First, SDA presents you with the Define General Keywords panel. Complete this screen as shown in 3 and press Enter. The detail given below provides explanations for the entries you've just made or accepted on the Define General Keywords panel.
First, SDA presents you with the Define General Keywords panel. Complete this screen as shown in Figure 3 and press Enter. The detail given below provides explanations for the entries you've just made or accepted on the Define General Keywords panel.
o A value of SFLREC is already supplied for the SFLCTL keyword. This is the name of the subfile control record you entered earlier.
o The SFLDSP keyword is required so the Y is already selected and cannot be removed. Indicator 90 controls the SFLDSP keyword.
An indicator is necessary on this keyword because if your program writes the subfile control record with the SFLDSP keyword in effect and the subfile empty, an error message is generated. To prevent this from happening, set on indicator 90 when you write records to the subfile. If there are any records in the subfile, SFL-DSP will be active and the subfile will be displayed. Otherwise, SFLDSP will be inactive, causing the program to display only the subfile control record without causing an error to occur.
o Indicator 91 controls the SFLCLR keyword. To clear the subfile (remove all active records), set on indicator 91, write the subfile control record, then set off indicator 91.
o The N03 and the Y on the SFLEND keyword cause the system to display "More..." at the bottom of the subfile when there are more records to display. The system will also display "Bottom" when there are no more records to display. This happens only if indicator 03 is off when you display the subfile. Since indicator 03 is also used to exit the program, this should always be true. This technique satisfies the indicator requirement of the SFLEND keyword without using an additional indicator.
Next, SDA presents you with the Define Display Layout panel. Two entries are necessary on this screen. Change the SFLSIZ number to 17 and the SFLPAG number to 16. This instructs the system to display 16 records at a time in the subfile. Specifying a SFLSIZ value which is greater than the SFLPAG value tells the system that you want OS/400 to handle the paging of the subfile when the user presses a Roll key.
Pressing Enter takes you to the Select Record Keywords panel. Place a Y in the Overlay Keywords option and press Enter. On the Select Overlay Keywords panel, place a Y next to the OVERLAY keyword. This causes the subfile and subfile control records to overlay whatever is on the screen when they are written. The overlaying is necessary for this application because the record containing the literal for the valid function key (FKEYS) will be written first. The OVERLAY keyword prevents this record from being erased. Press Enter three times to return to the Work with Display Records panel.
At this point, you should see two record formats listed: one for the subfile (SFLREC) and one for the subfile control (CTLREC). Although you have selected the keywords for these records, you have not yet designed the image. Before designing these images, create the third record format as follows.
Select option 1 on the top line and press Enter. On the Add New Record panel, type the name FKEYS in the New Record prompt and press Enter. This takes you to the Design Image work screen. Type the literal 'F3=Exit' in single quotes in the bottom, left corner (row 23, beginning in column 2) of the screen and press Enter. Use the cb (color blue) command to change the literal to blue-the standard color for function-key literals. When entering the cb command, place the c in front of the literal and the b over the first character, then press Enter. If you are using a color workstation, you will see the literal change from green to blue. Press F12 to return to the Work with Display Records panel.
Designing the Subfile Image
You should now see three record formats listed as shown in 4. To design the image for the subfile, select option 12 for the SFLREC record and press Enter. As stated earlier, the subfile record will contain database fields from the QADBXREF file. To retrieve these fields, press F10 to access the Select Database Files panel. Select option 1 and type QADBXREF under "Database File," QSYS under "Library" and QDBXREF under "Record." Press Enter to display the Select Database Fields panel shown in 5.
You should now see three record formats listed as shown in Figure 4. To design the image for the subfile, select option 12 for the SFLREC record and press Enter. As stated earlier, the subfile record will contain database fields from the QADBXREF file. To retrieve these fields, press F10 to access the Select Database Files panel. Select option 1 and type QADBXREF under "Database File," QSYS under "Library" and QDBXREF under "Record." Press Enter to display the Select Database Fields panel shown in Figure 5.
Use option 3 to select the DBXFIL, DBXLIB, DBXTXT and DBXATR fields for output. Press Enter twice to return to the Design Image work screen. The selected fields appear along the bottom of the screen, each preceded by a field number. Place the fields on the screen by specifying &n, where n is the field number. Place the fields on row five and use 1 as a reference to determine the column for each field. When you have finished, press F12 to return to the Work with Display Records panel.
Use option 3 to select the DBXFIL, DBXLIB, DBXTXT and DBXATR fields for output. Press Enter twice to return to the Design Image work screen. The selected fields appear along the bottom of the screen, each preceded by a field number. Place the fields on the screen by specifying &n, where n is the field number. Place the fields on row five and use Figure 1 as a reference to determine the column for each field. When you have finished, press F12 to return to the Work with Display Records panel.
The last task is to add the screen headings. To do this, select option 12 next to the CTLREC record and press Enter. Add the heading literals shown at the top of 1. When the heading literal is made up of more than one word, enclose them within single quotes. Highlight the headings by placing an h in front of each one and pressing Enter. The screen should now look like the one in 1 except that you can't see the function key literal at the bottom of the screen. To view it, press F9 to access the Select Additional Records for Display panel. Use option 2 to select FKEYS and press Enter. Now you can see all three record formats on the screen at once, just as 1 shows. Press F12 to once again return to the Work with Display Records panel.
The last task is to add the screen headings. To do this, select option 12 next to the CTLREC record and press Enter. Add the heading literals shown at the top of Figure 1. When the heading literal is made up of more than one word, enclose them within single quotes. Highlight the headings by placing an h in front of each one and pressing Enter. The screen should now look like the one in Figure 1 except that you can't see the function key literal at the bottom of the screen. To view it, press F9 to access the Select Additional Records for Display panel. Use option 2 to select FKEYS and press Enter. Now you can see all three record formats on the screen at once, just as Figure 1 shows. Press F12 to once again return to the Work with Display Records panel.
You have completed designing the display file, so it's time to save your work. Press F3 to exit SDA. You will see the Save DDS panel. The default is to save the DDS source code and create the display file object. Press Enter to perform these functions, then press Enter again to exit SDA. The DDS source code you have just created should look similar to the code in 6. The only difference is that I have removed the comment lines which SDA inserts and I have added the compile instruction comment box at the top of the source code.
You have completed designing the display file, so it's time to save your work. Press F3 to exit SDA. You will see the Save DDS panel. The default is to save the DDS source code and create the display file object. Press Enter to perform these functions, then press Enter again to exit SDA. The DDS source code you have just created should look similar to the code in Figure 6. The only difference is that I have removed the comment lines which SDA inserts and I have added the compile instruction comment box at the top of the source code.
The Subfile in Action
If you want to see your new display file run, I have provided a short RPG program shown in 7 which you can use. Here's how the program works. First, the program clears the subfile by setting on indicator 91 and writing the CTLREC record. You'll recall that indicator 91 controls the SFLCLR keyword.
If you want to see your new display file run, I have provided a short RPG program shown in Figure 7 which you can use. Here's how the program works. First, the program clears the subfile by setting on indicator 91 and writing the CTLREC record. You'll recall that indicator 91 controls the SFLCLR keyword.
Next, the program reads the QADBXREF file and writes the first 160 records (where the DBXLIB field is not blank) to the SFLREC record. When the program writes a subfile record, it sets on indicator 90. This indicator controls the SFLDSP keyword and prevents an error if the subfile is empty. The program then writes the FKEYS record followed by an EXFMT operation to the CTLREC record. Because the CTLREC record contains the OVERLAY keyword, OS/400 does not erase the FKEYS record. If there are any records in the subfile, they are displayed automatically when you write CTLREC. Finally, when the user presses F3 or Enter, the program ends.
Take Advantage of SDA
As you have seen, SDA simplifies the task of creating subfiles. With a little practice, you'll be creating subfiles from scratch in a matter of minutes. Using SDA to create subfiles means you'll spend less time working out the mechanics of subfile coding, giving you more time to design applications which help your business grow.
Robin Klima is a senior technical editor at Midrange Computing.
REFERENCES DDS Reference (SC41-9620, CD-ROM QBKA7402). SDA User's Guide and Reference (SC09-1340, CD-ROM QBKA0802).
Creating Subfiles with SDA
Figure 1 The Practice Subfile
Files On System Library File Attr Text OOOOOOOOOO OOOOOOOOOO OO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OO OOOOOOOOOOOOOOOOOOOOOOOOOO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with SDA
Figure 3 Define General Keywords
Define General Keywords Subfile control record . . . . . . . . . : CTLREC Type choices, press Enter. Keyword Related subfile record . . . . . . . SFLCTL SFLREC Name Subfile cursor relative record . . . SFLCSRRRN __________ Name Subfile mode . . . . . . . . . . . . SFLMODE __________ Name Y=Yes Indicators/+ Display subfile records . . . . . . SFLDSP Y 90 ___ ___ Display control record . . . . . . . SFLDSPCTL Y ___ ___ ___ Initialize subfile fields . . . . . SFLINZ _ ___ ___ ___ Delete subfile area . . . . . . . . SFLDLT ___ ___ ___ Clear subfile records . . . . . . . SFLCLR 91 ___ ___ Indicate more records . . . . . . . SFLEND N03 ___ ___ SFLEND parameter . . . . . . . . *MORE Y Record not active . . . . . . . . . SFLRNA _ More... F3=Exit F12=Cancel
Creating Subfiles with SDA
Figure 4 Work with Display Record
Work with Display Records File . . . . . . : SOURCE Member . . . . . . : SFL005DF Library . . . . : $KLIROB Source type . . . : DSPF Type options, press Enter. 1=Add 2=Edit comments 3=Copy 4=Delete 7=Rename 8=Select keywords 12=Design image Opt Order Record Type Related Subfile Date DDS Error __ __________ __ 10 SFLREC SFL 04/14/94 __ 20 CTLREC SFLCTL SFLREC 04/14/94 __ 30 FKEYS RECORD 04/14/94 Bottom F3=Exit F12=Cancel F14=File-level keywords F15=File-level comments F17=Subset F24=More keys
Creating Subfiles with SDA
Figure 5 Select Database Fields
Select Database Fields Record . . . : QDBXREF Type information, press Enter. Number of fields to roll . . . . . . . . . . . . . . . . . . 8 Name of field to search for . . . . . . . . . . . . . . . . . __________ Type options, press Enter. 1=Display extended field description 2=Select for input (I), 3=Select for output (O), 4=Select for both (B) Option Field Length Type Column Heading _ DBXFIL 10 A FILE NAME _ DBXLIB 10 A LIBRARY NAME _ DBXDIC 10 A DICTIONARY NAME _ DBXOWN 10 A FILE OWNER _ DBXTXT 50 A FILE TEXT _ DBXATR 2 A FILE ATTR _ DBXLNK 1 A LINK STATUS _ DBXSQL 1 A DICTIONARY TYPE More... F3=Exit F12=Cancel
Creating Subfiles with SDA
Figure 6 Display File SFL005DF
*=============================================================== * To compile: * * CRTDSPF FILE(XXX/SFL005DF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A CA03(03) A R SFLREC SFL A DBXFIL R O 5 2REFFLD(QDBXREF/DBXFIL QSYS/QADBXREF) A DBXLIB R O 5 13REFFLD(QDBXREF/DBXLIB QSYS/QADBXREF) A DBXTXT R O 5 30REFFLD(QDBXREF/DBXTXT QSYS/QADBXREF) A DBXATR R O 5 25REFFLD(QDBXREF/DBXATR QSYS/QADBXREF) A R CTLREC SFLCTL(SFLREC) A OVERLAY A 90 SFLDSP A SFLDSPCTL A 91 SFLDLT A N03 SFLEND(*MORE) A SFLSIZ(0017) A SFLPAG(0016) A 1 33'Files on System' A DSPATR(HI) A 4 2'File' A DSPATR(HI) A 4 13'Library' A DSPATR(HI) A 4 24'Attr' A DSPATR(HI) A 4 30'Text' A DSPATR(HI) A R FKEYS A 23 2'F3=Exit' A COLOR(BLU)
Creating Subfiles with SDA
Figure 7 RPG Program SFL005RG
*=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/SFL005RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FSFL005DFCF E WORKSTN F RN KSFILE SFLREC FQADBXREFIF E K DISK * * Clear the subfile C MOVE *ON *IN91 C WRITECTLREC C MOVE *OFF *IN91 * * Load the subfile C READ QDBXREF 99 C *IN99 DOWEQ*OFF C RN ANDLT160 C DBXLIB IFNE *BLANKS C ADD 1 RN 50 C WRITESFLREC C MOVE *ON *IN90 C ENDIF C READ QDBXREF 99 C ENDDO * * Display the screen C WRITEFKEYS C EXFMTCTLREC * C MOVE *ON *INLR
LATEST COMMENTS
MC Press Online