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: 

Using select-options table as method parameter

Peter_Inotai
Active Contributor
0 Kudos

How it is possible to use a select-options table as a method parameter?

Select-options table is an internal table with header line, but defining parameter with header line is not possible.

Is there a way to implement this?

Thanks in advance,

Incho

My code:

...

SELECT-OPTIONS:

        so_vbeln FOR wa_vbakp-vbeln MEMORY ID aun

          MATCHCODE OBJECT vmva,

        so_kunnr FOR wa_vbakp-kunnr MEMORY ID vag

          MATCHCODE OBJECT debi,

        so_matnr FOR wa_vbakp-matnr MEMORY ID mat,

        so_auart FOR wa_vbakp-auart MEMORY ID aat.

...

    CLASS-METHODS:

      fill_it_vbakp

        IMPORTING

            i_vbeln LIKE so_vbeln

            i_kunnr LIKE so_kunnr

            i_matnr LIKE so_matnr

            i_auart LIKE so_auart

            i_erdat LIKE so_erdat

            i_bstdk LIKE so_bstdk

            i_vkorg LIKE so_vkorg

            i_vtweg LIKE so_vtweg

            i_spart LIKE so_spart

        RETURNING

          value(r_it_vbakp) TYPE ty_t_vbakp.

....

  METHOD fill_it_vbakp.

    DATA: r_wa_vbakp TYPE ty_s_vbakp.

    SELECT kvbeln kkunnr kerdat kbstdk k~bstnk

           kvkorg kvtweg k~spart

           pposnr pmatnr p~arktx

           pnetwr pwaerk pkwmeng pvrkme

      FROM vbak AS k INNER JOIN vbap AS p

      ON kvbeln = pvbeln

      INTO CORRESPONDING FIELDS OF TABLE r_it_vbakp

      WHERE k~vbeln IN so_vbeln

        AND k~kunnr IN so_kunnr

        AND k~auart IN so_auart

        AND k~erdat IN so_erdat

        AND k~bstdk IN so_bstdk

        AND k~vkorg IN so_vkorg

        AND k~vtweg IN so_vtweg

        AND k~spart IN so_spart

        AND p~matnr IN so_matnr.

.......

So in the method I use so_* which are globals, so they are available within the method, but I would like to use i_* parameters somehow.

8 REPLIES 8

DirkAltmann
Active Participant
0 Kudos

Hi Peter,

create an internal table like the select-options table without headerline. Then move the values in your new table whitout headerline e. g.:

tables: bkpf.                            

select-options so_bukrs for bkpf-bukrs.  

data: it_bukrs like so_bukrs occurs 0.   

it_bukrs[] = so_bukrs[].                 

0 Kudos

Thanks Dirk!

Meanwhile I got a similar answer on SAPFANS ( http://www.sapfans.com/forums/viewtopic.php?t=79918 ).

Incho

Ps: In ABAP Objects 'OCCURS' is not allowed for internal table definition.

0 Kudos

Hello Incho,

you are right, but I work with an old version (3.1I) and it is the only way to create an internal table in this antique system.

Dirk

0 Kudos

Thanks Dirk for clarifying this!

After reading some news about ABAP in WAS 6.40 I have the impression that I work with an old system...and my ABAP knowledge is not really up-to-date...it's R/3 46C system....so working with version 3.1I is probable quite "painful";-(((

Incho

0 Kudos

If you want to create an internal table without a header line in a method use the following code:

DATA: i_tab TYPE STANDARD TABLE OF bukrs.

TYPE can be: STANDARD, SORTED OR HASHED

Also: UNIQUE, NON-UNIQUE

KEY can have , default key or, table_line

ie DATA: I_TAB TYPE STANDARD TABLE OF BUKRS

              WITH UNIQUE KEY TABLE_LINE.

Hope this helps.

0 Kudos

Thanks Mike!

Incho

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can still create ranges in the OO context.  Just use the following syntax:

DATA rangetab TYPE|LIKE RANGE OF ...

I usually create a table type with sign, option, low and high for my importing paramater.  I then copy the importing parameter into an OO Range using l_param[] = i_param[] and use the local OO Range in my select statement.

0 Kudos

Thanks Thomas!

I got the same answer in SAP fans. It worked fine, but I had to transfer the data from the select-options to the ranges.

After another tip from SAPFans I just defined the import parameters reference to the body of the select-option. Now I don't have to transfer the values, and it can be implemented with less coding.

It works fine now......

So, my code is the following now:

*----


*

*       CLASS lcl_vbakp DEFINITION

*----


*

CLASS lcl_vbakp DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS:

      fill_it_vbakp

        IMPORTING

            i_vbeln LIKE so_vbeln[]

            i_kunnr LIKE so_kunnr[]

            i_matnr LIKE so_matnr[]

            i_auart LIKE so_auart[]

            i_erdat LIKE so_erdat[]

            i_bstdk LIKE so_bstdk[]

            i_vkorg LIKE so_vkorg[]

            i_vtweg LIKE so_vtweg[]

            i_spart LIKE so_spart[]

        RETURNING

            value(r_it_vbakp) TYPE ty_t_vbakp.

ENDCLASS.

*----


*

*       CLASS lcl_vbakp IMPLEMENTATION

*----


*

CLASS lcl_vbakp IMPLEMENTATION.

  METHOD fill_it_vbakp.

    DATA: r_wa_vbakp TYPE ty_s_vbakp.

    SELECT kvbeln kkunnr kerdat kbstdk k~bstnk

           kvkorg kvtweg kspart kauart

           pposnr pmatnr p~arktx

           pnetwr pwaerk pkwmeng pvrkme

      FROM vbak AS k INNER JOIN vbap AS p

      ON kvbeln = pvbeln

      INTO CORRESPONDING FIELDS OF TABLE r_it_vbakp

      WHERE k~vbeln IN i_vbeln

        AND k~kunnr IN i_kunnr

        AND k~auart IN i_auart

        AND k~erdat IN i_erdat

        AND k~bstdk IN i_bstdk

        AND k~vkorg IN i_vkorg

        AND k~vtweg IN i_vtweg

        AND k~spart IN i_spart

        AND p~matnr IN i_matnr

        AND ( kvbtyp = 'C' OR kvbtyp = 'I' ). "SD document category

....

  ENDMETHOD.

ENDCLASS.

....

*eject

*&----

-


*&   Event START-OF-SELECTION

*&----

-


START-OF-SELECTION.

  CALL METHOD lcl_vbakp=>fill_it_vbakp

    EXPORTING

             i_vbeln = so_vbeln[]

             i_kunnr = so_kunnr[]

             i_matnr = so_matnr[]

             i_auart = so_auart[]

             i_erdat = so_erdat[]

             i_bstdk = so_bstdk[]

             i_vkorg = so_vkorg[]

             i_vtweg = so_vtweg[]

             i_spart = so_spart[]

    RECEIVING

             r_it_vbakp = it_vbakp.

....