Define Report Logic

Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

After you create a mock-up, you define the report logic in the Program Painter using AMB Report Writer structures. Report Writer structures let you automatically perform paging, calculate field values, test and execute control breaks, generate multiple reports, and generate all logic necessary to map fields between reports and databases or files. You can include multiple reports in a single program. Follow this process:

  1. Name the input and output files

    First, using the Program Painter IO and FD keywords, name the input data file, the output report file, and the report itself.

  2. Add a Report Section

    Then, with the Program Painter RED, MOCK, and 01 keywords, you add a Report Section naming the report and defining the format of each report named. There are two types of format entries.

    • Those that describe the physical aspects of the report format, such as the maximum number of lines per page, where report lines appear on the page, and which data items are controls.
    • Those that describe the function, format, and characteristics of each report line.
  3. Determine your report groups

    AMB categorizes the report lines into report groups, which are groups of report lines that make up the headings, body, and footings of the report. Report groups are:

    • Report Heading - Header lines that print once at the beginning of a report. Optionally, it can appear on a page by itself.
    • Page Heading - Header lines that print at the top of each page.
    • Control Heading - Header lines that print each time a control break occurs.
    • Detail - Detail lines that are the body of the report. Detail lines are not required for summary reports.
    • Control Footing - Line(s) of totals that print at the end of each detail group, immediately following the detail lines.
    • Page Footing - Footer lines that print at the bottom of each page.
    • Report Footing - Footer lines that print once at the end of a report.

    The following table shows a sample mock-up with the various report group types.

    Report Heading

    WONDERFUL WIDGETS INCORPORATED
    STOCK REPORT
    XXXXXX XXX

    Page Heading

    MID-ATLANTIC
    STOCK REPORT
    XXXXXX XXX

    Control Heading

    LOCATION LAST COUNT QUANTITY QUANTITY QUANTITY 
    DATE IN STOCK ISSUED RECEIVED

    Detail Line

    XXXXXXXXXXXX 99/99/99 ZZZ,ZZ9 ZZ,ZZ9 ZZZ,ZZ9
    --------- --------- ---------

    Control Footing

    TOTAL BY LOCATION: Z,ZZZ,ZZ9 Z,ZZZ,ZZ9 Z,ZZZ,ZZ9 

    Control Footing Final

    TOTAL NUMBER OF SALES BY LOCATION: ZZZ,ZZ9 
    TOTAL WONDERFUL WIDGETS IN STOCK: Z,ZZZ,ZZ9 
    TOTAL WONDERFUL WIDGETS ISSUED: Z,ZZZ,ZZ9
    TOTAL WONDERFUL WIDGETS RECEIVED: Z,ZZZ,ZZ9 
    TOTAL WONDERFUL WIDGETS SOLD: Z,ZZZ,ZZ9

    Page Footing

    PAGE ZZZ9 

    Report Footing

    ***** END OF REPORT ***** 
  4. Further define detail lines

    Entries for the detail lines that make up the body of the report describe the characteristics of the data items, such as the format, its placement in relation to the other data items, and any control factors. You use the following statements to define the line contents.

    • SOURCE statement - Use this statement to map a data item to the report output field, using the current value of this data item each time the field prints.
    • REFERENCE statement - Use this statement to identify a non-printing data item for summing in a control footing.
    • SUM statement - Use this statement to total the values in the named fields. When a SUM statement executes, AMB automatically:
      • Creates a Working-Storage SUM accumulator field for each data item.
      • Increments the SUM accumulator.
      • Prints the accumulated values at control break time.
      • Resets the SUM accumulator to zero after printing.
    • VALUE statement - Use this statement to designate a literal value to print for the field each time the line prints.
  5. Set control breaks

    You use controls to specify how to arrange the data your report displays. For example: you might want to display detail lines arranged by sales territories within cities or states or both. You can have up to 28 control breaks. AMB processes controls from the most inclusive down to the least inclusive, that is from major to minor. When a data item designated as a control changes value, such as a monthly change in a date field, a control break occurs, and AMB:

    • Prints the detail line that caused the break.
    • Prints control headings for any lower-level data items, followed by the heading for the data item that caused the control break.
    • Prints control totals for the current and lower-level data items.
    • Clears all associated counters and accumulators.
  6. Produce the report in the Procedure Division

    In the Procedure Division, you open your input and output files, execute and print the report, and close the files, using the following Report Writer statements:

    • INITIATE statement - perform functions in the Report Writer analogous to the OPEN statement for individual files. The figure below illustrates INITIATE processing.
      Figure 1. INITIATE Logic Processing
      INITIATE Logic Processing
    • GENERATE statement - produces the body of the report, and executes and prints the entire report. When this statement executes, AMB:
      • Prints specified headings and footings.
      • Increments and resets counters and accumulators as necessary.
      • Obtains source information.
      • Produces sum information.
      • Moves values to the data item(s) in the report group entries.
      • Tests controls.
      • Prints detail lines.
      • Pages the report.
      • Prints the all lines required when a control break occurs.

        The next two figures illustrate GENERATE processing.

        Figure 2. GENERATE Logic Processing 1
        GENERATE Logic Processing 1
        Figure 3. GENERATE Logic Processing 2
        GENERATE Logic Processing 2
    • Optional USE BEFORE REPORTING statement - specifies additional processing for a heading or footing report group, such as a calculation or a line edit, prior to printing.
    • TERMINATE statement - completes the processing of a report. It is analogous to the CLOSE statement for individual files. The following figure illustrates TERMINATE processing.
      Figure 4. TERMINATE Logic Processing
      TERMINATE Logic Processing
  7. Use special counters

    AMB provides two counters that you can use in any Procedure Division statement.

    • LINE-COUNTER - Reference LINE-COUNTER to determine when to print a PAGE HEADING or a PAGE FOOTING report group. The maximum value of the LINE-COUNTER is based on the number of lines per page specified in the PAGE LIMIT(S) clause.
    • PAGE-COUNTER - Reference PAGE-COUNTER in a SOURCE statement to print the page number.