Application Development and Automation 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: 
Read only

ALV grid display

i045323
Product and Topic Expert
Product and Topic Expert
0 Likes
916

hi,

i want to display the data of the internal table in the ALV grid. For this i am using the set_table_for_first_display method. Here i export the internal table, field catalog table and the DDIC structure of the internal table to the above method.

The structure of the internal table has a table type for one of its component.

So in each row of the internal table, the last column which is of table type has few records.

please some body let me know how to display such an ALV grid using the above method.

Thanks in advance.

hi,

i want to display the data of the internal table in the ALV grid. For this i am using the set_table_for_first_display method. Here i export the internal table, field catalog table and the DDIC structure of the internal table to the above method.

The structure of the internal table has a table type for one of its component.

So in each row of the internal table, the last column which is of table type has few records.

please some body let me know how to display such an ALV grid using the above method.

Thanks in advance.

5 REPLIES 5
Read only

Former Member
0 Likes
834

Hi,

Refer the following example :

REPORT zje_alv_grid.

TABLES: kna1,vbak.

DATA: it_vbak TYPE TABLE OF vbak,

wa_vbak TYPE vbak.

DATA: obj_ctrl TYPE REF TO cl_gui_custom_container,

obj_alv TYPE REF TO cl_gui_alv_grid.

SELECT-OPTIONS: s_kunnr FOR kna1-kunnr DEFAULT 1 TO 1000.

START-OF-SELECTION.

SELECT *

FROM vbak

INTO TABLE it_vbak

WHERE kunnr IN s_kunnr.

CALL SCREEN '318' .

&----


*& Module STATUS_0318 OUTPUT

&----


  • text

----


MODULE status_0318 OUTPUT.

SET PF-STATUS 'ALV_STATUS'.

  • SET TITLEBAR 'xxx'.

CREATE OBJECT obj_ctrl

EXPORTING

container_name = 'CUSTOM'.

CREATE OBJECT obj_alv

EXPORTING

i_parent = obj_ctrl.

ENDMODULE. " STATUS_0318 OUTPUT

&----


*& Module ALV OUTPUT

&----


  • text

----


MODULE alv OUTPUT.

CALL METHOD obj_alv->set_table_for_first_display

EXPORTING

  • i_buffer_active =

  • i_bypassing_buffer =

  • i_consistency_check =

i_structure_name = 'VBAK'

  • is_variant =

  • i_save =

  • i_default = 'X'

  • is_layout =

  • is_print =

  • it_special_groups =

  • it_toolbar_excluding =

  • it_hyperlink =

  • it_alv_graphics =

  • it_except_qinfo =

  • ir_salv_adapter =

CHANGING

it_outtab = it_vbak

  • it_fieldcatalog =

  • 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.

ENDMODULE. " ALV OUTPUT

&----


*& Module CONTROL INPUT

&----


  • text

----


MODULE control INPUT.

CALL METHOD obj_ctrl->free

EXCEPTIONS

cntl_error = 1

cntl_system_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.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE PROGRAM.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'CANCEL'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " CONTROL INPUT

For more information refer the following link:

http://www.saptechnical.com/Tutorials/ALV/ALVMainPage.htm

Read only

Former Member
0 Likes
834

PLease refer the following:

STEPS:

1. Call a screen.

2. Go to the screen layout and add a custom control .

3. Go to attribute and give a name to the custom control (Ex: 'CUSTOM_CONTROL').

4. Give a name to the ok_code ( Ex: ok_code) in the attribute of the screen.

5. Data Declaration section:

I. Data declaration for ALV

a. Declare a object type cl_gui_alv_grid for ALV Grid instance referance

b. Declare a object type cl_gui_custom_container for Custom container instance referance

c. Declare Name of the custom control added to the screen

d. Declare field catalog table of type lvc_t_fcat.

e. Declare layout of type lvc_s_layo.

II. Data declaration for fetching data as input

III. Declare variables for ok_code.

6. Set pf-status and titlebar for the screen.

7. Write PBO. IN PBO do the following:

i. Check whether gr_alvgrid is initial.

a. If yes do the following.

• Create instance for custom container (gr_container) by passing the container name.

• Create instance for ALV grid by passing the custom control instance reference.

• select the material data from database

• Build field ctalog

• Build layout

• Call method ‘set_table_for_first_display’ for the object gr_alvgrid(alv grid instance reference) with passing layout, input table and field catalog.

b. If NO do the following.

• Call method ‘refresh_table_display for the object gr_alvgrid(alv grid instance reference).

ii.

8. Write PAI. IN PAI do the following:

Check the ok_code, if ‘Exit’ then leave from program.

All the user commands where user do any actions in the screen will be code here . For this purpose check the value of ok_code and according that ok_code, code the functionality for the particular user actions.



REPORT  zdemoab.


************************************
*DATA DECLARATION
*************************************
*---Global data deckaration for alv
*--ALV Grid instance referance
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,
*--Name of the custom control added to the screen
      gc_custom_control_name TYPE scrfname VALUE 'CUSTOM_CONTROL',
*--Custom container instance referance
      gr_container TYPE REF TO cl_gui_custom_container,
*--Field catalog table
      gt_fieldcat TYPE lvc_t_fcat,
*--Layout structure
      gs_layout TYPE lvc_s_layo.

DATA: ok_code LIKE sy-ucomm,
      save_ok LIKE sy-ucomm.


*---Input table
TYPES: BEGIN OF t_mara,
        matnr TYPE mara-matnr,
        mtart TYPE mara-mtart,
        matkl TYPE mara-matkl,
        meins TYPE mara-meins,
      END OF t_mara.
TYPES: t_mara_table TYPE STANDARD TABLE OF t_mara.

DATA: gt_mara TYPE STANDARD TABLE OF t_mara.

************************************
*MAIN
*************************************
CALL SCREEN 101.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*

MODULE status_0101 OUTPUT.
  SET PF-STATUS 'STATUS-0101'.
  SET TITLEBAR 'TITLE'.

ENDMODULE.                 " STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  display_alv  OUTPUT
*&---------------------------------------------------------------------*

MODULE display_alv OUTPUT.

  IF gr_alvgrid IS INITIAL.
*----Create custom container instance
    CREATE OBJECT gr_container
      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 ALV grid instance
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent          = gr_container
      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.

* select the material data from database
    PERFORM get_input CHANGING gt_mara..
* prepare field catalog
    PERFORM prepare_fieldcatalog CHANGING gt_fieldcat.
* prepare layout
    PERFORM prepare_layout CHANGING gs_layout.


    CALL METHOD gr_alvgrid->set_table_for_first_display
      EXPORTING
        is_layout                     = gs_layout
      CHANGING
        it_outtab                     = gt_mara[]
        it_fieldcatalog               = gt_fieldcat
      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.
  ELSE.
    CALL METHOD gr_alvgrid->refresh_table_display
      EXCEPTIONS
        finished = 1
        OTHERS   = 2.
    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.
ENDMODULE.                 " display_alv  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  get_input
*&---------------------------------------------------------------------*
FORM get_input CHANGING gt_mara_table TYPE t_mara_table.
  SELECT matnr mtart matkl meins INTO TABLE gt_mara_table
                                 FROM mara UP TO 10 ROWS.
ENDFORM.                    " get_input
*&---------------------------------------------------------------------*
*&      Form  prepare_fieldcatalog
*&---------------------------------------------------------------------*

FORM prepare_fieldcatalog  CHANGING gt_fieldcat_table TYPE lvc_t_fcat.

  DATA: ls_fcat TYPE lvc_s_fcat,
        l_col_no TYPE i.

  CLEAR: ls_fcat,
         l_col_no .

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MATNR'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 18.
  ls_fcat-coltext   = 'Material No'.
  ls_fcat-seltext   = 'Material No'.
  APPEND ls_fcat TO gt_fieldcat_table.
  CLEAR: ls_fcat.

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MTART'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 4.
  ls_fcat-coltext   = 'Material type'.
  ls_fcat-seltext   = 'Material type'.
  APPEND ls_fcat TO gt_fieldcat_table.
  CLEAR: ls_fcat.

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MATKL'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 9.
  ls_fcat-coltext   = 'Material group'.
  ls_fcat-seltext   = 'Material group'.
  APPEND ls_fcat TO gt_fieldcat_table.
  CLEAR: ls_fcat.

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MEINS'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 3.
  ls_fcat-coltext   = 'Unit'.
  ls_fcat-seltext   = 'Unit'.
  APPEND ls_fcat TO gt_fieldcat_table.
 

  CLEAR: ls_fcat,
         l_col_no .

ENDFORM.                    " prepare_fieldcatalog
*&---------------------------------------------------------------------*
*&      Form  prepare_layout
*&---------------------------------------------------------------------*
FORM prepare_layout  CHANGING p_gs_layout TYPE lvc_s_layo.

  p_gs_layout-zebra = 'X'.
  p_gs_layout-grid_title = 'Material'.
  p_gs_layout-smalltitle = 'X'.

ENDFORM.                    " prepare_layout
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0101  INPUT
*&---------------------------------------------------------------------*

MODULE user_command_0101 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'EXIT'.
      PERFORM exit_program.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0101  INPUT
*&---------------------------------------------------------------------*
*&      Form  exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
  LEAVE PROGRAM.
ENDFORM.                    " exit_program

Read only

i045323
Product and Topic Expert
Product and Topic Expert
0 Likes
834

Guys i want the output in the form of

Column 1 Column 2 Column 3 Column 4

_____________________________________________________

____________

Row1

____________

____________

____________

_________________

_________

____________

____________

Row2

____________

_____________

_________________

_________

Here the row1 is first record fo the internal table and row2 is the second record of the internal table which i pass to the method.

And the column on top represents each columns of the inetrnal table.

Read only

Former Member
0 Likes
834

I think you can use hierarchal ALV or matrix in such case.

Read only

i045323
Product and Topic Expert
Product and Topic Expert
0 Likes
834

would you please let me now how to use either of them??