Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

File Conversion from .xlsx to .csv format

Former Member
0 Likes
8,797

Hi Experts,

I have one file in application server which is present in .xlsx format, now i want to convert .xlsx to .csv format.

Please guide me.

Hi Experts,

I have one file in application server which is present in .xlsx format, now i want to convert .xlsx to .csv format.

Please guide me.

9 REPLIES 9
Read only

Former Member
0 Likes
4,180

Hi Ravi,

Try something like this.

Get the .xlsx contents from Application Server to the an Internal Table using the Open/Read/Close Datasets. And then convert the Internal table to .csv using the function module SAP_CONVERT_TO_CSV_FORMAT or you can also download the internal table using the GUI_DOWNLOAD by changing the file name with .csv extension.

Regards,

AyyamPerumal


Read only

0 Likes
4,180

Hi

Gui_download wont work if the file is present in application server.

Using internal table is not possible I have tried  it.previously

Read only

0 Likes
4,180

This message was moderated.

Read only

former_member209120
Active Contributor
0 Likes
4,180

Hi  Ravi Chandra

Try like this

REPORT  ytest.

********* Pools
TYPE-POOLS: truxs.

********* Types
TYPES : BEGIN OF ty_itab,
         matnr TYPE rmmg1-matnr,
         bismt TYPE mara-bismt,
         END OF ty_itab.

********** Internal Table Declaration
DATA : it_itab    TYPE TABLE OF ty_itab,
        it_raw     TYPE truxs_t_text_data,
        it_final   TYPE truxs_t_text_data.
********** Work Area Declaration
DATA : wa_itab    TYPE ty_itab.

********** Variable Declaration
DATA : p_file1    TYPE string.

********** Selection Screen
PARAMETER: p_file TYPE rlgrap-filename OBLIGATORY.

********** Getting Excel File at Selection Screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
   PERFORM f4_file.

********** Start of selection
START-OF-SELECTION.
   IF  it_itab IS NOT INITIAL.

*    CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
*     EXPORTING
*       i_field_seperator          = ' '
**   I_LINE_HEADER              =
**   I_FILENAME                 =
**   I_APPL_KEEP                = ' '
*      TABLES
*        i_tab_sap_data             = it_itab
*     CHANGING
*       i_tab_converted_data       =   it_final
** EXCEPTIONS
**   CONVERSION_FAILED          = 1
**   OTHERS                     = 2
*              .
*    IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*    ENDIF.

     CALL FUNCTION 'GUI_DOWNLOAD'
       EXPORTING
*   BIN_FILESIZE                    =
     filename                        = 'D:/test.csv'
     write_field_separator           = 'X'
       TABLES
         data_tab                        it_itab.

     IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.


   ENDIF.

*&---------------------------------------------------------------------*
*&      Form  F4_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f4_file .

   CALL FUNCTION 'F4_FILENAME'
          EXPORTING
            program_name        = syst-cprog
            dynpro_number       = syst-dynnr
*   FIELD_NAME          = ' '
          IMPORTING
            file_name           = p_file.

   p_file1 = p_file.

   IF p_file1 IS NOT INITIAL.

     CALL FUNCTION 'GUI_UPLOAD'
       EXPORTING
         filename            = p_file1
         filetype            = 'ASC'
         has_field_separator = '#'
       TABLES
         data_tab            = it_raw.

     CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
       EXPORTING
         i_field_seperator    = 'X'
         i_line_header        = 'X'
         i_tab_raw_data       = it_raw
         i_filename           = p_file
       TABLES
         i_tab_converted_data = it_itab
       EXCEPTIONS
         conversion_failed    = 1
         OTHERS               = 2.
     IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ENDIF.
   ENDIF.

ENDFORM.                    " F4_FILE

See this thread for further information
http://scn.sap.com/message/3281554

Read only

Former Member
0 Likes
4,180

Hi Ravi,

If the file present in presentation server then we can use GUI_Download fm.

But if the file present in application server the we use the following syntax to read or write data into files.,

OPEN DATASET<file-name>FOR <input/output/append>IN TEXT MODE ENCODING DEFAULT.

READ DATASET<file name> INTO <variable>

TRANSFER<variable>TO <filename>

CLOSE DATASET<filename>

Incase of OPENDATASET the INPUT means the file is opened for reading the data from file.

                                            Output means the file is opened for writing the data into file.

                                        append    means the file is opened for appending new records into the fil

Transaction code AL11 is used to find the directories in application server.

The default directories which we generally used are,  DIR_HOME, DIR_NAME, DIR_TEMP

Read only

0 Likes
4,180

Hi Ajith,

Using dataset it is not possible to read the .xlsx format file.

I have tried using

open dataset in binary mode also , still not working....

Read only

0 Likes
4,180

Hi Ajith,

The above prog. won't if the file is present in .xlsx format , i have tried it long back.

Read only

Former Member
0 Likes
4,180

Hi,

Use the Program: RN2LN205N

Then Edit->Execute Command->Provide unix Command

cp <source complete path/filename> <destination complete path/filename> : Copy to New

mv <source complete path/filename> <destination complete path/filename>   : Move/ Rename

Thanks,

Kiran.

Read only

praveenboss
Participant
0 Likes
4,180

HI Ravi,

  You Can Convert this  by reading zlsx data into internal table

    and then through internal table u can save your data into csv file.

 

   PLEASE SEE THESE LINKS

  http://scn.sap.com/thread/1918265

How to create .csv file from ABAP report http://stackoverflow.com/questions/17483260/how-to-save-sap-internal-table-to-sap-directory-as-csv-f...

                                                 THANKS

                                                  PRAVEEN