‎2006 Nov 20 10:48 PM
Hi,
I have a requirement to create an ALV report. for that I need to create a field catelog for an internal table. currently I am doing the following way and it works fine. but for each field of the report i will have to call this function module. Is there any easy way to create field catelog from internal table? Your help is appriciated.
perform fill_fieldcat using 'INVOI' " Field name
'T_LOAD' " Table name
'Vendor Invoice' " Sel text
'10' " Length
'' " Hotspot
'X'. " Key
:
:
:
FORM fill_fieldcat USING P_F_NAME
P_TAB_NAME
P_SEL_TEXT_L
P_OUT_LEN
P_HOTSPOT
P_TAB_KEY.
clear wa_fieldcat.
wa_fieldcat-fieldname = p_f_name.
wa_fieldcat-tabname = p_tab_name.
wa_fieldcat-seltext_l = p_sel_text_l.
wa_fieldcat-outputlen = p_out_len.
wa_fieldcat-hotspot = p_hotspot.
wa_fieldcat-key = p_tab_key.
append wa_fieldcat to ts_fieldcat.
ENDFORM. " fill_fieldcat
Thank you,
Surya
‎2006 Nov 20 10:52 PM
try this FM
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_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.
Regards
Kathirvel
‎2006 Nov 20 10:53 PM
Hi,
Use the FM REUSE_ALV_FIELDCATALOG_MERGE to get the field catalog for the internal table..
Check this code..
TYPE-POOLS: slis.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: BEGIN OF wa_mara,
matnr LIKE mara-matnr,
bismt LIKE mara-bismt,
ernam LIKE mara-ernam,
ersda LIKE mara-ersda,
maktx LIKE makt-maktx,
END OF wa_mara.
data: v_repid type syrepid.
v_repid = sy-repid.
DATA it_mara LIKE STANDARD TABLE OF wa_mara.
SELECT *
FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_mara.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'WA_MARA'
i_inclname = v_repid
CHANGING
ct_fieldcat = gt_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = gt_fieldcat
TABLES
t_outtab = it_mara.
Thanks,
Naren
‎2006 Nov 20 10:56 PM
One more example is already available in demo programs
BCALV_FIELDCAT_TEST
Regards
Kathirvel
‎2006 Nov 27 5:04 PM
Hi All,
Here is the dump I am getting
"The ABAP source code lines are longer than the width of the internal"
Kathirvel:
I tried using FM LVC_FIELDCATALOG_MERGE, from program BCALV_FIELDCAT_TEST. This is running with no errors but no rows in field catelog table.
DATA: begin of ty_load occurs 0,
venin like zpoauto-venin,
venno like zpoauto-venno,
end of ty_load.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'TY_LOAD'
I_CLIENT_NEVER_DISPLAY = 'X'
changing
ct_fieldcat = p_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.
Thank you,
Surya.
‎2006 Nov 27 5:23 PM
Hi Surya,
You are passing internal table 'TY_LOAD' to i_structure_name, but you should pass this to i_internal_tabname as it is an internal table.
When there is a structure available in the Data Dictionary, then you can pass to i_structure_name.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'TY_LOAD'
changing
ct_fieldcat = p_fieldcat[].
Thanks
Ramakrishna
‎2006 Nov 27 6:16 PM
Ramakrishna,
I tried passing 'TY_LOAD' to i_internal_tabname parameter of LVC_FIELDCATALOG_MERGE, but getting error 'Field catalog not found'
Please note that my FM is LVC_FIELDCATALOG_MERGE. Your above code shows REUSE_ALV_FIELDCATALOG_MERGE. Even for this FM I am passing table name to I_INTERNAL_TABNAME prameter.
Thank you,
Surya.
Message was edited by:
Surya Manthina
‎2006 Nov 27 6:48 PM
Hi Surya,
As Chandrashekar mentioned, you need to specify the include name also. Since you write the code in the main program only, the include name is also your main program.
Please check the below working code.
REPORT ZSIMPLEALV .
TYPE-POOLS: SLIS.
DATA:BEGIN OF T_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,
MATKL LIKE MARA-MATKL,
MTART LIKE MARA-MATKL,
END OF T_MARA.
DATA: T_SLIS_FCAT TYPE SLIS_T_FIELDCAT_ALV.
SELECT-OPTIONS: MATERIAL FOR T_MARA-MATNR.
PARAMETER:LIST RADIOBUTTON GROUP R1,
GRID RADIOBUTTON GROUP R1.
START-OF-SELECTION.
SELECT MATNR MATKL MTART INTO TABLE T_MARA
FROM MARA
WHERE MATNR IN MATERIAL.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'T_MARA'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = T_SLIS_FCAT.
IF NOT LIST IS INITIAL.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
IT_FIELDCAT = T_SLIS_FCAT
TABLES
T_OUTTAB = T_MARA.
ELSE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = T_SLIS_FCAT
TABLES
T_OUTTAB = T_MARA.
ENDIF.
Thanks
Ramakrishna
‎2006 Nov 20 10:57 PM
Hi Surya,
Kathirvel 's logic will work only when you define the internal table fields using LIKE keyword.
For example:
DATA:BEGIN OF ITAB OCCURS 0,
FIELD1 LIKE ZTABLE-FIELD1,
FIELD2 LIKE ZTABLE-FIELD2,
......
END OF ITAB.
Thanks,
Ramakrishna
‎2006 Nov 20 11:34 PM
Hi All,
I am getting dumps. Here is more about my program structure.
I have report program(ZREP), it has an include ZXY which have all the sub routines and this include(ZXY) is having another include(ZZY) for data declarations. my internal table is in the data declarations include(ZZY).
data declarations: ZZY
DATA: begin of ty_load occurs 0,
venin like zpoauto-venin,
venno like zpoauto-venno,
end of ty_load.
From ZREP I am calling like this
INCLUDE ZXY.
:
:
perform reuse_alv_fieldcatalog_merge using sy-repid
'TY_LOAD'
changing
ts_fieldcat.
This routine is in ZXY and which is :
:
INCLUDE ZZY.
:
FORM reuse_alv_fieldcatalog_merge USING SY_REPID
TABL_NAME
CHANGING TS_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY_REPID
I_INTERNAL_TABNAME = TABL_NAME
I_STRUCTURE_NAME =
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = SY_REPID
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = TS_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. " reuse_alv_fieldcatalog_merge
Thank you,
Surya
‎2006 Nov 21 3:57 AM
Hi Surya,
Try using
v_repid = sy-repid.
perform reuse_alv_fieldcatalog_merge using v_repid
'TY_LOAD'
changing
ts_fieldcat
instead of
perform reuse_alv_fieldcatalog_merge using sy-repid
'TY_LOAD'
changing
ts_fieldcat
‎2006 Nov 21 4:00 AM
Hi Surya,
Try using
v_repid = sy-repid.
perform reuse_alv_fieldcatalog_merge using v_repid
'TY_LOAD'
changing
ts_fieldcat
instead of
perform reuse_alv_fieldcatalog_merge using sy-repid
'TY_LOAD'
changing
ts_fieldcat
‎2006 Nov 27 5:21 PM
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY_REPID
I_INTERNAL_TABNAME = TABL_NAME
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = <change the include name >--------------------------------here give ur include name where u had called this Function Module
* I_BYPASSING_BUFFER =
‎2006 Nov 20 11:38 PM
Hi,
What is the dump you are getting..
Make sure the field catalog internal table is declared like this..
DATA: TS_FIELDCAT TYPE SLIS_T_FIELCAT_ALV..
Thanks,
Naren
‎2006 Nov 20 11:38 PM
Please post the dump & complete code.
Please check your data declarations.
Then Try to move sy-repid to a variable and then pass it to the FM.
Regards
Kathirvel
‎2006 Nov 21 5:17 AM
Hi
There are two possible ways i can think of
Create a Z structure in se11 similar to the structure of the internal table and use the FM REUSE_ALV_FIELDCATALOG_MERGE with the structure.
Second option would be of using a macro
You can check the syntax by checking DEFINE
This is sample from the help.
DEFINE OPERATION.
RESULT = &1 &2 &3.
OUTPUT &1 &2 &3 RESULT.
END-OF-DEFINITION.
DEFINE OUTPUT.
WRITE: / 'The result of &1 &2 &3 is', &4.
END-OF-DEFINITION.
OPERATION 4 + 3.
OPERATION 2 ** 7.
OPERATION N2 - N1
‎2006 Nov 27 7:00 PM
Hi,
Check this example of how to prepare field catalog for an internal table..
TYPE-POOLS: slis.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: BEGIN OF wa_mara,
matnr LIKE mara-matnr,
bismt LIKE mara-bismt,
ernam LIKE mara-ernam,
ersda LIKE mara-ersda,
maktx LIKE makt-maktx,
END OF wa_mara.
DATA: v_repid TYPE syrepid.
v_repid = sy-repid.
DATA it_mara LIKE STANDARD TABLE OF wa_mara.
SELECT *
FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_mara.
<b>CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'WA_MARA'
i_inclname = v_repid
CHANGING
ct_fieldcat = gt_fieldcat.</b>
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = gt_fieldcat
TABLES
t_outtab = it_mara.
Thanks,
Naren
‎2006 Nov 27 8:22 PM
Ramakrishna/ Naren,
These programs you guys gave are working fine when I created them in different report program. But dump is giving when run the same code in my program. Please let me know if you need any information.
Thank you,
Surya
‎2006 Nov 27 8:40 PM
Hi,
Are you using any includes?
Can you please paste the code here?
Thanks
Ramakrishna
‎2006 Nov 27 10:46 PM
Yes, I am using two includes. One for data declarations one for all subroutines. main program has the subroutines include and subroutines include has data declarations include. I can not post the entire code here, it is too big.
Thank you,
Surya.
‎2006 Nov 27 10:52 PM
Hi,
Post the code that call the function module REUSE_ALV_FIELDCATALOG_MERGE..
Thanks,
Naren
‎2006 Nov 28 11:15 PM
Here is the code:
v_repid = sy-repid.
perform reuse_alv_fieldcatalog_merge using v_repid
'TY_LOAD'
changing
ts_fieldcat.
FORM reuse_alv_fieldcatalog_merge USING SY_REPID
TABL_NAME
CHANGING TS_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY_REPID
I_INTERNAL_TABNAME = TABL_NAME
I_STRUCTURE_NAME =
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = SY_REPID
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = TS_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. " reuse_alv_fieldcatalog_merge
‎2006 Nov 29 12:13 AM
Hi,
I tried your code..I changed the table declaration to use VBELN and POSNR..It is working fine..below is the code..
DATA: BEGIN OF ty_load OCCURS 0,
<b>venin LIKE vbak-vbeln,
venno LIKE vbap-posnr,</b>
END OF ty_load.
TYPE-POOLS: slis.
DATA: ts_fieldcat TYPE slis_t_fieldcat_alv.
DATA: v_repid TYPE syrepid.
v_repid = sy-repid.
PERFORM reuse_alv_fieldcatalog_merge USING v_repid
'TY_LOAD'
CHANGING
ts_fieldcat.
FORM reuse_alv_fieldcatalog_merge USING sy_repid
tabl_name
CHANGING ts_fieldcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy_repid
i_internal_tabname = tabl_name
i_inclname = sy_repid
CHANGING
ct_fieldcat = ts_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.
Thanks,
Naren