If you are retrieving data from several sources, the code gets more involved, but the central concept remains the same: you supply the code to retrieve the data needed to print one line of the report (regardless of whether that line is a record from a single data file or a collection of related data), then perform a generated routine to print that output in the format that you designed in the graphical Report Composer interface.
The code that follows demonstrates the process of populating a report with data from three indexed files. The report lists all of the clients of a veterinary clinic (recorded in a file called clients), all of the pets belonging to each client (recorded in a file called pets), and all of the treatments received by each pet (recorded in a file called trecord). In the interest of clarity, the file handling code has been simplified, leaving out INVALID KEY and AT END status checking.
The basic process retrieves data from the first file and uses that data to retrieve information from the second file. The data from the second file, in turn, is used to retrieve data from the third file. With all of the data in place, the print routine is executed to print a line (including group headers, group footers, and a detail section) of the report. The process then repeats until the entire report has been printed.
create-history-report. MOVE LOW-VALUES TO cl-client-id. START clients KEY >= cl-client-id. PERFORM UNTIL ws-client-status = "10" READ clients NEXT RECORD IF ws-client-status NOT = "10" AND ws-client-status NOT = "02" PERFORM get-pets-for-client END-IF END-PERFORM. * get-pets-for-client. MOVE cl-client-id TO pet-owner-id. START pets KEY = pet-owner-id. PERFORM UNTIL pet-owner-id NOT = cl-client-id READ pets NEXT RECORD IF pet-owner-id = cl-client-id PERFORM get-pet-treatment-history END-IF END-PERFORM. * get-pet-treatment-history. MOVE pet-id TO tr-pet-id. START trecord KEY = tr-pet-id. PERFORM UNTIL tr-pet-id NOT = pet-id READ trecord NEXT RECORD IF tr-pet-id = pet-id PERFORM Acu-RPT-comp-rpt-DO-PRINT-RTN END-IF END-PERFORM.