2012 Jan 02 9:42 AM
Hi Experts!!
We have a select-option on sel screen, say so_field. Now, we need to do soem validations for so_field by checking the entries in table ztable.
When so_field is provided as C* to F* then it has to check the entries in ztable and then it has to even validate both low and high. In other words, now selection is successful and we have got values as C123, C1234. But with F* there are no entries. So this has to be shown as an error.
When so_field is provided as C+ and then as second input line F111, this should throw an error again as even C+ doesn't have any matching entry.
And also, if the input is provided under Exclude selections as exclude C123, this should not throw an error as C123 is a valid input.
Can somebody please help me how I can code this? Your help is highly appreciable.
2012 Jan 02 11:41 AM
Hi Sri,
Instead of implementing select inside loop(never recommended), if the ztable doesn't have bulk data, you can
use Select statement before Loop to read all data of the ztable into an internal table. Then, inside the loop you can use
Read table <internal_table> to check the validity of data. Use the clause - 'Transporting No Fields' along with Read to make it better.
Regards,
Harsh Bansal
Hi Experts!!
We have a select-option on sel screen, say so_field. Now, we need to do soem validations for so_field by checking the entries in table ztable.
When so_field is provided as C* to F* then it has to check the entries in ztable and then it has to even validate both low and high. In other words, now selection is successful and we have got values as C123, C1234. But with F* there are no entries. So this has to be shown as an error.
When so_field is provided as C+ and then as second input line F111, this should throw an error again as even C+ doesn't have any matching entry.
And also, if the input is provided under Exclude selections as exclude C123, this should not throw an error as C123 is a valid input.
Can somebody please help me how I can code this? Your help is highly appreciable.
2012 Jan 02 9:47 AM
2012 Jan 02 9:58 AM
I have tried the below, but felt very awkward:
SELECT *
FROM ztable
INTO TABLE lt_table
WHERE field IN s_field.
LOOP AT lt_table INTO ls_table.
ls_field-low = ls_table-field.
ls_field-sign = gc_i.
ls_field-option = gc_eq.
APPEND ls_field TO lt_field.
CLEAR ls_field.
ENDLOOP.
LOOP AT s_field INTO gs_field.
IF gs_field-low CS gc_star OR gs_field-low CS gc_plus
OR gs_field-high CS gc_star OR gs_field-high CS gc_plus.
LOOP AT lt_field INTO ls_field
WHERE low CP gs_field-low.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
MESSAGE e000 WITH text-e02. " Error Message
ENDIF.
LOOP AT lt_field INTO ls_field
WHERE high CP gs_field-high.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
MESSAGE e000 WITH text-e02.
ENDIF.
ELSE.
IF gs_field-low NOT IN lt_field.
MESSAGE e000 WITH text-e02.
ENDIF.
IF NOT gs_field-high IS INITIAL.
IF gs_field-high NOT IN lt_field.
MESSAGE e000 WITH text-e02.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
And also, one more problem is that if I have the SELECT query, then validating while exclude selections is difficult.
2012 Jan 02 11:15 AM
Hi,
Since you need to validate every line entry in the select options.. you need to do something like below.
data: so_field1 like table of so_field.at selection screen.
loop at so_field.
append so_field to so_field1.
select single *
from ztable
into wa_ztable
where field in so_field1.
if sy-subrc ne 0.
message 'Error message'.
endif.
endloop.
here you will be selecting for each line of entries....
For exclude you can check using include if the entries are correct ......
Thanks,
Lalit Mohan Gupta
2012 Jan 02 11:23 AM
Hi Lalit,
Thanks for your code, but I am not willing to go with that because of the performance. SELECT inside a LOOP, will for sure degrade the performance.
Any other suggestions, please!!
2012 Jan 02 11:33 AM
A select option is an object defining what will be selected. Validation only makes sense for select options if single values are entered ( I EQ value ). When you have wildcards, exclusions, ranges, then "validation" isn't meaningful - you either get something returned or you don't. If you look at any standard SAP report, you'll see there's little or no validation on select options.
Admittedly, sometimes select-options can be used a a simple way of getting multiple values. In that case what's already been suggested is the only way forward.
matt
Edited by: Matt on Jan 2, 2012 12:34 PM
2012 Jan 02 11:41 AM
Hi Sri,
Instead of implementing select inside loop(never recommended), if the ztable doesn't have bulk data, you can
use Select statement before Loop to read all data of the ztable into an internal table. Then, inside the loop you can use
Read table <internal_table> to check the validity of data. Use the clause - 'Transporting No Fields' along with Read to make it better.
Regards,
Harsh Bansal
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |