|
Here's my shot. Recently worked a year on inquiry screens and reports from a
historical database, from which the company had migrated to a different package.
The code is NOT guaranteed, as it is off the top of my head while waiting for
my next program to work on... :) and I don't have the actual code used with
me...And this was with variations, but usually was about it.. And you get more
flexibility of course than you do within the cycle..as a side benefit...
I found it easiest (least thought-wracking) to emulate the cycle itself.
I set up two data structures for the purpose, one is a "look-ahead" to be able
to kick off total time while still inside the last record in the group.
D FileRecdDS E DS extname('FILE1')
D NextRecdDS E DS extname('FILE1') prefix(next_)
D LevelBreaks DS
D L1 N
D L2 N
D L3 N
.....
D L9 N
D Lbrks N overlay(LevelBreaks) dim(9)
Then in the code, as follows:
// Subroutine SR_READNEXT does the FETCH of the next record into
// the NEXTRECDDS data structure.
// It also sets on LR (or your program equivalent substitution)
// if no record is returned, or SQLCOD <> 0 (which matches also
// other unexpected conditions, really...(I like to name my
// indicator EOF or some such...
exsr sr_readnext ;
if LR ;
exsr Sr_LR_Totals ;
Else ;
// Set on all the level breaks...L1 through L9
Lbrks = *all'1' ; // or equivalent...
// Set on an indicator for the first record in case..
FirstRecd = *on ;
dow not LR;
FileRecdDS = nextRecdDS ;
if FirstRecd ; // Check for 1st record...
exsr Sr_FirstRecd ; // Leave FirstRecd=*on for this
FirstRecd = *off ; // in case needed for other subr's etc.
endif ;
exsr Sr_GroupHeaders ; // Check level breaks and process...
exsr sr_Detail ; // :)
exsr sr_ReadNext ; // Same pre-read as above...
// Fetches into NEXTRECDDS, and sets breaks..
exsr sr_Totals ; // Checks breaks from sr_ReadNext and processes..
Enddo ; // dow not LR...
//======================
begsr sr_FirstRecd ;
....
endsr ;
//======================
begsr sr_GroupHeaders ;
if L1 ;
exsr sr_L1processing ;
endif ;
.....
if L9 ;
exsr sr_L9processing ;
endif ;
endsr ;
//======================
begsr sr_Detail ;
....
endsr ;
//======================
begsr sr_ReadNext ;
// I like to put my SQL into subroutines
// at the bottom of the source file...
exsr sr_FetchNext ;
// Next a trick learned from the late Mr. Guthrie,
// he of the iSeriesNetwork IIRC,
// of making indicators part of the equation...
// Set for company, division, branch, and cust#, L8, L6, L4, L2
LR = (SqlCode <> 0) ;
L8 = Co# <> Next_Co# or LR ;
L6 = Division <> Next_Division or L8 ;
L4 = Branch <> Next_Branch or L6 ;
L2 = Customer# <> Next_Customer# or L4 ;
endsr ;
//======================
begsr sr_Totals ;
if L1 ;
exsr sr_L1_Totals ;
endif ;
if L2 ;
exsr sr_L2_Totals ;
endif ;
...........
if L9 ;
exsr sr_L9_Totals ;
endif ;
if LR ;
exsr sr_LR_Totals ;
endif ;
endsr ;
//======================
....FYI.....
--Alan
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.