<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using CL_FDT_XL_SPREADSHEET class for a .CSV XSTRING in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723897#M2019954</link>
    <description>&lt;P&gt;I have a program that maintains custom Z tables by exporting the table to an excel spreadsheet and it also refreshes the table and updates from an excel spreadsheet with .XSLX.&lt;/P&gt;
  &lt;P&gt;The upload to SAP from .XLSX is done with the CL_GUI_FRONTEND_SERVICES=&amp;gt;GUI_UPLOAD method to get the raw data. Then converted to XSTRING and passed into the CL_FDT_XL_SPREADSHEET class and the IF_FDT_DOC_SPREADSHEET~GET_ITAB_FROM_WORKSHEET method is called to pass that data to a variable where it is used in another method to upload to SAP. This works fine.&lt;/P&gt;
  &lt;P&gt;However, I also want the program to ALSO accept .CSV files.&lt;/P&gt;
  &lt;P&gt;I use the CL_GUI_FRONTEND_SERVICES=&amp;gt;GUI_UPLOAD method to get the raw data, but when I try to convert the raw data to an XSTRING, an error is thrown.&lt;/P&gt;
  &lt;P&gt;My question: Is the CL_FDT_XL_SPREADSHEET class suitable for .CSV file raw data or is it only suitable for .XLSX files? If it is, can anyone see where I am going wrong or where I can fix this?&lt;/P&gt;
  &lt;P&gt;I have played around with the CL_RSDA_CSV_CONVERTER but the 'rt_table' variable that is returned is a TYPE REF TO data which is used in another method that's written which converts excel to SAP table where it refreshes and updates the table. When I try to populate that with the CSV conversion, it obvioulsy doesn't like it&lt;/P&gt;
  &lt;P&gt;Code:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;&amp;lt;code&amp;gt;METHOD import_excel_data.

    DATA: lt_xtab TYPE cpt_x255,
          lv_size TYPE i.

    IF i_filetype = abap_true. "******.XLSX UPLOAD*********
      cl_gui_frontend_services=&amp;gt;gui_upload( EXPORTING filename   = i_file
                                                      filetype   = 'BIN'
                                            IMPORTING filelength = lv_size
                                             CHANGING data_tab   = lt_xtab
                                             EXCEPTIONS
                                                      file_open_error = 1
                                                      file_read_error = 2
                                                      error_no_gui            = 3
                                                      not_supported_by_gui    = 4
                                                      OTHERS                  = 5 ).
      IF sy-subrc &amp;lt;&amp;gt; 0.
        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
      ENDIF.
    ELSE."******.CSV UPLOAD*********

      cl_gui_frontend_services=&amp;gt;gui_upload( EXPORTING filename   = i_file
                                                      filetype   = 'ASC'
                                                      has_field_separator = abap_true
                                            IMPORTING filelength = lv_size
                                            CHANGING data_tab   = lt_xtab
                                            EXCEPTIONS
                                                    file_open_error = 1
                                                    file_read_error = 2
                                                    error_no_gui            = 3
                                                    not_supported_by_gui    = 4
                                                    OTHERS                  = 5 ).
      IF sy-subrc &amp;lt;&amp;gt; 0.
        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
      ENDIF.

    ENDIF.

    cl_scp_change_db=&amp;gt;xtab_to_xstr( EXPORTING im_xtab    = lt_xtab
                                              im_size    = lv_size
                                    IMPORTING ex_xstring = DATA(lv_xstring) ).

    DATA(lo_excel) = NEW cl_fdt_xl_spreadsheet( document_name = i_file
                                                xdocument     = lv_xstring ).
    lo_excel-&amp;gt;if_fdt_doc_spreadsheet~get_worksheet_names(
      IMPORTING worksheet_names = DATA(lt_worksheets) ).

    rt_table = lo_excel-&amp;gt;if_fdt_doc_spreadsheet~get_itab_from_worksheet( lt_worksheets[ 1 ] ).

    IF rt_table IS INITIAL.
      RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = 'No Data found in Excel File' ##no_text.
    ENDIF. &lt;/CODE&gt;&lt;/PRE&gt; 
  &lt;P&gt; ENDMETHOD.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2022 21:04:38 GMT</pubDate>
    <dc:creator>MattRook</dc:creator>
    <dc:date>2022-12-07T21:04:38Z</dc:date>
    <item>
      <title>Using CL_FDT_XL_SPREADSHEET class for a .CSV XSTRING</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723897#M2019954</link>
      <description>&lt;P&gt;I have a program that maintains custom Z tables by exporting the table to an excel spreadsheet and it also refreshes the table and updates from an excel spreadsheet with .XSLX.&lt;/P&gt;
  &lt;P&gt;The upload to SAP from .XLSX is done with the CL_GUI_FRONTEND_SERVICES=&amp;gt;GUI_UPLOAD method to get the raw data. Then converted to XSTRING and passed into the CL_FDT_XL_SPREADSHEET class and the IF_FDT_DOC_SPREADSHEET~GET_ITAB_FROM_WORKSHEET method is called to pass that data to a variable where it is used in another method to upload to SAP. This works fine.&lt;/P&gt;
  &lt;P&gt;However, I also want the program to ALSO accept .CSV files.&lt;/P&gt;
  &lt;P&gt;I use the CL_GUI_FRONTEND_SERVICES=&amp;gt;GUI_UPLOAD method to get the raw data, but when I try to convert the raw data to an XSTRING, an error is thrown.&lt;/P&gt;
  &lt;P&gt;My question: Is the CL_FDT_XL_SPREADSHEET class suitable for .CSV file raw data or is it only suitable for .XLSX files? If it is, can anyone see where I am going wrong or where I can fix this?&lt;/P&gt;
  &lt;P&gt;I have played around with the CL_RSDA_CSV_CONVERTER but the 'rt_table' variable that is returned is a TYPE REF TO data which is used in another method that's written which converts excel to SAP table where it refreshes and updates the table. When I try to populate that with the CSV conversion, it obvioulsy doesn't like it&lt;/P&gt;
  &lt;P&gt;Code:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;&amp;lt;code&amp;gt;METHOD import_excel_data.

    DATA: lt_xtab TYPE cpt_x255,
          lv_size TYPE i.

    IF i_filetype = abap_true. "******.XLSX UPLOAD*********
      cl_gui_frontend_services=&amp;gt;gui_upload( EXPORTING filename   = i_file
                                                      filetype   = 'BIN'
                                            IMPORTING filelength = lv_size
                                             CHANGING data_tab   = lt_xtab
                                             EXCEPTIONS
                                                      file_open_error = 1
                                                      file_read_error = 2
                                                      error_no_gui            = 3
                                                      not_supported_by_gui    = 4
                                                      OTHERS                  = 5 ).
      IF sy-subrc &amp;lt;&amp;gt; 0.
        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
      ENDIF.
    ELSE."******.CSV UPLOAD*********

      cl_gui_frontend_services=&amp;gt;gui_upload( EXPORTING filename   = i_file
                                                      filetype   = 'ASC'
                                                      has_field_separator = abap_true
                                            IMPORTING filelength = lv_size
                                            CHANGING data_tab   = lt_xtab
                                            EXCEPTIONS
                                                    file_open_error = 1
                                                    file_read_error = 2
                                                    error_no_gui            = 3
                                                    not_supported_by_gui    = 4
                                                    OTHERS                  = 5 ).
      IF sy-subrc &amp;lt;&amp;gt; 0.
        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
      ENDIF.

    ENDIF.

    cl_scp_change_db=&amp;gt;xtab_to_xstr( EXPORTING im_xtab    = lt_xtab
                                              im_size    = lv_size
                                    IMPORTING ex_xstring = DATA(lv_xstring) ).

    DATA(lo_excel) = NEW cl_fdt_xl_spreadsheet( document_name = i_file
                                                xdocument     = lv_xstring ).
    lo_excel-&amp;gt;if_fdt_doc_spreadsheet~get_worksheet_names(
      IMPORTING worksheet_names = DATA(lt_worksheets) ).

    rt_table = lo_excel-&amp;gt;if_fdt_doc_spreadsheet~get_itab_from_worksheet( lt_worksheets[ 1 ] ).

    IF rt_table IS INITIAL.
      RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = 'No Data found in Excel File' ##no_text.
    ENDIF. &lt;/CODE&gt;&lt;/PRE&gt; 
  &lt;P&gt; ENDMETHOD.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 21:04:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723897#M2019954</guid>
      <dc:creator>MattRook</dc:creator>
      <dc:date>2022-12-07T21:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using CL_FDT_XL_SPREADSHEET class for a .CSV XSTRING</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723898#M2019955</link>
      <description>&lt;P&gt;Please read the comments to this blog post, this class should not be used at all: &lt;A href="https://blogs.sap.com/2021/04/25/excel-upload-and-download-program-with-multiple-tabs-from-fiori-lauch-padweb-gui/" target="test_blank"&gt;https://blogs.sap.com/2021/04/25/excel-upload-and-download-program-with-multiple-tabs-from-fiori-lauch-padweb-gui/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;CSV and XLSX are very different formats and there is no standard class that would handle both. Whenever an "ABAP and Excel" blog post comes up here (and it happens monthly), people mention &lt;A href="https://github.com/abap2xlsx/abap2xlsx"&gt;ABAP2XLSX&lt;/A&gt; &lt;/P&gt;&lt;P&gt;It does have an option to write into CSV and maybe you could submit a suggestion to read CSV.&lt;/P&gt;&lt;P&gt;Since it sounds like this program was designed specifically for Excel format and relies on specific type provided by that class, you will run into a lot of refactoring required in the "update SAP" part. At this point I would reconsider if the effort is worth it.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 06:03:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723898#M2019955</guid>
      <dc:creator>Jelena_Perfiljeva</dc:creator>
      <dc:date>2023-01-06T06:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using CL_FDT_XL_SPREADSHEET class for a .CSV XSTRING</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723899#M2019956</link>
      <description>&lt;P&gt;Thanks for your well informed and clear answer.&lt;/P&gt;&lt;P&gt;I shall save and read through those blogs.&lt;/P&gt;&lt;P&gt;I have fixed the issue now by utilising the cl_rsda_csv_converter class and specifically the csv_to_structure method. Obviously a bit more to it but they are crux of it.&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 20:45:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-cl-fdt-xl-spreadsheet-class-for-a-csv-xstring/m-p/12723899#M2019956</guid>
      <dc:creator>MattRook</dc:creator>
      <dc:date>2023-01-15T20:45:12Z</dc:date>
    </item>
  </channel>
</rss>

