SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Convert ABAP Code to HTML



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Dictionary
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Oct 06, 2007 12:13 am    Post subject: Convert ABAP Code to HTML Reply with quote

http://sap4.com/wiki/index.php?title=ZSS_CODE_2_HTML

Code:
*&---------------------------------------------------------------------*
*& Report  ZSS_CODE_2_HTML   (Version 1.0)
*& by Stefan Schmöcker (1999)
*& emails:
* privat:                    unter der Woche mit Weiterleitung an privat
" [email protected]              [email protected]
" [email protected]
*&---------------------------------------------------------------------*
* Momentan realisiert: - Quellcode in HTML
*                      - Include-Quellcodes in HTML
*                      - Gesammelte Textelemente in Tabellen
*                      - Links zu den Untersektionen
* geplant: - feinere Linkaufteilung zu den einzelnen Includes
*          - Links innerhalb des Quellcodes zu entsprechenden Punkten
*          - GUI-Status,
*          - Dokumentation,
*          - Dynpro-ablauflogik und Fullscreen-Anzeige
*&---------------------------------------------------------------------*
 
REPORT  ZSS_CODE_2_HTML LINE-SIZE 255.
 
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.
PARAMETERS: HTMLFILE LIKE RLGRAP-FILENAME
                     DEFAULT 'c:\temp\test.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 = '<html>'.APPEND HTMLCODE.
  HTMLCODE-LINE = ' <head>'.APPEND HTMLCODE.
  HTMLCODE-LINE = '  <title>'.APPEND HTMLCODE.
  CLEAR HTMLCODE-LINE.
  HTMLCODE-LINE+3 = PROGNAME.APPEND HTMLCODE.
  HTMLCODE-LINE = '  </title>'.APPEND HTMLCODE.
  HTMLCODE-LINE = ' </head>'.APPEND HTMLCODE.
  CLEAR HTMLCODE-LINE.APPEND HTMLCODE.
  HTMLCODE-LINE = ' <body bgcolor=#ffffb0>'.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 '>+' '<h1 align=center>'.
  PERFORM ZEILEUMB USING '' PROGNAME.
  PERFORM ADDZEILE USING '->' '</h1>'.
  CLEAR HTMLCODE-LINE.APPEND HTMLCODE.
* Link auf Includes
  IF MITINCLD = 'X'.
    PERFORM ADDZEILE USING '>+' '<h2 align=left>'.
    PERFORM ZEILEUMB USING '' '<a href="#Includes">Includes</a>'.
    PERFORM ADDZEILE USING '->' '</h2>'.
  ENDIF.
* Link auf Textelemente
  IF MITTEXTL = 'X'.
    PERFORM ADDZEILE USING '>+' '<h2 align=left>'.
    PERFORM ZEILEUMB USING ''
                '<a href="#Textelemente">Elementos de texto</a>'.
    PERFORM ADDZEILE USING '->' '</h2>'.
  ENDIF.
 
* Und Linie zum Trennen gegen den Quellcode
  PERFORM ADDZEILE USING '>+' '<h2 align=left>'.
  PERFORM ZEILEUMB USING '' '<hr>'.
  PERFORM ADDZEILE USING '->' '</h2>'.
 
* 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 '&' INTO DUMMY.
      ZEILE+LASTHIT = DUMMY.
      LASTHIT = SY-FDPOS + LASTHIT + 1.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
 
* ÄÖÜäöüß<>"
  DO.
    S = 1.
    REPLACE 'é' WITH 'e'   INTO ZEILE.  S = S * SY-SUBRC / 4.
    REPLACE 'á' WITH 'a'   INTO ZEILE.  S = S * SY-SUBRC / 4.
    REPLACE 'í' WITH 'i'   INTO ZEILE.  S = S * SY-SUBRC / 4.
    REPLACE 'ó' WITH 'o'   INTO ZEILE.  S = S * SY-SUBRC / 4.
    REPLACE 'ú' WITH 'u'   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 'ß' 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.
    IF S = 1.EXIT.ENDIF.
  ENDDO.
 
ENDFORM.                               " SONDERZEICHEN
 
*&---------------------------------------------------------------------*
*&      Form  ZEILEUMB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM ZEILEUMB USING    VALUE(EINRUECKEN) LIKE CHAR2
                       VALUE(TEXT).
  CONCATENATE TEXT '<br>' 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 '>+' '<p><pre>'.
  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 '<font color=red><i>'
                  SOURCECODE-LINE
                  '</i></font>'
          INTO SOURCECODE-LINE.
    ENDIF.
* Bei Zeilennummerierung diese in dunkelblau dazustellen
    IF MITZEILE = 'X'.
      ZEILE = SY-TABIX.
      SHIFT SOURCECODE-LINE RIGHT BY 35 PLACES.
      CONCATENATE '<font color=blue>'
                  ZEILE
                  '</font> '
           INTO SOURCECODE-LINE(35).
    ENDIF.
    PERFORM ADDZEILE USING '' SOURCECODE-LINE.
  ENDLOOP.
  PERFORM ADDZEILE USING '->' '</pre></p>'.
 
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 = '<h1 align=center><font color=red>'. APPEND HTMLCODE.
  HTMLCODE-LINE = '<hr>'. APPEND HTMLCODE.
  HTMLCODE-LINE = '<a name="Includes">INCLUDES</a>'.APPEND HTMLCODE.
  HTMLCODE-LINE = '</font></h1>'. APPEND HTMLCODE.
 
ENDFORM.                               " ADD_INCLUDES_HEADER
 
*---------------------------------------------------------------------*
*       FORM ADD_INCLUDE_NAME                                         *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  UEBERGABE                                                     *
*---------------------------------------------------------------------*
FORM ADD_INCLUDE_NAME USING UEBERGABE LIKE D010INC.
  HTMLCODE-LINE = ' <h2 align=center><font color=blue>'.APPEND HTMLCODE.
  HTMLCODE-LINE = '  <hr width=70%>'. APPEND HTMLCODE.
  CLEAR HTMLCODE-LINE.
  HTMLCODE-LINE+2 = UEBERGABE-INCLUDE.
  PERFORM SONDERZEICHEN CHANGING HTMLCODE-LINE.
  APPEND HTMLCODE.
 
  HTMLCODE-LINE = ' </font></h2>'. 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 'en programa principal'.
  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 = '<h1 align=center><font color=red>'. APPEND HTMLCODE.
  HTMLCODE-LINE = '<hr>'. APPEND HTMLCODE.
  HTMLCODE-LINE = '<a name="Textelemente">'.APPEND HTMLCODE.
  HTMLCODE-LINE = 'Elementos de texto</a><br>'.APPEND HTMLCODE.
  HTMLCODE-LINE = '</font></h1>'. 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 = '<p align=center>'.APPEND HTMLCODE.
  CONCATENATE '<b>' WOHERNAME '</b>' INTO HTMLCODE-LINE.APPEND HTMLCODE.
  HTMLCODE-LINE = '<table border width=100%>'.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 = '<tr>'.APPEND HTMLCODE.
    CONCATENATE '<td>' TID '</td>' INTO HTMLCODE-LINE.
    APPEND HTMLCODE.
    CONCATENATE '<td>' TKEY '</td>' INTO HTMLCODE-LINE.
    APPEND HTMLCODE.
    CONCATENATE '<td>' TENTRY '</td>' INTO HTMLCODE-LINE.
    APPEND HTMLCODE.
    HTMLCODE-LINE = '</tr>'.APPEND HTMLCODE.
  ENDLOOP.
  HTMLCODE-LINE = '</table>'.APPEND HTMLCODE.
  HTMLCODE-LINE = '</p>'.APPEND HTMLCODE.
ENDFORM.                               " HTML_TEXTELEMENTE
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Dictionary All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.