cancel
Showing results for 
Search instead for 
Did you mean: 

Days in a Month

Former Member
0 Kudos

Can someone give me a code for exit variable which gives the number of days in a month automatically with out the user's entering anything, as input. For example if i run the query today (march 1) it should return 31.

Thank You

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

hi,

As say Chamarthy, there is no reason why a FM does not work in your system.

When you call a FM, be careful about importing and exporting variable types. They must be the same as those declared in your FM.

Try this code:

data: L_GJAHR type T009B-BDATJ,

L_PERIV type T009B-PERIV,

L_POPER type T009B-POPER,

L_DATE type SY-DATUM.

data: MY_LAST_DAY type string.

L_GJAHR = [MY_GJAHR].

L_PERIV = [MY_PERIV].

L_POPER = [MY_POPER].

L_DATE = [MY_DATE].

CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'

EXPORTING

I_GJAHR = l_GJAHR

  • I_MONMIT = 00

I_PERIV = L_PERIV

I_POPER = L_POPER

IMPORTING

E_DATE = L_DATE

EXCEPTIONS

INPUT_FALSE = 1

T009_NOTFOUND = 2

T009B_NOTFOUND = 3

OTHERS = 4

.

MY_LAST_DAY = L_DATE+4(2).

Jacques

Former Member
0 Kudos

Jacques,

Appreciate your response. But when i am running it its returning a alue of 0. Dont know what to do. Any suggestions?

Former Member
0 Kudos

neha,

DATA: Z_DATE TYPE D.

CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'

EXPORTING

DAY_IN = Z_DATE

IMPORTING

LAST_DAY_OF_MONTH = Z_DATE

  • EXCEPTIONS

  • DAY_IN_NOT_VALID = 1

  • OTHERS = 2

.

and your value is z_date(2)

alessandro

Message was edited by:

alessandro cherchi

Former Member
0 Kudos

i had the same problem a couple weeks ago and i wrote an ABAP code for this, I_STEP.

here's my code. It's very similiar and if you know a liitle bit of ABAP you should be able to understand it

DATA: L_S_RANGE TYPE RSR_S_RANGESID.

DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT.

DATA: lv_text(20) type c,

lv_year(4) type c,

lv_month(3) type c,

lv_rawdate(7) type c.

DATA: WA_I_T_VAR_RANGE like line of I_T_VAR_RANGE.

if i_step eq 1.

case i_vnam.

when 'ZVAR6'.<---- Custom exit Variable

L_S_RANGE-LOW = lv_text.

L_S_RANGE-SIGN = 'I'.

L_S_RANGE-OPT = 'EQ'.

APPEND L_S_RANGE TO E_T_RANGE.

endcase.

elseif i_step eq 2.

case i_vnam.

when 'ZVAR6'.

loop at I_T_VAR_RANGE into wa_I_T_VAR_RANGE.

if wa_I_T_VAR_RANGE-vnam eq 'ZP_FYSR01'.

lv_rawdate = wa_I_T_VAR_RANGE-low.

lv_month = lv_rawdate+4(3).

lv_year = lv_rawdate+0(4).

endif.

endloop.

if lv_month eq '001'.

concatenate 'October' lv_year into lv_text.

elseif lv_month eq '002'.

concatenate 'November' lv_year into lv_text.

elseif lv_month eq '003'.

concatenate 'December' lv_year into lv_text.

elseif lv_month eq '004'.

concatenate 'January' lv_year into lv_text.

elseif lv_month eq '005'.

concatenate 'February' lv_year into lv_text.

elseif lv_month eq '006'.

concatenate 'March' lv_year into lv_text.

elseif lv_month eq '007'.

concatenate 'April' lv_year into lv_text.

elseif lv_month eq '008'.

concatenate 'May' lv_year into lv_text.

elseif lv_month eq '009'.

concatenate 'June' lv_year into lv_text.

elseif lv_month eq '010'.

concatenate 'July' lv_year into lv_text.

elseif lv_month eq '011'.

concatenate 'August' lv_year into lv_text.

elseif lv_month eq '012'.

concatenate 'September' lv_year into lv_text.

else.

lv_text = 'UNKN.MO'.

endif.

udayabhanupattabhiram_cha
Active Contributor
0 Kudos

Hi:

The Code for Function Module is not very useful to you if Functions Modules are not Executing in your system.

Because, this FM - LAST_DAY_IN_PERIOD_GET itself calls other FMs (e.g., GET_ACCOUNT_OF_PERIODS).

So, how can you create your own FM or ABAP Code if the SAP deliverd one doesn't work?

Your best bet is to find out why the FM is not working rather than re-invent the wheel with your own ABAP Code.

Good luck,

Chamarthy

Former Member
0 Kudos

Hi,

Try Function Module LAST_DAY_IN_PERIOD_GET. With Fiscal Year, Fiscal year variant and Period, you obtain the last ay of the month.

An other tips. You take the first day of the next month and you substract 1. Then you obtain the last day of the current month.

Jacques

Former Member
0 Kudos

Hi Jacques,

Appreciate your response, but i am unable to make any functional modules work on my system. I dont know why. Could you give me a complete code to get this or alternately can u give me the code to execute "Function Module LAST_DAY_IN_PERIOD_GET". I am an ABAP illitrate so finding it difficult to compile stuff. Thank You.