2024 Feb 01 10:23 AM
Bit of an old-school ABAP question!
I have a report with two similar select-options on the selection screen, both type NUMC and 6 in length. I want the user to be free to enter number range(s) plus individual values, exclusions etc if they want to (ie. the normal ways you are able to populate a select-option). However the values in the two ranges must have no overlap or contradiction. Typical range for the first select-option would be 230000 - 249999 and for the second 500000-599999, but if the user entered 230000 - 249999 and 249000 - 259999 for example an error should be raised.
What I am looking for is an SAP standard function module (or similar) to which I could provide the two select-options and get it to check for any clashes. The only solution I have come up with so far is to expand the individual values into two (potentially massive) internal tables and then loop through one of them looking for a matching value in the other. My code for doing this with "BT" ranges looks like this:
loop at s_voynr.
if s_voynr-sign = 'I' and s_voynr-option = 'BT'.
n = s_voynr-high - s_voynr-low + 1.
x_voynr = s_voynr-low.
do n times.
append x_voynr to itab_voynr.
x_voynr = x_voynr + 1.
enddo.
endif.
endloop.
loop at s_aotrf.
if s_aotrf-sign = 'I' and s_aotrf-option = 'BT'.
n = s_aotrf-high - s_aotrf-low + 1.
x_aotrf = s_aotrf-low.
do n times.
append x_aotrf to itab_aotrf.
x_aotrf = x_aotrf + 1.
enddo.
endif.
endloop.
loop at itab_voynr assigning <fs_i_voynr>.
read table itab_aotrf transporting no fields
with table key voynr = <fs_i_voynr>-voynr.
if sy-subrc = 0.
message e023(z1) with text-028.
endif.
endloop.
However this is very slow plus I would need to code around the other possible alternatives such as "EQ", "NB" if I wanted the user to have full flexibility.
Any ideas on this?
2024 Feb 01 1:28 PM
You could reduce user options with FM such as SELECT_OPTIONS_RESTRICT.
But if you really want user to be allowed full select-options, It would be easier to check overlap in database, with some
SELECT *
FROM DBTABLE
WHERE FIELD IN RANGE1 AND FIELD IN RANGE2...
sy-subrc must be 4 else there are overlapping records.
Or write a complex code to match every Include record from both select-options checking for exclude record...
2024 Feb 05 9:03 AM
Thanks for the input Raymond!
Think I am going to force the user to enter a single range in both select-options and go with logic similar to that which I was looking at originally.
2024 Feb 01 2:01 PM
See the good answer by Raymond.
But please, next time, format your code via "..." and "</>" e.g.
loop at s_voynr.
if s_voynr-sign = 'I' and s_voynr-option = 'BT'.
n = s_voynr-high - s_voynr-low + 1.
x_voynr = s_voynr-low.
do n times.
append x_voynr to itab_voynr.
x_voynr = x_voynr + 1.
enddo.
endif.
endloop.