you will need to replace this midstr('$$INP_CALMONTH$$',5,6) - 1),"A",0)
with the below function for month -3
to_char(ADD_MONTHS (TO_DATE (concat( '$$INP_CALMONTH$$' ,'01'), 'YYYYMMDD'), -3),'YYYYMM')
What I am doing here is creating the fist date of that month using concat and then and going 3month back from that month using ADD_MONTH (with -3) and then converting the date back to your YYYYMM formar..