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 query

Former Member
0 Likes
1,265

Hi all,

Plz tell me how to write select query .

I have 5 inputs in selection screen, 2 are obligatory , 3aro not.

In my first select qyery of my report how how can i write the conditions in where clause for this.

select ekgrp matnr werks lgort r menge meins badat

frgdt ebeln ebelp

into table itab_eban from eban

where ( ekgrp eq p_ekgrp ) and

( matnr in s_matnr ) and

werks eq p_werks and

( lgort eq p_lgort ) and

badat in s_badat.

endif.

I knew that if the input field is not obligatory, then we write the condition in brackets.

Plz tell me.

Savita

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,230

Hi Savita,

You can make all selection screen parameters as select-options, as select-options work fine even we donot give any value.

That is all the obligatory and optional fields you need to make them as select-options without intervals and extensions.

SELECT-OPTIONS: p_date FOR SY-DATUM NO-EXTENSION NO INTERVALS.

Plz reward if useful.

Thanks,

Dhanashri.

10 REPLIES 10
Read only

Former Member
0 Likes
1,230

hi savita,

ur select stmt should be like this.

SELECT FIELD1 FIELD2.... FROM <TABLE> INTO TABLE <INTERNAL TABLE> WHERE COND1 AND

COND2 AND

COND3.

DO NOT BOTHER ABOUT OBLIGATORY.

Rgds.,

subash

Read only

0 Likes
1,230

Hi Gaddameedi,

No data is populating in my internal table by the way u said & the way I wrote. but when i wrote only obligatory fields then the data is coming in internal table.

Savita

Read only

0 Likes
1,230

Hi Savitha,

This is only based on the data entered in the Selection Screen. Can you share your code over here.

Regards,

Viji.

Read only

Former Member
0 Likes
1,230

Hi Savitha,

If the Selection Screen Filed is mandatory or not, No need to write in BRACKETS. Remove the brackets in your code and check it.

Reward if it Helps.

Regards,

Viji.

Read only

Former Member
0 Likes
1,230

Hi,

There is no need to give in brackets. There is nothing like that if the input field is not obligatory, then we write the condition in brackets.

Regards

Susheel

Read only

Former Member
0 Likes
1,230

HI,

Obligatory fields are the mandatory fields on the selection screen, These fields will not make difference in fetching the data. Write the select according to your requirement, don't bother about the mandatory fields on the selection screen.

Functionality: Obligatory fields will not allow to leave the selection screen until these fields are filled properly.

Reward points if it is helpful.

Read only

0 Likes
1,230

Hello Ravi,

I m getting a problem in fetching data when i m not giving any input in non-obligatory fields,

the it is taking as those fields value as null value(i feel)

.

Savita

Read only

0 Likes
1,230

Dear,

Try like this,

if p_ekgrp is initial and

p_werks is intial and

s_badat is initial.

select ekgrp matnr werks lgort r menge meins badat

frgdt ebeln ebelp

into table itab_eban from eban

matnr in s_matnr and

lgort eq p_lgort .

elseif p_ekgrp is not initial and

p_werks is intial and

s_badat is initial.

select ekgrp matnr werks lgort r menge meins badat

frgdt ebeln ebelp

into table itab_eban from eban

matnr in s_matnr and

ekgrp eq p_ekgrp and

lgort eq p_lgort .

elseif

......................

......................

elseif

......................

else.

select ekgrp matnr werks lgort r menge meins badat

frgdt ebeln ebelp

into table itab_eban from eban

where ekgrp eq p_ekgrp and

matnr in s_matnr and

werks eq p_werks and

lgort eq p_lgort and

badat in s_badat.

endif.

Regards,

Read only

sachin_mathapati
Contributor
0 Likes
1,230

Hi Savita,

No need to bother about weather input field is obligatory or not, if the input field is blank the select query does not consider that input field.

select ekgrp matnr werks lgort r menge meins badat

frgdt ebeln ebelp

into table itab_eban from eban

where ekgrp eq p_ekgrp and

matnr in s_matnr and

werks eq p_werks and

lgort eq p_lgort and

badat in s_badat.

Regards,

Sachin M M

Read only

Former Member
0 Likes
1,231

Hi Savita,

You can make all selection screen parameters as select-options, as select-options work fine even we donot give any value.

That is all the obligatory and optional fields you need to make them as select-options without intervals and extensions.

SELECT-OPTIONS: p_date FOR SY-DATUM NO-EXTENSION NO INTERVALS.

Plz reward if useful.

Thanks,

Dhanashri.