cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Select-options in ABAP OO?

Peter_Inotai
Active Contributor

I'm trying to convert my ABAP/4 program to ABAP OO, but I couldn't find any example how to use select-options in ABAP OO. All the example I could find worked with paramterers:-(

I'm on SAP R/3 46C...is there a demo program for this?

I'd like to convert an easy reporting program, where the data filling would happen in a method instead of a form, what I use normally in ABAP/4.

I didn't know how to define the selection screen, since it didn't accepted an internal table without header line....but I know internal table and header line/work area should be separated in ABAP OO :-(((

So my code, which I'm sure is incorrect....

  • internal table with header line:-(((((

TYPES: ty_catsdb TYPE STANDARD TABLE OF catsdb

             WITH NON-UNIQUE KEY zzaufnr zzvornr.

DATA: it_catsdb_p LIKE TABLE OF catsdb WITH HEADER LINE.

...

*eject

*=======================================================================

*             Selection screen

*=======================================================================

SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE text-sb1.

SELECT-OPTIONS: so_aufnr FOR it_catsdb_p-zzaufnr

                      MEMORY ID aun

                      MATCHCODE OBJECT vmva, "Sales Order

                so_vornr FOR it_catsdb_p-zzvornr

                      MEMORY ID kpo, "Item

                so_pernr FOR it_catsdb_p-pernr

                      MEMORY ID per

                      MATCHCODE OBJECT prem. "Personnel Number

PARAMETERS: pa_date LIKE it_catsdb_p-laeda

                      DEFAULT sy-datum. "Entered date

SELECTION-SCREEN END OF BLOCK sel .

....

*----


*

*       CLASS lcl_catsdb_post DEFINITION

*----


*

*       ........ *

*----


*

CLASS lcl_catsdb_post DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS:

      fill_it_catsdb_post

      IMPORTING

           cl_aufnr LIKE so_aufnr

           cl_vornr LIKE so_vornr

           cl_pernr LIKE so_pernr

           cl_date LIKE pa_date

      RETURNING

          value(cl_it_catsdb_p) TYPE ty_catsdb.

ENDCLASS.

*----


*

*       CLASS lcl_catsdb_post IMPLEMENTATION

*----


*

*       ........ *

*----


*

CLASS lcl_catsdb_post IMPLEMENTATION.

  METHOD fill_it_catsdb_post.

    SELECT dzzaufnr dzzvornr d~pernr

         dworkdate dlaeda

         dmeinh dcatshours

         dstatus dcounter d~refcounter

         dkokrs dbelnr

         d~raufnr

         d~lstar

         c~transfer

    FROM catsdb AS d INNER JOIN catsco AS c

      ON dcounter = ccounter

    INTO CORRESPONDING FIELDS OF TABLE cl_it_catsdb_p

    WHERE d~zzaufnr <> space

      AND d~zzvornr <> space

      AND d~zzaufnr IN so_aufnr "Sales Order

      AND d~zzvornr IN so_vornr "Item

      AND d~laeda = pa_date "Changed On Date

      AND c~transfer = flagged "Transferred to CO

      AND d~pernr IN so_pernr. "Personnel Number

  ENDMETHOD.

ENDCLASS.

.....

*----


*

*   Main Program

*----


*

START-OF-SELECTION.

*--> Confirmation

  CALL METHOD lcl_catsdb_post=>fill_it_catsdb_post

  EXPORTING

     cl_aufnr = so_aufnr

     cl_vornr = so_vornr

     cl_pernr = so_pernr

     cl_date = pa_date

  RECEIVING

     cl_it_catsdb_p = it_catsdb_p[].

.....

Any idea how to correct this part of the code?

Thanks in advance,

Incho

Accepted Solutions (0)

Answers (1)

Answers (1)

horst_keller
Product and Topic Expert
Product and Topic Expert

Hi,

to make a long thing short:

Since Selection Screens are working with global data, they are not supported in Class Pools (global Classes). On the other hand, local classes have access to the global data of their program . Therefore, you can work with Selection-Screens in local classes of executable programs, module pools, and function pools  by accessing the respective selection tables from inside a local class. You just cannot use the short syntax forms for internal tables, but you must adress the header line explicitely.

Examples for OO-programs using Selection Screens can be found in the ABAP Example Library (transaction ABAPDOCU) under the ABAP Objects node. In the Appendix of my 2003 Teched talk - Why use ABAP Objects - that is available in SDN, you find another way of how to use selection screens with ABAP Objects (the idea is, to separate screen handling from application programming by encapsulating all screens in a function group).

Best regards

Horst

Peter_Inotai
Active Contributor
0 Kudos

Hi Horst,

Thank you very much for your reply!

Meanwhile I figured it out how to define it, and it worked fine....unfortunately I posted first instead of thinking first..:-((((

So, like this it works fine:

*=======================================================================

TYPES: ty_catsdb TYPE STANDARD TABLE OF catsdb

             WITH NON-UNIQUE KEY zzaufnr zzvornr.

DATA: it_catsdb_p type ty_catsdb,

      wa_catsdb_p type line of ty_catsdb.

*eject

*=======================================================================

*             Selection screen

*=======================================================================

SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE text-sb1.

SELECT-OPTIONS: so_aufnr FOR wa_catsdb_p-zzaufnr

                      MEMORY ID aun

                      MATCHCODE OBJECT vmva, "Sales Order

                so_vornr FOR wa_catsdb_p-zzvornr

                      MEMORY ID kpo, "Item

                so_pernr FOR wa_catsdb_p-pernr

                      MEMORY ID per

                      MATCHCODE OBJECT prem. "Personnel Number

PARAMETERS: pa_date LIKE wa_catsdb_p-laeda

                      DEFAULT sy-datum. "Entered date

SELECTION-SCREEN END OF BLOCK sel .

I have seen your Teched material, this is the main reason I tried to convert my program. I didn't get the message of Appendix C..but now it's getting clearer. Where can I find more details/examples about this separate screen handling and the recommended way of implementation of this?

Is it a kind of MVC in ABAP?

BTW is it planned that your Teched talk will be available as a Webcast in the SAP Community?

I would love to see it!

Thanks,

Incho