Writing Excel file into Application Server using horizontal tab
For writing a file in Application server we can use DATASET. Normally what we are doing is concatenating all the values into sequential string and transfer it into the file created in server using OPEN DATASET. But if we want to create an excel file, then the complete concatenated values will be placed in a single box of excel file. So here we need to separate each data into columns. To achieve this we can use horizontal tab.
TYPES: BEGIN OF ty_final1,
findata(2000) TYPE c,
END OF ty_final1.
DATA : gs_final TYPE ty_final1,
gt_final TYPE STANDARD TABLE OF ty_final1.
DATA : hex(1) TYPE c VALUE ‘,’. “Tab Space
DATA: tab TYPE x VALUE 9,
htab(1) TYPE c.
htab = cl_abap_char_utilities=>horizontal_tab.
DATA : snetpr TYPE string.
LOOP AT t_vbap.
snetpr = t_vbap-netpr.
CONCATENATE t_vbap-vbeln
t_vbap-matnr
t_vbap-waerk
snetpr
t_vbap-meins INTO gs_final-findata SEPARATED BY htab.
APPEND gs_final TO gt_final.
CLEAR : gs_final.
ENDLOOP.
WAIT UP TO 1 SECONDS.
DATA : lv_dsn(100) TYPE c,
lv_vbeln TYPE vbeln_vl,
lv_date TYPE d,
lv_time TYPE t.
lv_date = sy-datum.
lv_time = sy-uzeit.
lv_dsn = p_file.
CONCATENATE lv_dsn lv_date lv_time ‘.XLS’ INTO lv_dsn.*
OPEN DATASET lv_dsn FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH
SMART LINEFEED.
IF sy-subrc = 0.
LOOP AT gt_final INTO gs_final.
TRANSFER gs_final TO lv_dsn.
CLEAR t_vbap.
ENDLOOP.
ENDIF.
CLOSE DATASET lv_dsn.
Output :-
Thanks …..
Anoop Satheesan
Thanks Anoop for the blog.I used the above information to write a file on to the application server(using OPEN DATASET) in excel format.
However the only problem Im facing is some of the data in the file is in Chinese language and those show up as junk characters in the column of the excel file.
I'm using the following syntax:
OPEN DATASET par_unix FOR OUTPUT IN TEXT MODE ENCODING UTF-8 MESSAGE lv_msg WITH WINDOWS LINEFEED.
Any pointers what am I missing?
How to create XLSX file?