用html将内表数据输出

写了一个简易程序,用于将内表数据以html格式保存于本地,并且打开该html文件

 

TYPE-POOLSslis.
TABLES sflight.
*   define internal table
DATABEGIN OF gt_sfli_info OCCURS 0,
      carrid TYPE sflight-carrid,
      connid TYPE sflight-connid,
      price TYPE sflight-price,
      currency TYPE sflight-currency,
      END OF gt_sfli_info.
*   Define fieldcat
DATA  gt_field_cat TYPE STANDARD TABLE OF slis_fieldcat_alv WITH HEADER LINE.
*   Define title of html table
DATA  gs_title TYPE w3head.
*   Define internal table to store html content
DATA  gt_html TYPE STANDARD TABLE OF w3html.
*   Define table values
DATA  gt_fields TYPE STANDARD TABLE OF w3fields WITH HEADER LINE.
*   Define table header
data  gt_header type STANDARD TABLE OF W3HEAD WITH HEADER LINE.


START-OF-SELECTION.
*   Build fieldcat
  PERFORM sub_build_field_cat.
*   Retrieve data from database
  PERFORM sub_retrieve_data.
*   Build table title and header
  PERFORM sub_set_header.
*   Convert to HTML
  PERFORM sub_convert_html.
*   Download html to local
  PERFORM sub_download_file.
*   Open html file
  PERFORM sub_open_file.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELD_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM sub_build_field_cat .
  gt_field_cat-fieldname 'CARRID'.
  gt_field_cat-seltext_m 'Airline Code'.
  APPEND gt_field_cat.
  gt_field_cat-fieldname 'CONNID'.
  gt_field_cat-seltext_m 'Flight Connection Number'.
  APPEND gt_field_cat.
  gt_field_cat-fieldname 'PRICE'.
  gt_field_cat-seltext_m 'Airfare'.
  APPEND gt_field_cat.
  gt_field_cat-fieldname 'CURRENCY'.
  gt_field_cat-seltext_m 'Local currency of airline'.
  APPEND gt_field_cat.
ENDFORM.                    " BUILD_FIELD_CAT
*&---------------------------------------------------------------------*
*&      Form  SUB_RETRIEVE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM sub_retrieve_data .
  SELECT
    carrid
    connid
    price
    currency
    FROM sflight
    INTO TABLE gt_sfli_info
    UP TO 25 ROWS.

ENDFORM.                    " SUB_RETRIEVE_DATA
*&---------------------------------------------------------------------*
*&      Form  SUB_SET_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM sub_set_header .
  gs_title-text 'Flight information'.
  gs_title-size '2'.

  LOOP AT gt_field_cat.
    gt_fields-nr sy-tabix.
    gt_fields-size '3'.
    APPEND gt_fields.

    gt_header-nr sy-tabix.
    gt_header-text gt_field_cat-seltext_m.
    gt_header-size '4'.
    gt_header-fg_color 'BLACK'.
    gt_header-bg_color 'GREEN'.
    APPEND gt_header.
  ENDLOOP.

ENDFORM.                    " SUB_SET_HEADER
*&---------------------------------------------------------------------*
*&      Form  SUB_CONVERT_HTML
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SUB_CONVERT_HTML .
  CALL FUNCTION 'WWW_ITAB_TO_HTML'
    EXPORTING
*      table_attributes = 'BORDER=1'
      table_header     gs_title
      all_fields       'X'
    TABLES
      html             gt_html
      fields           gt_fields
      ROW_HEADER       gt_header
      itable           gt_sfli_info.
endform.                    " SUB_CONVERT_HTML
*&---------------------------------------------------------------------*
*&      Form  SUB_DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SUB_DOWNLOAD_FILE .
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                        'C:\html_text.html'
    tables
      data_tab                        gt_html.
endform.                    " SUB_DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*&      Form  SUB_OPEN_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SUB_OPEN_FILE .
  CALL METHOD cl_gui_frontend_services=>execute
     EXPORTING
       document               'C:\html_text.html'
       operation              'OPEN'.
endform.                    " SUB_OPEN_FILE

你可能感兴趣的:(html,File,header,Build,download,attributes)