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 report

Former Member
0 Likes
731

Hi All,

I have requirement where I have been asked to create a ALV_Grid report and the fina outcome of the report might have around 50-60 fields, but I read somewhere that there is some kind of restriction on the number of fields that one can have in ALV_grid, if that's the case then anyone of you please tell me what's the alternative for this.

Thanks,

Rajeev

1 ACCEPTED SOLUTION
Read only

venkat_o
Active Contributor
0 Likes
677

Hi Rajeev Gupta, I am giving guarantee that ALV grid does not have any output width restrictions. But field width restrictions are there . Simple example is,goto SE16 tcode and take any Table which has more than 80 fields and display data using ALV Grid. Go ahead and develop ALV grid report. If you don't have sample program.Check the below one.

REPORT  zvenkat_alv_grid. 
TABLES:t001. 
"Types 
TYPES: 
      BEGIN OF t_1001, 
        bukrs TYPE t001-bukrs, 
        butxt TYPE t001-butxt, 
        ort01 TYPE t001-ort01, 
        land1 TYPE t001-land1, 
      END OF t_1001. 
"Work area 
DATA: 
      w_t001 TYPE t_1001. 
"Internal table 
DATA: 
      i_t001 TYPE STANDARD TABLE OF t_1001. 

*&---------------------------------------------------------------------* 
" ALV Declarations 
*----------------------------------------------------------------------* 
* Types Pools 
TYPE-POOLS: 
   slis. 
* Types 
TYPES: 
   t_fieldcat         TYPE slis_fieldcat_alv, 
   t_events           TYPE slis_alv_event, 
   t_layout           TYPE slis_layout_alv. 
* Workareas 
DATA: 
   w_fieldcat         TYPE t_fieldcat, 
   w_events           TYPE t_events, 
   w_layout           TYPE t_layout. 
* Internal Tables 
DATA: 
   i_fieldcat         TYPE STANDARD TABLE OF t_fieldcat, 
   i_events           TYPE STANDARD TABLE OF t_events. 
*&---------------------------------------------------------------------* 
*&    start of selection 
*&---------------------------------------------------------------------* 
START-OF-SELECTION. 
  PERFORM get_data. 

*&---------------------------------------------------------------------* 
*&    end-of-selection. 
*&---------------------------------------------------------------------* 
END-OF-SELECTION. 

  PERFORM build_fieldcatlog. 
  PERFORM build_events. 
  PERFORM build_layout. 
  PERFORM list_display. 
*&---------------------------------------------------------------------* 
*&      Form  get_data 
*&---------------------------------------------------------------------* 
FORM get_data . 

  SELECT bukrs 
         butxt 
         ort01 
         land1 
    FROM t001 
    INTO TABLE i_t001 
    UP TO 30 ROWS. 

ENDFORM.                    " get_data 
*&---------------------------------------------------------------------* 
*&      Form  build_fieldcatlog 
*&---------------------------------------------------------------------* 
FORM build_fieldcatlog . 
  CLEAR:w_fieldcat,i_fieldcat[]. 

  PERFORM build_fcatalog USING: 
           'BUKRS' 'I_T001' 'BUKRS', 
           'BUTXT' 'I_T001' 'BUTXT', 
           'ORT01' 'I_T001' 'ORT01', 
           'LAND1' 'I_T001' 'LAND1'. 

ENDFORM.                    "BUILD_FIELDCATLOG 
*&---------------------------------------------------------------------* 
*&      Form  BUILD_FCATALOG 
*&---------------------------------------------------------------------* 
FORM build_fcatalog USING l_field l_tab l_text. 

  w_fieldcat-fieldname      = l_field. 
  w_fieldcat-tabname        = l_tab. 
  w_fieldcat-seltext_m      = l_text. 

  APPEND w_fieldcat TO i_fieldcat. 
  CLEAR w_fieldcat. 

ENDFORM.                    " build_fieldcatlog 
*&---------------------------------------------------------------------* 
*&      Form  build_events 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
FORM build_events. 
  CLEAR : 
        w_events, i_events[]. 
  w_events-name = 'TOP_OF_PAGE'."Event Name 
  w_events-form = 'TOP_OF_PAGE'."Callback event subroutine 
  APPEND w_events TO i_events. 
  CLEAR  w_events. 

ENDFORM.                    "build_events 
*&---------------------------------------------------------------------* 
*&      Form  build_layout 
*&---------------------------------------------------------------------* 
FORM build_layout . 

  w_layout-colwidth_optimize = 'X'. 
  w_layout-zebra             = 'X'. 

ENDFORM.                    " build_layout 
*&---------------------------------------------------------------------* 
*&      Form  list_display 
*&---------------------------------------------------------------------* 
FORM list_display . 
  DATA: 
        l_program TYPE sy-repid. 
  l_program = sy-repid. 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
    EXPORTING 
      i_callback_program = l_program 
      is_layout          = w_layout 
      it_fieldcat        = i_fieldcat 
      it_events          = i_events 
    TABLES 
      t_outtab           = i_t001 
    EXCEPTIONS 
      program_error      = 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. 
ENDFORM.                    " list_display 
*&---------------------------------------------------------------------* 
*&      Form  top_of_page 
*&---------------------------------------------------------------------* 
FORM top_of_page. 
  DATA : 
   li_header TYPE slis_t_listheader, 
   w_header  LIKE LINE OF li_header. 
  DATA: 
        l_date TYPE char10. 
  WRITE sy-datum TO l_date. 
  w_header-typ  = 'H'. 
  CONCATENATE sy-repid ':' 'From Date' l_date INTO w_header-info SEPARATED BY space. 
  APPEND w_header TO li_header. 
  CLEAR w_header. 

  w_header-typ  = 'S'. 
  w_header-info = sy-title. 
  APPEND w_header TO li_header. 
  CLEAR w_header. 

  w_header-typ  = 'A'. 
  w_header-info = sy-uname. 
  APPEND w_header TO li_header. 
  CLEAR w_header. 

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' 
    EXPORTING 
      it_list_commentary = li_header. 

ENDFORM.                    "top_of_page
Regards, Venkat.O

Hi All,

I have requirement where I have been asked to create a ALV_Grid report and the fina outcome of the report might have around 50-60 fields, but I read somewhere that there is some kind of restriction on the number of fields that one can have in ALV_grid, if that's the case then anyone of you please tell me what's the alternative for this.

Thanks,

Rajeev

5 REPLIES 5
Read only

venkat_o
Active Contributor
0 Likes
678

Hi Rajeev Gupta, I am giving guarantee that ALV grid does not have any output width restrictions. But field width restrictions are there . Simple example is,goto SE16 tcode and take any Table which has more than 80 fields and display data using ALV Grid. Go ahead and develop ALV grid report. If you don't have sample program.Check the below one.

REPORT  zvenkat_alv_grid. 
TABLES:t001. 
"Types 
TYPES: 
      BEGIN OF t_1001, 
        bukrs TYPE t001-bukrs, 
        butxt TYPE t001-butxt, 
        ort01 TYPE t001-ort01, 
        land1 TYPE t001-land1, 
      END OF t_1001. 
"Work area 
DATA: 
      w_t001 TYPE t_1001. 
"Internal table 
DATA: 
      i_t001 TYPE STANDARD TABLE OF t_1001. 

*&---------------------------------------------------------------------* 
" ALV Declarations 
*----------------------------------------------------------------------* 
* Types Pools 
TYPE-POOLS: 
   slis. 
* Types 
TYPES: 
   t_fieldcat         TYPE slis_fieldcat_alv, 
   t_events           TYPE slis_alv_event, 
   t_layout           TYPE slis_layout_alv. 
* Workareas 
DATA: 
   w_fieldcat         TYPE t_fieldcat, 
   w_events           TYPE t_events, 
   w_layout           TYPE t_layout. 
* Internal Tables 
DATA: 
   i_fieldcat         TYPE STANDARD TABLE OF t_fieldcat, 
   i_events           TYPE STANDARD TABLE OF t_events. 
*&---------------------------------------------------------------------* 
*&    start of selection 
*&---------------------------------------------------------------------* 
START-OF-SELECTION. 
  PERFORM get_data. 

*&---------------------------------------------------------------------* 
*&    end-of-selection. 
*&---------------------------------------------------------------------* 
END-OF-SELECTION. 

  PERFORM build_fieldcatlog. 
  PERFORM build_events. 
  PERFORM build_layout. 
  PERFORM list_display. 
*&---------------------------------------------------------------------* 
*&      Form  get_data 
*&---------------------------------------------------------------------* 
FORM get_data . 

  SELECT bukrs 
         butxt 
         ort01 
         land1 
    FROM t001 
    INTO TABLE i_t001 
    UP TO 30 ROWS. 

ENDFORM.                    " get_data 
*&---------------------------------------------------------------------* 
*&      Form  build_fieldcatlog 
*&---------------------------------------------------------------------* 
FORM build_fieldcatlog . 
  CLEAR:w_fieldcat,i_fieldcat[]. 

  PERFORM build_fcatalog USING: 
           'BUKRS' 'I_T001' 'BUKRS', 
           'BUTXT' 'I_T001' 'BUTXT', 
           'ORT01' 'I_T001' 'ORT01', 
           'LAND1' 'I_T001' 'LAND1'. 

ENDFORM.                    "BUILD_FIELDCATLOG 
*&---------------------------------------------------------------------* 
*&      Form  BUILD_FCATALOG 
*&---------------------------------------------------------------------* 
FORM build_fcatalog USING l_field l_tab l_text. 

  w_fieldcat-fieldname      = l_field. 
  w_fieldcat-tabname        = l_tab. 
  w_fieldcat-seltext_m      = l_text. 

  APPEND w_fieldcat TO i_fieldcat. 
  CLEAR w_fieldcat. 

ENDFORM.                    " build_fieldcatlog 
*&---------------------------------------------------------------------* 
*&      Form  build_events 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
FORM build_events. 
  CLEAR : 
        w_events, i_events[]. 
  w_events-name = 'TOP_OF_PAGE'."Event Name 
  w_events-form = 'TOP_OF_PAGE'."Callback event subroutine 
  APPEND w_events TO i_events. 
  CLEAR  w_events. 

ENDFORM.                    "build_events 
*&---------------------------------------------------------------------* 
*&      Form  build_layout 
*&---------------------------------------------------------------------* 
FORM build_layout . 

  w_layout-colwidth_optimize = 'X'. 
  w_layout-zebra             = 'X'. 

ENDFORM.                    " build_layout 
*&---------------------------------------------------------------------* 
*&      Form  list_display 
*&---------------------------------------------------------------------* 
FORM list_display . 
  DATA: 
        l_program TYPE sy-repid. 
  l_program = sy-repid. 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
    EXPORTING 
      i_callback_program = l_program 
      is_layout          = w_layout 
      it_fieldcat        = i_fieldcat 
      it_events          = i_events 
    TABLES 
      t_outtab           = i_t001 
    EXCEPTIONS 
      program_error      = 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. 
ENDFORM.                    " list_display 
*&---------------------------------------------------------------------* 
*&      Form  top_of_page 
*&---------------------------------------------------------------------* 
FORM top_of_page. 
  DATA : 
   li_header TYPE slis_t_listheader, 
   w_header  LIKE LINE OF li_header. 
  DATA: 
        l_date TYPE char10. 
  WRITE sy-datum TO l_date. 
  w_header-typ  = 'H'. 
  CONCATENATE sy-repid ':' 'From Date' l_date INTO w_header-info SEPARATED BY space. 
  APPEND w_header TO li_header. 
  CLEAR w_header. 

  w_header-typ  = 'S'. 
  w_header-info = sy-title. 
  APPEND w_header TO li_header. 
  CLEAR w_header. 

  w_header-typ  = 'A'. 
  w_header-info = sy-uname. 
  APPEND w_header TO li_header. 
  CLEAR w_header. 

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' 
    EXPORTING 
      it_list_commentary = li_header. 

ENDFORM.                    "top_of_page
Regards, Venkat.O

Read only

Former Member
0 Likes
677

Hi Venkat,

Thanks for the reply, but the sample code that you gave me has only 4 fields i.e. bukrs, butxt, ort01 and land1. But in my case based on few selection parameters I need to create a report that might have 50-60 diff. diff columns just for one record.

Please advise

Thanks,

Rajeev

Read only

Former Member
0 Likes
677

Yes Rajeev,

It is possible. All you have to do is, popoluate the internal table according to your selection criteria.

Let me say,

DATA: itab type table of MARA occurs 0.

START-OF-SELECTION.

SELECT * FROM MARA INTO TABLE ITAB WHERE <.....YOUR SELECTION CRITERIA.....>.

Now write the code as you do usually.

Even if you have 1 select option, you can populate the internal table and Hence ALV grid with numerous fields in the Database table.

I hope you got it, else let me know,

Shiv

Read only

venkat_o
Active Contributor
0 Likes
677

Hi Rajeev, I gave it as sample program. I did not mind that u expect 80 fields sample program. never mind. Check this sample program where i used PA0008 table where it has many fields as u expected. Run and count howmany fields are being displayed. REPORT zvenkat_alv_grid1.

DATA:i_pa0008 TYPE STANDARD TABLE OF pa0008.

START-OF-SELECTION.
  SELECT * FROM pa0008 INTO TABLE i_pa0008 UP TO 20 ROWS.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      i_structure_name   = 'PA0008'
    TABLES
      t_outtab           = i_pa0008.
Thanks, Venkat.O

Read only

Former Member
0 Likes
677

There is restriction on only the number fileds that are to be displayed on Selection Screen. There is no limitation for the number of fields that are to be displayed on ALV Grid. I guess you can have upto 90 number fields be displayed on your ALV grid.

However if you have numerous fields , you cannot have all the fields on your Selection Screen as Parameters and/or Selelct options. You can group them in order to limit them.

I hope this will answer your question. Reward if helpful.