Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

ALV using Oops :
 Steps :

ü      Create container ( this is the area where u can view ur output ) by calling a screen.

Create reference variable for the container and create instance for container of class .Eg:  r_container TYPE REF TO cl_gui_custom_container
 
ü      Create a grid which is laid on the container .

Create  reference variable for the grid and create instance for grid.Eg : r_alv_grid TYPE REF TO cl_gui_alv_grid
 
ü      Create internal table to hold the records of specific structure. 
ü      Write select query to extract records into the internal table . 
ü      Call method set_table_for_first_display of grid to display the ALV list.

Pass the internal table and structure to the method.

Procedure for call screen :

In SE38 ,create a program after writing select query,call screen .

Then follow the below procedure. 
Call screen 200.( U can give any number )

Double click on screen number,i.e 200,which gives a pop asking u if u want to create it.

There u give a description for the screen and goto layout. 
This takes u to Graphical screen painter.



 

A icon with 'c' appears on the left side, click on it, this will come on right frame where u can drag it (this will be your container).Give a name for the container.


Save and activate.


Goto flow logic,there u can find PBO(PROCESS BEFORE OUTPUT ),PAI(PROCESS AFTER INPUT ) events with commented modules.



Uncomment them and double click ,this will come to ur program. 

For Module status_screennumber

 Uncomment status_screennumber under PBO event and double click

It gives a popup if you want to create it.

Click on yes,then a popup comes to include,select main program,click yes.

Then below popup comes .

  

 Here click yes to save.

  U will get set pf-status and set title bar in the program .

With these create pf-status and give title for the ALV list. 

For Module  user_command_screennumber.
 Uncomment user_command_screennumber under PAI event and double click.


Click on yes and include main program and click yes.

Save it.

Through this u can handle user commands.

 Create module under this event and double click this which will come to your program

.  

Do as above and save it. 

Here u need to create objects for container and grid and call method of grid for displaying ALV list.

From SE38 ,in the above module select pattern tab. 

In this screen select pattern for creating objects of container and grid

.

Create object of container and give the container name which u have assigned through Graphical Screen painter. 

Now create object for the grid by selecting pattern and assign container as parent class.

Select ABAP objects pattern.

 

Now call method of grid for ALV list display by selecting pattern

 

Pass the structure name and internal table name to this method.

Program : This is a simple ALV output which displays spfli records with ALV list.

DATA : r_container TYPE REF TO cl_gui_custom_container,
       r_alv_grid TYPE REF TO cl_gui_alv_grid.
DATA :
              S_tab LIKE STANDARD TABLE OF Spfli.
START-OF-SELECTION.
  SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------* 

MODULE status_2000 OUTPUT.
  SET PF-STATUS 'ALV'.
  SET TITLEBAR 'Program to display spfli details'.
ENDMODULE.                 " STATUS_2000  OUTPUT
*----------------------------------------------------------------------*
*  MODULE alv_output OUTPUT
*----------------------------------------------------------------------
MODULE alv_output OUTPUT.
 CREATE OBJECT r_container
    EXPORTING
*    parent                      =
      container_name              = 'CCCONTAINER'------->( container name )
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 CREATE OBJECT r_alv_grid
    EXPORTING
*    i_shellstyle      = 0
*    i_lifetime        =
      i_parent          = r_container -------> (reference variable of container)
*    i_appl_events     = space
      .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
*
CALL METHOD r_alv_grid->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'SPFLI' -------> ( Pass the structure )
 *     is_layout                     = w_lay
    CHANGING
      it_outtab                     =  s_tab  -----> (Give internal table name )
*      it_fieldcatalog               = 

*      it_sort                       =    

 *     it_filter                     =           .
  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 *&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2000  INPUT
*----------------------------------------------------------------------
MODULE user_command_2000 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'RETURN'.
      SET SCREEN '0'.
    WHEN 'DISPLAY'.
      LEAVE TO SCREEN 200.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_2000  INPUT
  
The output of the above program is