Application Development and Automation 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: 
Read only

ALV through OOPS

former_member193947
Participant
0 Likes
729

Hi Guru's,

I have an working ALV report that calls REUSE_ALV_GRID_DISPLAY to display the internal table content.

Since our standard's don't accept FORM / ENDFORM usage after it became obsolete, I need to change the complete report to OOPS based approach.

I need to replace the below forms especially into oops approach.

FORM pf_status USING p_extab TYPE slis_t_extab.

ENDFORM.

FORM user_command  USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.

ENDFORM.

Can someone please post example code on how to achieve this?

Thanks.

3 REPLIES 3
Read only

Juwin
Active Contributor
Read only

mauro_blanc3
Active Participant
0 Likes
680

Check SLIS package in SAP.

Particulary, check programs BCALV_GRID_*

Mauro.

Read only

Former Member
0 Likes
680

Hello Sap Seeker,

You might try using the Class cl_salv instead of the function module. This class is extremely easy to use.

And you can treat the user commnds with event handling. Your report will be entirely OO.

I just copied this fro ma code I wrote some days ago.

FORM f_print_alv .


  "Build the output table in alv

  TRY.

      cl_salv_table=>factory( IMPORTING r_salv_table = o_table

                              CHANGING  t_table      = t_wtm019 ).

    CATCH cx_salv_msg.

      MESSAGE e846 WITH text-e02. "Error

  ENDTRY.


* Define the column attributes

  o_columns = o_table->get_columns( ).


  TRY.

      o_column ?= o_columns->get_column( 'MANDT' ).

      o_column->set_visible( space ).

      o_column ?= o_columns->get_column( 'VBELN' ).

      o_column->set_cell_type( if_salv_c_cell_type=>hotspot ).

    CATCH cx_salv_not_found.

      MESSAGE e846 WITH text-e02. "Error

  ENDTRY.


  "Set all ALV functions

  o_functions = o_table->get_functions( ).

  o_functions->set_all( abap_true ).


  "Set ALV Zebra

  o_display = o_table->get_display_settings( ).

  o_display->set_striped_pattern( cl_salv_display_settings=>true ).


  "Set Events

  o_events = o_table->get_event( ).

  CREATE OBJECT o_event.

  SET HANDLER o_event->on_single_click FOR o_events.

  "Print ALV

  o_table->display( ).


ENDFORM.                    " F_PRINT_ALV

For handling the events such as single_click, this is the code:

*---------------------------------------------------------------------*

*       CLASS lcl_handle_events DEFINITION

*---------------------------------------------------------------------*

CLASS lcl_handle_events DEFINITION.

  PUBLIC SECTION.

    METHODS:

      on_single_click FOR EVENT link_click OF cl_salv_events_table

        IMPORTING row column.

ENDCLASS.                    "lcl_handle_events DEFINITION


*---------------------------------------------------------------------*

*       CLASS lcl_handle_events IMPLEMENTATION

*---------------------------------------------------------------------*

CLASS lcl_handle_events IMPLEMENTATION.

  METHOD on_single_click.

    PERFORM f_call_va03 USING row column.

  ENDMETHOD.                    "on_single_click

ENDCLASS.                    "lcl_handle_events IMPLEMENTATION

If you want to handle the user command, you change to this:

*---------------------------------------------------------------------*

*       CLASS lcl_handle_events DEFINITION

*---------------------------------------------------------------------*

* Define uma classe local para handle events

*---------------------------------------------------------------------*

CLASS lcl_handle_events DEFINITION FINAL.

   PUBLIC SECTION.

     METHODS:

       on_user_command FOR EVENT added_function OF cl_salv_events

         IMPORTING e_salv_function.

ENDCLASS.                    "lcl_handle_events DEFINITION

*---------------------------------------------------------------------*

*       CLASS lcl_handle_events IMPLEMENTATION

*---------------------------------------------------------------------*

* Implementação da Classe Local de Handle Events

*---------------------------------------------------------------------*

CLASS lcl_handle_events IMPLEMENTATION.

   METHOD on_user_command.

     CASE e_salv_function.

       WHEN 'XD01'.

         "Create Customer

         PERFORM f_create_customer.

       WHEN OTHERS.

     ENDCASE.

   ENDMETHOD.                    "on_user_command

ENDCLASS.                    "lcl_handle_events IMPLEMENTATION


Hope this helped,


Regards,

Thales Schmidt