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 with Oops  using field catalog and layout.
 Fieldcatalog :
 
If  you want to display some of the fields of a table or some fields of  more than one

 table , then a field catalog is needed .

Here u can specify how your fields should look on the list.

You can position the columns , round the numbers,give column texts, give colors for specified columns ( use Emphasize field ) make them editable,find sum for some columns etc. 
There is a structure called lvc_s_fcat.

Here you can find all options for fieldcatalog.

Create internal table for the structure and a workarea.

The most important thing is you have to populate the fieldcatalog internal table with fields that you require ,because only those will appear on the list. Layout :
 
If you want your grid to change your grid display ,change title,edit ,give alternate colorsoptimize column widths,you can go for layout.

There is a structure called lvc_s_layo.

Here you can find all options for layout.

Create a workarea for the structure.  Program :
 TABLES :
  spfli.
TYPES :
  BEGIN OF type_s_fs,
    carrid TYPE spfli-carrid,
    connid TYPE spfli-connid,
    cityfrom TYPE spfli-cityfrom,
    cityto TYPE spfli-cityto,
  END OF type_s_fs.
DATA fs TYPE type_s_fs.
DATA : r_container TYPE REF TO cl_gui_custom_container,
       r_alv_grid TYPE REF TO cl_gui_alv_grid.
DATA itab LIKE STANDARD TABLE OF fs.
DATA :
  t_cat TYPE lvc_t_fcat,
  w_cat TYPE lvc_s_fcat,
  w_lay TYPE lvc_s_layo.
START-OF-SELECTION.
  SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
  CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
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.
  w_cat-fieldname = 'CARRID'.
  w_cat-coltext = 'CARRID'.
  w_cat-col_pos = 1.  "-à( give column position )
  w_cat-emphasize = 'C700'. "-à( for coloring column )
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'CONNID'.
  w_cat-coltext = 'Connection id'."-à (Change text for heading )
  w_cat-col_pos = 2.
  w_cat-lzero = 'X'. "-à(Assign leading zeros)
  w_cat-just = 'C'. " à( Jusitify column values)
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'CITYFROM'.
  w_cat-coltext = 'DEPARTURE CITY'.
  w_cat-col_pos = 3.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_cat-fieldname = 'CITYTO'.
  w_cat-coltext = 'ARRIVAL CITY'.
  w_cat-col_pos = 4.
  APPEND w_cat TO t_cat.
  CLEAR w_cat.
  w_lay-grid_title = 'Flight details'.
  w_lay-zebra = 'X'. " -à( alternate colors black and white)
  w_lay-edit = 'X'. "-à( Edit mode)
  w_lay-no_toolbar = 'X'. "à( hide title bar)
  w_lay-CWIDTH_OPT = 'X'. "-à( optimize width)
CREATE OBJECT r_container
    EXPORTING
*    parent                      =
      container_name              = 'CCCONTAINER'       "(Give the name of container )
      .
  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.
  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              = 'FS'       "(give structure name )
      is_layout                     = w_lay       " (give layout name )
    CHANGING
      it_outtab                     = itab  "( pass internal table which holds data )
      it_fieldcatalog               = t_cat ("pass internal table of fieldcatalogue )
      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.
ENDMODULE.                    "alv_output OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'RETURN'.
      SET SCREEN '0'.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_2000  INPUT
 

  • No labels