Skip to Content

Create CSV to send it via cl_bsc

Hallo,

I try to make a csv by:

*...
  LOOP AT t_sflight INTO wa_sflight.
      CONCATENATE "cl_abap_char_utilities=>CR_LF
                  wa_sflight-carrid
                  wa_sflight-connid
                  wa_sflight-fldate
                  wa_sflight-currency
                  wa_sflight-planetype
             INTO xls_file SEPARATED BY ';'.

      APPEND xls_file TO t_content_text.
    ENDLOOP.


    ca_attachment_header-line = 'MyFile.csv'.
    APPEND ca_attachment_header TO ca_t_attachment_header.

    CLEAR ca_documents.
    CLEAR content.


    ca_documents-type = 'csv'.           

*...

The Problem is, all data sets are in the first row...

kind regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Apr 14, 2011 at 02:28 PM

    You need to add the CR_LF at the end. You should also consider encapsulating your field values with double-quotes and using a string -> xstring -> binary format to attach/send the file.

    Add a comment
    10|10000 characters needed characters exceeded

    • I've never had that issue, nor do I need the new line character as the other poster suggested. Here is some older code that I still use in an email class. The binary conversion could be updated with some newer syntax and done without the functions.

      
      ...
      
      * Now add the internal table to the string
        LOOP AT ATTACH ASSIGNING <FS_LINE>.
      
          DO.
      
      *     Access each component of the structure
            ASSIGN COMPONENT SY-INDEX OF STRUCTURE <FS_LINE> TO <FS_FIELD>.
            IF SY-SUBRC NE 0.
              EXIT.
            ENDIF.
      
      *     Add the field to the line
            IF SY-INDEX EQ 1.
              CONCATENATE '"' <FS_FIELD> '"' INTO LV_CSV_STRING.
            ELSE.
              CONCATENATE LV_CSV_STRING
                          ','
                          '"'
                          <FS_FIELD>
                          '"'
                          INTO LV_CSV_STRING.
            ENDIF.
      
          ENDDO.
      
          CONCATENATE LV_CSV_STRING_FULL
                      LV_CSV_STRING
                      CL_ABAP_CHAR_UTILITIES=>CR_LF INTO LV_CSV_STRING_FULL.
      
        ENDLOOP.
      
      ...
      
            CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
              EXPORTING
                TEXT     = LV_CSV_STRING_FULL
                MIMETYPE = 'CSV'
              IMPORTING
                BUFFER   = LV_CSV_XSTRING
              EXCEPTIONS
                FAILED   = 1
                OTHERS   = 2.
      
            CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
              EXPORTING
                BUFFER        = LV_CSV_XSTRING
              IMPORTING
                OUTPUT_LENGTH = LV_LEN
              TABLES
                BINARY_TAB    = LT_CSVBIN.
      
      

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.