Skip to Content
0
Former Member
Nov 28, 2011 at 10:29 AM

ALV won't display

15 Views

Hi all,

I'm at internship and have to learn ALV.

The below code won't display anything. Am i doing something worng?

REPORT  ZRE_PRM2_LIST_DISPLAY.

*-- Global data definitions for ALV

*--- ALV Grid instance reference
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .
*--- Name of the custom control added on the screen
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' .
*-- Custom container instance reference
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .
*-- Field catalog table
DATA gt_fieldcat TYPE lvc_t_fcat .
*-- Layout Structure
DATA gs_layout TYPE lvc_s_layo .

**-- Internal table
DATA gt_list TYPE zprm2_material occurs 0 with header line .
*----------------------------------------------------------------------*
* START OF SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION .

PERFORM get_data .

PERFORM display_alv .

*&---------------------------------------------------------------------*
*&      Form  display ALV
*&---------------------------------------------------------------------*
*       Display selected PRM2 data.
*----------------------------------------------------------------------*
FORM display_alv .
  IF gr_alvgrid IS INITIAL .
*---- Creating custom container instance
    CREATE OBJECT GR_CCONTAINER
      EXPORTING
        CONTAINER_NAME              = gc_custom_control_name
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        others                      = 6
        .
    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 GR_ALVGRID
      EXPORTING
        I_PARENT          = gr_ccontainer
      EXCEPTIONS
        ERROR_CNTL_CREATE = 1
        ERROR_CNTL_INIT   = 2
        ERROR_CNTL_LINK   = 3
        ERROR_DP_CREATE   = 4
        others            = 5
        .
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

*----Preparing field catalog
    PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure
    PERFORM prepare_layout CHANGING gs_layout .

    CALL METHOD gr_alvgrid->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
*        I_BUFFER_ACTIVE               =
*        I_BYPASSING_BUFFER            =
*        I_CONSISTENCY_CHECK           =
*        I_STRUCTURE_NAME              = 'zprm2_material'
*        IS_VARIANT                    =
*        I_SAVE                        =
*        I_DEFAULT                     = 'X'
        IS_LAYOUT                     = gs_layout
*        IS_PRINT                      =
*        IT_SPECIAL_GROUPS             =
*        IT_TOOLBAR_EXCLUDING          =
*        IT_HYPERLINK                  =
*        IT_ALV_GRAPHICS               =
*        IT_EXCEPT_QINFO               =
*        IR_SALV_ADAPTER               =
      CHANGING
        IT_OUTTAB                     = gt_list[]
        IT_FIELDCATALOG               = gt_fieldcat
*        IT_SORT                       =
*        IT_FILTER                     =
      EXCEPTIONS
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        others                        = 4
            .
    IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF .
ENDFORM .
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       GET data from prm2 tables.
*----------------------------------------------------------------------*
FORM get_data .
  select * from zprm2_material into gt_list .
    APPEND gt_list .
  ENDSELECT.
ENDFORM .

FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
  DATA ls_fcat type lvc_s_fcat .

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
   EXPORTING
     I_STRUCTURE_NAME             = 'zprm2_material'
    CHANGING
      CT_FIELDCAT                  = pt_fieldcat[]
   EXCEPTIONS
     INCONSISTENT_INTERFACE       = 1
     PROGRAM_ERROR                = 2
     OTHERS                       = 3
            .
  IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM .

FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo .
  ps_layout-zebra = 'X' .
  ps_layout-grid_title = 'PRM2' .
  ps_layout-smalltitle = 'X'.
ENDFORM .