2017 Jun 13 9:40 AM
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?
2017 Jun 13 10:57 AM
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".
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.
2017 Jun 13 10:57 AM
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".
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.
2017 Jun 13 12:53 PM
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!
2017 Jun 13 12:57 PM