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

Select Querry,

Former Member
0 Likes
727

Hello friends,

I have date field in my selection screen.

When the user inputs date it should pick records for that date else it should pick for the current date.

My querry is,

Select * from zpmtras into itab

Where ( erdat = sy-datum ) or ( erdat in s_erdat ).

Let me know if this is right and what are the changes that I should make

Ster.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
702

Hi Ster,

Try this..

if s_erdat[] is initial.

Select * from zpmtras into itab Where erdat = sy-datum.

Else.

Select * from zpmtras into itab Where erdat in s_erdat.

Endif.

Regards

SAB

5 REPLIES 5
Read only

Former Member
0 Likes
703

Hi Ster,

Try this..

if s_erdat[] is initial.

Select * from zpmtras into itab Where erdat = sy-datum.

Else.

Select * from zpmtras into itab Where erdat in s_erdat.

Endif.

Regards

SAB

Read only

Former Member
0 Likes
702

should something like this.

if s_erdat[] is initial.

Select * from zpmtras into itab

Where erdat = sy-datum.

else.

Select * from zpmtras into itab

Where erdat in s_erdat.

endif.

Read only

amit_khare
Active Contributor
0 Likes
702

IF v_date[] is initial.

v_date = sy-datum.

endif.

select 8 from <table> where date = v_date.

Regards,

Amit

Reward all helpful replies.

Read only

0 Likes
702

Thanks Guys.

Ster.

Read only

Former Member
0 Likes
702

Hi Ster,

You will have to separate the date criteria based upon whether the user enters data in the selection screen or not. Currently if the user does not enter data the query will retrieve all the data from the Z table in the database. Your code should look like this:

IF NOT s_erdat[] IS INITIAL.
  SELECT <field list>
  FROM zpmtras
  INTO TABLE itab
  WHERE erdat IN s_erdat.
ELSE.
  SELECT <field list>
    FROM zpmtras
    INTO TABLE itab
    WHERE erdat EQ sy-datum.
ENDIF.