Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

regarding the first day of the previous month

Former Member
0 Kudos

hi experts,

suppose the date is '010406' what i want that is der any function module so that i can get the first date of the previous month i.e '010306' plz let me know......or sud i add logic for that if yes plz help me........

1 ACCEPTED SOLUTION

varma_narayana
Active Contributor
0 Kudos

Hi You can use the code below.

DATA : V_DATE TYPE SY-DATUM value '20070720'.

V_DATE+6(2) = '01'. "First day of current month.

CALL FUNCTION 'SG_PS_ADD_MONTH_TO_DATE'

EXPORTING

months = '-1'

olddate = v_date

IMPORTING

NEWDATE = v_date

.

write:/ v_date.

<b>Reward if helpful</b>

6 REPLIES 6

former_member188827
Active Contributor
0 Kudos

use fm:

date_to_day...

data day type DTRESR-WEEKDAY.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

DATE = '01/03/07'

IMPORTING

WEEKDAY = day

.

write day.

Message was edited by:

abapuser

varma_narayana
Active Contributor
0 Kudos

Hi You can use the code below.

DATA : V_DATE TYPE SY-DATUM value '20070720'.

V_DATE+6(2) = '01'. "First day of current month.

CALL FUNCTION 'SG_PS_ADD_MONTH_TO_DATE'

EXPORTING

months = '-1'

olddate = v_date

IMPORTING

NEWDATE = v_date

.

write:/ v_date.

<b>Reward if helpful</b>

Former Member
0 Kudos

better to use own logic for your requirement....

suppose you have date field

data : date1 like sy-datum,

mon(2) type n,

year(4),

prev like sy-datum.

date1 = '20070720'.

mon = date1+4(2).

year = date1+0(4).

if mon ne '01'.

mon = mon - 1.

concatenate year mon '01' into prev.

else.

mon = '12'.

year = year - 1.

concatenate year mon '01' into prev.

endif.

write : / prev.

if the date is like your format i.e. 010406 then

data : date1(6) value '010406',

mon(2) type n,

year(4),

prev like sy-datum.

date1 = '20070720'.

mon = date1+2(2).

year = date1+4(2).

if mon ne '01'.

mon = mon - 1.

concatenate year mon '01' into prev.

else.

mon = '12'.

year = year - 1.

concatenate year mon '01' into prev.

endif.

write : / prev.

regards

shiba dutta

kesavadas_thekkillath
Active Contributor
0 Kudos

first get the first day of the previous month of the date.

for example u want the first date of july.

pass 01.06.2007.

to Functional module

call function 'RP_LAST_DAY_OF_MONTHS'

exporting

day_in = 01.06.2007

importing

last_day_of_month = l_dat_mon

exceptions

day_in_no_date = 1

others = 2 .

l_dat_mon holds the last day of june.

then add l_dat_mon + 1 .

u will get the date..

reward if useful

Former Member
0 Kudos

try this FM,

/BEV4/PLPS__ADD_MONTH_TO_DATE.

for months give input as '-1' .

award points if it helps.

kesavadas_thekkillath
Active Contributor
0 Kudos

if u have the current month...

u can concatenate '01' currentmonth - 1 year.

if current month = 1.then take month as 12 and year = year-1 and concatenate