Skip to Content
author's profile photo
Former Member

Inseting tabs when using open dataset statement

I need to write a file to application server, and i wanted it to be a excel file.

I tried binary mode, text mode but i am not able to print the tab charater in the file.

any suggestions to print the tab charater?

thanks,

Gopi.

CODE:

v_file = "/usr/test.xls".

OPEN DATASET v_file FOR OUTPUT in binary mode.

LOOP AT i_hr.

  • move-corresponding i_hr to i_out.

  • TRANSFER i_out TO v_file.

transfer i_out-pernr to v_file.

transfer '\t' to v_file.

transfer i_out-nachn to v_file.

transfer '\t' to v_file.

transfer i_out-vorna to v_file.

TRANSFER '\n' TO v_file.

ENDLOOP.

CLOSE DATASET v_file.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Posted on Jan 18, 2005 at 08:02 PM

    Hi Gopi,

    You can do it by declaring another variable with a length that can accommodate your internal table fields and the tabs in between. Change your code as follows(in bold).

    <b><i>data: v_filerecord(1000) type c.
    constants: c_tab_delimiter type x value '09'.</i></b>
    
    v_file = "/usr/test.xls".
    
    OPEN DATASET v_file FOR OUTPUT in binary mode.
    LOOP AT i_hr.
    <b><i>
    concatenate i_hr-field1
                i_hr-field2
    ....... and so on for all fields
           into v_filerecord separated by c_tab_delimiter.
    transfer v_filerecord to v_file.
    </i></b>
    * move-corresponding i_hr to i_out.
    * TRANSFER i_out TO v_file.
    *transfer i_out-pernr to v_file.
    *transfer 't' to v_file.
    *transfer i_out-nachn to v_file.
    *transfer 't' to v_file.
    *transfer i_out-vorna to v_file.
    
    *TRANSFER 'n' TO v_file.
    ENDLOOP.
    CLOSE DATASET v_file.
    

    Please let me know if you need any further help in this regard. If it solves your problem, please reward and close the issue.

    Regards,

    Srinivas

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Gopi,

      Glad to see that your issue has been resolved. If not, I was about to suggest that you define another internal table as follows and use that for download.

      begin itab

      field1

      tabseparator1

      field2

      tabseparator2

      end itab.

      and so on...

      Now that you resolved your issue, could you please reward and close the issue?

      Thanks,

      Srinivas

  • author's profile photo
    Former Member
    Posted on Jan 18, 2005 at 08:14 PM

    Try this piece of coding. I think it will work for you.

    REPORT ZTAB_IN_FILE .

    data: separator type x value '09'.

    data: field1(10) type c,

    field2(8) type c,

    field3(6) type c.

    data: wa_ausgabe(30) type c.

    data: lv_file type rlgrap-filename value 'tab_test.xls'.

    start-of-selection.

    field1 = 'Schmitt'.

    field2 = 'Ludwig'.

    field3 = 'Firma'.

    concatenate field1 separator

    field2 separator

    field3

    into wa_ausgabe.

    open dataset lv_file for output in text mode.

    transfer wa_ausgabe to lv_file.

    transfer wa_ausgabe to lv_file.

    close dataset lv_file.

    • I know, coding needs a little more for being cute

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 19, 2005 at 09:01 AM

    Hi Gopi,

    unchecked unicode is just a workaround. If you are interested in a solution, have a look at ascii-value

    In short: define a separator as char1 and fill in value like this:

    CLASS cl_abap_char_utilities DEFINITION LOAD.
    wa_line-sep01 = l_abap_char_utilities=>horizontal_tab.
    

    Regards,

    Christian

    Add comment
    10|10000 characters needed characters exceeded