cancel
Showing results for 
Search instead for 
Did you mean: 

Customer Exit to get last day of previous month

Former Member
0 Kudos

Dear Experts,

I need to create a customer exit to get the last day of previous month. I found a FM "SN_LAST_DAY_OF_MONTH" but i dont have abap knowhow.

for Example :

Today = 13.05.2019 ---> Output = 30.04.2019

Today = 31.05.2019 --> Output = 30.04.2019

Today = 01.06.2019 --> Output = 31.05.2019

Can someone help me with the ABAP code?

Thx alot

Sascha

Accepted Solutions (1)

Accepted Solutions (1)

p244500
Active Contributor

Hi,

you can try bellow code

using this program you can get last date of the any month. 
REPORT zlastday.

PARAMETERS: p_date TYPE sy-datum.   "provide any date 
p_date+4(2) = p_date+4(2) + 1.

IF p_date+4(2) = '13'.
  p_date+4(2) = '01'.
  p_date(4) = p_date(4) + 1.
ENDIF.

p_date+6(2) = '01'.
p_date = p_date - 1.
WRITE:/ 'last day ',p_date .

or you can use FM

LAST_DAY_OF_MONTH
Former Member
0 Kudos

Hi Nawanandana,

thx alot for your share. could you please provide me, how can i write your code in to customer-exit ?

I dont have FM "LAST_DAY_OF_MONHT" in my SAP BW System.

i have a variable "ZVAR_0001" my code starting like this ;

DATA: ZDAYS TYPE SY-DATUM.

***** 
 WHEN 'ZVAR_0001'.
      CALL FUNCTION 'SN_LAST_DAY_OF_MONTH'
        EXPORTING
         DAY_IN       = ZDAYS
        IMPORTING
          END_OF_MONTH = ZZGEST.
      CLEAR: L_S_RANGE.
      L_S_RANGE-LOW = ZZGEST.
      L_S_RANGE-SIGN = 'I'.
      L_S_RANGE-OPT = 'EQ'.
      APPEND L_S_RANGE TO E_T_RANGE.

thx alot

p244500
Active Contributor

Hi,

You can use this code. No need to used any FM , used bellow code still if you have issue let me know


DATA: zdays TYPE sy-datum,   "Current date.
      zzgest TYPE sy-datum.  "Last date of previous month 

DATA: BEGIN OF l_date,
        year(4),
        month(2),
        day(2),
      END OF l_date.

zdays =  sy-datum. " you have to pass Current date 

l_date = zdays.
l_date-day = '01'.
zzgest = l_date.
SUBTRACT 1 FROM zzgest.


      CLEAR: L_S_RANGE.
      L_S_RANGE-LOW = ZZGEST.
      L_S_RANGE-SIGN = 'I'.
      L_S_RANGE-OPT = 'EQ'.
      APPEND L_S_RANGE TO E_T_RANGE.


Regards,
Nawa
Former Member
0 Kudos

Hi Nawa,

thx alot for your code. its work

regards

Answers (2)

Answers (2)

0 Kudos

Hello all!

I´m looking a FM or exit to get the last day of the "period" entered in the query. But, the last day is

Example:

If I enter a period 01.01.2019 - 31.03.2019 then a need: (31.03.2018) or

If I enter 01.06.2019 - 30.06.2018 then a need: TODAY because we are still in the current month.

Thanks in advance

Alex

former_member586947
Contributor
0 Kudos

Hi Sascha Skgisasy,

Try the below code.

   
  WHEN 'ZVAR_0001'.

 IF i_step EQ 2.
 DATA: ZDAY LIKE SY-DATUM.

 ZDAY+6(2) = '01'.
 ZDAY = ZDAY - 1.

CLEAR: L_S_RANGE.
      L_S_RANGE-LOW = ZDAY.
      L_S_RANGE-SIGN = 'I'.
      L_S_RANGE-OPT = 'EQ'.
      APPEND L_S_RANGE TO E_T_RANGE.
ENDIF.
ENDCASE.