Application Development and Automation 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: 
Read only

Hi all

Former Member
0 Likes
1,072

hi all can anyone give me the logic . on selection screen i have date field date-low and date-high in high it is bydefault sy-datum but in low i need 4 months back date how do i do it..

please its urgent

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,052

In initialization :

USE FM .. to subtract months to the date ..

CALL FUNCTION 'OIL_DATE_SUBTRACT_MONTH'

EXPORTING

date = sy-datum

months = '4'

IMPORTING

DATE_E = v_newdate

  • EXCEPTIONS

  • DATE_ERROR = 1

  • OTHERS = 2

.

date-low = v_newdate

date-high = sy-dayum

date-sign = 'I'

date-option = 'BT'.

append date.

8 REPLIES 8
Read only

Former Member
0 Likes
1,052

Hi,

I guess u need to validate if the date-low values is within four months from the current date. If that is so,

use this FM to find diff betn dates and throw error msg.

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

i_datum_bis = s_audat-high

i_datum_von = s_audat-low

i_kz_excl_von = '0'

i_kz_incl_bis = '0'

i_kz_ult_bis = ' '

i_kz_ult_von = ' '

i_szbmeth = '1'

IMPORTING

e_tage = lf_days

EXCEPTIONS

days_method_not_defined = 1

OTHERS = 2.

IF sy-subrc = 0.

IF lf_days GT <days>.

MESSAGE e004 WITH text-t12. "Error if date span is more

"than 4 months

ENDIF.

ENDIF.

Reward if helpful.

Regards,

Ramya

Read only

Former Member
0 Likes
1,052

Hi Amit,

Calculate the date you are looking for as a backdated one in the INITIALISATION EVENT of your program/report.

Get the desired previous date in a variable and give that variable as you are displaying sy-datum.

Regds,

Gaurav

Read only

Former Member
0 Likes
1,052

Hi,

IN the Initialization event,

Use the function module CALCULATE_DATE, and get the 4 months back date and pass it DAY-LOW

Regards

Sudheer

Read only

rodrigo_paisante3
Active Contributor
0 Likes
1,052

Hi,

Try something like this:

SELECTION-SCREEN begin of block b1.

PARAMETERS: p_dhigh type sy-datum DEFAULT sy-datum,

p_dlow type sy-datum .

SELECTION-SCREEN end of BLOCK b1.

load-OF-PROGRAM.

p_dlow = sy-datum - 120.

Read only

Former Member
0 Likes
1,052

sy-datum stores date as yyyymmdd in SAP.

so in initialization write as

v1 = sy-datum+4(2).

if v1 > 4.

v1 = v1 - 4.

elseif V1 = 3.

v1 = 12.

elseif V1 = 2.

V1 = 11.

elseif V1 = 1.

V1 = 10.

endif.

concatenate yyyy V1 dd into p_date-low.

Read only

Former Member
0 Likes
1,053

In initialization :

USE FM .. to subtract months to the date ..

CALL FUNCTION 'OIL_DATE_SUBTRACT_MONTH'

EXPORTING

date = sy-datum

months = '4'

IMPORTING

DATE_E = v_newdate

  • EXCEPTIONS

  • DATE_ERROR = 1

  • OTHERS = 2

.

date-low = v_newdate

date-high = sy-dayum

date-sign = 'I'

date-option = 'BT'.

append date.

Read only

Former Member
0 Likes
1,052

Hi,

You can do this in the INITIALIZATION event of your program.

Call FM RP_CALC_DATE_IN_INTERVAL

pass signum as '-' months as '04' date as s_date-high.



select-options: s_date for sy-datum.

INITIALIZATION.

s_date-sign = 'I'.
s_date-option = 'BT'.
s_date-high = sy-datum.

  call function 'RP_CALC_DATE_IN_INTERVAL'
       exporting
            date      = s_date-high
            days     = '00'
            months    = '04'
            signum    = '-'
            years     = '00'
       importing
            calc_date = s_date-high.

append s_date.

Hope this helps.

Thanks

Balaji

Read only

Former Member
0 Likes
1,052

Hi amit,

Try this code ,

TABLES vbak.

SELECT-OPTIONS : so_date FOR vbak-erdat.

DATA : gv_date TYPE sydatum,gv_mon TYPE i.

INITIALIZATION.

MOVE:

sy-datum to so_date-high .

gv_mon = so_date-high+4(2).

IF so_date-high+4(2) GT 4.

gv_mon = gv_mon - 4.

gv_date+4(2) = gv_mon .

elseif so_date-high+4(2) eq 4.

gv_mon = 12.

elseif so_date-high+4(2) eq 3.

gv_mon = 11.

elseif so_date-high+4(2) eq 2.

gv_mon = 10.

elseif so_date-high+4(2) eq 1.

gv_mon = 9.

ENDIF.

gv_date0(4) = sy-datum0(4).

gv_date6(2) = sy-datum6(2).

MOVE:

'BT' TO so_date-option,

sy-datum TO so_date-high .

so_date-low = gv_date.

APPEND so_date.

reward points