Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Writing Excel file into Application Server using horizontal tab

$
0
0

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: BEGINOF ty_final1,
            findata(
2000) TYPEc,
          
ENDOF ty_final1.
          
   
DATA  :  gs_final  TYPE ty_final1,
             gt_final 
TYPESTANDARDTABLEOF ty_final1.

   
DATA : hex(1) TYPEcVALUE','. "Tab Space
   
DATA: tab TYPExVALUE9,
    htab(
1) TYPEc.
    htab = cl_abap_char_utilities=>horizontal_tab.

   
DATA : snetpr TYPE string.

   
LOOPAT t_vbap.
      snetpr = t_vbap-netpr.

     
CONCATENATE t_vbap-vbeln
                  t_vbap-matnr
                  t_vbap-waerk
                  snetpr
                  t_vbap-meins 
INTO  gs_final-findata SEPARATEDBY htab.


     
APPEND gs_final TO gt_final.
     
CLEAR : gs_final.

   
ENDLOOP.

   
WAITUPTO1 SECONDS.
   
DATA  :  lv_dsn(100) TYPEc,
             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.*
   
OPENDATASET lv_dsn FOROUTPUTINTEXTMODEENCODINGDEFAULTWITH
     SMART LINEFEED.
   
IF sy-subrc = 0.
     
LOOPAT gt_final INTO gs_final.
       
TRANSFER gs_final TO lv_dsn.
       
CLEAR t_vbap.
     
ENDLOOP.

   
ENDIF.
   
CLOSEDATASET lv_dsn.

 

 

Output :-

 

out.jpg

 

Thanks .....

Anoop Satheesan


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>