Retrieve the last day of the month in ILE RPG

To retrieve the last day of the month first make sure you are dealing with a valid date with TEST(D). Next add one month to the date with ADDDUR, make the day equal to the first day of that month, then subtract one with SUBDUR and you've got it!
 
D DateEnd                 D    Datfmt(*ISO)
D DateDay               2      Overlay(DateEnd:9)
 *

 *
c             eval       *in99 = *off
c     *YMD    TEST(D)                     ted8     99
c             select
c             when       *in99 = *off
c     *YMD    move       ted8             DateEnd
c             ADDDUR     1:*M             DateEnd
c             eval       DateDay = '01'
c             SUBDUR     1:*D             DateEnd
c     *ISO    move       DateEnd          @@ted8
c             other
c             eval       @@ted8 = *zeros
c             endsl
 *
  
In free-format RPG IV you use the '+' and '-' operators in conjunction with built-in functions (%days, %months, etc.) instead of ADDDUR and SUBDUR.

 /free
   Date = Date - %days(1)                                    
 /end-free