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: 

Simple ALV Gris Display?

Former Member
0 Kudos

Experts,

I have a large internal table. I want to display it to the screen in an ALV grid....nothing fancy.

Is there simple syntax to do this, or any good comments or references anyone has is greatly appreciated.

Thank-You.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, please see this sample program. This is a very simple ALV grid.



report zrich_0004
       no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of imara.

* Selection Screen
selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for imara-matnr .
selection-screen end of block b1.

start-of-selection.

  perform get_data.
  perform write_report.


************************************************************************
*  Get_Data
************************************************************************
form get_data.

  select  mara~matnr makt~maktx
            into corresponding fields of table imara
              from mara
               inner join makt
                 on mara~matnr = makt~matnr
                    where mara~matnr in s_matnr
                      and makt~spras = sy-langu.

endform.

************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.

  perform build_field_catalog.

* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat = fieldcat
       tables
            t_outtab    = imara.

endform.

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.

  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat. refresh: fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.


  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.

endform.

Regards,

Rich Heilman

5 REPLIES 5

Former Member
0 Kudos

See the standard SAP reports starting with BCALV_GRID*

-Kiran

Message was edited by: Kiran Raorane

0 Kudos

hi,

CHeck the standard Programs of <b>BCALV</b> in se38

REPORT  ZTUFI091                                .
*&---------------------------------------------------------------------*
*& Report  ZDEMO_ALVGRID                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& Example of a simple ALV Grid Report                                 *
*& ...................................                                 *
*&                                                                     *
*& The basic requirement for this demo is to display a number of       *
*& fields from the EKKO table.                                         *
*&---------------------------------------------------------------------*
*REPORT  zdemo_alvgrid                 .

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_repid
            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
            i_callback_user_command = 'USER_COMMAND'
*            i_grid_title           = outtext
            is_layout               = gd_layout
            it_fieldcat             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
            it_events               = gt_events
            is_print                = gd_prntparams
            i_save                  = 'X'
*            is_variant              = z_template
       tables
            t_outtab                = it_ekko
       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.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.
endform.                    " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
      wa_header type slis_listheader,
      t_line like wa_header-info,
      ld_lines type i,
      ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  append wa_header to t_header.
  clear wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  append wa_header to t_header.
  clear: wa_header.

* Total No. of Records Selected
  describe table it_ekko lines ld_lines.
  ld_linesc = ld_lines.
  concatenate 'Total No. of Records Selected: ' ld_linesc
                    into t_line separated by space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  append wa_header to t_header.
  clear: wa_header, t_line.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.


*------------------------------------------------------------------*
*       FORM USER_COMMAND                                          *
*------------------------------------------------------------------*
*       --> R_UCOMM                                                *
*       --> RS_SELFIELD                                            *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.

* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
    IF rs_selfield-fieldname = 'EBELN'.
*     Read data table, using index of row user clicked on
      READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
*     Set parameter ID for transaction screen field
      SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
      CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDCASE.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Build events table
*----------------------------------------------------------------------*
form build_events.
  data: ls_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = gt_events[].
  read table gt_events with key name =  slis_ev_end_of_page
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_PAGE' to ls_event-form.
    append ls_event to gt_events.
  endif.

    read table gt_events with key name =  slis_ev_end_of_list
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_LIST' to ls_event-form.
    append ls_event to gt_events.
  endif.
endform.                    " BUILD_EVENTS


*&---------------------------------------------------------------------*
*&      Form  BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*       Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
  gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
  gd_prntparams-no_coverpage = 'X'.
endform.                    " BUILD_PRINT_PARAMS


*&---------------------------------------------------------------------*
*&      Form  END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  write: sy-uline(50).
  skip.
  write:/40 'Page:', sy-pagno .
endform.


*&---------------------------------------------------------------------*
*&      Form  END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  skip.
  write:/40 'Page:', sy-pagno .
endform.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, please see this sample program. This is a very simple ALV grid.



report zrich_0004
       no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of imara.

* Selection Screen
selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for imara-matnr .
selection-screen end of block b1.

start-of-selection.

  perform get_data.
  perform write_report.


************************************************************************
*  Get_Data
************************************************************************
form get_data.

  select  mara~matnr makt~maktx
            into corresponding fields of table imara
              from mara
               inner join makt
                 on mara~matnr = makt~matnr
                    where mara~matnr in s_matnr
                      and makt~spras = sy-langu.

endform.

************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.

  perform build_field_catalog.

* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat = fieldcat
       tables
            t_outtab    = imara.

endform.

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.

  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat. refresh: fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.


  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.

endform.

Regards,

Rich Heilman

Former Member
0 Kudos

hi tom,

check this sample code.

report z*** no standard page heading line-count 5.

tables: lfa1,lfb1,lfm1.

type-pools: slis.

type-pools: icon.

***DATA DECLN.

data: v_lifnr like lfa1-lifnr,

v_bukrs like lfb1-bukrs,

v_ekorg like lfm1-ekorg,

v_ktokk like lfa1-ktokk.

***FIELD CATALOG.

*CHANGES BY LAXMI

data: itab_fieldcat type slis_t_fieldcat_alv with header line.

*END CHANGES

***SORTING

data: itab_sort type slis_t_sortinfo_alv.

    • FOR LAYOUT

data: wa_layout type slis_layout_alv.

data : v_repid type sy-repid.

*INTERNAL TABLE DECLN

data: begin of itab occurs 0,

lifnr like lfa1-lifnr,

bukrs like lfb1-bukrs,

ekorg like lfm1-ekorg,

ktokk like lfa1-ktokk,

name1 like lfa1-name1,

stras like lfa1-stras,

ort01 like lfa1-ort01,

regio like lfa1-regio,

pfort like lfa1-pfort,

pstlz like lfa1-pstlz,

pstl2 like lfa1-pstl2,

telf1 like lfa1-telf1,

color(3) type c,

*CELLCOLOR TYPE LVC_T_SCOL,

end of itab.

*SELECTION-SCREEN.

selection-screen: begin of block b1 with frame.

select-options: s_lifnr for lfa1-lifnr.

select-options: s_bukrs for lfb1-bukrs.

select-options: s_ekorg for lfm1-ekorg.

select-options: s_ktokk for lfa1-ktokk.

selection-screen: end of block b1.

parameters: r_list radiobutton group g1,

r_grid radiobutton group g1.

**AT SELECTION-SCREEN.

at selection-screen.

if not s_lifnr is initial.

select single lifnr

into v_lifnr

from lfa1

where lifnr in s_lifnr.

if sy-subrc <> 0.

message e001(zz1).

endif.

else.

message e005(zz1).

endif.

if not s_bukrs is initial.

select single bukrs

from t001

into v_bukrs

where bukrs in s_bukrs.

if sy-subrc <> 0.

message e002(zz1).

endif.

else.

message e006(zz1).

endif.

if not s_ekorg is initial.

select single ekorg

from t024e

into v_ekorg

where ekorg in s_ekorg.

if sy-subrc <> 0.

message e003(zz1).

endif.

else.

message e007(zz1).

endif.

if not s_ktokk is initial.

select single ktokk

from t077k

into v_ktokk

where ktokk in s_ktokk.

if sy-subrc <> 0.

message e008(zz1).

endif.

else.

message e008(zz1).

endif.

***start of selection.

start-of-selection.

v_repid = sy-repid.

perform get_data.

****END OF SELECTION.

end-of-selection.

perform get_field_catalog.

*PERFORM BUILD_FIELDCAT.

if r_list = 'X'.

perform list_display.

else.

perform grid_display.

endif.

&----


*& Form GET_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_data .

select lfa1~lifnr

lfb1~bukrs

lfm1~ekorg

lfa1~ktokk

lfa1~name1

lfa1~stras

lfa1~ort01

lfa1~regio

lfa1~pfort

lfa1~pstlz

lfa1~pstl2

lfa1~telf1

from lfa1 inner join lfb1 on lfa1lifnr = lfb1lifnr

inner join lfm1 on lfa1lifnr = lfm1lifnr

into corresponding fields of table itab

where lfa1~lifnr in s_lifnr.

endform. " GET_DATA

&----


*& Form GET_FIELD_CATALOG

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_field_catalog .

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = v_repid

i_internal_tabname = 'ITAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = v_repid

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

changing

ct_fieldcat = itab_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. " GET_FIELD_CATALOG

&----


*& Form LIST_DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form list_display .

wa_layout-info_fieldname = 'COLOR'.

wa_layout-zebra = 'X'.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_STRUCTURE_NAME =

is_layout = wa_layout

it_fieldcat = itab_fieldcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = 'A'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = itab

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 BUILD_FIELDCAT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_fieldcat .

itab_fieldcat-col_pos = 0.

itab_fieldcat-fieldname = 'LIFNR'.

itab_fieldcat-key = 'X'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-outputlen = '10'.

itab_fieldcat-seltext_l = 'VENDOR'(009).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 1.

itab_fieldcat-fieldname = 'BUKRS'.

itab_fieldcat-key = 'X'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-outputlen = '4'.

itab_fieldcat-seltext_l = 'COMPANY CODE'(010).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 2.

itab_fieldcat-fieldname = 'EKORG'.

itab_fieldcat-key = 'X'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-outputlen = '4'.

itab_fieldcat-seltext_l = 'PURCHASING ORG'(011).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 3.

itab_fieldcat-fieldname = 'KTOKK'.

itab_fieldcat-outputlen = '4'.

itab_fieldcat-seltext_l = 'ACCOUNT GRP'(012).

itab_fieldcat-emphasize = 'X'.

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 4.

itab_fieldcat-fieldname = 'NAME1'.

itab_fieldcat-outputlen = '12'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-seltext_l = 'VENDOR NAME'(013).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 5.

itab_fieldcat-fieldname = 'STRAS'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-outputlen = '12'.

itab_fieldcat-seltext_l = 'STREET'(014).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 6.

itab_fieldcat-fieldname = 'ORT01'.

itab_fieldcat-outputlen = '12'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-seltext_l = 'CITY'(015).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 7.

itab_fieldcat-fieldname = 'REGIO'.

itab_fieldcat-outputlen = '2'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-seltext_l = 'REGION'(016).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 8.

itab_fieldcat-fieldname = 'PFORT'.

itab_fieldcat-outputlen = '10'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-seltext_l = 'PO BOX'(017).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 9.

itab_fieldcat-fieldname = 'PFTLZ'.

itab_fieldcat-emphasize = 'X'.

itab_fieldcat-outputlen = '10'.

itab_fieldcat-seltext_l = 'POST CODE'(018).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 10.

itab_fieldcat-fieldname = 'PSTL2'.

itab_fieldcat-outputlen = '10'.

itab_fieldcat-seltext_l = 'PO ZIP'(019).

append itab_fieldcat.

clear itab_fieldcat.

itab_fieldcat-col_pos = 11.

itab_fieldcat-fieldname = 'TELF1'.

itab_fieldcat-outputlen = '16'.

itab_fieldcat-seltext_l = 'TELEPHONE'(020).

append itab_fieldcat.

clear itab_fieldcat.

*L_POS = L_POS + 1.

*DATA: LS_CELLCOLOR TYPE LVC_S_SCOL.

*DATA: L_INDEX TYPE SY-TABIX.

*

*LOOP AT ITAB.

  • L_INDEX = SY-TABIX.

  • if l_index = 1 or l_index = 10.

  • LS_CELLCOLOR-FNAME = 'VBELN'.

  • LS_CELLCOLOR-COLOR-COL = '6'.

  • LS_CELLCOLOR-COLOR-INT = '1'.

  • APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

  • MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

  • endif.

  • if l_index = 5 or l_index = 20.

  • LS_CELLCOLOR-FNAME = 'VBELN'.

  • LS_CELLCOLOR-COLOR-COL = '4'.

  • LS_CELLCOLOR-COLOR-INT = '1'.

  • APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

  • MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

  • endif.

*ENDLOOP.

endform. " BUILD_FIELDCAT

&----


*& Form GRID_DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form grid_display .

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

  • IS_LAYOUT =

it_fieldcat = itab_fieldcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = itab

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

<b>check this links..</b>

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_basic.htm

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_endlist.htm

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_enhanced.htm

Message was edited by: Priya

Former Member
0 Kudos

hi,

1. populate internal table

2. Populate field catalog using REUSE_ALV_FIELDCATALOG_MERGE. remember internal table decleration must contain only 'like' no 'types.

3. Call FM REUSE_ALV_GRID_DISPLAY pass fieldcatalog and internal table name and 'call back program name'.

Regards,

Manohar.