Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Abap Method declare importing parameter TYPE RANGE OF

Former Member
21,154

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?

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
14,782

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[] ).
9 REPLIES 9
Read only

MateuszAdamus
Active Contributor
14,782

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[] ).
Read only

14,782

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...

Read only

matt
Active Contributor
14,782

SHP_KUNNR_RANGE_T is on my 750 system as well.

Read only

Sandra_Rossi
Active Contributor
14,782

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).

Read only

jrgkraus
Active Contributor
14,782

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[] ).
Read only

thalesvb
Active Contributor
0 Likes
14,782

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).

Read only

Sandra_Rossi
Active Contributor
14,783

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[] ).
Read only

Former Member
14,782

sandra.rossi i can't seem to edit my question anymore, i only see the options "See Revisions", "Redirect" and "Close"

Read only

Sandra_Rossi
Active Contributor
0 Likes
14,782

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.