Skip to Content
0

How to get the clicked area when using ABAP Objects to WRITE?

Jun 13, 2017 at 08:40 AM

67

avatar image

Hi there,

I'm currently creating a classic ABAP report (No ALV. Just WRITE Statements) to list material numbers and other data. The program is very complex and has a ton of code, so it was created as a methods of an ABAP object (The instance is stored in "go_logic_class"). Those WRITE statements all happen in the methods of a local class.

The program basically looks like this:

TOP-OF-PAGE.
go_logic_class->display_headings(...).

START-OF-SELECTION.
CREATE OBJECT go_logic_class.
go_logic_class->read_all_the_data(...).
go_logic_class->display_all_the_data(...). " This is doing the WRITE statements

AT-LINE-SELECTION.
" I need to fill lv_matnr with the clicked material number here somehow.
SET PARAMETER ID 'MAT' FIELD lv_matnr.
CALL TRANSACTION 'MD04' AND SKIP FIRST SCREEN.

I want the user to be able to click on a material number and go into into another transaction (Using "CALL TRANSACTION AND SKIP FIRST SCREEN"). But I need the material number to use the "SET PARAMETER" statement before.

Since the WRITE statements happen IN the method of the class (and not report itself) I'm not able to use the HIDE statement. (It requires a global object of the report, which I can't access in the instance of a class)

Switching from WRITE to ALV is also not possible.

Are there any ways left how I can identify what material number was clicked?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Horst Keller
Jun 13, 2017 at 09:57 AM
1

The statement

"It requires a global object of the report, which I can't access in the instance of a class"

is apparently wrong.

Of course you can access the global data objects of a program in the classes and methods of the same program. That's why they are called "global".

https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abenlifetime_and_visibility.htm

The HIDE field is filled during the list events. The best way is to call an appropriate method when handling the list event and pass the hide field to a parameter instead of accessing the global field directly.

DATA g_hide TYPE i.
CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: write,
                   meth IMPORTING i_hide LIKE g_hide.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD write.
    DATA number TYPE i VALUE 555.
    WRITE number.
    g_hide = number.
    HIDE g_hide.
  ENDMETHOD.
  METHOD meth.
    "access to g_hide and i_hide, the latter is recommended
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>write( ).

AT LINE-SELECTION.
  demo=>meth( g_hide ).
  CLEAR g_hide.
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Horst, thanks for the answer.

It took me quite a while to figure out why I wasn't able to access a global object in my class. You are correct - you should be able too! In my case, the object definition happened in a seperate include and this include was always included before the declaration of the global object. Once I changed the order it worked flawlessly!

Thanks, you've solved my problem!

0
Good!

Yes, yes, the order of Includes ...

0