2013 Dec 10 11:33 AM
Hi All,
I have selection screen with 8 parameters. Now i have to fetch data from table ABC into itab based on the selection screen data.
for example :
parameters: ztable-para1 ztable-para5 ====> All fields from same table.
ztable-para2 ztable-para6
ztable-para3 ztable-para7
ztable-para4 ztable-para8
Now i need to select data from ztable based on selecting data from parameters. Now lets say i fill all fields and i will get data based on that.
now, what if i fill only 2 parameters, that is para1 & para2 and rest is blank. now i want data based on para1 and para2. it is checking other field is blank and comparing for that.
para1 = Userid , para2 = name para3 = rollnum para4 = class,
do i need to put where condition in all fields? because if i put some fields empty, still it should fetch data based on my para selection.
if i need to check each para empty or not, it is not feasible.
please help.
Thanks
2013 Dec 10 11:39 AM
Hi
In that case use select option. If you do pass value to select option, it will restrict to that value, if you do not pass any value it will check for all possible values.
Regards,
Atul Mohanty
2013 Dec 10 11:43 AM
Hi KSRCM,
before doing a select to the database, build a range for each parameter in the selection screen then it will work. sample code for the same below.
parameters: var1 type data1
var2 type data2
var3 type data3
data: lr_range1 type range of data1,
lw_range1 like line of lr_range1,
lr_range2 type range of data2,
lw_range2 like line of lr_range2,
lr_range3 type range of data3,
lw_range3 like line of lr_range3.
lw_range1-sign = lw_range2-sign = lw_range3-sign = 'I'.
lw_range1-option = lw_range2-option = lw_range3-option = 'EQ'.
lw_range1-low = var1.
lw_range2-low = var2.
lw_range3-low = var3.
append: lw_range1 to lr_range,
lw_range2 to lr_range,
lw_range3 to lr_range.
select *
from abc
into table lt_tab
where var1 in lr_range1
and var2 in lr_range2
and var3 in lr_range3.
now even though one of the parameters is not passed the above select will fetch the correct data
2013 Dec 10 11:45 AM
Hi,
Declare all the fields like:
SELECT-OPTIONS: s1 for ztable-fieldname1,
s2 for ztable-fieldname2.
And got for the select query in this way:
SELECT FI F2 F3 F4 F5
FROM TABLE TAB
INTO TABLE ITAB
WHERE S1 IN S1
AND S2 IN S2.
It will automatically take care even if the values are blank.
Regards,
Dinesh
2013 Dec 10 11:47 AM
You need to use select options instead of parameters. Paramaters considers blank value as a value in itself and will do the select query based on that. However, for a select-option, no values inputted means, it can take any value and hence will retrieve data based only on the inputs entered.
To make the display look like parameters, you can give the addition no-extension and no-intervals.
SELECT-OPTIONS : p_bukrs for anla-bukrs NO-EXTENSION NO INTERVALS.
2013 Dec 10 12:36 PM
Should you not want to use SELECT-OPTIONS you can build a dynamic where clause. Do f1 on Select statement. The SAP Documentation is good with some examples.
In short, a dynamic select statement will then look something like this
TRY.
SELECT * FROM (p_table_name)
INTO CORRESPONDING FIELDS OF TABLE <it_table>
WHERE (it_select_where).
CATCH cx_sy_dynamic_osql_error INTO gr_exc.
EXIT.
ENDTRY
2013 Dec 10 4:21 PM
Hi KSRCM,
Follow the below code its solve your problem.
data text type table of string.
IF s_bukrs[] IS NOT INITIAL .
APPEND ' BUKRS IN S_BUKRS ' TO text .
ENDIF .
IF s_pernr[] IS NOT INITIAL .
APPEND ' AND PERNR IN S_PERNR ' TO text .
ENDIF .
LOOP AT text .
IF sy-tabix = 1 .
REPLACE ALL OCCURRENCES OF ' AND ' IN text WITH ' ' .
MODIFY text .
EXIT .
ENDIF .
ENDLOOP .
IF text[] IS NOT INITIAL .
CONCATENATE LINES OF text INTO text1 . " This can combine all th e line into one line.
SELECT lifnr FROM lfb1 INTO CORRESPONDING FIELDS OF TABLE it_itab1 WHERE (text1).
ENDIF .
Let me know if you have any other issue.
Regards.
Nishant Bansal.