Application Development 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: 

ALV won't display

Former Member
0 Kudos

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 .

6 REPLIES 6

former_member305388
Active Contributor
0 Kudos

Hi,

The code looks fine. But where is custom control? CC_ALV? Did you create a screen with a custom control CC_ALV? You need to, actually. Then as the last line of the program, you should call that screen as CALL SCREEN 100 or so.

0 Kudos

No i did'nt. I'll check out how to.

Thanks.

0 Kudos

I made these changes:


DATA gr_ccontainer TYPE REF TO cl_gui_dialogbox_container .

so i changed the reference of the container to cl_gui_dialogbox_container, and...


    CREATE OBJECT GR_CCONTAINER
      EXPORTING
        width                       = 1000
       height                      = 250
        top                         = 50
        left                        = 50
        caption                     = 'TEST'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 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.

Changed this method. Now it says that the fieldcatalog is empty.

I just want it to auto create the container. Is it a possibility?

0 Kudos

Hi,

Give the structure name in caps ('zprm2_material' to 'ZPRM2_MATERIAL')

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = 'zprm2_material'

Regards

Srinvias B

0 Kudos

Hi Egemen,

What you need to do is actually create a screen first.

Go to SE80 , open your program and create a screen say 2000.

No go to the screen painter for this screen and create a custom control element whose name is 'CC_ALV'.

Now there s the PBO and PAI events of the Screen as well for the program.

Now after you have called your SET_TABLE_FOR_FIRST_DISPLAY ,

CALL SCREEN 2000.

Now you ll be able to view the ALV that you are creating.

regards,

Arun

0 Kudos

Basic difference between classic ALV and OOPS ALV is that in the case of OOPS ALV , you have to actually create a screen for it and your default selection screen will not serve the purpose.

You have to create a screen and manually create your custom container there. And then you can create an instance of the container and then create an instance of the grid with this container as parent..

Hope the explanation solves your doubts.

Regards,

Arun