SUBROUTINE SUB.AGE.BUCKET(RETURN, VALUE, TARGET.DATE, SAVE.CURRENT.DATE, SAVE.BUCKET.MAP)
* Subroutine to backet values based on age.
LastUpdated... = "Rev: 10:06 18Dec1997 andrew 39 /roi/URO.MAIN/URO.BP/SUB.AGE.BUCKET"
***
* Abstract
*    This program will generate an easily configurable set of aging buckets.
* The bucketing is controlled by a bucket map which indicates the thresholds
* to apply to each age date.
*   The argument list is as follows:
*
*   RETURN - The return value, a multi-valued array of buckets, only one will
*            have the correct value based on the CURRENT.DATE and TARGET.DATE
*            arguments.
*   VALUE  - The data to be bucketed. Can be alpha as well as numeric.
*   TARGET.DATE - The target date to use to determine which bucket the value
*            should be placed in.
*   CURRENT.DATE - A control date to be used to determine the relative age.
*            If the current system date is required, leave this field blank.
*   BUCKET.MAP - An array of values to show the bucketing thresholds. The
*            format of this field should be: "n,n,n,n" where "n" is an integer
*            value and represents the number of days that the corresponding
*            bucket represents. If left blank, the value of "0,30,60,90,120"
*            is assumed. Seperators between values may be comma, @FM or @VM.
***
* Revision Log
* Proj Who..... When.... Why................................................
*  211 andrew   12-08-97 Initial coding.
*
***

* Normalize the delimiter...
BUCKET.MAP = CONVERT(",":@VM,@FM:@FM,  IF SAVE.BUCKET.MAP  THEN  SAVE.BUCKET.MAP  ELSE  "0,30,60,90,120" )                                                               

* Resolve current date (then or now or future?)...
CURRENT.DATE = IF SAVE.CURRENT.DATE THEN SAVE.CURRENT.DATE ELSE DATE()

DAYS = IF TARGET.DATE GE CURRENT.DATE THEN   0   ELSE   (CURRENT.DATE - TARGET.DATE)
LOCATE DAYS IN BUCKET.MAP<1> BY "AR" SETTING IDX ELSE IDX -= 1
RETURN = ""
RETURN<1,IDX> = VALUE
RETURN
END
