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

Interactive ALV report using OOPs

Former Member
0 Likes
11,489

Hi All,

I am doing my first Interactive ALV report using OOPs. There are certain codes given on wiki.scn and other sites. I have tried almost all. But the problem is that I am not getting the output. I have been trying since many hours. I fail to understand where I am lacking. However, I have done 2-3 ALV report using OOPs. I am stuck in drilling part.

Following is the code of a basic report for learning purpose:

REPORT zrough MESSAGE-ID z1.

TABLES : mara.

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

* Types Declaration..

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

TYPES :

BEGIN OF t_mara,

matnr TYPE matnr,

mtart TYPE mtart,

maktx TYPE maktx,

END OF t_mara,

BEGIN OF t_marc,

matnr TYPE matnr,

werks TYPE werks_d,

mtart TYPE mtart,

maktx TYPE maktx,

END OF t_marc.

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

* Internal Tables Declaration..

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

DATA :

i_mara TYPE TABLE OF t_mara,

i_marc TYPE TABLE OF t_marc,

i_fcat1 TYPE lvc_t_fcat,

i_fcat2 TYPE lvc_t_fcat.

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

* Constants Declaration..

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

CONSTANTS :

c_cont1 TYPE scrfname VALUE 'CONT1',

c_cont2 TYPE scrfname VALUE 'CONT2'.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

SELECT-OPTIONS:

s_matnr FOR mara-matnr NO INTERVALS.

SELECTION-SCREEN SKIP 1.

PARAMETERS :

p_hotspt RADIOBUTTON GROUP r1 DEFAULT 'X',

p_bttn RADIOBUTTON GROUP r1.

SELECTION-SCREEN END OF BLOCK b1.

* Class forward referncing.

CLASS lcl_rcvr_class DEFINITION DEFERRED.

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

* Pointers Declaration..

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

DATA :

lp_rcvr TYPE REF TO lcl_rcvr_class,

lp_cont1 TYPE REF TO cl_gui_custom_container,

lp_cont2 TYPE REF TO cl_gui_custom_container,

lp_grid1 TYPE REF TO cl_gui_alv_grid,

lp_grid2 TYPE REF TO cl_gui_alv_grid.

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

* Local Class Definiton.

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

CLASS lcl_rcvr_class DEFINITION.

   PUBLIC SECTION.

     METHODS :

     hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid

     IMPORTING e_row_id e_column_id es_row_no,

     handle_double_click FOR EVENT double_click OF cl_gui_alv_grid

     IMPORTING e_row e_column.

ENDCLASS.                    "lcl_rcvr_class DEFINITION

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

* Local Class Implementation.

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

CLASS lcl_rcvr_class IMPLEMENTATION.

   METHOD hotspot_click.

     DATA :

     wa_mara TYPE t_mara,

     wa_marc TYPE t_marc.

     DATA :

     l_index TYPE sy-tabix.

     READ TABLE i_mara INTO wa_mara INDEX e_row_id-index.

     IF sy-subrc EQ 0.

       REFRESH i_marc.

       SELECT matnr

       werks

       INTO TABLE i_marc

       FROM marc

       WHERE matnr EQ wa_mara-matnr.

       IF sy-subrc EQ 0.

         LOOP AT i_marc INTO wa_marc.

           l_index = sy-tabix.

           wa_marc-mtart = wa_mara-mtart.

           wa_marc-maktx = wa_mara-maktx.

           MODIFY i_marc FROM wa_marc INDEX l_index

           TRANSPORTING mtart maktx.

         ENDLOOP.

         CALL SCREEN 200.

       ELSE.

         MESSAGE e121 WITH text-005 wa_mara-matnr.

       ENDIF.

     ENDIF.

   ENDMETHOD.                    "hotspot_click

   METHOD handle_double_click.

     DATA :

     wa_mara TYPE t_mara,

     wa_marc TYPE t_marc.

     DATA :

     l_index TYPE sy-tabix.

     READ TABLE i_mara INTO wa_mara INDEX e_row-index.

     IF sy-subrc EQ 0.

       REFRESH i_marc.

       SELECT matnr

       werks

       INTO TABLE i_marc

       FROM marc

       WHERE matnr EQ wa_mara-matnr.

       IF sy-subrc EQ 0.

         LOOP AT i_marc INTO wa_marc.

           l_index = sy-tabix.

           wa_marc-mtart = wa_mara-mtart.

           wa_marc-maktx = wa_mara-maktx.

           MODIFY i_marc FROM wa_marc INDEX l_index

           TRANSPORTING mtart maktx.

         ENDLOOP.

         CALL SCREEN 200.

       ELSE.

         MESSAGE e121 WITH text-005 wa_mara-matnr.

       ENDIF.

     ENDIF.

   ENDMETHOD.                    "handle_double_click

ENDCLASS.                    "lcl_rcvr_class IMPLEMENTATION

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

* Start of Selection

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

START-OF-SELECTION.

* Extract the Material Master data for the Input Material.

   SELECT a~matnr

   a~mtart

   b~maktx

   INTO TABLE i_mara

   FROM mara AS a

   INNER JOIN makt AS b

   ON a~matnr EQ b~matnr

   WHERE a~matnr IN s_matnr

   AND b~spras EQ sy-langu.

END-OF-SELECTION.

   IF NOT i_mara[] IS INITIAL.

* Call Screen to display the Material Master data.

     CALL SCREEN 100.

   ELSE.

     MESSAGE s121 WITH text-006.

   ENDIF.

*&---------------------------------------------------------------------*

*& Module DISP_GRID OUTPUT

*&---------------------------------------------------------------------*

MODULE disp_grid OUTPUT.

* Build the Field catelog for Material Master data.

   PERFORM build_fcat.

* Display the Material Master data using ALV.

   PERFORM disp_alv.

ENDMODULE. " DISP_GRID OUTPUT

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*

MODULE user_command_0100 INPUT.

*when exit or cancel is clicked program has to come out

   CASE sy-ucomm.

     WHEN 'EXIT' OR 'CANC'.

       LEAVE PROGRAM.

     WHEN 'BACK'.

       LEAVE TO SCREEN 0.

   ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*

*& Form build_fcat

*&---------------------------------------------------------------------*

FORM build_fcat.

   DATA : ws_fcat TYPE lvc_s_fcat.

   ws_fcat-fieldname = 'MATNR'.

   ws_fcat-scrtext_m = text-001.

   ws_fcat-tabname = 'I_MARA'.

   IF p_hotspt EQ 'X'.

     ws_fcat-hotspot = 'X'.

   ENDIF.

   APPEND ws_fcat TO i_fcat1.

   CLEAR ws_fcat.

   ws_fcat-fieldname = 'MTART'.

   ws_fcat-scrtext_m = text-002.

   ws_fcat-tabname = 'I_MARA'.

   APPEND ws_fcat TO i_fcat1.

   CLEAR ws_fcat.

   ws_fcat-fieldname = 'MAKTX'.

   ws_fcat-scrtext_m = text-003.

   ws_fcat-tabname = 'I_MARA'.

   APPEND ws_fcat TO i_fcat1.

   CLEAR ws_fcat.

ENDFORM. " build_fcat

*&---------------------------------------------------------------------*

*& Form disp_alv

*&---------------------------------------------------------------------*

FORM disp_alv.

   IF lp_cont1 IS INITIAL.

* Create the Container Object of Material Master.

     CREATE OBJECT lp_cont1

       EXPORTING

         container_name              = c_cont1

       EXCEPTIONS

         cntl_error                  = 1

         cntl_system_error           = 2

         create_error                = 3

         lifetime_error              = 4

         lifetime_dynpro_dynpro_link = 5

         OTHERS                      = 6.

     IF sy-subrc NE 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ELSE.

* Create the Object for Grid of Material Master.

       CREATE OBJECT lp_grid1

         EXPORTING

           i_parent          = lp_cont1

         EXCEPTIONS

           error_cntl_create = 1

           error_cntl_init   = 2

           error_cntl_link   = 3

           error_dp_create   = 4

           OTHERS            = 5.

       IF sy-subrc NE 0.

         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

       ELSE.

* Dipslay Material Master data by calling method.

         CALL METHOD lp_grid1->set_table_for_first_display

           CHANGING

             it_outtab                     = i_mara

             it_fieldcatalog               = i_fcat1

           EXCEPTIONS

             invalid_parameter_combination = 1

             program_error                 = 2

             too_many_lines                = 3

             OTHERS                        = 4.

         IF sy-subrc NE 0.

           MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

         ELSE.

* Set Handler for the Hot Spot Event.

           CREATE OBJECT lp_rcvr.

           IF p_hotspt EQ 'X'.

             SET HANDLER lp_rcvr->hotspot_click FOR lp_grid1.

           ELSE.

             SET HANDLER lp_rcvr->handle_double_click FOR lp_grid1.

           ENDIF.

         ENDIF.

       ENDIF.

     ENDIF.

   ENDIF.

ENDFORM. " disp_alv

*&---------------------------------------------------------------------*

*& Module STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*

MODULE status_0100 OUTPUT.

   SET PF-STATUS 'MAIN_STAT'.

   SET TITLEBAR 'T_100'.

ENDMODULE. " STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*

*& Module STATUS_0200 OUTPUT

*&---------------------------------------------------------------------*

MODULE status_0200 OUTPUT.

   SET PF-STATUS 'PLANT_STAT'.

   SET TITLEBAR 'T_200'.

ENDMODULE. " STATUS_0200 OUTPUT

*&---------------------------------------------------------------------*

*& Module DISP_GRID_plant OUTPUT

*&---------------------------------------------------------------------*

MODULE disp_grid_plant OUTPUT.

* Build the Field catelog for Material Plant data.

   PERFORM build_fcat_plant.

* Display the Material Master Plant data using ALV.

   PERFORM disp_alv_plant.

ENDMODULE. " DISP_GRID_plant OUTPUT

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_0200 INPUT

*&---------------------------------------------------------------------*

MODULE user_command_0200 INPUT.

*when exit or cancel is clicked program has to come out

   CASE sy-ucomm.

     WHEN 'EXIT' OR 'CANC'.

       LEAVE PROGRAM.

     WHEN 'BACK'.

       LEAVE TO SCREEN 0.

   ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

*&---------------------------------------------------------------------*

*& Form build_fcat_plant

*&---------------------------------------------------------------------*

FORM build_fcat_plant.

   DATA : ws_fcat TYPE lvc_s_fcat.

   ws_fcat-fieldname = 'MATNR'.

   ws_fcat-scrtext_m = text-001.

   ws_fcat-tabname = 'I_MARC'.

   APPEND ws_fcat TO i_fcat2.

   CLEAR ws_fcat.

   ws_fcat-fieldname = 'WERKS'.

   ws_fcat-scrtext_m = text-004.

   ws_fcat-tabname = 'I_MARC'.

   APPEND ws_fcat TO i_fcat2.

   CLEAR ws_fcat.

   ws_fcat-fieldname = 'MTART'.

   ws_fcat-scrtext_m = text-002.

   ws_fcat-tabname = 'I_MARC'.

   APPEND ws_fcat TO i_fcat2.

   CLEAR ws_fcat.

   ws_fcat-fieldname = 'MAKTX'.

   ws_fcat-scrtext_m = text-003.

   ws_fcat-tabname = 'I_MARC'.

   APPEND ws_fcat TO i_fcat2.

   CLEAR ws_fcat.

ENDFORM. " build_fcat_plant

*&---------------------------------------------------------------------*

*& Form disp_alv_plant

*&---------------------------------------------------------------------*

FORM disp_alv_plant.

   IF lp_cont2 IS INITIAL.

* Create the Container Object of Material Plant data.

     CREATE OBJECT lp_cont2

       EXPORTING

         container_name              = c_cont2

       EXCEPTIONS

         cntl_error                  = 1

         cntl_system_error           = 2

         create_error                = 3

         lifetime_error              = 4

         lifetime_dynpro_dynpro_link = 5

         OTHERS                      = 6.

     IF sy-subrc NE 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ELSE.

* Create the Object for Grid of Material Plant data.

       CREATE OBJECT lp_grid2

         EXPORTING

           i_parent          = lp_cont2

         EXCEPTIONS

           error_cntl_create = 1

           error_cntl_init   = 2

           error_cntl_link   = 3

           error_dp_create   = 4

           OTHERS            = 5.

       IF sy-subrc NE 0.

         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

       ELSE.

* Display Material Plant data by calling method.

         CALL METHOD lp_grid2->set_table_for_first_display

           CHANGING

             it_outtab                     = i_marc

             it_fieldcatalog               = i_fcat2

           EXCEPTIONS

             invalid_parameter_combination = 1

             program_error                 = 2

             too_many_lines                = 3

             OTHERS                        = 4.

         IF sy-subrc NE 0.

           MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

         ENDIF.

       ENDIF.

     ENDIF.

   ELSE.

* Call method 'REFRESH_TABLE_DISPLAY' to refresh the grid data.

     CALL METHOD lp_grid2->refresh_table_display.

   ENDIF.

ENDFORM. " disp_alv_plant







And the output comes like this:




And if I enter any material from the input help, it gives the following output:



Regards

Mani

12 REPLIES 12
Read only

nishantbansal91
Active Contributor
0 Likes
5,864

HI Mani,

Its a little mistake. But this type of mistake also clear the many concept.

You have defined two constant for the container .

c_cont1 TYPE scrfname VALUE 'CONT1',

c_cont2 TYPE scrfname VALUE 'CONT2'.

Please update the constant value of Attribute C_cont2 to  'C_CONT2' its the name of the container you defined in the screen.

But you have passed the name of the container that is not exist in the screen.

Regards.

Nishant Bansal

Read only

0 Likes
5,864

Hi Nishant,

I appreciate your reply. Still the output is coming as a blank screen.

Regards

Mani

Read only

0 Likes
5,864

Check BC_ALV* for examples and reference code

Read only

0 Likes
5,864

HI Mani,

Its looks like that everything is fine in your code.

Please Go in debugging mode and see the method RefreshDisplay is called or not.

& Second go to se80 and activate program with all the screen.

Regards.

Nishant Bansal

Read only

0 Likes
5,864

Good

Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
5,864

Mani please check in SE38 BC_ALV* examples you will find many

Read only

0 Likes
5,864

Hi Nabheet,

Thanks for the reply. Certain reports are not found in the system except for the HTML and EXCEL reports in the above package. Or can someone post me code for the basic ALV interactive using OOPs.

Regards

Mani

Read only

Former Member
0 Likes
5,864

Hi,

Other reports I am trying too, getting the same blank output.

Regards

Mani

Read only

0 Likes
5,864

Do the following corrections

(1) Set the Container name of screen100 to 'CONT2'

(2) In the Flow layout of screen 100 , add the module to display the plant ALV

    PROCESS BEFORE OUTPUT.

     MODULE STATUS_0100.

     MODULE disp_grid_plant.

(3) In FORM disp_alv_plant.

        CALL METHOD lp_grid2->set_table_for_first_display

          CHANGING

            it_outtab                     = i_marc

            it_fieldcatalog             = i_fcat2

   The table i_marc is not filled but after filling i_mara from the selection screen ,screen 100 is called and thereafter the data contents of i_mara are not transferred to i_marc

In short , the first ALV with the results on the screen will be displayed after above corrections.

Happy coding.....

Read only

0 Likes
5,864

Continued....

From the first ALV , the second ALV needs to be called.

There is  a local class definition and implementation done.

(1) Create an object for this local event class defined to handle doubel click and hot spot

Before the CAll screen 100 , declare the following .

   DATA : lcl_event type ref to lcl_rcvr_class .

  IF NOT i_mara[] IS INITIAL.

* call screen to display the material master data.

    CALL SCREEN 100.

(2) Link this event class to the first ALV grid

   In the form FORM disp_alv_plant.

       CALL METHOD lp_grid2->set_table_for_first_display

          CHANGING

            it_outtab                     = i_mara

            it_fieldcatalog               = i_fcat2

          EXCEPTIONS

            invalid_parameter_combination = 1

            program_error                 = 2

            too_many_lines                = 3

            OTHERS                        = 4.

        IF sy-subrc = 0.

         create object lcl_event.

         SET handler lcl_event->hotspot_click  for lp_grid2.

         SET handler lcl_event->handle_double_click  for lp_grid2.

        ELSE.

          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

        ENDIF.

(3) Set the display properties of screen 200

PROCESS BEFORE OUTPUT.

  MODULE status_0200.

  MODULE disp_grid.

Please rearrange the internal tables and ALV to suit your requirement.My objective was just to keep the program running....

For understanding the events better use, the sample program : BCALV_TEST_GRID_EVENTS

Hope it helps...

Read only

Former Member
0 Likes
5,864

Make sure that the container in your screen 100, (probably C_CONT1) is same as the container name given in your program.

CREATE OBJECT lp_cont1

       EXPORTING

         container_name              = 'C_CONT1'

       EXCEPTIONS

         cntl_error                  = 1

         cntl_system_error           = 2

         create_error                = 3

         lifetime_error              = 4

         lifetime_dynpro_dynpro_link = 5

         OTHERS                      = 6.

Read only

0 Likes
5,864

Hi,

Apologies for the late reply. Both the names are the same.

Regards

Mani