Skip to Content
avatar image
Former Member

Issuw while downloading CSV file

Hi,

Need one help with the below issue.

We are using FM 'GUI_DOWNLOAD' to download CSV file but if we use double quote and comma simultaneously in any text field (for ex. 6"yard ,Machine) , so downloaded file is splitting this field and shifting the text after comma into the next column in the file , so subsequent field are shifted to the next columns.

Do we have any reason for this and suggest if there is any solution to handle this situation.

Regards,

Anup

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jan 01, 2015 at 01:42 PM

    Hi,

    Try this sample program .

    It using cl_gui_frontend_services=>gui_download.

    The output is tab separator.

    In excel:

    Regards.


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Eitan Rosenberg

      hi Eitan,

      Your solution solved the problem.

      I could be able to generate the file without any issue following the rules mentioned in the site.

      ------------------------------------------

      Sample source is attached for reference

      REPORT  ZR_CSV_DOWNLOAD.
      TYPES: BEGIN OF TY,
               MATNR TYPE MARA-MATNR,
               WERKS TYPE WERKS,
               LIFNR TYPE LIFNR,
               REMARKS TYPE C LENGTH 50,
              END OF TY.

      DATA: WA TYPE TY,
             WA1 TYPE TY,
             ITAB LIKE STANDARD TABLE OF WA,
             ITAB1 LIKE STANDARD TABLE OF WA.

      types truxs_t_text_data(4096) type c occurs 0.
      data: csv_converted_table type TRUXS_T_TEXT_DATA.

      data: tbuffer type table of string .

      data: buffer type string.

      field-symbols: <fs>.

      START-OF-SELECTION.

      WA-MATNR = 'mat'.
      WA-werks = 'unt'.
      WA-lifnr = 'lif'.
      WA-remarks = 'REMARKS'.
      APPEND WA TO ITAB.
      CLEAR WA.

      WA-MATNR = 'mat1'.
      WA-werks = 'unt1'.
      WA-lifnr = 'lif1'.
      WA-remarks = 'ITEM 6" yard, machine'.
      APPEND WA TO ITAB.
      CLEAR WA.

      WA-MATNR = 'mat2'.
      WA-werks = 'unt2'.
      WA-lifnr = 'lif2'.
      APPEND WA TO ITAB.
      CLEAR WA.

      WA-MATNR = 'mat3'.
      WA-werks = 'unt3'.
      WA-lifnr = 'lif3'.
      APPEND WA TO ITAB.
      CLEAR WA.

      DATA: SEPARATOR TYPE C VALUE ','.

      DATA: FNAME type SAPB-SAPPFAD VALUE 'TEST.CSV',
      cNAME type SAPB-SAPPFAD VALUE 'C:\TEST.CSV'.

      open dataset fname for output IN TEXT MODE ENCODING DEFAULT.

      loop at itab into wa.

         clear buffer.
         do.
           assign component sy-index of structure wa to <fs>.
           if sy-subrc <> 0.
             exit.
           endif.

           REPLACE ALL OCCURRENCES OF '"' IN <fs> WITH '""'.

           SEARCH <fs> for ','.
           IF SY-FDPOS NE 0.
              CONCATENATE '"' <fs>  INTO <fs>.
              CONCATENATE <fs> '"'  INTO <fs>.
           ENDIF.

           if sy-index = 1.
             buffer = <fs>.
           else.
             concatenate buffer <fs> into buffer separated by ','.
           endif.
         enddo.

         append buffer to tbuffer.

         TRANSFER buffer to fname.

      endloop.
      CLOSE DATASET fname.

      CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'
           EXPORTING
             path             = FNAME
            TARGETPATH        = CNAME
        EXCEPTIONS
          ERROR_FILE       = 1
          OTHERS           = 2
          .

  • Dec 31, 2014 at 11:35 AM

    Hi Anup,

    You can Use the SAP_CONVERT_TO_CSV_FORMAT Function Module to change the internal data information to csv format,

    and then the same data table you download through GUI_DOWNLOAD function module.

    Regards.

    Praveer.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 01, 2015 at 07:25 AM

    hi anup,

    since there is a comma in the text it is better you change delimiter to some other character then only it is possible to write correctly to the text file.

    Add comment
    10|10000 characters needed characters exceeded