‎2008 Feb 27 10:09 AM
Hi,
i am trying to fetch data from table s003 into internal table itab.
i have selection screen designed for entering fields as below.
1)material
2)sales organization
3)distribution channel
4)currency
5)period
now the problem is when ever user fills any one or some or all of input selection screen fields, only data relating to that should be fetchd from table s003.
for example,... here when i give material number, all the data based on this material only should be fetched.
But what is happening is , all the records in the table s003 are being fetched. if i give only one input screen field.
Below is my code. please correct and suggest me.
___________________________________________
REPORT Zmaterial_analysis.
TABLES: MVKE, S003, MCS0.
DATA: BEGIN OF ITAB OCCURS 0,
SPBUP LIKE S003-SPBUP,
VKORG LIKE S003-VKORG,
VTWEG LIKE S003-VTWEG,
MATNR LIKE S003-MATNR,
STWAE LIKE S003-STWAE,
AENETWR LIKE S003-AENETWR,
UMNETWR LIKE S003-UMNETWR,
UMMENGE LIKE S003-UMMENGE,
MVGR1 LIKE MVKE-MVGR1,
MVGR2 LIKE MVKE-MVGR2,
MVGR3 LIKE MVKE-MVGR3,
END OF ITAB.
DATA: BEGIN OF I_MVKE OCCURS 0,
MATNR LIKE MVKE-MATNR,
MVGR1 LIKE MVKE-MVGR1,
MVGR2 LIKE MVKE-MVGR2,
MVGR3 LIKE MVKE-MVGR3,
END OF I_MVKE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-003.
SELECT-OPTIONS: S_MATNR FOR S003-MATNR.
SELECT-OPTIONS: S_VKORG FOR S003-VKORG.
SELECT-OPTIONS: S_VTWEG FOR S003-VTWEG.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_STWAE FOR S003-STWAE NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS: S_SPBUP FOR MCS0-SPBUP.
SELECTION-SCREEN END OF BLOCK B3.
START-OF-SELECTION.
SELECT SPBUP
VKORG
VTWEG
MATNR
STWAE
AENETWR
UMNETWR
UMMENGE
FROM S003
INTO CORRESPONDING FIELDS OF TABLE ITAB
WHERE MATNR IN S_MATNR
OR VKORG IN S_VKORG
OR VTWEG IN S_VTWEG
OR SPBUP IN S_SPBUP
OR STWAE EQ S_STWAE.
SELECT MATNR MVGR1 MVGR2 MVGR3 FROM MVKE
INTO CORRESPONDING FIELDS OF TABLE I_MVKE
FOR ALL ENTRIES IN ITAB
WHERE MATNR EQ ITAB-MATNR.
LOOP AT ITAB.
WRITE:/ ITAB-MATNR,ITAB-VKORG,ITAB-VTWEG.
ENDLOOP.
‎2008 Feb 27 10:14 AM
hi,
replace all ORs with ANDs in your selection:
SELECT SPBUP
VKORG
VTWEG
MATNR
STWAE
AENETWR
UMNETWR
UMMENGE
FROM S003
INTO CORRESPONDING FIELDS OF TABLE ITAB
WHERE MATNR IN S_MATNR
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPBUP IN S_SPBUP
AND STWAE EQ S_STWAE.
hope this helps
ec
‎2008 Feb 27 10:14 AM
hi,
replace all ORs with ANDs in your selection:
SELECT SPBUP
VKORG
VTWEG
MATNR
STWAE
AENETWR
UMNETWR
UMMENGE
FROM S003
INTO CORRESPONDING FIELDS OF TABLE ITAB
WHERE MATNR IN S_MATNR
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPBUP IN S_SPBUP
AND STWAE EQ S_STWAE.
hope this helps
ec
‎2008 Feb 27 10:14 AM
‎2008 Feb 27 10:17 AM
Hi,
Do like this
SELECT SPBUP
VKORG
VTWEG
MATNR
STWAE
AENETWR
UMNETWR
UMMENGE
FROM S003
INTO CORRESPONDING FIELDS OF TABLE ITAB
WHERE MATNR IN S_MATNR
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPBUP IN S_SPBUP
AND STWAE EQ S_STWAE.
if not itab[] is initial.
SELECT MATNR MVGR1 MVGR2 MVGR3 FROM MVKE
INTO CORRESPONDING FIELDS OF TABLE I_MVKE
FOR ALL ENTRIES IN ITAB
WHERE MATNR EQ ITAB-MATNR.
endif.
Regards,
Nagaraj
‎2008 Feb 27 10:22 AM
Hi,
You r using OR in ur select query for where conditon this means any of the input field is entered then the data is fetching.
If u use AND in select query u will get relevent data.
Regards,
kavitha
‎2008 Feb 27 10:42 AM
Thanks for quick reply,
but i am facing the problem.
not problem with the second select query in the code that i have put.
please look at the first one only.
if i use in the where clause
or --> it is fetching all the records in database table.( when one selection screen input is given on screen.)
and--> it is not fetching at all any records if all the fields are not filled mandatory.
my problem is all the fields on selection screen are not mandatory. so whether i enter single or two or three or four or five(i.e. all screen inputs) i should get records basing on that selection criteria.
one more thing is u have to observe is my screen fields are select-optins.
Edited by: krishna chaitanya on Feb 27, 2008 11:44 AM
‎2008 Feb 27 11:09 AM
hi everybody,
thanks to one and all of you for efforts in replying to my question.
my problem is solved.
i have used and in the where clause
but for selection field of type cuky i used or operator.
there is some problem with cuky type on select query.
if use and operator for that type, data is not fetched.
thanks to all,
i am awarding points to all.
krishna