06-13-2008 3:44 PM
Hi friends,
I am using function module to detemine fields. REUSE_ALV_FIELDCATALOG_MERGE
you people might be known already it should work only when the internal table fields declared with LIKE.
data: begin of itab occurs 0,
MATERIAL like mara-matnr,
DESC like makt-maktx,
end of itab.
it will not work if you declared fields with TYPE.
data: begin of itab occurs 0,
MATERIAL(18) type c,
DESC(40) type c,
end of itab.
Could you pls let me know, how to use REUSE_ALV_FIELDCATALOG_MERGE function module... if the internal table fields declared using types.
or is there any function module or anything is available to find out field names?
Thanks in advance
Regards
Raghu
06-13-2008 3:51 PM
Hi Raghunath,
That is the reason we generally dont use in our programming.
we need to defin the tables with like only
Please check this link
This is the example with LIKE keyword
*data definition
tables:
marav. "Table MARA and table MAKT
*---------------------------------------------------------------------*
* Data to be displayed in ALV
* Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
* matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.
*---------------------------------------------------------------------*
* Other data needed
* field to store report name
data i_repid like sy-repid.
* field to check table length
data i_lines like sy-tabix.
*---------------------------------------------------------------------*
* Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
*---------------------------------------------------------------------*
select-options:
s_matnr for marav-matnr matchcode object MAT1.
*---------------------------------------------------------------------*
start-of-selection.
* read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
* Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
* Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
*---------------------------------------------------------------------*
*
* Now, we start with ALV
*
*---------------------------------------------------------------------*
*
*
* To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
* The fieldcatalouge can be generated by FUNCTION
* 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
* report source, including this report.
* The only problem one might have is that the report and table names
* need to be in capital letters. (I had it 😞 )
*
*
*---------------------------------------------------------------------*
* Store report name
i_repid = sy-repid.
* Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
* I_PROGRAM_NAME is the program which calls this function
*
* I_INTERNAL_TABNAME is the name of the internal table which you want
* to display in ALV
*
* I_INCLNAME is the ABAP-source where the internal table is defined
* (DATA....)
* CT_FIELDCAT contains the Fieldcatalouge that we need later for
* ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
*---------------------------------------------------------------------*
*
* And now, we are ready to display our list
* Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
* I_CALLBACK_PROGRAM is the program which calls this function
*
* IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
* now the data definition needed for display
*
* I_SAVE allows the user to save his own layouts
*
* T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
Best regards,
raam
06-13-2008 3:53 PM
Hi ,
Check the below code ....You will get all answers you have ....
_----
tables: marav. "Table MARA and table MAKT
----
Data to be displayed in ALV
Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr,
maktx like marav-maktx,
matkl like marav-matkl,
ntgew like marav-ntgew,
gewei like marav-gewei,
end of imat.
----
Other data needed
field to store report name
data i_repid like sy-repid.
field to check table length
data i_lines like sy-tabix.
----
Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
----
select-options:
s_matnr for marav-matnr." matchcode object MAT1
----
start-of-selection.
read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
----
*
Now, we start with ALV
*
----
*
*
To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
The fieldcatalouge can be generated by FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
report source, including this report.
The only problem one might have is that the report and table names
need to be in capital letters. (I had it )
*
*
----
Store report name
i_repid = sy-repid.
Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
I_PROGRAM_NAME is the program which calls this function
*
I_INTERNAL_TABNAME is the name of the internal table which you want
to display in ALV
*
I_INCLNAME is the ABAP-source where the internal table is defined
(DATA....)
CT_FIELDCAT contains the Fieldcatalouge that we need later for
ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
----
*
And now, we are ready to display our list
Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
I_CALLBACK_PROGRAM is the program which calls this function
*
IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
now the data definition needed for display
*
I_SAVE allows the user to save his own layouts
*
T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
_----
Reward If useful
Thanks
Jagadeesh.G
06-13-2008 3:58 PM
Hi,
In cases where you ahve internal table with fields declared using types, you have to build your own field catalog.
Here are the different ways of building your field catalog:
http://www.sapdevelopment.co.uk/reporting/alv/alv_variousfcat.htm
Regards,
Ravi Kanth Talagana
06-13-2008 4:38 PM
Hi all,
you can use the new ALV object model (cl_salv_table, see Rich Heilmans fantastic blogs on this. Finally even SAP knows how to determine the field catalog at runtime.
Or use my proved routines for this:
*&---------------------------------------------------------------------*
*& Form ALV_FIELDCAT_FOR_ITAB
*&---------------------------------------------------------------------*
* Field catalog from (arbitrary) internal Table (c) Clemens Li
* * build field catalog from type description
*----------------------------------------------------------------------*
FORM alv_fieldcat_for_itab "#EC *
TABLES pt_outtab TYPE table "#EC * table for ALV display
CHANGING pt_alv_fieldcat TYPE slis_t_fieldcat_alv."#EC * field catalog
DATA:
lv_desc TYPE sydes_desc,
ls_alv_fieldcat TYPE slis_fieldcat_alv,
lv_longfield TYPE fname.
FIELD-SYMBOLS:
<typeinfo> TYPE sydes_typeinfo,
<nameinfo> TYPE sydes_nameinfo.
DESCRIBE FIELD pt_outtab INTO lv_desc. "#EC *
LOOP AT lv_desc-types
ASSIGNING <typeinfo>
WHERE NOT idx_name IS INITIAL
AND table_kind IS INITIAL "no entries for deep table like color
AND back = 1. "top-level-entries only.
READ TABLE lv_desc-names INDEX <typeinfo>-idx_name
ASSIGNING <nameinfo>.
CHECK <nameinfo>-name <> 'INCLUDE'.
ls_alv_fieldcat-fieldname = <nameinfo>-name.
WHILE NOT <nameinfo>-continue IS INITIAL.
ADD 1 TO <typeinfo>-idx_name.
READ TABLE lv_desc-names INDEX <typeinfo>-idx_name
ASSIGNING <nameinfo>.
CONCATENATE
ls_alv_fieldcat-fieldname
<nameinfo>-name
INTO ls_alv_fieldcat-fieldname.
ENDWHILE." not <nameinfo>-continue IS INITIAL.
READ TABLE lv_desc-names INDEX <typeinfo>-idx_help_id
ASSIGNING <nameinfo>.
IF sy-subrc = 0.
* Caution: Help-ID may be Tablename-Fieldname and thus longer
* than 30 Chars; ls_alv_fieldcat-rollname is 30 Chars only
ls_alv_fieldcat-rollname = <nameinfo>-name.
lv_longfield = <nameinfo>-name.
WHILE NOT <nameinfo>-continue IS INITIAL.
ADD 1 TO <typeinfo>-idx_help_id.
READ TABLE lv_desc-names INDEX <typeinfo>-idx_help_id
ASSIGNING <nameinfo>.
CONCATENATE
lv_longfield
<nameinfo>-name
INTO lv_longfield.
ENDWHILE." not lv_desc-continue is initial.
* help id may be data element or <table>-<field>
IF lv_longfield CA '-'.
* get data type for table field
PERFORM get_rollname_4_tabfield
USING lv_longfield CHANGING ls_alv_fieldcat.
ENDIF." lv_longfield ca '-'.
ELSE.
* No Help-ID: Use Fieldname as text
ls_alv_fieldcat-seltext_s =
ls_alv_fieldcat-seltext_m =
ls_alv_fieldcat-seltext_l =
ls_alv_fieldcat-reptext_ddic =
<nameinfo>-name.
ENDIF." sy-subrc = 0.
* Starting 4.7: get edit mask
IF NOT <typeinfo>-idx_edit_mask IS INITIAL.
READ TABLE lv_desc-names INDEX <typeinfo>-idx_edit_mask
ASSIGNING <nameinfo>.
ls_alv_fieldcat-edit_mask = <nameinfo>-name.
IF NOT <nameinfo>-continue IS INITIAL.
ADD 1 TO <typeinfo>-idx_edit_mask.
READ TABLE lv_desc-names INDEX <typeinfo>-idx_edit_mask
ASSIGNING <nameinfo>.
CONCATENATE
ls_alv_fieldcat-edit_mask
<nameinfo>-name
INTO ls_alv_fieldcat-edit_mask.
ENDIF." not <nameinfo>-continue IS INITIAL.
ENDIF." not <typeinfo>-IDX_EDIT_MASK is initial.
* assign length, output length and decimals
ls_alv_fieldcat-intlen = <typeinfo>-length.
ls_alv_fieldcat-outputlen = <typeinfo>-output_length.
ls_alv_fieldcat-decimals_out = <typeinfo>-decimals.
ls_alv_fieldcat-inttype = <typeinfo>-type.
APPEND ls_alv_fieldcat TO pt_alv_fieldcat.
CLEAR: "prevent anything 2 B taken for subsequent fields
ls_alv_fieldcat.
ENDLOOP." at lv_desc-types where not IDX_NAME is in initial.
ENDFORM. " ALV_FIELDCAT_FOR_ITAB
*&---------------------------------------------------------------------
*& Form get_rollname_4_tabfield
*&---------------------------------------------------------------------
* Get Data type for Table field
*----------------------------------------------------------------------
FORM get_rollname_4_tabfield
USING p_fname TYPE fname
CHANGING p_alv_fieldcat TYPE slis_fieldcat_alv.
FIELD-SYMBOLS:
<dfies> TYPE dfies.
DATA:
lv_tabname TYPE tabname,
lt_dfies TYPE TABLE OF dfies,
lv_fieldname TYPE fieldname.
SPLIT p_fname AT '-'
INTO lv_tabname lv_fieldname.
CLEAR p_alv_fieldcat-rollname.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = lv_tabname
fieldname = lv_fieldname
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
dfies_tab = lt_dfies
* FIXED_VALUES =
EXCEPTIONS
not_found = 1
internal_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.
ELSE.
READ TABLE lt_dfies ASSIGNING <dfies> INDEX 1.
p_alv_fieldcat-rollname = <dfies>-rollname.
* Und wenn keinerlei Twexte gepflegt sind?
IF <dfies>-reptext IS INITIAL AND
<dfies>-scrtext_s IS INITIAL AND
<dfies>-scrtext_m IS INITIAL AND
<dfies>-scrtext_l IS INITIAL.
* No Text: Use Fieldname as text
p_alv_fieldcat-seltext_s =
p_alv_fieldcat-seltext_m =
p_alv_fieldcat-seltext_l =
p_alv_fieldcat-reptext_ddic =
p_alv_fieldcat-fieldname.
ENDIF." <dfies>-reptext IS INITIAL AND
ENDIF.
ENDFORM. " get_rollname_4_tabfield
Note: This works for all tables displayed in ALV.
Regards,
Clemens
06-14-2008 8:40 PM
Hello Clemens Li,
thanks for the information.
I am trying to use your code. But , when checking syntax, there is a problem with the line code :
CHECK <nameinfo>-name 'INCLUDE'.
A comparator ("=" "<>" ...) is missing no ?
Cordialement,
Chaouki.
06-14-2008 5:27 AM
Hi,
For your problem the solutions is develope field catalog manually.
You can get the solution. Pass this fieldcatalog to ur grid/list function module
Regards,
Chandu