---
title: "ABAP---如何将内表数据转成HTML格式文件"
author: "Jack Wu"
date: "2008-07-21T11:28:00Z"
tags: []
slug: "abap-html"
draft: false
lastmod: "2008-07-21T11:28:00Z"
id: 229270
url: "https://silverw0396.iteye.com/blog/229270"
---

&lt;style type="text/css"&gt; SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L1S31 { font-style: italic; color: #808080; } .L1S32 { color: #3399FF; } .L1S33 { color: #4DA619; } .L1S52 { color: #0000FF; } &lt;/style&gt; 本代码使用下列三个函数来完成将内表数据转换成本地的 HTML文件，并使用 IE打开浏览。三个函数说明如下：  
'WWW\_ITAB\_TO\_HTML\_HEADERS'  "This is used to Set the Column properties  
'WWW\_ITAB\_TO\_HTML\_LAYOUT'  "This is used to set the layout properties  
'WWW\_ITAB\_TO\_HTML'   "Using the Columns Definitions and Internal table this Function converts the internal table data into HTML format.

REPORT zdownload\_table\_html.  
\*-Internal table Declaration  
TYPES: BEGIN OF ty\_vbap,  
             vbeln TYPE vbeln,  
             posnr TYPE posnr,  
             matnr TYPE matnr,  
         END OF ty\_vbap.  
\*-ALL related Declarations  
DATA:    t\_header TYPE STANDARD TABLE OF w3head WITH HEADER LINE,  "Header  
              t\_fields TYPE STANDARD TABLE OF w3fields WITH HEADER LINE,    "Fields  
             t\_html TYPE STANDARD TABLE OF w3html,                          "Html  
             wa\_header TYPE w3head,  
            w\_head TYPE w3head.  
DATA: it\_vbap TYPE STANDARD TABLE OF ty\_vbap,  
           it\_fcat TYPE lvc\_t\_fcat WITH HEADER LINE.  
START-OF-SELECTION.  
  SELECT vbeln posnr matnr  
          FROM vbap  
          INTO TABLE it\_vbap  
         UP TO 20 ROWS.

END-OF-SELECTION.  
\*-Populate the Columns  
  it\_fcat-coltext = 'SalesOrder'.  
  APPEND it\_fcat.  
  it\_fcat-coltext = 'ItmeNumber'.  
  APPEND it\_fcat.  
  it\_fcat-coltext = 'Material'.  
  APPEND it\_fcat.  
\*-Fill the Column heading and Filed Properties  
  LOOP AT it\_fcat.  
    w\_head-text = it\_fcat-coltext.  
    CALL FUNCTION 'WWW\_ITAB\_TO\_HTML\_HEADERS'  
      EXPORTING  
        field\_nr = sy-tabix  
        text     = w\_head-text  
        fgcolor  = 'black'  
        bgcolor  = 'green'  
      TABLES  
        header   = t\_header.  
    CALL FUNCTION 'WWW\_ITAB\_TO\_HTML\_LAYOUT'  
      EXPORTING  
        field\_nr = sy-tabix  
        fgcolor  = 'black'  
        size     = '3'  
      TABLES  
        fields   = t\_fields.  
  ENDLOOP.  
\*-Title of the Display  
  wa\_header-text = 'Sales Order Details' .  
  wa\_header-font = 'Arial'.  
  wa\_header-size = '2'.  
\*-Preparing the HTML from Intenal Table  
  REFRESH t\_html.  
  CALL FUNCTION 'WWW\_ITAB\_TO\_HTML'  
    EXPORTING  
      table\_header = wa\_header  
    TABLES  
      html         = t\_html  
      fields       = t\_fields  
      row\_header   = t\_header  
      itable       = it\_vbap.  
\*-Download  the HTML into frontend  
  CALL FUNCTION 'GUI\_DOWNLOAD'  
    EXPORTING  
      filename                = 'C:\\Sales.htm'  
    TABLES  
      data\_tab                = t\_html  
    EXCEPTIONS  
      file\_write\_error        = 1  
      no\_batch                = 2  
      gui\_refuse\_filetransfer = 3  
      invalid\_type            = 4  
      no\_authority            = 5  
      unknown\_error           = 6  
      header\_not\_allowed      = 7  
      separator\_not\_allowed   = 8  
      filesize\_not\_allowed    = 9  
      header\_too\_long         = 10  
      dp\_error\_create         = 11  
      dp\_error\_send           = 12  
      dp\_error\_write          = 13  
      unknown\_dp\_error        = 14  
      access\_denied           = 15  
      dp\_out\_of\_memory        = 16  
      disk\_full               = 17  
      dp\_timeout              = 18  
      file\_not\_found          = 19  
      dataprovider\_exception  = 20  
      control\_flush\_error     = 21  
      OTHERS                  = 22.  
  IF sy-subrc &lt;&gt; 0.  
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno  
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.  
  ENDIF.  
\*-Display the HTML file  
  CALL METHOD cl\_gui\_frontend\_services=&gt;execute  
    EXPORTING  
      document               = 'C:\\Sales.htm'  
      operation              = 'OPEN'  
    EXCEPTIONS  
      cntl\_error             = 1  
      error\_no\_gui           = 2  
      bad\_parameter          = 3  
      file\_not\_found         = 4  
      path\_not\_found         = 5  
      file\_extension\_unknown = 6  
      error\_execute\_failed   = 7  
      synchronous\_failed     = 8  
      not\_supported\_by\_gui   = 9  
      OTHERS                 = 10.  
  IF sy-subrc &lt;&gt; 0.  
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno  
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.  
  ENDIF.