Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

2 Comments