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: 

OO ABAP

Former Member
0 Kudos
216

Hi all,

I am new to OO programing and need your help

in some aspects .I was going through this blog

/people/thomas.jung3/blog/2005/10/26/alv-om-template-program

<a href="/people/thomas.jung3/blog/2005/10/26/alv-om-template-program Thomas Jung</a>

AS per the blog I created a Global class in se24,

and using it in reports to create the instance.

My question is :

<b>Will it be ok to call a subroutine from the global class - method implementation section, this subroutine is placed in the report where the global class is instanciated.</b>

eg:

This method is part of the global class -created through

SE24.

method ON_LINK_CLICK.

PERFORM ON_LINK_CLICK IN PROGRAM (me->repid) using !COLUMN !ROW.

endmethod.

--se38 program where the above class is used to create object

          • FOR LINKS *** SUBROUTINE

FORM ON_LINK_CLICK USING COLUMN TYPE SALV_DE_COLUMN ROW TYPE SALV_DE_ROW.

DATA: wa_it_bseg like line of it_bseg.

IF COLUMN EQ 'BELNR' .

read table it_bseg index row into wa_it_bseg.

set parameter id 'BLN' field wa_it_bseg-belnr.

set parameter id 'BUK' field wa_it_bseg-bukrs .

set parameter id 'GJR' field wa_it_bseg-GJAHR.

CALL TRANSACTION 'FB03' and SKIP FIRST SCREEN.

ENDIF.

ENDFORM.

---

The web log says, to inherit and redefine the mothods

Like ON_DOUBLE_CLICK , or ON_LINK_CLICK etc to

suit your requirements.

if we use the above approch of calling a suroutine ,

we can code the custom requirements differently in different programs with out worring about inheritance and redefenition ,in the same way we did when using the function module approch in ALV ,(Reuse_alv_list_display etc)

<b>Please suggest whether this approch is OK ?

I am using the globel class in many reports , so

any suggestion is appriciated and rewarded .</b>

Thanks for your help.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
168

Hi SKJS,

Yes you can do that. But you have to call the Event handler.

Have you called SET HANDLER after you called the method : SET_TABLE_FOR_FIRST_DISPLAY.

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = GS_LAYOUT

IS_VARIANT = GS_VARIANT

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

I_SAVE = X_SAVE

I_DEFAULT = P_DEF

CHANGING

IT_FIELDCATALOG = GT_FIELDCAT

IT_OUTTAB = I_PROD_TA[].

SET HANDLER G_EVENT_RECEIVER->CATCH_DOUBLECLICK FOR G_GRID.

Lanka

10 REPLIES 10

Former Member
0 Kudos
169

Hi SKJS,

Yes you can do that. But you have to call the Event handler.

Have you called SET HANDLER after you called the method : SET_TABLE_FOR_FIRST_DISPLAY.

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = GS_LAYOUT

IS_VARIANT = GS_VARIANT

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

I_SAVE = X_SAVE

I_DEFAULT = P_DEF

CHANGING

IT_FIELDCATALOG = GT_FIELDCAT

IT_OUTTAB = I_PROD_TA[].

SET HANDLER G_EVENT_RECEIVER->CATCH_DOUBLECLICK FOR G_GRID.

Lanka

Former Member
0 Kudos
168

Hi lanka,

This is working fine , But i wanted your suggestions on this approch .

Are you talking about CL_SALV* classes ?

thanks.

0 Kudos
168

Hi SK,

Yes. I have used CL_SALV* classes .

lanka

Former Member
0 Kudos
168

Hi SK JS,

What you are doing is perfectly ok. Just one suggestion from me is to instead of putting it in one of the many reports you are creating, it will make more sense to have this form created in a separate include. So that the modularization is more clearer.

Rgds,

Prabhu.

0 Kudos
168

Hi prabhu,

The Content in the include is different in

different programs , based on that report requirement ,

for ex : in case of FORM ON_LINK_CLICK ,

the content may be logic to call tcode fb03 , or me22

or somthing else.

same way forms with unique names are defined for other events - double click etc,

Only the routine name ( form name ) remain same in all reports ,the contents vary ..

My only intenton is to simplify the coding and avoid

inheritance and redefenition and make use of the global class as it is.

So predefined subroutines(forms ) should be used in all programs like in case of ALV-using function modules .

I am not sure whether it is good approach in terms of OO methodologies.

Thanks for your help.

0 Kudos
168

Hello SK JS,

Can you tell me what the class is and what it does.

It will then make sense, if it is right to do this in the class in the 1st case.

I personally feel that a OO class has to be completely OO. And you need to be able to draw a line and say that some things need to be done by the calling report and the OO should provide only those that should is truly the responsibility of the object/class. Normally I feel the event handling of the report like line click, etc shd be a responsibility of the report and not the class.

Pls provide more info on the class you are talking about, and may be even the requirement. And i shd b able to help you.

Rgds,

Prabhu.

0 Kudos
168

HI Prabhu,

Could you please refer the below Blog ,

and see the the PDF by Download Content,in The New Template section .

Thanks again and waiting to hear from you again .

<a href="/people/thomas.jung3/blog/2005/10/26/alv-om-template-program OM</a>

/people/thomas.jung3/blog/2005/10/26/alv-om-template-program

.

0 Kudos
168

Hi All,

Any suggestions ? Help apreciated and rewarded .

Thnks..

Former Member
0 Kudos
168

Hi,

"My question is :

Will it be ok to call a subroutine from the global class - method implementation section, this subroutine is placed in the report where the global class is instanciated.

eg:

This method is part of the global class -created through

SE24.

method ON_LINK_CLICK.

PERFORM ON_LINK_CLICK IN PROGRAM (me->repid) using !COLUMN !ROW.

endmethod. "

First of all it should be to make sure there will be no runtime errors,

PERFORM ON_LINK_CLICK IN PROGRAM (me->repid) using !COLUMN !ROW <b>IF FOUND</b>.

I can think of another approach which is completely OO based. Define an event ON_LINK_CLICK with parameters !COLUMN and !ROW in your Global Class in SE24 (take a look at Events for CL_GUI_ALV_GRID class in case you want some reference). And then in method ON_LINK_CLICK, do the following,

<b>method ON_LINK_CLICK.

  RAISE EVENT on_link_click EXPORTING e_column = column
                                      e_row = row.

endmethod.</b>

Then in all your custom reports that use this class, you have to define a local class say LCL_EVENT_HANDLER.

<b>CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS: on_link_click 
             FOR EVENT on_link_click 
             OF <your class here>
             IMPORTING e_column e_row.

ENDCLASS.


CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_link_click.
****Your logic here

  ENDMETHOD.

ENDCLASS.</b>

Declare a reference object for this local class in your program,

<b>DATA: ref_event_handler TYPE REF TO lcl_event_handler.</b>

And wherever you instantiate your Global class in your report, you also instantiate this reference object and register the handler for the event,

<b>CREATE OBJECT ref_event_handler.

SET HANDLER: ref_event_handler->on_link_click
             FOR <your global class reference here>.</b>

Hope this helps..

Sri

0 Kudos
168

Hi Srikanth,

Thanks for your help,

I was thinking about the above approch, because it is simple and no worries of extra coding.Thanks again