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

simple question

Former Member
0 Likes
798

hi!

I have an abap program where I should build a check on the following

parameters: p_date type dats.

How can I check if p_date is at least one year ago compared to today? If not, an error message should be printed to screen, and the rest of the program should not be executed.

also, if possible, default value for the p_data parameter should be the date one year ago compared to today

simple question from a beginning abap programmer

thanks !

Message was edited by: Joris Hens

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
769

Hello Joris,

parameters: p_date type dats.

at selection-screen on p_date.

data: l_date type dats.

l_date = sy-datum.

l_date0(4) = sy-datum0(4) - 1.

if p_date > l_date.

message e308(00) with 'Enter date one year ago'.

endif.

Regards,

Naimesh

7 REPLIES 7
Read only

naimesh_patel
Active Contributor
0 Likes
770

Hello Joris,

parameters: p_date type dats.

at selection-screen on p_date.

data: l_date type dats.

l_date = sy-datum.

l_date0(4) = sy-datum0(4) - 1.

if p_date > l_date.

message e308(00) with 'Enter date one year ago'.

endif.

Regards,

Naimesh

Read only

Former Member
0 Likes
769

Hi,

DATA : v_i type i.

v_i = sy-datum - p_date.

IF v_i LE 365.

MESSAGE to show "p_date is at least one year ago compared to today"

ENDIF.

*This will solve your query

*Reward all helpful answers

Read only

Former Member
0 Likes
769

Hi Joris,

There is an event called "AT SELECTION-SCREEN" where you can check the input given by the user is a valid one or not. Justt check out and see

Bye

Murthy

Read only

Former Member
0 Likes
769

you can use AT SELECTION SCREEN ON field

Have a look at below link. It will give you details abt this processing block.

http://help.sap.com/saphelp_nw04/helpdata/en/79/34a237d9b511d1950e0000e8353423/content.htm

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

dani_mn
Active Contributor
0 Likes
769

HI,

check this logic.

<b>

parameters: p_date type dats.
data: a type datum.

a = sy-datum.
a(4) = sy-datum(4) - 1.

if p_date(4) > a.
    MESSAGE E000(su) WITH 'date is not valid'.
endif.
write:/ a.

</b>

REgards,

Read only

Former Member
0 Likes
769

Hi Joris,

U can validate any selection screen fields in the event

at-selection screen.

1. To validate date,

the internal format for the date storage is : DDMMYYYY.

take a variable say w_year.

w_year = sy-datum+4(4).

The above statement will store the date.

take another variable which contains the previous years date (use offset as of above). Compare and generate am error message.

2. U can default values in the selection screen using the event initialization.

Regards,

Santosh.

Read only

0 Likes
769

thanks everyone, learned something again today

points have been rewarded