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 REPORT:

Former Member
0 Kudos

I am using FM REUSE_ALV_FIELDCATALOG_MERGE as follows:

types: begin of t_final,

NAME1 LIKE KNA1-NAME1,

ORT01 LIKE KNA1-ORT01,

LAND1 LIKE KNA1-LAND1,

end of t_final.

data: i_final type table of t_final,

w_final type t_final.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_STRUCTURE_NAME = 'T_FINAL'

CHANGING

CT_FIELDCAT = FIELDCATALOG

getting dump and error saying that

Field symbol is not assigned.

can anyone tell me where I am getting wrong?

thanks in advance........

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hI

Supports the creation of the field catalog for the ALV function modules

based either on a structure or table defined in the ABAP Data

Dictionary, or a program-internal table.

The program-internal table must either be in a TOP Include or its

Include must be specified explicitly in the interface.

The variant based on a program-internal table should only be used for

rapid prototyping since the following restrictions apply:

o Performance is affected since the code of the table definition must

always be read and interpreted at runtime.

o Dictionary references are only considered if the keywords LIKE or

INCLUDE STRUCTURE (not TYPE) are used.

If the field catalog contains more than 90 fields, the first 90 fields

are output in the list by default whereas the remaining fields are only

available in the field selection.

If the field catalog is passed with values, they are merged with the

'automatically' found information.

Below is an example ABAP program which will populate a simple internal table(it_ekpo) with data and

display it using the basic ALV grid functionality(including column total). The example details the main

sections of coding required to implement the ALV grid functionality:

Data declaration

Data retrieval

Build fieldcatalog

Build layout setup

&----


*& 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.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

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-do_sum = 'X'. "Display column total

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_XEVENTS

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

6 REPLIES 6

Former Member
0 Kudos

Hi,

T_FINAL is a table type. It doesn't have any header line.

Instead you can use W_FINAL.

JozsefSzikszai
Active Contributor
0 Kudos

hi Kartikey,

instead of i_structure_name you have to use i_internal_tabname:

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

*I_STRUCTURE_NAME = 'T_FINAL'

I_INTERNAL_TABNAME = 'I_FINAL'

CHANGING

...

hope this helps

ec

0 Kudos

Your structure name should be 'I_FINAL' not 'T_FINAL'.

0 Kudos

I used i_final as internal table name but it gives the sdame error of field symbols.....

Former Member
0 Kudos

hI

Supports the creation of the field catalog for the ALV function modules

based either on a structure or table defined in the ABAP Data

Dictionary, or a program-internal table.

The program-internal table must either be in a TOP Include or its

Include must be specified explicitly in the interface.

The variant based on a program-internal table should only be used for

rapid prototyping since the following restrictions apply:

o Performance is affected since the code of the table definition must

always be read and interpreted at runtime.

o Dictionary references are only considered if the keywords LIKE or

INCLUDE STRUCTURE (not TYPE) are used.

If the field catalog contains more than 90 fields, the first 90 fields

are output in the list by default whereas the remaining fields are only

available in the field selection.

If the field catalog is passed with values, they are merged with the

'automatically' found information.

Below is an example ABAP program which will populate a simple internal table(it_ekpo) with data and

display it using the basic ALV grid functionality(including column total). The example details the main

sections of coding required to implement the ALV grid functionality:

Data declaration

Data retrieval

Build fieldcatalog

Build layout setup

&----


*& 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.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

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-do_sum = 'X'. "Display column total

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_XEVENTS

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

Former Member
0 Kudos

Hi,

As you are defining the structure, instead of using Standard structure,You have to build the field catalog manually as below,

* Create the Field Catalog.
  PERFORM field_catalog USING 'NAME1' .
  PERFORM field_catalog USING 'ORT01' .
  PERFORM field_catalog USING 'LAND1' .
 
* Build Layout
  PERFORM build_layout.
 
*display report
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      is_layout          = gv_layout1
      it_fieldcat             = git_fieldcatalog[]
    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.         " IF sy-subrc <> 0.
 
 
FORM field_catalog  USING    xv_fieldname TYPE slis_fieldname.
  DATA:  gv_colpos              TYPE i,
              git_fieldcatalog       TYPE slis_t_fieldcat_alv,
              lwa_fieldcatalog TYPE LINE OF slis_t_fieldcat_alv,
             gv_layout1             TYPE slis_layout_alv.
 
  gv_colpos = gv_colpos + 1.
 
  lwa_fieldcatalog-col_pos    = gv_colpos.
  lwa_fieldcatalog-fieldname  = xv_fieldname.
  APPEND lwa_fieldcatalog TO git_fieldcatalog.
  CLEAR lwa_fieldcatalog.
 
ENDFORM.                    " field_catalog
 
FORM build_layout .
  gv_layout1-colwidth_optimize = 'X'.
  gv_layout1-zebra             = 'X'.
  gv_layout1-group_change_edit = 'X'.
  gv_layout1-f2code            = 'DISPLAY'.
ENDFORM.                    " build_layout

Regards,

Satish