‎2007 Dec 10 1:14 PM
hi
i m stuck in a program. a date is entered in the selection screen. my condition is to get the data from the 1st date to the last date of the previous month.
for eg: if the date in selection screen is 8th nov , i need to get the data from 1st oct to 31st oct.
how do i do? can anybody help me with it?
‎2007 Dec 10 1:20 PM
Hi,
Get Month out of the date which you have , take the value of the previous month by subtracting one from the same and then use FM HR_JP_MONTH_BEGIN_END_DATE to get first and last date of that month.
Hope this helps.
Regards,
Lalit
‎2007 Dec 10 1:20 PM
hi,
DATA : first_day TYPE sy-datum,
last_day TYPE sy-datum.
PARAMETERS : in TYPE sy-datum.
START-OF-SELECTION.
in+6(2) = '01'. "In is first day of current month
last_day = in - 1. "Last day of last month
CALL FUNCTION 'CALCULATE_DATE'
EXPORTING
* DAYS = '0'
months = '1' "To deduct one month
start_date = in
IMPORTING
result_date = first_day. "First day of last month
hope this helps
ec
‎2007 Dec 10 1:20 PM
Hi navinkumar,
1. this is one way.
2. use the FM HRAR_SUBTRACT_MONTH_TO_DATE
and pass 18.11.2007
and u will get 18.10.2007
3. Then use the FM - HR_JP_MONTH_BEGIN_END_DATE
and pass the above found date 18.10.2007
<b> and u will get
begin date - 01.10.2007
end daet = 30.10.2007</b>
regards,
amit m.
‎2007 Dec 10 1:24 PM
well the first is easy, its always the first
and here´s a FM for the last: BKK_GET_MONTH_LASTDAY.
just substract one of your month before using this.
‎2007 Dec 10 1:25 PM
if p_date is the variable in the selection screen.
use this logic
1) use function module CCM_GO_BACK_MONTHS to go back one month and store the date in v_prvdat.
2) v_prvdat+6(2) = '01'.
3) use function moule SG_PS_GET_LAST_DAY_OF_MONTH and pass v-prvdat to get last day of the month.
Sarfaraz
‎2007 Dec 10 1:36 PM
Hi,
You can use the below code
First use FM CCM_GO_BACK_MONTHS to go to the previous month .
Use below code:
CALL FUNCTION 'CCM_GO_BACK_MONTHS'
EXPORTING
currdate = sp_date
backmonths = '1'
IMPORTING
newdate = gv_datum.
now you have the last month start date in gv_datum.
Declare a variable to hold month.
month = gv_datum+4(2).
*And use the below code to get the last of the previous month
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = sp_gjahr "Year
i_periv = 'K4' "Fiscal Year variant
i_poper = month "Pass the month from result of the above FM
IMPORTING
e_date = gv_lastday
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.Now you will have gv_lastday the last daet of the previous month and gv_datum will hold the first of the previous month.
Thanks,
Sriram Ponna.
‎2007 Dec 10 1:41 PM
‎2007 Dec 10 1:53 PM
Hi
try this logic..
need not check for leap years as well...
DATA : date TYPE sy-datum VALUE '20071108',
date_low TYPE sy-datum,
date_high TYPE sy-datum.
date+6(2) = '01'.
date_high = date_low = date - 1.
date_low+6(2) = '01'.
WRITE :/ date_low, date_high.
‎2007 Dec 10 2:04 PM
This can be done in two ways.
1, through coding as described in replies above
2, create a variant for the report and assign dynamic values to the date field in the variant attributes. u can give the values here accurately