Quantcast
Channel: SCN : Blog List - ABAP Development
Viewing all articles
Browse latest Browse all 943

OOPs ALV Simplified [without Module Pool Screen]

$
0
0

This in continuation to earlier blogs on SCN :

 

Part I : Basics of OO ABAP Implementation

Part II : OO ABAP Implementation [ Method Parameters ]

 

This is the III posts for people who are new to OOPs ABAP it is just to make things simpler for those who are shifting from procedural to OO ABAP.

 

As we all know that ALV is no longer an addition to the reporting it is the basis of reporting so WRITE statements are a things of the past.

 

So let's begin how to use ALV in the OO context for reporting. I will use the same example of the second blog for output in BASIC ALV. Now there are 2 ways, one is you create a module pool define a screen there and put a container on the screen. Then use this container to display your ALV. The second is using the SCREEN0 [Default Screen] to display our ALV. This is generally better when we are having a SINGLE ALV Report output to be generated.

 

CLASS DEFINITION:

CLASS lcl_material_list DEFINITION FINAL.

      PUBLIC SECTION.

      METHODS: display_material

            IMPORTING i_matnr TYPE matnr.

      PRIVATE SECTION.

     

      DATA : BEGIN OF ls_material,

               werks TYPE werks_d,

               lgort TYPE lgort_d,

               labst TYPE labst,
           
END OF ls_material,

           

            lt_material LIKE TABLE OF ls_material.

      DATA : lo_alvTYPE REF TO   cl_gui_alv_grid,

             lt_fcat TYPE TABLE OF lvc_s_fcat.

 

      METHODS: get_description

            IMPORTING i_matnr       TYPE matnr

            RETURNING VALUE(r_maktx) TYPE maktx,

 

            build_fcat.

 

ENDCLASS.

There is a global class provided by SAP for creating ALV : CL_GUI_ALV_GRID. Similar as we are creating instance of our own class locally, we can also use global classes defined in repository directly in our programs.

THE PROGRAM :

Will be same as it was in Part II no changes.

Well, thanks to Amit Gupta for noting it for the default screen to appear we need to initiate it with the WRITE statement.

After the call method of display_material( ). just put a "Write space."

 

CLASS IMPLEMENTATION:

 

CLASS lcl_material_list IMPLEMENTATION.

METHOD get_description.

      SELECT SINGLE maktx FROM makt

                          INTO r_maktx

                        WHERE matnr = i_matnr

                           AND spras= sy-langu.

ENDMETHOD.

METHOD build_fcat.

 

      DATA : ls_fcat TYPE lvc_s_fcat.

 

ls_fcat-scrtext_m = 'Plant'(001).

ls_fcat-fieldname = 'WERKS'.

ls_fcat-tabname  = 'LT_MATERIAL'.

APPEND ls_fcat TO lt_fcat.

ls_fcat-scrtext_m = 'SLoc'(002).

ls_fcat-fieldname = 'LGORT'.

APPEND ls_fcat TO lt_fcat.

ls_fcat-scrtext_m = 'Un-restricted Stock'(003).

ls_fcat-fieldname = 'LABST'.

APPEND ls_fcat TO lt_fcat.

 

ENDMETHOD.

 

METHOD display_material.

 

      DATA : lv_maktx TYPE maktx,

             lv_title TYPE lvc_title.

 

      lv_maktx = get_description( i_matnr ).

 

      CONCATENATE 'Material : ' i_matnr ' - ' lv_maktx

            INTO lv_title.

 

      SELECT werkslgortlabst FROM mard

                          INTO TABLE lt_material

                                WHERE matnr = i_matnr.

 

      build_fcat( ).

 

      CREATE OBJECT lo_alv

        EXPORTING

          i_parent= cl_gui_container=>screen0.

 

      CALL METHOD lo_alv->set_gridtitle

        EXPORTING

          i_gridtitle= lv_title.

 

      CALL METHOD lo_alv->set_table_for_first_display

        CHANGING

          it_outtab       = lt_material

          it_fieldcatalog = lt_fcat.

 

ENDMETHOD.

ENDCLASS.

 

 


Viewing all articles
Browse latest Browse all 943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>