Use HTML to output internal table data

Source: Internet
Author: User

Article from http://blog.csdn.net/liangziyisheng/article/details/7020326

I wrote a simple program to save the internal table data in HTML format and open the HTML file.

Type-pools:
Slis.
Tables sflight.
* Define internal table
Data: Begin
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 =
'Cardri '.
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.