Application Development 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: 

Passing Select-Option to OO method via parameter list

Former Member

Is it possible to pass a reference to a select-option through the parameter list of a method such that the parameter can be used in a "where clause" using the conventional "IN" operator? If so, how should the parameter be typed?

Thanks in advance,

Philip Smith

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate

Sure, here's how.



report zrich_0002 no standard page heading.

tables: mara.



*---------------------------------------------------------------------*
*       CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app definition.

  public section.

    types: t_matnr type range of mara-matnr.

    data: imara type table of mara.
    methods: constructor importing im_matnr type t_matnr.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.


  method constructor.

    select * into table imara from mara up to  100 rows
                 where matnr in im_matnr.

    check sy-subrc = 0.
  endmethod.

endclass.


data: myapp type ref to lcl_app.

select-options: s_matnr for mara-matnr.

start-of-selection.


  create object myapp
        exporting
             im_matnr = s_matnr[].

Welcome to SDN!. Be sure to award points for helpful answers and mark your post as solved when solved completely. Thanks.

REgards,

Rich Heilman

7 REPLIES 7

former_member188685
Active Contributor
0 Kudos

use type any .

Former Member
0 Kudos

u can convert the parameter to ranges and use IN operator

RichHeilman
Developer Advocate
Developer Advocate

Sure, here's how.



report zrich_0002 no standard page heading.

tables: mara.



*---------------------------------------------------------------------*
*       CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app definition.

  public section.

    types: t_matnr type range of mara-matnr.

    data: imara type table of mara.
    methods: constructor importing im_matnr type t_matnr.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.


  method constructor.

    select * into table imara from mara up to  100 rows
                 where matnr in im_matnr.

    check sy-subrc = 0.
  endmethod.

endclass.


data: myapp type ref to lcl_app.

select-options: s_matnr for mara-matnr.

start-of-selection.


  create object myapp
        exporting
             im_matnr = s_matnr[].

Welcome to SDN!. Be sure to award points for helpful answers and mark your post as solved when solved completely. Thanks.

REgards,

Rich Heilman

0 Kudos

Thank you, 🙂

former_member188685
Active Contributor
             GETDATA
                 IMPORTING S_OPTION TYPE ANY TABLE.

      implementation.

method getdata.

select ..

 where field in s_option[].

endmethod.

Former Member
0 Kudos

Or if you want to create this attribute in the class , you can define a type group

for e.g. TYPES: s_vbeln TYPE RANGE OF vbrk-vbeln.

Then you can directly use this in the attributes of your class with type s_vbeln.

- Kalpana

Former Member
0 Kudos

Thanks for the help guys very quick response.