‎2009 Feb 03 12:51 PM
Hi guru's,
Hope someone can help me out. I need to know what the best way is to check if values from a select option is valid.
For example
SELECT-OPTION: so_vndr for wa_lfa1-lifnr.
Now I want to check if all values for so_vndr are in the table lfa1-lifnr.
Hope someone can help me out.
Best regards,
Guido Koopmann
‎2009 Feb 03 2:24 PM
Hi,
Now I want to check if all values for so_vndr are in the table lfa1-lifnr
Not possible. Imagine a situation where the user simply enters "" in the select options or some other pattern like B or AB*or ranges 1 to 100 etc or all of the values mentioned before at the same time.
It will be very difficult to find out which entry of the range or the pattern is valid and which is not.
So the best way to validate this is to select the vendors from lfa1 where lifnr in so_vndr. And if you get a sy-subrc 0 means there are vendors else the entry is invalid. And this validation should be done in the at selection-screen on so_vndr event.
regards,
Advait
‎2009 Feb 03 12:54 PM
if lfa1-lifnr in so_vndr.
"it is ... do your coding here
endif.
Regards
Marcin
‎2009 Feb 03 12:56 PM
Hi,
As you are holding the value in a variable just write a select statement.
After this right a sy-subrc statement like
select single lifnr from lfa1 into wa_lfa1 where lifnr = so_vndr.
IF sy-subrc = 0.
message 'Value exists' type 'I'
endif.
else.
Message 'Value doesnt exists' 'I'.
Hope my answer helps you or least it would have given you an idea.
Cheers!!
VEnk@
‎2009 Feb 03 1:01 PM
select lifnr
from lfa1
into table t_lifnr
where lifnr in so_vndr.
loop ar so_vndr where sign eq 'I' and option eq 'EQ'.
read table t_lifnr with key lifnr = so_vndr-low.
if sy-subrc ne 0.
**message
endif.
endloop.
‎2009 Feb 03 1:01 PM
Hi,
U can use the following code to validate the select-option values
at selection-screen on s_lifnr-low.
SELECT SINGLE lifnr FROM lfa1
INTO w_lifnr
WHERE lifnr = s_lifnr-low.
IF sy-subrc NE 0.
MESSAGE w000 WITH text-001.
ENDIF.
at selection-screen on s_lifnr-high.
SELECT SINGLE lifnr FROM lfa1
INTO w_lifnr
WHERE lifnr = s_lifnr-high.
IF sy-subrc NE 0.
MESSAGE w000 WITH text-001.
ENDIF.
‎2009 Feb 03 1:05 PM
Hi
Try this
LOOP AT so_lifnr.
SELECT lifnr FROM lfa1 INTO lv_lifnr
UP TO 1 ROWS WHERE lifnr EQ so_lifnr-low.
IF sy-subrc NE 0.
* flag set
ENDIF.
ENDLOOP.
CLEAR lv_lifnr.
IF so_lifnr-high IS NOT INITIAL.
SELECT lifnr FROM lfa1 INTO lv_lifnr
UP TO 1 ROWS WHERE lifnr EQ so_lifnr-high.
IF sy-subrc NE 0.
* flag set
ENDIF.
ENDIF.
Pushpraj
‎2009 Feb 03 1:14 PM
Hi,
To validate the entered values in the SO_VDNR..Check this code..
AT SELECTION-SCREEN ON SO_VDNR.
IF NOT SO_VDNR[] IS INITIAL.
SELECT * UPTO 1 ROWS FROM LFA1
WHERE LIFNR IN SO_VDNR.
ENDSELECT.
IF SY_SUBRC NE 0.
" Error Message
ENDIF.
ENDIF.
‎2009 Feb 03 1:59 PM
Thnx for all the replies. If I look at some logic, then not all entries for the select option are checked. It's always the case if one entry is correct, it passes the logic and in my case I need to check all entries.
Best Regards,
Guido Koopmann
‎2009 Feb 03 2:13 PM
Hi Guido
Nope, the code posted by me loops through the select option table thereby checking all the entries.
Do give it a try.
Pushpraj
‎2009 Feb 03 2:15 PM
Generally in select options if one entry is also correct it should pass the logic as you have to process it as user have atleast given one correct entry and you have to give a reault for the same.
Anyways for high and low do it as below and if you want for all the value in select options than retrieve all the value in a internal table and than you have to check:
DATA:
wa_lfa1_lifnr type lfa1-lifnr,
wa_lifnr type lfa1-lifnr.
SELECT-OPTIONS:
so_vndr for wa_lfa1_lifnr.
AT SELECTION-SCREEN ON so_vndr.
If so_vndr-low is not initial.
Clear wa_lifnr.
Select single lifnr
from lfa1
into wa_lifnr
where lifnr eq so_vndr-low. " Compare the low value
If sy-subrc ne 0 and wa_lifnr is initial.
Message 'enter correct value in low' type 'E'.
Elseif sy-subrc eq 0 and so_vndr-high is not initial.
Clear wa_lifnr.
Select single lifnr
from lfa1
into wa_lifnr
where lifnr eq so_vndr-high. " Compare the high value
If sy-subrc ne 0.
Message 'enter correct value in high' type 'E'.
Endif. " If sy-subrc ne 0
Endif. " If sy-subrc ne 0 and wa_lifnr
Endif. " If so_vndr-low is not initialWith luck,
Pritam.
Edited by: Pritam Ghosh on Feb 3, 2009 3:33 PM
‎2009 Feb 03 2:29 PM
Hi,
This code below show an example of checking each select options condition separately. Just paste it and run. Then adapt the logic to work with your data objects.
PARAMETERS pa_val type i.
data success. "does entry satisfy all so_int entries?
select-options so_int for pa_val.
data wa_so_int like line of so_int.
"suppose we have such entries in so_int
so_int-sign = 'I'.
so_int-option = 'BT'.
so_int-low = 2.
so_int-high = 5.
append so_int.
so_int-option = 'EQ'.
so_int-low = 4.
append so_int.
loop at so_int into wa_so_int.
if pa_val in so_int.
success = 'X'.
else.
success = space.
exit.
endif.
ENDLOOP.
if success = 'X'.
write 'Entry satifies all so_int conditions'.
else.
write 'Some entries are not satified'.
endif.
As you can see only entry 4 to pa_val will satisfy both entires in selection options. These anyhow must be checked separately as the system implicitly puts there OR between the conditions. As you said, if one of them is met no more are checked. I think this is the only way to check all of them, simply checking each of them separately.
Regards
Marcin
‎2009 Feb 03 2:05 PM
Hi,
you can do it like
AT SELECTION-SCREEN.
SELECT SINGLE * FROM lfa1
WHERE lifnr IN so_lifnr.
IF sy-subrc NE 0.
" Error message MESSAGE
ENDIF.Regards,
Manoj Kumar P
‎2009 Feb 03 2:19 PM
Hi,
Test the following Code Hope will solve out your problem,
TABLES: lfa1.
SELECT-OPTIONS solifnr FOR lfa1-lifnr.
DATA: it_lfa1 LIKE STANDARD TABLE OF lfa1 WITH HEADER LINE.
SELECT * FROM lfa1
INTO CORRESPONDING FIELDS OF TABLE it_lfa1
WHERE lifnr IN solifnr.Please Reply if any Problem,
Kind Regards,
Faisal
‎2009 Feb 03 2:24 PM
Hi,
Now I want to check if all values for so_vndr are in the table lfa1-lifnr
Not possible. Imagine a situation where the user simply enters "" in the select options or some other pattern like B or AB*or ranges 1 to 100 etc or all of the values mentioned before at the same time.
It will be very difficult to find out which entry of the range or the pattern is valid and which is not.
So the best way to validate this is to select the vendors from lfa1 where lifnr in so_vndr. And if you get a sy-subrc 0 means there are vendors else the entry is invalid. And this validation should be done in the at selection-screen on so_vndr event.
regards,
Advait
‎2009 Feb 03 2:30 PM
Hi,
Check the below code, it will check for all inputs in select option
Here it_check contains only lifnr field an wa_check is work area for the same.
AT SELECTION-SCREEN.
LOOP AT so_lifnr.
wa_check-lifnr = so_lifnr-low. "For values specified individually
"in list
APPEND wa_check TO it_check.
ENDLOOP.
wa_check-lifnr = so_lifnr-low.
APPEND wa_check TO it_check.
wa_check-lifnr = so_lifnr-high.
APPEND wa_check TO it_check.
SORT it_check.
DELETE ADJACENT DUPLICATES FROM it_check.
"Now it_check contains all values with unique entries
DESCRIBE TABLE it_check LINES w_cnt.
SELECT lifnr FROM lfa1
INTO TABLE it_check1
FOR ALL ENTRIES IN it_check
WHERE lifnr = it_check-lifnr.
IF w_cnt NE sy-dbcnt. "If not equal then mismatch of data
MESSAGE e000 WITH 'please verify your input'.
ENDIF.Regards,
Manoj Kumar P