Create HTML file from SAP data with ABAP
Details
- Details
- Category: ABAP
- Created on Thursday, 22 November 2012 13:11
- Last Updated on Thursday, 22 November 2012 13:11
- Published on Thursday, 22 November 2012 13:11
- Written by Administrator
- Hits: 19483
The following simple ABAP program creates html file with SAP data.
REPORT zcreate_html.
*--------------------------------------------------
* www.developerpages.gr
*--------------------------------------------------
* Create html file from SAP data
tables : kna1.
data : t_html TYPE STANDARD TABLE OF w3html WITH HEADER LINE.
data : p_html TYPE TABLE OF string.
parameters : fname type string DEFAULT 'C:\test.html'.
t_html = '<html><head>'. append t_html.
t_html-line = '<title>www.developerpages.gr - Create HTML file from SAP data with ABAP</title>'. append t_html.
t_html-line = '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1253"></head>'. append t_html.
t_html-line = '<body>'.append t_html.
t_html-line = '<div id = "customers" width= "100%" style = >'.append t_html.
select * from kna1 up to 50 ROWS.
t_html-line = kna1-kunnr. append t_html.
t_html-line = kna1-name1. append t_html.
t_html-line = '<br>'.append t_html.
endselect.
t_html-line = '</div>'.append t_html.
t_html-line = '</html>'. append t_html.
t_html-line = '</body>'.append t_html.
p_html[] = t_html[].
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_download
EXPORTING
filename = fname
CHANGING
data_tab = p_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 = 0.
write :/ 'file ', fname , ' Created !'.
else.
write :/ 'file ', fname, ' cannot Created !'.
endif.