Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Want report output in HTML

Hi All!

is it possible to get the report output in HTML based output?

if yes, can anyone send me the details?

thanks in advance

Alankaar

Tags:
replied

Hi,

Yes it is possible to do that.

You can go thru the program below. Hope it could help you.

REPORT ZSS_CODE_2_HTML LINE-SIZE 300 .

TABLES: D010INC.

  • Tabelle für die aufzunehmenden ABAP-Texte

DATA: BEGIN OF SOURCECODE OCCURS 0,

LINE(200),

END OF SOURCECODE.

  • Tabelle für den erzeugten HTMLCode

DATA: BEGIN OF HTMLCODE OCCURS 5000,

LINE(256),

END OF HTMLCODE.

DATA: BEGIN OF INCLUDETAB OCCURS 0,

NAME LIKE D010INC-INCLUDE,

END OF INCLUDETAB.

DATA: TEXTELEMENTETAB LIKE TEXTPOOL OCCURS 50 WITH HEADER LINE.

DATA: EINRUECK TYPE I, " Soweit im HTML einrücken

CHAR2(2).

*----

-


Selektionsbild und Verarbeitung -

-


SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME.

PARAMETERS: PROGNAME LIKE D010SINF-PROG

DEFAULT 'ZSS_CODE_2_HTML'.

PARAMETERS: HTMLFILE LIKE RLGRAP-FILENAME

DEFAULT 'c: emp est.html'.

PARAMETERS: MITINCLD AS CHECKBOX DEFAULT 'X',

MITTEXTL AS CHECKBOX DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK BL1.

SELECTION-SCREEN BEGIN OF BLOCK BL2 WITH FRAME.

PARAMETERS: MITZEILE AS CHECKBOX DEFAULT 'X',

ONSCREEN AS CHECKBOX DEFAULT 'X',

SAPINCLD AS CHECKBOX DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK BL2.

  • Ein subtrivialer Tests

AT SELECTION-SCREEN.

READ REPORT PROGNAME INTO SOURCECODE.

IF SY-SUBRC <> 0.

MESSAGE E159(AT) WITH 'Programm konnte nicht eingelesen werden'.

ENDIF.

*----

-


Programmanfang -

-


END-OF-SELECTION.

  • In der Tabelle sourcecode sollte hier schon der Quelltext stehen.

PERFORM ERZEUGE_KOPF.

PERFORM WRITE_SOURCE.

  • Includes falls erwünscht

IF MITINCLD = 'X'.

PERFORM WRITE_INCLUDES.

ENDIF.

  • Textelemente falls erwünscht

  • Includes falls erwünscht

IF MITTEXTL = 'X'.

PERFORM WRITE_TEXTELEMENTE.

ENDIF.

  • Und abschließen des Files

PERFORM ERZEUGE_SCHWANZ.

PERFORM ABSPEICHERN TABLES HTMLCODE

USING HTMLFILE.

*----

-


Unterroutinen -

-


INCLUDE ZCD_SS_DEBUGROUTINEN.

*----


*

  • FORM ABSPEICHERN *

*----


*

  • ........ *

*----


*

  • --> FILENAME *

*----


*

FORM ABSPEICHERN TABLES TEXT_ZU_SCHREIBEN

USING FILENAME LIKE RLGRAP-FILENAME.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

CODEPAGE = 'IBM'

FILENAME = HTMLFILE

FILETYPE = 'ASC'

  • MODE = ' '

TABLES

DATA_TAB = TEXT_ZU_SCHREIBEN

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

GUI_REFUSE_FILETRANSFER = 8

OTHERS = 9.

IF ONSCREEN = 'X'.

LOOP AT TEXT_ZU_SCHREIBEN.

PERFORM SHOW_ANY_STRUC USING TEXT_ZU_SCHREIBEN.NEW-LINE.

ENDLOOP.

ENDIF.

ENDFORM.

*&----


*

*& Form ERZEUGE_KOPF

*&----


*

  • Erzeugt einen HTML-Rumpf bis zum Body

*----


*

FORM ERZEUGE_KOPF.

HTMLCODE-LINE = ''.APPEND HTMLCODE.
HTMLCODE-LINE = ' '.APPEND HTMLCODE.
HTMLCODE-LINE = '
CLEAR HTMLCODE-LINE.
HTMLCODE-LINE+3 = PROGNAME.APPEND HTMLCODE.
HTMLCODE-LINE = ' '.APPEND HTMLCODE.
HTMLCODE-LINE = ' '.APPEND HTMLCODE.
CLEAR HTMLCODE-LINE.APPEND HTMLCODE.
HTMLCODE-LINE = ''.APPEND HTMLCODE.

EINRUECK = 2.

ENDFORM. " ERZEUGE_KOPF

*&----


*

*& Form ERZEUGE_SCHWANZ

*&----


*

  • Erzeugt die abschließenden HTML-Befehle

*----


*

FORM ERZEUGE_SCHWANZ.

HTMLCODE-LINE = ' </body>'.APPEND HTMLCODE.

HTMLCODE-LINE = '</html>'.APPEND HTMLCODE.

ENDFORM. " ERZEUGE_SCHWANZ

*&----


*

*& Form WRITE_SOURCE

*&----


*

  • Schreibt den Sourcecode

*----


*

FORM WRITE_SOURCE.

DATA: ROT.

  • Erstmal die Überschrift hinstellen

PERFORM ADDZEILE USING '>+' '

'.
PERFORM ZEILEUMB USING '' PROGNAME.
PERFORM ADDZEILE USING '->' '

'.

CLEAR HTMLCODE-LINE.APPEND HTMLCODE.

  • Link auf Includes

IF MITINCLD = 'X'.

PERFORM ADDZEILE USING '>+' '

'.
PERFORM ZEILEUMB USING '' '[Includes | #Includes]'.
PERFORM ADDZEILE USING '->' '

'.

ENDIF.

  • Link auf Textelemente

IF MITTEXTL = 'X'.

PERFORM ADDZEILE USING '>+' '

'.
PERFORM ZEILEUMB USING ''
'[Textelemente | #Textelemente]'.
PERFORM ADDZEILE USING '->' '

'.

ENDIF.

  • Und Linie zum Trennen gegen den Quellcode

PERFORM ADDZEILE USING '>+' ''.

  • Und jetzt der Quellcode

PERFORM CODELINES.

ENDFORM. " WRITE_SOURCE

*&----


*

*& Form ADDZEILE

*&----


*

  • Fügt eine Zeile in den HTML-Code ein und korrigiert Einrücktiefe

*----


*

FORM ADDZEILE USING VALUE(EINRUECKEN) LIKE CHAR2

VALUE(TEXT).

DATA: ER.

ER = EINRUECKEN(1).

IF ER = '+'.

EINRUECK = EINRUECK + 1.

ELSEIF ER = '-'.

EINRUECK = EINRUECK - 1.

ENDIF.

CLEAR HTMLCODE.

HTMLCODE+EINRUECK = TEXT.

APPEND HTMLCODE.

ER = EINRUECKEN+1(1).

IF ER = '+'.

EINRUECK = EINRUECK + 1.

ELSEIF ER = '-'.

EINRUECK = EINRUECK - 1.

ENDIF.

ENDFORM. " ADDZEILE

*&----


*

*& Form SONDERZEICHEN

*&----


*

  • Sonderzeichen in HTML darstellen

*----


*

FORM SONDERZEICHEN CHANGING ZEILE.

DATA: S LIKE SY-SUBRC,

LASTHIT LIKE SY-FDPOS,

DUMMY(256).

  • &

LASTHIT = 0.

DO.

DUMMY = ZEILE+LASTHIT.

IF DUMMY CA '&'.

REPLACE '&' WITH '&amp;' INTO DUMMY.

ZEILE+LASTHIT = DUMMY.

LASTHIT = SY-FDPOS + LASTHIT + 1.

ELSE.

EXIT.

ENDIF.

ENDDO.

  • ÄÖÜäöüß<>"

DO.

S = 1.

REPLACE 'Ä' WITH 'Ä' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE 'Ö' WITH 'Ö' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE 'Ü' WITH 'Ü' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE 'ä' WITH 'ä' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE 'ö' WITH 'ö' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE 'ü' WITH 'ü' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE 'ß' WITH 'ß' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE '<' WITH '&lt;' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE '>' WITH '&gt;' INTO ZEILE. S = S * SY-SUBRC / 4.

REPLACE '"' WITH '&quot;' INTO ZEILE. S = S * SY-SUBRC / 4.

IF S = 1.EXIT.ENDIF.

ENDDO.

ENDFORM. " SONDERZEICHEN

*&----


*

*& Form ZEILEUMB

*&----


*

  • text

*----


*

*----


*

FORM ZEILEUMB USING VALUE(EINRUECKEN) LIKE CHAR2

VALUE(TEXT).

CONCATENATE TEXT '
' INTO TEXT.

PERFORM ADDZEILE USING EINRUECKEN TEXT.

ENDFORM. " ZEILEUMB

*&----


*

*& Form CODELINES

*&----


*

  • Schiebt die Zeilen aus sourcecode ins HTML-Format

*----


*

FORM CODELINES.

DATA ZEILE(5).

PERFORM ADDZEILE USING '>+' '

'.

LOOP AT SOURCECODE.

  • Erst mal die Sonderzeichen ersetzen

PERFORM SONDERZEICHEN CHANGING SOURCECODE-LINE.

  • Bei einem Kommentar diesen Rot und kursiv darstellen

IF SOURCECODE-LINE(1) = '*'. " roter Kommentar

CONCATENATE '+'
SOURCECODE-LINE
'+
'

INTO SOURCECODE-LINE.

ENDIF.

  • Bei Zeilennummerierung diese in dunkelblau dazustellen

IF MITZEILE = 'X'.

ZEILE = SY-TABIX.

SHIFT SOURCECODE-LINE RIGHT BY 35 PLACES.

CONCATENATE ''
ZEILE
'
'
INTO SOURCECODE-LINE(35).
ENDIF.
PERFORM ADDZEILE USING '' SOURCECODE-LINE.
ENDLOOP.
PERFORM ADDZEILE USING '->' '

'.

ENDFORM. " CODELINES

*&----


*

*& Form WRITE_INCLUDES

*&----


*

  • Die ganzen Includesources anfügen

*----


*

FORM WRITE_INCLUDES.

DATA: FIRSTTIME.

FIRSTTIME = 'X'.

SELECT * FROM D010INC WHERE MASTER = PROGNAME.

IF SAPINCLD = 'X'

AND D010INC-INCLUDE(1) = '<'.

CONTINUE.

ENDIF.

IF FIRSTTIME = 'X'.

PERFORM ADD_INCLUDES_HEADER.

CLEAR FIRSTTIME.

ENDIF.

  • Die Namen der Includes merken und nacher am Anfang in den Quellcode

  • als Navigationspunkte hinzufügen

APPEND D010INC-INCLUDE TO INCLUDETAB.

  • Namen und Quelltext schreiben

PERFORM ADD_INCLUDE_NAME USING D010INC.

READ REPORT D010INC-INCLUDE INTO SOURCECODE.

PERFORM CODELINES.

ENDSELECT.

ENDFORM. " WRITE_INCLUDES

*&----


*

*& Form ADD_INCLUDES_HEADER

*&----


*

  • Für den 1. Include eine kleine Sonderbehandlung

*----


*

FORM ADD_INCLUDES_HEADER.

HTMLCODE-LINE = ''. APPEND HTMLCODE.

ENDFORM. " ADD_INCLUDES_HEADER

*----


*

  • FORM ADD_INCLUDE_NAME *

*----


*

  • ........ *

*----


*

  • --> UEBERGABE *

*----


*

FORM ADD_INCLUDE_NAME USING UEBERGABE LIKE D010INC.

HTMLCODE-LINE = ' '. APPEND HTMLCODE.

ENDFORM. " ADD_INCLUDE_NAME

*&----


*

*& Form WRITE_TEXTELEMENTE

*&----


*

  • Textelemente des Hauptprogramms auch noch ausgeben

*----


*

FORM WRITE_TEXTELEMENTE.

PERFORM TEXTELEMENTE_HEADER.

READ TEXTPOOL PROGNAME INTO TEXTELEMENTETAB.

PERFORM HTML_TEXTELEMENTE USING 'im Hauptprogramm'.

LOOP AT INCLUDETAB.

READ TEXTPOOL INCLUDETAB-NAME INTO TEXTELEMENTETAB.

CHECK SY-SUBRC = 0.

PERFORM HTML_TEXTELEMENTE USING INCLUDETAB-NAME.

ENDLOOP.

ENDFORM. " WRITE_TEXTELEMENTE

*&----


*

*& Form TEXTELEMENTE_HEADER

*&----


*

*----


*

FORM TEXTELEMENTE_HEADER.

HTMLCODE-LINE = ''. APPEND HTMLCODE.

ENDFORM. " TEXTELEMENTE_HEADER

*&----


*

*& Form HTML_TEXTELEMENTE

*&----


*

  • text

*----


*

FORM HTML_TEXTELEMENTE USING WOHER.

DATA: WOHERNAME(80),

TID(80),

TKEY(80),

TENTRY(80).

WOHERNAME = WOHER.

PERFORM SONDERZEICHEN CHANGING WOHERNAME.

  • Das Ganze als Tabelle rauswerfen

HTMLCODE-LINE = '

'.APPEND HTMLCODE.
CONCATENATE '

' WOHERNAME '

' INTO HTMLCODE-LINE.APPEND HTMLCODE.
HTMLCODE-LINE = '

'.APPEND HTMLCODE.

LOOP AT TEXTELEMENTETAB.

TID = TEXTELEMENTETAB-ID.

TKEY = TEXTELEMENTETAB-KEY.

TENTRY = TEXTELEMENTETAB-ENTRY.

  • und HTML-Sonderzeichen ersetzen

PERFORM SONDERZEICHEN CHANGING TID.

PERFORM SONDERZEICHEN CHANGING TKEY.

PERFORM SONDERZEICHEN CHANGING TENTRY.

HTMLCODE-LINE = ''.APPEND HTMLCODE.
CONCATENATE '' INTO HTMLCODE-LINE.
APPEND HTMLCODE.
CONCATENATE '' INTO HTMLCODE-LINE.
APPEND HTMLCODE.
CONCATENATE '' INTO HTMLCODE-LINE.
APPEND HTMLCODE.
HTMLCODE-LINE = ''.APPEND HTMLCODE.
ENDLOOP.
HTMLCODE-LINE = '

' TID '

' TKEY '

' TENTRY '

'.APPEND HTMLCODE.
HTMLCODE-LINE = '

'.APPEND HTMLCODE.

ENDFORM. " HTML_TEXTELEMENTE

Regards

Rakesh

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question