Deriving High and Low Non-Zero Values

Cecil

19+ years progress programming and still learning.
Hi Guys.

This should be simple. I'm wanting to fetch the 'highs' and 'lows' of a series of values but I don't want to present a zero value for either high or lows.

This is what I have done as a prototype, but it does not look very elegant, nor efficient. How could it be made better?

Code:
DEFINE VARIABLE deNumber    AS DECIMAL     NO-UNDO.
DEFINE VARIABLE deMaxValue  AS DECIMAL     NO-UNDO.
DEFINE VARIABLE deMinValue  AS DECIMAL     NO-UNDO.
DEFINE VARIABLE deNUMBERS AS DECIMAL     NO-UNDO EXTENT 7.
DEFINE VARIABLE iLoop     AS INTEGER     NO-UNDO.

ASSIGN
    deNUMBERS[1] = 0 
    deNUMBERS[2] = .0579345088
    deNUMBERS[3] = .0579345088
    deNUMBERS[4] = .0579345088
    deNUMBERS[5] = .0502793296
    deNUMBERS[6] = .0346715328
    deNUMBERS[7] = .029455081
        .

DO iLoop = 1 TO EXTENT(deNUMBERS):
    IF deNUMBERS[iLoop] NE 0 THEN
        deMaxValue = MAXIMUM (deMaxValue, deNUMBERS[iLoop] ).
END.

/** Do it again for the minimum value**/
deMinValue = deMaxValue.

DO iLoop = 1 TO EXTENT(deNUMBERS):
    IF deNUMBERS[iLoop] NE 0 THEN
        deMinValue = MINIMUM (deMinValue, deNUMBERS[iLoop] ).
END.

MESSAGE
    deMinValue  skip
    deMaxValue  
    VIEW-AS alert-box info.
 

FrancoisL

Member
You can do it in one loop...

Code:
DEFINE VARIABLE deMaxValue  AS DECIMAL     NO-UNDO. 
DEFINE VARIABLE deMinValue  AS DECIMAL     NO-UNDO. 
DEFINE VARIABLE deNUMBERS AS DECIMAL     NO-UNDO EXTENT 7 INIT [ 0, 0.0579345088, 0.0579345088, 0.0579345088, 0.0502793296, 0.0346715328, 0.029455081  ] . 
DEFINE VARIABLE iLoop     AS INTEGER     NO-UNDO.  


 DO iLoop = 1 TO EXTENT(deNUMBERS):     
    IF deNUMBERS[iLoop] NE 0 THEN DO:         
      deMaxValue = MAXIMUM (deMaxValue, deNUMBERS[iLoop] ).
      deMinValue = IF deMinValue EQ 0 THEN deNUMBERS[iLoop] ELSE MINIMUM (deMinValue, deNUMBERS[iLoop] ).     
    END.
 END.  

 MESSAGE deMinValue  skip deMaxValue VIEW-AS alert-box info.
 

Cringer

ProgressTalk.com Moderator
Staff member
Alternatively you could write your own MINIMUM() function that ignores 0.
 

Stefan

Well-Known Member
Any reason you're running through an extent? You could create temp-table records and find last / find first where value <> 0.
 
Top