Easily Modify Report Programs because you have better
Easily Modify Report Programs (because you have better things to do) Ted Holt Sr. Software Developer, Profound Logic Software Sr. Technical Editor, Four Hundred Guru
Agenda • Definitions and background • The "Cletus" method • An example
Format of Columnar Reports Contributions 3/17/15 Page 1 Shift Name Amount =============== 1 Fife, Bernard P. 20. 00 1 Haywood, Jesse W. 5. 00 Shift total 25. 00 2 Heggs, Luther 10. 00 2 Figg, Hollis 10. 00 Shift total 20. 00 Grand total 45. 00 3
Traditional Methods of Report Definition • Output specifications • DDS Remember these? 4
Problem with Traditional Methods Making one change. . . • Adding a column • Deleting a column • Moving a column • Resizing a column 5
Problem with Traditional Methods requires making more changes. • Adjust column headings, detail lines, subtotals, and grand totals. 6
Problem with Traditional Methods • Modifying DDS and O specs by hand is tedious. • RLU stinks.
Agenda • Definitions and background • The "Cletus" method • An example
A Different Approach • Published in Four Hundred Guru on April 14, 2004 "An Alternative to Externally Described Printer Files" • http: //www. itjungle. com/fhg 041404 -story 02. html • Updated "An Alternative to Externally Described Printer Files, Take 2" • http: //www. itjungle. com/fhg 041404 -story 02. html 9
Advantages of the "Cletus" Method • Column headings, detail line, and total lines adjust together. 10
Advantages of the "Cletus" Method • Spacing and skipping are easily controlled with simple assignment statements. 11
Advantages of the "Cletus" Method • Most of the report logic is reusable code in a template. 12
The Print. Line Data Structure • Length is the record length • Defines the columns of a report • All subfields are alpha 13
The Print. Line Data Structure • Includes unnamed spacer fields to separate the columns • Overlapping columns may be defined with OVERLAY keyword. 14
The Print. Line Data Structure D Print. Line D Column 01 D D Column 02 D D Column 03 D D Column 04 ds 132 7 1 25 1 7 2 15 15
The Print. Line Data Structure D Print. Line D Col. Cus. No D D Col. Cus. Name D D Col. Qty. Sold D D Col. Amount ds 132 7 1 25 1 7 2 15 16
Loading the Data Structure • Use same structure for column headings, detail lines, and column totals 17
Loading the Data Structure • Use EVAL for character data • Use EVALR for numeric data 18
Loading the Data Structure • Use %EDITC and %EDITW functions to load numeric fields 19
Loading Column Headings evalr eval exsr Column 01 Column 02 Column 03 Column 04 Print = = 'State' 'Name' 'Account' 'City' 20
Loading a Detail Line eval Column 01 = State Column 02 = %trimr(Lst. Nam) + ' ' + Init evalr Column 03 = %editc(Cus. Num: '4') eval Column 04 = City exsr Print 21
Loading Column Totals evalr eval exsr Column 02 = State + ' total' Column 04 = %editc(Count: '3') Space. Before = Double. Space Print Note: There is no need to load unused columns because each write clears the data structure. 22
Spacing and Skipping Use a printer control data structure to control spacing and skipping. FPAY 922 P o F f D Prt. Ctl D Space. And. Skip D Space. Before D Space. After D Skip. Before D Skip. After D Current. Line 132 printer prtctl(Prt. Ctl) oflind(Overflow) ds 1 1 4 7 10 13 12 3 6 9 12 15 s 0 23
Spacing and Skipping • If Space. And. Skip is blank, the program assumes you want to space once before printing. 24
Writing to the Printer Use the WRITE opcode with the printer file name in factor 2 and the data structure in the result field. write Pay 922 P Print. Line 25
Features of the Template • Single spacing (before) is assumed. • The printer data structure and spacing/skipping data structure always cleared after writing to the printer. 26
Features of the Template • Predefined spacing and skipping constants improve readability. • Works with SQL input (my preference) or input opcodes (e. g. , READ). 27
Agenda • Definitions and background • The "Cletus" method • An example
Example Time Programs DEMO 1 C (CL driver) and DEMO 1 R (Report program) File QCUSTCDT is in library QIWS. 29
Example Time DEMO 1 C (CL driver) pgm ovrdbf qcustcdt share(*yes) opnqryf qcustcdt + keyfld((state) (lstnam) (init)) call demo 1 r clof qcustcdt dltovr qcustcdt endpgm 30
Example Time Fqcustcdt if e disk prefix(C_) Fqsysprt o f 132 printer oflind(Overflow) F prtctl(Prt. Ctl) Program described 31
Example Time D Prt. Ctl ds D Space. And. Skip D Space. Before D Space. After D Skip. Before D Skip. After D Current. Line 1 1 4 7 10 13 2 3 6 9 12 15 s 0 32
Example Time D D Single. Space Double. Space No. Spacing Top. Of. Form c c '001' '002' '000' '001' 33
Example Time D Print. Line ds D Column 01 D D Column 02 D … 3 columns omitted D Column 06 D D Column 07 132 7 1 25 1 12 1 2 34
Example Time D D D Save. State Cdt. Due 1 Cdt. Due. R Bal. Due 1 Bal. Due. R s s s like(C_State) like(C_Cdt. Due) like(Cdt. Due 1) like(C_Bal. Due) like(Bal. Due 1) 35
Example Time // subroutine Print. Detail Column 01 = C_State Column 02 = %trimr(C_Lst. Nam) + ' ' + C_Init evalr Column 03 = %editc(C_Cus. Num: '4') Column 04 = C_City evalr Column 05 = %editc(C_Cdt. Due: 'J') evalr Column 06 = %editc(C_Bal. Due: 'J') exsr Print 36
Example Time // subroutine Print. Headers Double. Strike = True Page. Nbr += 1 Print. Line = 'Customer List by State (' + %trim(psds. Proc. Name) + ') ' + %editc(psds. Sys. Date: 'Y') + ' ' + %editw(psds. Sys. Time: ' : : ') + ' Page ' + %char(Page. Nbr) Skip. Before = Top. Of. Form exsr Print 37
Example Time evalr Column 03 = 'Account' evalr Column 05 = 'Credit' evalr Column 06 = 'Balance' Space. Before = Double. Space exsr Print 38
Example Time // control totals Column 02 = ' ' + Save. State + ' total' evalr Column 05 = %editc(Cdt. Due 1: 'J': *Cur. Sym) evalr Column 06 = %editc(Bal. Due 1: 'J': *Cur. Sym) eval Column 07 = '*' Space. Before = Single. Space. After = Single. Space exsr Print 39
Quizzette How would you make the following changes? 1. Allow 5 fewer positions for the name. 2. Add 2 spaces between credit due and balance due. 40
Quizzette 3. Double-space the detail lines. 4. Double-strike the control totals and grand total. 5. Put the city column after state? 41
EVAL *INLR = *ON;
- Slides: 42