‎2020 Aug 05 1:37 PM
Hey everyone,
i want to pass a SELECT-OPTIONS to a method.
Is there a way to declare the method parameter as something like TYPE RANGE OF KNA1-KUNNR
Thanks in advance!
EDIT:
I found a workaround:
TYPES T_SO_KUNNR TYPE RANGE OF KNA1-KUNNR.
IMPORTING SO_KUNNR TYPE T_SO_KUNNR
Is there a more elegant solution?
‎2020 Aug 06 3:44 PM
As proposed by the author of the question + embedding the code in the one proposed by Jörg Krause:
class app definition.
public section.
TYPES T_SO_KUNNR TYPE RANGE OF KNA1-KUNNR.
methods main
importing customer_range type T_SO_KUNN.
endclass.
class app implementation.
method main.
select * from kna1
where kunnr in @customer_range
into table @data(result).
endmethod.
endclass.
select-options s_kunnr for kna1-kunnr.
start-of-selection.
new app( )->main( s_kunnr[] ).
‎2020 Aug 05 1:45 PM
Hello Former Member
Create a range structure type, then a range table type in your class and use this type as a type of your method's parameter. For example:
TYPES:
BEGIN OF ygs_range,
sign TYPE sign,
option TYPE option,
low TYPE kunnr,
high TYPE kunnr,
END OF ygs_range,
ygt_range TYPE TABLE OF ygs_range.
" use YGT_RANGE in you method's parameters
Kind regards,
Mateusz
Edit: or you could use a range table type defined in ABAP dictionary, if you find it.
Edit2: you can later provide your select-options value as shown below:
lo_object->my_method( it_range = sel_opt[] ).
‎2020 Aug 05 3:22 PM
Note, in my old 46C system, range type exist for customer :
SHP_KUNNR_RANGE_T for table and SHP_KUNNR_RANGE for line type.
Perhaps it exist also for Kevin...
‎2020 Aug 05 3:48 PM
‎2020 Aug 05 2:26 PM
Please move out your "workaround" (solution in fact) to an answer so that people can vote for it.
Please use the CODE button to format your code so that it's shown in a more user-friendly format (colorized).
‎2020 Aug 06 1:12 PM
This may be a *bit* dirty, but in some cases, I find it tolerable to declare the parameter in your method as a generic standard table. As long as you use the select option for selecting (and you do not have to access the columns SIGN, OPTION, LOW, HIGH directly), this seems a simple and very slim solution to me.
select-options s_kunnr for kunnr.
class app definition.
public section.
methods main
importing customer_range type standard table.
endclass.
class app implementation.
method main.
select * from kna1
where kunnr in @customer_range
into table @data(result).
endmethod.
endclass.
start-of-selection.
new app( )->main( s_kunnr[] ).
‎2020 Aug 06 2:32 PM
I must say that I also do this, for the sake of readability that 8-char restricted PARAMETER/SELECT-OPTIONS can't provide (as your snippet demonstrates).
‎2020 Aug 06 3:44 PM
As proposed by the author of the question + embedding the code in the one proposed by Jörg Krause:
class app definition.
public section.
TYPES T_SO_KUNNR TYPE RANGE OF KNA1-KUNNR.
methods main
importing customer_range type T_SO_KUNN.
endclass.
class app implementation.
method main.
select * from kna1
where kunnr in @customer_range
into table @data(result).
endmethod.
endclass.
select-options s_kunnr for kna1-kunnr.
start-of-selection.
new app( )->main( s_kunnr[] ).
‎2020 Aug 07 7:38 AM
sandra.rossi i can't seem to edit my question anymore, i only see the options "See Revisions", "Redirect" and "Close"
‎2020 Aug 07 8:20 AM
You're right. It's too late to edit your question after someone has posted an answer. Anyway, you might post an answer with your solution. But in fact, I did it yesterday for you.