07-08-2008 1:58 PM
Hi,
In my MPP screen, I have 5 fields out of which only 2 are required/mandatory. But if the user enters data into the optional field (or fields), I need to include them also in my selection criteria.
Now, do I need to check if the data exists in the optional fields and write separate select statements for cases where the user has provided some input? Is there an alternative solution to achieve this rather than writing so many select statements?
Thanks,
Mohit
07-08-2008 2:00 PM
Hi Mohit,
You can directly write a SELECT query containing the Optional Field, if you Enter value in that field the SELECT query will limit the Records based on that field also, otherwise when you don't specify a Value in this Optional Field it will be Ignored in the SELECT query.
In other Words the System Automatically checks this Optional Field whether it has some value or not and Fetches the Data based on that.
Best Regards,
Sunil
07-08-2008 2:01 PM
Hi Mohit,
There is no need for validating the mandatory/obligatory fields. The system automatically checks whether the field is empty or not and if it is empty it will give an error specifying that enter all mandatory fields.
And for optional fields there is no need to check whether they are empty or not, becouse they are optional.
Hope this helps you.
Regards,
Chandra Sekhar
07-08-2008 2:02 PM
Hi,
If it is select option then no need to have seperate select. Just include this condition also in the select. If this field is blank then select will ignore this condition.
If it is parameter then u have to have 2 selects.
IF thatfield IS INITIAL.
SELECT1.....With out that condition.
ELSE.
SELECT1 ... With that condition.
ENDIF.
Thanks,
Vinod.
07-08-2008 2:02 PM
Hello,
You can create the where condition dynamically [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae], or use the the field for validate the fields in pai [http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbaa3a35c111d1829f0000e829fbfe/frameset.htm].
Regards.
07-08-2008 2:02 PM
Hi,
I think you are using parameters and not select-options.
Check if you can change the selection screen parameters to
select-options: p_fld for tab-fld no intervals no extension. Then you can use single select by using 'IN' .
Thanks,
Keerthi.
07-08-2008 2:04 PM
HI Mohit,
YOu can have select-options declared for the optional fields instead of parameters.
If you still want to make them look like parameters, you can declare them like this
DATA spfli_wa TYPE spfli.
SELECT-OPTIONS s_carrid FOR spfli_wa-carrid NO-EXTENSION NO INTERVALS.
your select should be some thing like:
select * from <table> into table <intenal table>
where matnr in s_matnr.....
Regards,
Ravi
07-08-2008 2:05 PM
If your five fields are parameters, you can't just leave them in your WHERE criteria as your Select will fail - say you are selecting from MARA where MATNR = null - you won't find anything will you?
The best solution is to build a dynamic where statement like this:-
&---------------------------------------------------------------------*
*& Form build_dynamic_where_statement
*&---------------------------------------------------------------------*
* This routine takes the key values passed into module
* ZPP_PO_READ_LAB_HOURS_TABLE and builds a dynamic where statement
* into a string field that can then be used for SELECT statements
*----------------------------------------------------------------------*
form build_dynamic_where_statement.
*--- Ensure the last where statement is cleared
clear: gv_where_statement.
*--- Need to go through each variable and add to the where statement if it
*--- has a value assigned
if gv_werks is not initial.
gv_where_statement = 'WERKS EQ GV_WERKS'.
endif.
if gv_resrce is not initial.
if gv_where_statement is not initial.
concatenate gv_where_statement
'AND RESRCE EQ GV_RESRCE'
into gv_where_statement
separated by space.
else.
gv_where_statement = 'RESRCE EQ GV_RESRCE'.
endif.
endif.
if gv_begda is not initial.
if gv_where_statement is not initial.
concatenate gv_where_statement
'AND BEGDA EQ GV_BEGDA'
into gv_where_statement
separated by space.
else.
gv_where_statement = 'BEGDA EQ GV_BEGDA'.
endif.
endif.
if gv_budat is not initial.
if gv_where_statement is not initial.
concatenate gv_where_statement
'AND BUDAT EQ GV_BUDAT'
into gv_where_statement
separated by space.
else.
gv_where_statement = 'BUDAT EQ GV_BUDAT'.
endif.
endif.
if gv_schgrup is not initial.
if gv_where_statement is not initial.
concatenate gv_where_statement
'AND SCHGRUP EQ GV_SCHGRUP'
into gv_where_statement
separated by space.
else.
gv_where_statement = 'SCHGRUP EQ GV_SCHGRUP'.
endif.
endif.
if gv_kaptprog is not initial.
if gv_where_statement is not initial.
concatenate gv_where_statement
'AND KAPTPROG EQ GV_KAPTPROG'
into gv_where_statement
separated by space.
else.
gv_where_statement = 'KAPTPROG EQ GV_KAPTPROG'.
endif.
endif.
endform. " build_dynamic_where_statement
And then write your select something like this:-
select *
into table t_lab_hours
from zpp_po_lab_hours
where (gv_where_statement).
07-08-2008 2:06 PM
HI,
You can achieve this by LIKE key word.
for ex: if you have the field1, field2 (where these fields are not ranges) on the screen. if these are filled you should select the data regarding this, if they are empty you should fetch the data without considering this, so you can do as below.
if field1 is initial.
field1 = '%'.
endif.
if field2 is initial.
field2 = '%'.
endif.
the query should be as below.
select f1 f2
from table1
into table itab1
where f1 LIKE field1
and f2 LIKE field2.
This will solve your problem.