05-23-2008 10:01 AM
In my program the internal table consists many fields from various tables and structure doesn't belong to a single data table.
In order to get output in ALV grid following FM has been used
REUSE_ALV_GRID_DISPLAY
for field catalog the fields are defined specifically.
l_fieldcat-fieldname = 'VBELN'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Billing doc'.
l_fieldcat-no_zero = 'X'.
l_fieldcat-hotspot = 'X'.
append l_fieldcat to p_fieldtab.
..............and so on for all the fields.
Just wanted to know is there any other method to display all the fields of this internal table automatically so each field is not specified specifically.
anya
05-23-2008 10:06 AM
Hi,
Use this function module:
REUSE_ALV_FIELDCATALOG_MERGE
Example :
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'TP_MARA'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = ' '
i_inclname = sy-repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
changing
ct_fieldcat = lt_fldcat[]
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.
NOTE :
TP_MARA is not internal table name. Here the internal table declared using types as below:
types : begin of tp_mara,
matnr type mara-matnr,
ersda type mara-ersda,
ernam type mara-ernam,
laeda type mara-laeda,
end of tp_mara.
data : ig_mara type standard table of tp_mara,
wg_mara type tp_mara.
And also note while declaring types all fields declare using TYPE and not using LIKE.
Regards,
Raghu
05-23-2008 10:06 AM
Hi,
Use this function module:
REUSE_ALV_FIELDCATALOG_MERGE
Example :
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'TP_MARA'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = ' '
i_inclname = sy-repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
changing
ct_fieldcat = lt_fldcat[]
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.
NOTE :
TP_MARA is not internal table name. Here the internal table declared using types as below:
types : begin of tp_mara,
matnr type mara-matnr,
ersda type mara-ersda,
ernam type mara-ernam,
laeda type mara-laeda,
end of tp_mara.
data : ig_mara type standard table of tp_mara,
wg_mara type tp_mara.
And also note while declaring types all fields declare using TYPE and not using LIKE.
Regards,
Raghu
05-23-2008 10:13 AM
HI
In fm
I_STRUCTURE_NAME = VBAK "name io DB table
internal table which u r passing in FM should be of type VBAK.
Regards
Aditya
05-23-2008 10:16 AM
Hi,
then make the structure of required fields in SE11.
then pass the parameter i_structure_name = '<UR STRUCTURE>' in FMs
'REUSE_ALV_LIST_DISPLAY'
REUSE_ALV_GRID_DISPLAY
you need not to do fieldcat at all in your program
check the example function module
i used the table KNA1 as my reference structure
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'KNA1'
is_layout = wa_layout
TABLES
t_outtab = it_kna1.
reward if helpful
prasanth
05-23-2008 10:32 AM
hi
There is another way of filling the fieldcatalogue...
perform append_fc using '1' 'ITAB' 'FIELD1' 'DESCIPTION'.
inside the form pass the fields to wa_fieldcata nd append wa_fieldat to it_fieldcat.
repeat this for every field
10-03-2014 2:49 PM
Hi
Try this instead:
*&---------------------------------------------------------------------*
*& Form create_fieldcatalog
*&---------------------------------------------------------------------*
* Create a field catalogue from any internal table
*----------------------------------------------------------------------*
* -->PT_TABLE Internal table
* -->PT_FIELDCAT Field Catalogue
*----------------------------------------------------------------------*
FORM create_fieldcatalog
USING pt_table TYPE ANY TABLE
CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA:
lr_tabdescr TYPE REF TO cl_abap_structdescr
, lr_data TYPE REF TO data
, lt_dfies TYPE ddfields
, ls_dfies TYPE dfies
, ls_fieldcat TYPE lvc_s_fcat
.
CLEAR pt_fieldcat.
CREATE DATA lr_data LIKE LINE OF pt_table.
lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).
lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
LOOP AT lt_dfies
INTO ls_dfies.
CLEAR ls_fieldcat.
MOVE-CORRESPONDING ls_dfies TO ls_fieldcat.
APPEND ls_fieldcat TO pt_fieldcat.
ENDLOOP.
ENDFORM. "create_fieldcatalog
12-04-2020 5:19 AM
01-05-2022 7:48 AM