Application Development 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: 

Convert lines of itab into csv

Former Member
0 Kudos

Hi!

I have an itab with many lines and want to save this itab to a file as csv. That means, that the fields of the structure the table consists of should be separated by a comma, not the lines!

I found the solution in this forum, the function 'SAP_CONVERT_TO_CSV_FORMAT' should do this!

But on our system this function is missing!? Is there a class which can do this conversion?

Thanks

Manfred

Edited by: Manfred Fettinger on Sep 18, 2009 2:37 PM

6 REPLIES 6

Former Member
0 Kudos

Hi,

Are you on ECC 6?

Regards,

Vikranth

0 Kudos

Hi!

I am not sure what you mean with ECC 6!?

brgds

manfred

0 Kudos

Hi,

Thats one of the versions of SAP in which the FM SAP_CONVERT_TO_CSV_FORMAT was considered obsolete and removed.

Anyway if its not available in your system have a look at erik's final post in this thread. That should be useful

[]

Regards,

Vikranth

Former Member
0 Kudos

what version of SAP you are using?

system->status : component version : SAP ECC 6.0 or SAP 4.6c etc

0 Kudos

Hi!

Its SAP EHP 1 for SAP NetWeaver 7.0

Ok, it looks like i have it to implement my own. Thanks to max bianchi for the code example!

Former Member
0 Kudos

Hi

Which is your release?

Anyway this is a method I've developed for my reports:

CLASS LC_FILE DEFINITION.
    ......
    CLASS-METHODS: INSERT_SEPARATOR_CHAR
                                     IMPORTING
                                          SEPARATOR TYPE STRING
                                          RECORD_IN TYPE ANY
                                          NO_GAPS   TYPE C DEFAULT SPACE
                                     EXPORTING
                                          RECORD_OUT  TYPE STRING.
     ..........
ENDCLASS.

.CLASS LC_FILE IMPLEMENTATION.
  METHOD INSERT_SEPARATOR_CHAR.

    FIELD-SYMBOLS: <FS_FIELD> TYPE ANY.

    DATA: WA_STRING(10000) TYPE C,
          WA_VALUE(1000)   TYPE C.

    DATA: LEN_SEPAR  TYPE I,
          LEN_FIELD  TYPE I,
          LEN_STRING TYPE I,
          LEN_VALUE  TYPE I.

    DATA: TYPE_FIELD TYPE C.

    LEN_SEPAR = STRLEN( SEPARATOR ).

    DO.
      ASSIGN COMPONENT SY-INDEX OF STRUCTURE RECORD_IN TO <FS_FIELD>.
      IF SY-SUBRC <> 0. EXIT. ENDIF.

*      DESCRIBE FIELD <FS_FIELD> LENGTH LEN_FIELD IN CHARACTER MODE
*                      TYPE TYPE_FIELD.
      DESCRIBE FIELD <FS_FIELD> LENGTH LEN_FIELD IN BYTE MODE
                      TYPE TYPE_FIELD.
      IF TYPE_FIELD = 'g'.
        LEN_FIELD = STRLEN( <FS_FIELD> ).
      ENDIF.

      CLEAR WA_VALUE.

      WRITE: <FS_FIELD> TO WA_VALUE(LEN_FIELD),
             <FS_FIELD> TO WA_STRING+LEN_STRING(LEN_FIELD).
      LEN_VALUE  = STRLEN( WA_VALUE ).

      IF NOT NO_GAPS IS INITIAL.
        LEN_FIELD = LEN_VALUE.
      ENDIF.

      LEN_STRING = LEN_STRING + LEN_FIELD.
      WRITE: SEPARATOR(LEN_SEPAR) TO WA_STRING+LEN_STRING.

      LEN_STRING = LEN_STRING + LEN_SEPAR.
    ENDDO.

    LEN_STRING = STRLEN( WA_STRING ).
    MOVE WA_STRING(LEN_STRING) TO RECORD_OUT.

  ENDMETHOD.                    "INSERT_SEPARATOR_CHAR
  ............
ENDCLASS.

.

Some stataments are adjusted for rel ECC 6.00

Max