sap create alv report select from mara and display materia and description
- User
sap create alv report select from mara and display materia and description
- Assistant
- User
Function parameter "T_FIELDCAT" is unknown.
- Assistant
sap create alv report select from mara and display materia and description
Function parameter "T_FIELDCAT" is unknown.
Creating an ALV (ABAP List Viewer) report in SAP involves several steps. You'll need to write an ABAP program that selects data from the database table MARA and uses SAP's ALV functionality to display it. Here’s a simple example for creating an ALV report that displays material (MATNR) and material description (MAKTX) from MARA and its related table MAKT. This example assumes you have access to the necessary SAP development environment (such as SE80 or SE38) to create and run this program.
Here's a step-by-step guide:
You need to select data from the MARA and MAKT tables. MARA contains material numbers, and MAKT contains material descriptions.
Set up your internal tables and work areas to hold the selected data.
You will use the REUSE_ALV_GRID_DISPLAY function module to display the data.
Here is an example program:
REPORT zexample_alv_mara.
TABLES: mara.
TYPES: BEGIN OF ty_material,
matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
END OF ty_material.
DATA: it_material TYPE TABLE OF ty_material,
wa_material TYPE ty_material.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
PARAMETERS: p_matnr TYPE mara-matnr.
SELECT-OPTIONS: so_matnr FOR mara-matnr.
START-OF-SELECTION.
SELECT mara~matnr makt~maktx
INTO TABLE it_material
FROM mara
INNER JOIN makt
ON mara~matnr = makt~matnr
WHERE mara~matnr IN so_matnr
AND makt~spras = sy-langu.
IF it_material[] IS INITIAL.
MESSAGE 'No data found' TYPE 'I'.
EXIT.
ENDIF.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_MATERIAL'
i_client_never_display = 'X'
CHANGING
ct_fieldcat = lt_fieldcat.
IF sy-subrc <> 0.
MESSAGE 'Error generating field catalog' TYPE 'E'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
TABLES
t_outtab = it_material
t_fieldcat = lt_fieldcat
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Error displaying ALV' TYPE 'E'.
ENDIF.
MARA database table.ty_material is defined to hold the data retrieved from MARA and MAKT.it_material is the internal table, and wa_material is the work area.SPRAS) matches the current logon language (SY-LANGU).REUSE_ALV_FIELDCATALOG_MERGE function is used to create a field catalog automatically.REUSE_ALV_GRID_DISPLAY is the function module that displays the data in an ALV grid format.Make sure to replace zexample_alv_mara with your actual program name and adjust the logic as needed for your specific requirements. Also, ensure that you have the necessary authorizations and access to tables MARA and MAKT.
The error message you encountered suggests that the parameter T_FIELDCAT isn't recognized in the REUSE_ALV_GRID_DISPLAY function call. This typically happens when the relevant SAP structures or internal tables are not declared or configured correctly.
Below are some steps and code adjustments to ensure everything is correctly defined:
Ensure SLIS Structures Are Used Properly:
SLIS) are correctly referenced in your program.Declare Type Pools:
SLIS type-pool, which contains definitions for structures used with ALV reports.Here is the corrected code with necessary declarations:
REPORT zexample_alv_mara.
TYPE-POOLS: slis.
TABLES: mara, makt.
TYPES: BEGIN OF ty_material,
matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
END OF ty_material.
DATA: it_material TYPE TABLE OF ty_material,
wa_material TYPE ty_material.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
PARAMETERS: p_matnr TYPE mara-matnr.
SELECT-OPTIONS: so_matnr FOR mara-matnr.
START-OF-SELECTION.
SELECT mara~matnr makt~maktx
INTO TABLE it_material
FROM mara
INNER JOIN makt
ON mara~matnr = makt~matnr
WHERE mara~matnr IN so_matnr
AND makt~spras = sy-langu.
IF it_material[] IS INITIAL.
MESSAGE 'No data found' TYPE 'I'.
EXIT.
ENDIF.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_MATERIAL'
i_structure_name = 'TY_MATERIAL'
CHANGING
ct_fieldcat = lt_fieldcat.
IF sy-subrc <> 0.
MESSAGE 'Error generating field catalog' TYPE 'E'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
TABLES
t_outtab = it_material
t_fieldcat = lt_fieldcat
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Error displaying ALV' TYPE 'E'.
ENDIF.
Type-Pool Declaration: The TYPE-POOLS statement includes SLIS, which is essential for using pre-defined types like slis_t_fieldcat_alv.
Field Catalog Parameter: lt_fieldcat should match the TYPE used in the REUSE_ALV_FIELDCATALOG_MERGE call (slis_t_fieldcat_alv).
Field Catalog Configuration: Ensure the function REUSE_ALV_FIELDCATALOG_MERGE specifies both the internal table and its corresponding structure.
By confirming these declarations and settings, you should resolve errors related to unknown function parameters in your ALV report.
Not yet included in a published release.