Ok, here's the general gist:
1) Trying to print out how many sales calls a sales consultant talks to.
2) Using a data structure array to do this:
* Consultant = consultant name.
* Count = increment by one each time another record for this consultant comes through.
3) Having some problems with %LOOKUP & %XFOOT.
4) Code with comments documenting the logic is listed below.
1) Trying to print out how many sales calls a sales consultant talks to.
2) Using a data structure array to do this:
* Consultant = consultant name.
* Count = increment by one each time another record for this consultant comes through.
3) Having some problems with %LOOKUP & %XFOOT.
4) Code with comments documenting the logic is listed below.
Code:
* Data structure to count number of calls
D wdConsCount DS Dim(20) Qualified
D wdCons 8A Overlay(wdConsCount)
D wdCount 3S 0 Overlay(wdConsCount : *Next)
*********************************************************************
/FREE
//******************************************************************
BegSR ProcessRecord;
//------------------------------------------------------------------
// wdConsCount is a Data Structure array that tracks the Consultant
// and the number of calls they have taken.
// wwMaxIdx = last index number assigned in the wdConsCount data
// structure array.
// If zero, first time assigning to a consultant.
If (wwMaxIdx = *Zeros);
wdConsCount(1).wdCons = dAsnCn; // Use element #1 as index
wdConsCount(1).wdCount = 1; // Set initial count to 1
wwMaxIdx = 1; // Init "max index" to 1
// If not zero, at least one consultant assigned to wdConsCount
// data structure array
Else;
// Use %Lookup to determine if this consultant is already
// in the array
ww = %LOOKUP(dAsnCn : wdConsCount.wdCons);
If (ww = *Zeros); // Zero = not yet in data struct array
wwMaxIdx += 1; // Increment "maximum index" by one
wdConsCount(wwMaxIdx).wdCons = dAsnCn; // Set consult
wdConsCount(wwMaxIdx).wdCount = 1; // Init count to one
// If consultant already exists in data structure array...
Else;
wdConsCount(ww).wdCount += 1; // Increment counter by one
EndIf;
EndIf;
EndSR;
//******************************************************************
BegSR LRTotals;
//------------------------------------------------------------------
// Sort consultants ascedning alpha order
SortA wdConsCount.wdCons;
// Spin through all consultants to print
For ww = 1 to wwMaxIdx;
// O-Spec fields names must be 14 chars long or shorter.
// Move fields from data structure to standalone fields with
// shorter names
wwCons = wdConsCount(ww).wdCons;
wwCount = wdConsCount(ww).wdCount;
wwCount = wdConsCount(ww).wdCount;
Except LRTotPrint; // Print contultant total information
EndFor;
// Get grand number of calls for all consultants & print
wwTotalCalls = %XFOOT(wdConsCount.wdCount);
Except TotalCalls;
EndSR;
//******************************************************************
/END-FREE
*********************************************************************











Comment