Rabu, 03 April 2013

AS400 Showcase Article - Report Layout Utility (RLU)


Learning to use the tools on the AS/400 is one of the best ways to leverage your expertise. Managers may be surprised to learn how easy it is to provide users with sample report layouts that can be designed with an on-line tool. This on-line tool is RLU, Report Layout Utility. Because many programmers find its interface to be confusing, not many have become proficient RLU users. Read on and you will learn to create report layouts quickly and easily.
In the early days of RPG, reports were always printed using OUTPUT specifications. With the advent of DDS, it became possible to make print files using DDS. This is similar to the way DDS is used to make display files. The AS/400 provides SDA, Screen Design Aid, as an on-line tool to design display files. Similarly, RLU, is an on-line tool to design reports.
Suppose a user needs a report showing:

1.  Customer number
2.  Customer name
3.  Customer city
4.  Annual purchase amount
These fields are in the customer master file, CUST. We will write an RPG program, CUSR005 to read the CUST file and write a print file, CUSW005. Figure 1 shows the finished report that we will design with RLU. To start RLU, enter the command STRRLU and hit F4. Enter QDDSSRC as the source file. Enter the library name and CUSW005 as the source member. Since this is a narrow report, enter 65 for the page width. For a standard width report, you would use 132 for the page width.
RLU now displays its DESIGN REPORT screen. RLU uses so many function keys that there is a base set of function keys and an alternate set of keys. F22 is used to toggle between the base keys and the alternate keys. Right now RLU shows the word, BASE in the upper left portion of the screen to indicate that the base set of function keys is in use. F22 changes to the alternate keys and the changes the display from BASE to ALT.
The simplest way to use RLU is to define each line as a separate record. To start working with a line of the report, key DR for DEFINE RECORD in the command area on a blank line. When you hit the enter key, RLU names the record with the default name RCD001. After defining a record, enter VF for VIEW FIELDS in the command area of the same line. RLU then adds a line above the record to show the field information.
The heading for the report will be CUSTOMER ANNUAL PURCHASES. On the line with RCD001, key in the heading. Then, convert this string of characters to a constant. Do this by placing the cursor on the first character of the heading and hitting F11 for DEFINE FIELD. Hit F11 again and then ENTER to convert the string of characters to a constant. Finally, center the heading by keying CF for CENTER FIELD on the command portion of the RCD001 line. When you hit ENTER, the heading will center.
Now, create a second record. This will be used to print the customer fields. First insert a line to work with. Key I for INSERT in the command area of the RCD001 line and hit ENTER. Then, as before, key DR to define this as a record and then VF for VIEW FIELDS.
Next, use RLU to retrieve the field definitions from the master file. Hit F10 for DATABASE FIELDS. Key 1 for the option to ADD FIELD. Leave the FIELD value blank. Enter the library name and CUST for the File. Enter the record name of the CUST file. RLU will then retrieve all the fields in the CUST file and list them. Select the fields for the report. Hit ENTER until you return to the DESIGN REPORT screen.
The names of the fields you selected are at the bottom of the screen. Each field is sequentially numbered. To insert the first field in the report, key 1 in the text area of the FLD record above the detail record line. When you hit ENTER, RLU puts that field in the layout. RLU has re-sequenced the remaining fields. Place the remaining fields in the report.
If you overlap fields, RLU can get confusing. The simplest way to recover is to delete the record by keying a D in the command area of the record. Then start the record over. If you want to remove a field, put the cursor on the field and hit F16. If you need to move a field, use F13 to mark where the cursor is positioned and then F15 to move the field to a new location.
Now that you have placed the fields in a detail record, create headings for the detail line. Insert a line above the detail line. As always, key DR for DEFINE RECORD and then VF to VIEW FIELDS. Simply key the headings in the text area of the blank record that you inserted. Then convert each field to a constant by putting the cursor on the first character of each literal and hitting F11 twice.
To help visualize the report, create some sample data lines. Make 5 copies of the detail line by keying SD5 on the command line of the detail line.
Now, add a line at the bottom of the report for the total annual purchases. Do this by keying I in the command line of the last record on the screen. As always, key DR and then VF in the command area of the record.
Key the word TOTAL in the text area of the record. Convert the word to a constant by placing the cursor on the first letter of the word and hitting F11 twice. Now, add a new field for the accumulated total. This can get confusing.
Place the cursor where you want the total amount to print. Hit F11 to DEFINE FIELD. On the DEFINE FIELD INFORMATION screen, change the name of the field from the default FLD001 to TOTPUR. Change the length of data to 9. Hit PAGE DOWN. Change the data type to 2 for ZONED and enter 2 for decimal positions. Then hit F10 to WORK WITH KEYWORDS. Select EDTCDE by keying 2 next to it. Hit ENTER and key 1 for the EDTCDE value. Hit ENTER a few times and you will see that you have added a field for the total purchases.
Finally, add the date and page counter to the first heading line. Do this by adding a field of the appropriate length, converting it to a constant and then selecting the appropriate keyword. Also, rename the records by using F18 for RECORD KEYWORDS and then F10 to rename the record.
Exit RLU with F3. You can save the DDS, compile it and generate a prototype report all from the exit screen.
Figure 2 shows the complete RPG program to print the report.


 
Figure 1 - This is the finished report designed by RLU.  

                                                                 
FLD1    <........>          <.......................>       <..>   <...>      
   HDG1 01/04/2001          CUSTOMER ANNUAL PURCHASES       Page   9,999      
FLD1    <..>    <...........>             <..>           <..........>         
   HDG2 CUS#    CUSTOMER NAME             CITY           ANNUAL PURCH         
00004 +                                                                       
FLD1    <....>  <.......................> <.............>   <.......>         
    DTL 999999  XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX   99,999.99         
00006 S 999999  XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX   99,999.99         
00007 S 999999  XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX   99,999.99         
00008 S 999999  XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX   99,999.99         
00009 S 999999  XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX   99,999.99         
00010 S 999999  XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX   99,999.99         
FLD1                                      <...>          <..........>         
   TOTL                                   TOTAL          9,999,999.99         



Figure 2 - This is the complete RPG program to print the report.

FCUST      IF   E           K DISK                                     
FCUSW005   O    E             PRINTER OFLIND(*In99)                    
C                   Move      *On           *In99                      
C                   Read      CUST                                   90
C     *In90         DoWEq     *Off                                     
C     *In99         IfEq      *ON                                      
C                   Write     HDG1                                     
C                   Write     HDG2                                     
C                   Move      *Off          *In99                      
C                   EndIf                                              
C                   Add       CUSAP         TOTPUR                     
C                   Write     DTL                                      
C                   Read      CUST                                   90
C                   EndDo                                              
C                   Write     TOTL                                     
C                   Eval      *INLR = *On                              
C                   Return 

Tidak ada komentar:

Posting Komentar