cancel
Showing results for 
Search instead for 
Did you mean: 

User-Exit previous day from 0calmonth

Former Member
0 Kudos

Dear Abap Experts,

i should need a one Customer-Exit for my query.

Manuel Input Variable: ZKSUJ (from 0CALMONTH)

Output: if input is actual month, output should be previous day. else last day from previous month..

Example :

Input : 08.2019 (Manuel input) (today= 08.08.2019)

Output : 07.08.2019

or

Input : 07.2019 (Manuel input)

Output : 31.07.2019

i tried it, my code look like this; i got it last month last day but doenst previous day.. Any help?

WHEN 'ZKSUJ'.
IF i_step EQ 2.
  READ TABLE i_t_var_range INTO h_t_var_range
      WITH KEY vnam = '0PCALMON'
               iobjnm = '0CALMONTH'.
  MOVE h_t_var_range-low(4) TO hyear.
  MOVE h_t_var_range-low+4(2) TO hmonth.

  IF hmonth = '01'.
    hmonth = '12'.
    hyear = hyear - 1.
  ELSE.
    hmonth = hmonth - 1.
  ENDIF.

* hday = sy-datum - 1.
CONCATENATE hjyear hmonth '01' INTO hday.  

  CLEAR hperiode.
  CALL FUNCTION 'FIMA_END_OF_MONTH_DETERMINE'
    EXPORTING
      i_date          = hday
    IMPORTING
      e_days_of_month = hperiode.   
  l_s_range-sign = 'I'.
  l_s_range-opt = 'EQ'.
  CONCATENATE hyear hmonth hperiode INTO l_s_range-low.
  APPEND l_s_range TO e_t_range.
ENDIF.


Thanks alot for your help.

Regards..

former_member586947
Contributor
0 Kudos

Hi Sascha,

I have updated my previous comment with complete code.

Pls check.

Regards,

Satya.

former_member586947
Contributor
0 Kudos

Hi Sacha,

I have updated the code. Pls check.

Regards,

Satya.

Accepted Solutions (1)

Accepted Solutions (1)

former_member586947
Contributor
0 Kudos

Hi Sacha,

You need to check the user entered month with current month. If yes, then populate the previous day of the current month. Else, populate the last day of the user inputted month. Am I right in understanding the requirement. If yes, then chnage the code as below.

Declare cmonth variable as like hmonth and pday as sy-datum.

WHEN 'ZKSUJ'.
IF i_step EQ 2.
Data: pday type sy-datum,
      Hmonth type /BI0/calmonth,
      Cmonth type /BI0/calmonth,
      Hday type sy-datum,
      Hyear type /bi0/fiscyear.
  READ TABLE i_t_var_range INTO h_t_var_range
      WITH KEY vnam = '0PCALMON'
               iobjnm = '0CALMONTH'.
  MOVE h_t_var_range-low(4) TO hyear.
  MOVE h_t_var_range-low+4(2) TO hmonth.
cmonth = sy_datum+4(2).
If hmonth = cmonth.
   Hday = sy_datum-1.
Else.
   Concatenate hyear hmonth '01' into hday.
 ** Use function module to get the last day of the month.
CALL FUNCTION 
'SLS_MISC_GET_LAST_DAY_OF_MONTH'
Exporting 
    Dayin = hday
Importing 
    Last_day_of_month = pday.
Hday = pday.
Endif.
** Move hday to e_t_range 
l_s_range-sign = 'I'.
  l_s_range-opt = 'EQ'.
  CONCATENATE hyear hmonth hperiode INTO l_s_range-low.
  APPEND l_s_range TO e_t_range.
ENDIF.
Former Member
0 Kudos

thanks alot for ur code Satya. Yes, u wrote it actually what i want. But your code doesnt clear for me.. Could you please write me exactly? I am Abap-beginner!

Thanks alot.

Former Member
0 Kudos

hi Satya,

thx alot for your code.. but i have a error on code.. "_month = sy-datum+4(2)" could you please fix it?

 MOVE h_t_var_range-low+4(2) TO hmonth._month = sy_datum+4(2).

thanks

Former Member
0 Kudos

Thanks alot Satya.. its work. But i changed this;

l_s_range-low = pday. 
** CONCATENATE hyear hmonth hperiode INTO l_s_range-low.
former_member586947
Contributor
0 Kudos

Hi Sascha,

Instead of pday, you should pass hday to get the code workes as expected.

l_s_range-low = hday.

Regards,

Satya.

Answers (0)