2014 Sep 23 2:49 PM
Dear experts,
I'm trying to display some data from simple csv-file in ALV as following:
DATA: BEGIN OF st_csv_data,
vkorg TYPE vkorg,
matnr TYPE matnr,
preis(10) TYPE c,
END OF st_csv_data.
DATA: ta_files TYPE filetable.
DATA: v_sysubrc TYPE sysubrc.
DATA: v_user_action TYPE i.
DATA: v_filename TYPE string.
DATA: v_record TYPE string.
DATA: ta_csv LIKE STANDARD TABLE OF v_record.
DATA: ta_csv_data TYPE STANDARD TABLE OF zst_preisupload,
wa_csv_data LIKE LINE OF ta_csv_data.
"ALV-Grid Paknum
DATA: alv_grid_csv TYPE REF TO cl_gui_alv_grid,
ccontainer_csv TYPE REF TO cl_gui_custom_container,
ta_field_catalog_csv TYPE lvc_t_fcat,
wa_field_catalog_csv LIKE LINE OF ta_field_catalog_csv,
st_layout_csv TYPE lvc_s_layo.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
PARAMETERS p_art TYPE rv13a-kschl.
PARAMETERS p_accseq TYPE v_t682i-kozgf.
PARAMETERS p_fname(4096) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
" Dateiselektor für Lokale Dateiauswahl
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
multiselection = abap_false
file_filter = '*.csv'
default_extension = 'csv'
CHANGING
file_table = ta_files
rc = v_sysubrc
user_action = v_user_action.
"Keine Kopfzeile bei ta_files
READ TABLE ta_files INTO p_fname INDEX 1.
START-OF-SELECTION.
v_filename = p_fname.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_filename
filetype = 'ASC'
TABLES
data_tab = ta_csv.
IF sy-subrc <> 0.
MESSAGE e000(z_preisupload).
ENDIF.
LOOP AT ta_csv INTO v_record.
"Ausblenden von Buchstaben sowie Sonderzeichen
REPLACE ALL OCCURRENCES OF REGEX '[^\d;,.]' IN v_record WITH ''.
IF sy-tabix = 1.
CONTINUE.
ENDIF.
SPLIT v_record AT ';'
INTO st_csv_data-vkorg
st_csv_data-matnr
st_csv_data-preis.
MOVE: st_csv_data-vkorg TO wa_csv_data-vkorg,
st_csv_data-matnr TO wa_csv_data-matnr,
st_csv_data-preis TO wa_csv_data-preis.
APPEND wa_csv_data TO ta_csv_data.
ENDLOOP.
CALL SCREEN 2000.
st_layout_csv-no_toolbar = 'X'.
st_layout_csv-no_headers = 'X'.
st_layout_csv-no_rowmark = 'X'.
st_layout_csv-zebra = 'X'.
st_layout_csv-sel_mode = 'D'.
st_layout_csv-cwidth_opt = 'X'.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'VkOrg'.
"wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'Material'.
"wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'Preis'.
"2wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
"Erstelle den Container für das spätere ALV
IF ccontainer_csv IS INITIAL.
CREATE OBJECT ccontainer_csv
EXPORTING
container_name = 'UPLOAD'.
"Erstelle das eigentliche ALV-Grid
CREATE OBJECT alv_grid_csv
EXPORTING
i_parent = ccontainer_csv.
ENDIF.
"Bereite das ALV auf die Darstellung vor
CALL METHOD alv_grid_csv->set_table_for_first_display
EXPORTING
is_layout = st_layout_csv
CHANGING
it_outtab = ta_csv_data
it_fieldcatalog = ta_field_catalog_csv.
ENDMODULE.
But I get the error PopUp "The fieldcatalog cannot be generated"
What do I do wrong?
Many thanks in advance
BR
Denis
2014 Sep 24 8:14 AM
Hi,
If you can try to use cl_salv_table .(No need for field catalog)
See http://wiki.scn.sap.com/wiki/display/Snippets/displaying+icons+in+alv+using+class+cl_salv_table or demo program that use this class .
- To use CL_GUI_ALV_GRID look at demo program in package SLIS.
- Use this search in google: site:help.sap.com CL_GUI_ALV_GRID
See chapter "Building Field Catalog Manually"
CLEAR ls_fcat .
ls_fcat-fieldname = 'CONNID' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_field = 'CONNID' .
APPEND ls_fcat to pt_fieldcat .
Regards.
2014 Sep 23 2:52 PM
type wa_field_catalog_csv-fieldname = 'VkOrg'. in capitals and check
wa_field_catalog_csv-fieldname = 'VKORG
and laso fill wa_field_catalog_csv- tabname '. with internal table name
2014 Sep 24 7:36 AM
what do you mean with this?:
and also fill wa_field_catalog_csv- tabname '. with internal table name
Should I somehow declare it or just write in the fieldcatalog part?
2014 Sep 23 3:18 PM
Hi Denis,
Looks like your fields are
MOVE: st_csv_data-vkorg TO wa_csv_data-vkorg,
st_csv_data-matnr TO wa_csv_data-matnr,
st_csv_data-preis TO wa_csv_data-preis.
VKORG, MATNR & PREIS
You should use fieldname as 'MATNR', 'VKORG' & 'PREIS' and also reference as internal table.
you mention as 'VkOrg' & 'Material' which is wrong.
Please Change and check.
Regards,
K.S.
2014 Sep 23 3:31 PM
Hi Denis
In your output table struecture - zst_preisupload
is the field names - 'VkOrg' & 'Material', 'preis' are valid? Kindly check it.
Secondly, the field names should be in Capital - in the field catalog section.
Example: 'preis' - should be 'PREIS' - same as other fields as well
Regards,
Venkat
2014 Sep 23 3:43 PM
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'VkOrg'.
wa_field_catalog_csv-fieldname = 'VKORG'.
"wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'Material'.
wa_field_catalog_csv-fieldname = 'MATNR'.
"wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'Preis'.
wa_field_catalog_csv-fieldname = 'PREIS'.
"2wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
2014 Sep 24 7:38 AM
2014 Sep 24 7:44 AM
Hi Denis,
Check the zst_preisupload Structure, Declare the same field name in capital letters,
Regards,
Venkat.
2014 Sep 24 7:56 AM
I use this structure:
And whateever I use here:
wa_field_catalog_csv-fieldname = Component or Data Type i keep getting the message:
"Field catalog not found"
2014 Sep 24 8:26 AM
Hi,
wa_field_catalog_csv-ref_table = 'ZST_PREISUPLOAD'.
wa_field_catalog_csv-ref_field = 'VKORG'.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-ref_table = 'ZST_PREISUPLOAD'.
wa_field_catalog_csv-ref_field = 'MATNR'.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-ref_table = 'ZST_PREISUPLOAD'.
wa_field_catalog_csv-ref_field = 'PREIS'.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
Try this and check whether it works.
Regards,
K.S.
2014 Sep 24 8:08 AM
Hi Denis,
Try,
wa_field_catalog_csv-fieldname = 'VKORG'.
wa_field_catalog_csv-seltext_m = 'Sales Organization'.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'MATNR'.
wa_field_catalog_csv-seltext_m = 'Material'.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
CLEAR wa_field_catalog_csv.
wa_field_catalog_csv-fieldname = 'PREIS'.
wa_field_catalog_csv-seltext_m = 'Proposed Amount'.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
Regards,
Venkat.
2014 Sep 24 8:14 AM
Hi,
If you can try to use cl_salv_table .(No need for field catalog)
See http://wiki.scn.sap.com/wiki/display/Snippets/displaying+icons+in+alv+using+class+cl_salv_table or demo program that use this class .
- To use CL_GUI_ALV_GRID look at demo program in package SLIS.
- Use this search in google: site:help.sap.com CL_GUI_ALV_GRID
See chapter "Building Field Catalog Manually"
CLEAR ls_fcat .
ls_fcat-fieldname = 'CONNID' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_field = 'CONNID' .
APPEND ls_fcat to pt_fieldcat .
Regards.
2014 Sep 24 9:04 AM
Hi Denis,
Also add col_pos and ref_tabname in field catalog internal table.
wa_field_catalog_csv-col_pos = 1
wa_field_catalog_csv-fieldname = 'VKORG'.
wa_field_catalog_csv-ref_tabname = 'VBAK'.
"wa_field_catalog_csv-edit = abap_true.
APPEND wa_field_catalog_csv TO ta_field_catalog_csv.
Please Change and check.