cancel
Showing results for 
Search instead for 
Did you mean: 

Table data is displaying and fielld catalog is not showing in alv format

Junaidshaik284
Participant
0 Kudos

I just converted excel to internal table but field catalog is not showing in final internal table. I used lvc_fieldcatlog_merge function module to get field catalog and i declared structure as locally and I need to include structure and tell anyway to display field catalog and I used factory method to display alv report.

TYPES : BEGIN OF d_emp,
name(10) TYPE c,
address(10) TYPE c,
age(10) TYPE c,
gender(10) TYPE c,
END OF d_emp.
DATA : w_path1(60) TYPE c,
t_emp TYPE TABLE OF d_emp,
wa_emp TYPE d_emp,
w_file TYPE string,
t_trux TYPE truxs_t_text_data,
t_trux1 TYPE truxs_t_text_data,
w_directory(30) TYPE c VALUE 'D:\usr\sap\LD7\SYS\src',
w_string TYPE string,
o_alv type ref to cl_salv_table,
t_fieldcat type LVC_T_FCAT,
wa_fieldcat type LVC_S_FCAT.
wa_fieldcat-col_pos = 1.
wa_fieldcat-scrtext_l = 'NAME'.
APPEND WA_FIELDCAT TO T_FIELDCAT.
CLEAR WA_FIELDCAT.
wa_fieldcat-col_pos = 2.
wa_fieldcat-scrtext_l = 'ADDRESS'.
APPEND WA_FIELDCAT TO T_FIELDCAT.
CLEAR WA_FIELDCAT.
wa_fieldcat-col_pos = 3.
wa_fieldcat-scrtext_l = 'AGE'.
APPEND WA_FIELDCAT TO T_FIELDCAT.
CLEAR WA_FIELDCAT.
wa_fieldcat-col_pos = 4.
wa_fieldcat-scrtext_l = 'GENDER'.
APPEND WA_FIELDCAT TO T_FIELDCAT.
CLEAR WA_FIELDCAT.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'D_EMP'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = T_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CONSTANTS : w_path(30) TYPE c VALUE 'D:\usr\sap\LD7\SYS\src\JUNEED',
w_text(10) TYPE c VALUE '.TXT'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file1 TYPE localfile,
p_file2 TYPE rlgrap-filename,
r1 RADIOBUTTON GROUP rad1 DEFAULT 'X',
r2 RADIOBUTTON GROUP rad1.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
*F4 help for file name on Presentation Server.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2.
*F4 help for file name on SAP application server
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = w_directory
IMPORTING
serverfile = p_file2
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Error Message' TYPE 'I'.
ENDIF.

START-OF-SELECTION.
AT SELECTION-SCREEN ON RADIOBUTTON GROUP rad1.



IF r1 = 'X'.
w_file = p_file1. " type casting.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = t_trux
i_filename = p_file1
* I_STEP = 1
TABLES
i_tab_converted_data = t_emp[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
WRITE : w_path1.
CONCATENATE w_path sy-datum sy-uzeit w_text INTO w_path1 IN CHARACTER MODE.
OPEN DATASET w_path1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
LOOP AT t_emp ASSIGNING FIELD-SYMBOL(<fs_emp>).
CONCATENATE <fs_emp>-name <fs_emp>-address <fs_emp>-age <fs_emp>-gender INTO w_string SEPARATED BY ','.
TRANSFER w_string TO w_path1.
ENDLOOP.
CLOSE DATASET w_path1.
ELSE.
MESSAGE 'error' TYPE 'E'.
ENDIF.




CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = t_emp
.
CALL METHOD o_alv->display.

ELSEIF r2 = 'X'.
write 'UnderMaintainence'.
ENDIF.
raymond_giuseppi
Active Contributor

Did you expect that cl_salv_table would find your field catalog by itself. Perform some search on methods CL_SAL_TABLE->GET_COLUMNS and CL_SALV_COLUMNS_TABLE->SET_COLUMN_POSITION.

Junaidshaik284
Participant
0 Kudos

It automatically creates field catalog b

Accepted Solutions (0)

Answers (2)

Answers (2)

xiswanto
Active Participant
0 Kudos

some issue with your coding:

1. d_emp is inline declared type, which I think will not be found using the FM LVC_FIELDCATALOG_MERGE, unless you create it from SE11, not inline code.
2. you are using the OO alv, which automatically created the fieldcat. If you do need to additional ALV column, you could use the method add_column, after getting the value through method get_columns.

Junaidshaik284
Participant
0 Kudos

yeah it automatically creates field catalog right