Hi all,
I am trying to use an array and a do loop to calculate the 1st date of the month for the previous 18 months in order to show usage for items for each of the previous 18 months.
My problem is how to decrement the year twice to go back to 2011 when the mnth value is < 1.
Here is my current code:
def new shared var periods as int extent 19 label "Start".
def new shared var p as int.
def new shared var mnth as int.
def new shared var w-months as date extent 19 label "Start".
/* Include file for E and O Monthly Buckets */
/* Calculate Monthly Buckets */
Assign
periods[1] = 0
periods[2] = 1
periods[3] = 2
periods[4] = 3
periods[5] = 4
periods[6] = 5
periods[7] = 6
periods[8] = 7
periods[9] = 8
periods[10] = 9
periods[11] = 10
periods[12] = 11
periods[13] = 12
periods[14] = 13
periods[15] = 14
periods[16] = 15
periods[17] = 16
periods[18] = 17
periods[19] = 18.
p = 0.
do p = 1 to 19:
mnth = month(today) - periods[p].
/* message p mnth view-as alert-box. pause. */
if mnth < 1 then /*decrement year*/
w-months[p] = date(12 + mnth,1,year(today) - 1).
else
w-months[p] = date(month(today) - periods[p], 1, year(today)).
end. /* DO */
display w-months with side-labels width 80.
Any advice greatly appreciated,
Best regards,
Martin
I am trying to use an array and a do loop to calculate the 1st date of the month for the previous 18 months in order to show usage for items for each of the previous 18 months.
My problem is how to decrement the year twice to go back to 2011 when the mnth value is < 1.
Here is my current code:
def new shared var periods as int extent 19 label "Start".
def new shared var p as int.
def new shared var mnth as int.
def new shared var w-months as date extent 19 label "Start".
/* Include file for E and O Monthly Buckets */
/* Calculate Monthly Buckets */
Assign
periods[1] = 0
periods[2] = 1
periods[3] = 2
periods[4] = 3
periods[5] = 4
periods[6] = 5
periods[7] = 6
periods[8] = 7
periods[9] = 8
periods[10] = 9
periods[11] = 10
periods[12] = 11
periods[13] = 12
periods[14] = 13
periods[15] = 14
periods[16] = 15
periods[17] = 16
periods[18] = 17
periods[19] = 18.
p = 0.
do p = 1 to 19:
mnth = month(today) - periods[p].
/* message p mnth view-as alert-box. pause. */
if mnth < 1 then /*decrement year*/
w-months[p] = date(12 + mnth,1,year(today) - 1).
else
w-months[p] = date(month(today) - periods[p], 1, year(today)).
end. /* DO */
display w-months with side-labels width 80.
Any advice greatly appreciated,
Best regards,
Martin