Hi Experts,
I'm trying to find a code snippet which will help to implement previous month calculation based on calendar day. I have implemented the following ABAP program in CMOD, but its does not calculate previous month correctly,
WHEN < Variable Name>LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = '<Variable Name>'.CLEAR: l_s_range.ENDLOOP.
ZDT1 = loc_var_range-low. ZDT2 = loc_var_range-HIGH. CALL FUNCTION 'DATE_CREATE' EXPORTING ANZAHL_JAHRE = 0 ANZAHL_KALTAGE = 0 ANZAHL_MONATE = '-1' ANZAHL_TAGE = 0 DATUM_EIN = ZDT1 * DATUM_EIN_ULT = ' ' * ULTIMO_SETZEN = ' ' IMPORTING DATUM_AUS = ZFIDAY . * E_TT = * E_ULTKZ = CALL FUNCTION 'DATE_CREATE' EXPORTING ANZAHL_JAHRE = 0 ANZAHL_KALTAGE = 0 ANZAHL_MONATE = '-1' ANZAHL_TAGE = 0 DATUM_EIN = ZDT2 * DATUM_EIN_ULT = ' ' * ULTIMO_SETZEN = ' ' IMPORTING DATUM_AUS = ZLSDAY. * E_TT = * E_ULTKZ = l_s_range-low = ZFIDAY . l_s_range-high = ZLSDAY . l_s_range-sign = 'I'. l_s_range-opt = 'EQ'. APPEND l_s_range TO e_t_range.
for e.g. if the user enters; 01.09.2016 to 30.09.2016 as the current month, the previous month should start with 01.08.2016 to 31.08.2016 , the code calculates up until 30.08.2016. I would really like to see if there's any other logic to implement. I'm having moderate knowledge in ABAP and would kindly require your ABAP assistance.
Thank you.
Regards.
Hi
The date is a numeric string, so you can use the main comands manage a number and a string
If the the first date of the interval is the first day of the current period, you can subtract 1 to the date:
DATA LAST_DAY_PREV TYPE SY-DATUM. LAST_DAY_PREV = FIRST_DAY_CURR - 1.
The date is string with format YYYYMMDD, so yuo can calculate the first day from the last one, it need to replace the days:
DATA FIRST_DAY_PREV TYPE SY-DATUM. FIRST_DAY_PREV = LAST_DAY_PREV. FIRST_DAY_PREV+6(2) = '01'.
Of course there are many ways and function module, i think you can look for them by google
Where you want to add this logic? In Sale Order? In condition record? Please explain the business requirement so that suitable suggestions can be given from functional point of view if it is made available.
Hi,
In our cmod code we have implemented a table which is called from a functional module.I need to add this inside the functional module. All our customer exits are based on this functional module. I Just to calculate the previous period month from the given variable entry.
Hay Hi,
You can use the FM "RP_CALC_DATE_IN_INTERVAL" to get the last month 1st day & Fm " OIL_LAST_DAY_OF_PREVIOUS_MONTH " to get the last day of previous month .
for the further detail u can visit on following link.
Hi Las W,
There are so many function module you can utilize to achieve this,
Procedure:
1. You can get input dates from user
2. Pass loc_var_range-low values to RE_ADD_MONTH_TO_DATE. with input MONTHS : -1 OLDDATE : loc_var_range-low
3. It will give output as
1. RE_ADD_MONTH_TO_DATE
----------------------------------------------------------------------------------------------------
2. BCA_US_DATES_CALC_DATE
Pass the following
I_START_DATE = 'Todays Date'
I_TERM = '-6' "Yes '- 6' (it actually Works)
I_PERIODUNIT = any one from the list
1 Calendar Days
2 Weeks
3 Months
4 Quarter
5 Year
It will get you the date
----------------------------------------------------------------------------------------------------
3.RP_CALC_DATE_IN_INTERVAL
input:
DATE 02.11.2016
DAYS 00 (give how many days back ex; 12,30,200)
MONTHS 01 (give how many months back ex: 02,10,03,04)
SIGNUM - (give +to add or - to previous)
YEARS 00
Export parameters Value
CALC_DATE 02.10.2016 (OUTPUT)
----------------------------------------------------------------------------------------------------
4. CCM_GO_BACK_MONTHS
CURRDATE 11.11.2016
BACKMONTHS 001
output : 11.10.2016
-----------------------------------------------------------------------------------------------------
5. This will give last date of month:
RS_VARI_V_L_LAST_MONTH
input:
SYSTIME 01.11.2016
output:
P_DATE 31.10.2016
None of this FMs are released. Kindly avoid providing such suggestions. Also let's encourage others to help themselves by searching instead of spoon-feeding them information. Such questions have been discussed on SCN numerous times. OP should be perfectly capable of finding an answer in Google.
Thanks all for your kind help. I will be closing this post, will do more research online to find a appropriate solution.