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

Create an Excel File Using OPEN DATASET Command

Former Member
0 Likes
4,248

Hey, everyone.

How can I create an Excel file by using OPEN DATASET command ??

The file is created but the columns are no seperated like thay should.

I need to seperate the internal table's fields with a comma - How can I do it ?

Here's my code:

OPEN DATASET filename1 FOR OUTPUT IN TEXT MODE.

IF SY-SUBRC = 0.

LOOP AT gt_vend_info into gwa_vend_info.

TRANSFER gwa_vend_info TO filename1.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

Thanks in advance.

4 REPLIES 4
Read only

Former Member
0 Likes
1,323

Hi Beki,

Hope the gt_vend_info is having the data with comma separated and is a single string which you'll be writing into the file. In that case your internal table goes in as a line with fields separated with commas.

For writing it as a excel file (.csv file) try passing the filename1 as "try.csv" and check whether its working properly by creating a excel file.

Cheers

JK

Read only

0 Likes
1,323

For ur requirement, one way,what we can do is :

a) open the file using open dataset.

b) read and load it into internal table.

c) save this internal table to front-end

using GUI_DOWNLOAD.

D) then again read the file

using GUI_UPLOAD

Read only

0 Likes
1,323

Hi,

make these changes to the above code.

OPEN DATASET filename1 FOR OUTPUT IN TEXT MODE.
IF SY-SUBRC = 0.
LOOP AT <b>itab1</b> into <b>wa_itab</b>.
TRANSFER <b>wa_itab</b> TO filename1.
IF SY-SUBRC <> 0.
EXIT.ENDIF.
ENDLOOP.
ENDIF.

just modify my above code..

regards

vijay

Read only

Former Member
0 Likes
1,323

Hi Beki,


REPORT  ZTESTAA.

TYPE-POOLS:TRUXS.
DATA: BEGIN OF ITAB OCCURS 0,
      VBELN LIKE VBAP-VBELN,
      POSNR LIKE VBAP-POSNR,
      END OF ITAB.
DATA:
ITAB1 TYPE TRUXS_T_TEXT_DATA.
SELECT  VBELN
        POSNR
     UP TO 10 ROWS
     FROM VBAP
     INTO TABLE ITAB.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
  EXPORTING
    I_FIELD_SEPERATOR    = ';'
  TABLES
    I_TAB_SAP_DATA       = ITAB
  CHANGING
    I_TAB_CONVERTED_DATA = ITAB1
  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.
OPEN DATASET filename1 FOR OUTPUT IN TEXT MODE.
IF SY-SUBRC = 0.
LOOP AT gt_vend_info into gwa_vend_info.
TRANSFER gwa_vend_info TO filename1.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.

the above code give CSV format file, all fields will be separated by ';'

Regards

vijay