2019 Jul 02 2:59 PM
Dear all,
I'm trying to find a method or FM that takes an internal table as input and creates an HTML representation of that internal table.
FM WWW_ITAB_TO_HTML can do that - but it is marked as obsolete.
I searched for alternatives but wasn't able to find anything useful - besides code snipes generating HTML manually.
I need to create HTML in order to get formatted information into an XML format defined by a regulatory body in the EU.
The program needs to be running in the background without any user interaction.
Thanks for your help on this
Mark
2019 Jul 10 2:27 PM
Maybe there's no library because it's so simple to do, and there are so many possible HTML renderings for one table... Just take that one and adapt it for your case:
CLASS lcl_ DEFINITION.
PUBLIC SECTION.
CLASS-METHODS itab_to_html
IMPORTING
table TYPE ANY TABLE
RETURNING
VALUE(html) TYPE string.
ENDCLASS.
CLASS lcl_ IMPLEMENTATION.
METHOD itab_to_html.
DATA: lt_field TYPE TABLE OF string,
l_field TYPE string,
l_num TYPE i.
FIELD-SYMBOLS:
<l_field> TYPE any.
html = '<table border="1">'.
LOOP AT table ASSIGNING FIELD-SYMBOL(<line>).
l_num = 0.
CLEAR lt_field.
DO.
ADD 1 TO l_num.
ASSIGN COMPONENT l_num OF STRUCTURE <line> TO <l_field>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
l_field = <l_field>.
APPEND l_field TO lt_field.
ENDDO.
html = html && '<tr><td>' && concat_lines_of( table = lt_field sep = '</td><td>' ) && '</td></tr>'.
ENDLOOP.
html = html && '</table>'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECT * FROM scarr INTO TABLE @DATA(scarrs).
DATA(html) = lcl_=>itab_to_html( table = scarrs ).
2019 Jul 02 3:30 PM
Hi,
I think you can do this using XLS Transformations. Just check .
2019 Jul 02 3:53 PM
Any transformation, whatever it's XSLT or ST (prefer ST, much faster)
2019 Jul 03 9:03 AM
Dear Nawanandana,
I check but could find a build in transformation of an internal table into HTML... Did I look in the wrong spot?
I guess I could write a transformation myself - but that is exactly what I don't want to do 🙂
I check in S4 HANA 1709 - the FMs are still there....
2019 Jul 03 10:14 AM
<table><tr><td>R1C1</td><td>R1C2</td></tr><tr><td>R2C1</td><td>R2C2</td></tr></table>
Example done in 2 minutes (very easy via the wizard because the internal table is based on a DDIC structure, I just needed to replace default names with table, tr and td):
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root line-type="ddic:SFLIGHT" name="SFLIGHT"/>
<tt:template>
<table>
<tt:loop ref=".SFLIGHT">
<tr>
<td tt:value-ref="MANDT"/>
<td tt:value-ref="CARRID"/>
<td tt:value-ref="CONNID"/>
<td tt:value-ref="FLDATE"/>
<td tt:value-ref="PRICE"/>
<td tt:value-ref="CURRENCY"/>
<td tt:value-ref="PLANETYPE"/>
<td tt:value-ref="SEATSMAX"/>
<td tt:value-ref="SEATSOCC"/>
<td tt:value-ref="PAYMENTSUM"/>
<td tt:value-ref="SEATSMAX_B"/>
<td tt:value-ref="SEATSOCC_B"/>
<td tt:value-ref="SEATSMAX_F"/>
<td tt:value-ref="SEATSOCC_F"/>
</tr>
</tt:loop>
</table>
</tt:template>
</tt:transform>
2019 Jul 03 2:13 PM
Hi Mark,
You can do it with given blog , it's clearly explain. you have to create structure and then go to tcode XSLT_TOOL(Transformation)
and assign your structure into the transformation. I have done couple of program using this its very easy. ex: download master information in to XML format . For the information check attached document which is in the blog . Still if you need any help let me know.
2019 Jul 10 11:07 AM
Hi sandra.rossi,
Thanks for your comment and explanation!
I don't want to write an HTML transformation as I don't want to believe that I'm the first person that has such a requirement and that no easy to use, straightforward (e.g. not to call an ALV GRID or Print a list on convert from there etc..) solution has ever been developed by SAP 😉 .
I need to convert data from SAP's Class System (think material classification - not ABAP class) into an HTML table.
And the classes I need to convert are configurable via customizing... so it is not as straightforward and I can't use a DDIC structure.
As said I'm not familiar with the transformations: Could I dynamically generate them based on a type?
Best
Mark
2019 Jul 15 7:48 AM
Hello sandra.rossi,
I guess your correct - in the end of the day the HTML generation of an HTML Table is not that complicated.
Your example would be an nice addition to the SAP Standard (if it would be extend with standard HTML formatting options) in my opinion!
Only because it is easy doesn't justify that everyone needs to reinvent the wheel 😉
I would vote your comment as "best answer" - if you would convert it to an answer 🙂
Best
Mark
2019 Jul 15 8:36 AM
DATA(html_table) = NEW lcl_itab_to_html( itab ).
html_table->set_heading( column = 1 text = 'Price' css = 'font-weight:bold' ).
html_table->set_format( column = 1 number_format = html_table->number_format_no_grouping ).
DATA(html_string) = html_table->render( ).
In the end, a global HTML composer class would be even better... (note that in the past, SAP has had an unfortunate attempt with Dynamic Documents - I'm looking for one composer by the way, please let a message if you know one 😉 )
2019 Jul 03 10:14 PM
I would assume there are better (newer) ways of doing it, but you could check for the following 'classic' Function Modules and (Demo-)Programs on how HTML is generated ...
Functions :
Demo programs :
Kind regards
Nic T.
2019 Jul 15 7:39 AM
Hello nic.teunckens ,
Thank you for your answer!
The FM G_PP_TABLE_TO_HTML_TAB is not available on the lowest release I need to support - and I'm not 100% sure if the HR FMs are part of standard ECC - or if HR needs to be "activated".
I decided you just implement the HTML generation myself in the end.
Best
Mark
2019 Jul 10 2:27 PM
Maybe there's no library because it's so simple to do, and there are so many possible HTML renderings for one table... Just take that one and adapt it for your case:
CLASS lcl_ DEFINITION.
PUBLIC SECTION.
CLASS-METHODS itab_to_html
IMPORTING
table TYPE ANY TABLE
RETURNING
VALUE(html) TYPE string.
ENDCLASS.
CLASS lcl_ IMPLEMENTATION.
METHOD itab_to_html.
DATA: lt_field TYPE TABLE OF string,
l_field TYPE string,
l_num TYPE i.
FIELD-SYMBOLS:
<l_field> TYPE any.
html = '<table border="1">'.
LOOP AT table ASSIGNING FIELD-SYMBOL(<line>).
l_num = 0.
CLEAR lt_field.
DO.
ADD 1 TO l_num.
ASSIGN COMPONENT l_num OF STRUCTURE <line> TO <l_field>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
l_field = <l_field>.
APPEND l_field TO lt_field.
ENDDO.
html = html && '<tr><td>' && concat_lines_of( table = lt_field sep = '</td><td>' ) && '</td></tr>'.
ENDLOOP.
html = html && '</table>'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECT * FROM scarr INTO TABLE @DATA(scarrs).
DATA(html) = lcl_=>itab_to_html( table = scarrs ).