Posted: Sat Sep 08, 2007 7:30 pm Post subject: ABAP Code WebViewer
ABAP Code WebViewer
Beta Version
Description:
As an ABAP developer, I found it difficult to read ABAP codes shared on web. This utility converts the ABAP Report / FM Code into an HTML file and downloads it on the chosen directory of your PC. Further,developers can share the code on websites by directly sending it in an HTML format.
Create a new ABAP Report and upload the text version of this program.
Create text elements for the new program.
Text Symbols :
001 Choose either a Report or a Function Module
002 Choose Output Directory on your PC
003 Make your code Search Engine Friendly on web.
Selection Text :
P_DESC Program Description
P_KEYW Keywords (Separated by comma)
P_OUTDIR Output Directory
P_PROG Report
P_PROGF Function Module
Check and activate.
Execute and enter selection parameters.
Code:
REPORT Z_RMTIWARI_ABAP_CODE_WEBVIEWER .
*----------------------------------------------------------------------*
* ABAP Code WebViewer Beta Version - Date - 20.03.2005
*----------------------------------------------------------------------*
* Written By: Ram Manohar Tiwari
*----------------------------------------------------------------------*
* Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*
* This utility tool converts the ABAP Report / FM Code into an html
* file and downloads it on the chosen directory of your PC.
* Further,developers can share the code on websites by directly
* sending it in an HTML format.
* The code downloaded by this utility is more readable on web for an
* ABAP developer as:
* 1. It retains the blue color of comments and documentation with
* the code and hence HTML version looks exactly like the ABAP
* editor code.
*
* 2. The generated HTML will be search engine friendly as it will
* have its own title and meta search keywords. This way search
* engines can directly find the code on your site. Code Sharer
* has the option of providing his own < title> suitable for the
* program and relevant meta keywords to find it on web.
*
* 3. Just like ABAP editor, viewers can click on a variable to
* reach its directly at its DATA definition.
*
* 4. Similarly, viewers can click on PERFORM calls to reach
* directly at the defined FORM routine.
*-----------------------------------------------------------------------
* This utility is developed on MiniSAP and should be compatible with
* SAP4.7 version. Though with slight modifications to remove
* the value added aspects will make it compatible with any versions of
* SAP.
*-----------------------------------------------------------------------
* SELECTION SCREEN
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_PROG TYPE TRDIR-name,
P_PROGF TYPE TFDIR-funcname.
SELECTION-SCREEN END OF BLOCK b1 .
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: P_OUTDIR LIKE rlgrap-filename obligatory.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-003.
data : GV_DIRECTORY LIKE rlgrap-filename,
GV_FILE_NAME TYPE STRING,
GV_HTML_FILE_NAME TYPE TRDIR-name.
DATA : BEGIN OF GT_HTML OCCURS 0,
REC(200) TYPE c,
END OF GT_HTML.
DATA : GV_HTML_WA like line of GT_HTML.
*----------------------------------------------------------------------*
* Type declaration
*----------------------------------------------------------------------*
* Type for report
TYPES: BEGIN OF TY_REPORT_WO_INDEX,
LINE(300),
END OF TY_REPORT_WO_INDEX.
* Type for Report with line index
TYPES: BEGIN OF TY_REPORT_WITH_INDEX,
INDEX TYPE i,
LINE(300),
END OF TY_REPORT_WITH_INDEX.
*----------------------------------------------------------------------*
* CONSTANTS *
*----------------------------------------------------------------------*
CONSTANTS : GC_FALSE(1) TYPE c VALUE ' ',
GC_TRUE(1) TYPE c VALUE 'X',
GC_QUOTES1(1) TYPE c VALUE '''',
GC_ASTERIK(1) TYPE c VALUE '*',
GC_COMMA(1) TYPE c VALUE ',',
GC_QUOTES(1) TYPE c VALUE '"',
GC_PERCENT(1) TYPE c VALUE '%'.
*----------------------------------------------------------------------*
* Data declaration
*----------------------------------------------------------------------*
DATA : GT_REP_TABLE TYPE STANDARD TABLE OF TY_REPORT_WO_INDEX WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 500,
GV_REP_WA TYPE TY_REPORT_WO_INDEX,
GV_REP_WA_NEXT TYPE TY_REPORT_WO_INDEX.
DATA : GV_PROG_NAME TYPE TRDIR-name.
*-----------------------------------------------------------------------
* ALV stuff
type-pools: slis.
data: GT_FIELDCAT type SLIS_T_FIELDCAT_ALV,
GS_LAYOUT type SLIS_LAYOUT_ALV,
GT_SORT type SLIS_T_SORTINFO_ALV.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PROG.
PERFORM GET_REPORT_NAME USING 'P_PROG'
CHANGING P_PROG.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PROGF.
PERFORM GET_REPORT_NAME USING 'P_PROGF'
CHANGING P_PROGF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_OUTDIR.
PERFORM GET_DIRECTORY_NAME USING 'P_OUTDIR'
CHANGING P_OUTDIR.
AT SELECTION-SCREEN.
PERFORM SELECTION_SCREEN_VALIDATIONS.
START-OF-SELECTION.
* read the report code lines in an internal table
READ REPORT GV_PROG_NAME INTO GT_REP_TABLE.
IF SY-subrc < > 0.
MESSAGE e001(AQ) WITH
'Code is blank'.
EXIT.
ENDIF.
* Read the lines of report one by one and convert to HTML.
PERFORM CONVERT_CODE_TO_HTML TABLES GT_REP_TABLE
GT_HTML.
PERFORM PREPARE_FILE_NAME USING P_OUTDIR
GV_HTML_FILE_NAME
CHANGING GV_FILE_NAME.
PERFORM DOWNLOAD_HTML_FILE_ON_PC tables GT_HTML
using GV_FILE_NAME.
PERFORM SHOW_HTML_FILE using GV_FILE_NAME.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form get_report_name
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
FORM get_report_name using X_REPORT_FIELD_NAME
changing Y_REPORT_NAME.
PERFORM READ_SCREEN_VALUES USING X_REPORT_FIELD_NAME
CHANGING Y_REPORT_NAME.
*&---------------------------------------------------------------------*
*& Form get_file_name
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
FORM get_directory_name using X_FILE_FIELD_NAME
changing Y_DIRECTORY_NAME.
class CL_GUI_FRONTEND_SERVICES definition load.
data : LV_FILE_PATH type rlgrap-filename,
LV_FILE_NAME type rlgrap-filename,
LV_OUTDIR type string,
LV_DIRECTORY type string.
CONSTANTS : LC_WINDOW_TITLE type string
value 'Select HTML download folder'.
PERFORM READ_SCREEN_VALUES USING X_FILE_FIELD_NAME
CHANGING Y_DIRECTORY_NAME.
READ TABLE LT_DYNPVALUETAB INDEX 1.
MOVE: LT_DYNPVALUETAB-fieldvalue TO Y_VALUE.
ENDIF.
ENDFORM. " read_screen_values
*&---------------------------------------------------------------------*
*& Form selection_screen_validations
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
FORM selection_screen_validations .
IF NOT P_PROG IS INITIAL AND
NOT P_PROGF IS INITIAL.
MESSAGE e001(AQ) WITH
'Please use either program of function module'.
ELSEIF P_PROG IS INITIAL AND
P_PROGF IS INITIAL.
MESSAGE e001(AQ) WITH
'Please provide any of the program or function module name'.
ELSEIF NOT P_PROGF IS INITIAL.
SELECT SINGLE *
FROM TFDIR
WHERE funcname = P_PROGF.
IF SY-subrc EQ 0.
CONCATENATE TFDIR-pname 'U'(793) tfdir-include INTO GV_PROG_NAME.
GV_PROG_NAME = gv_prog_name+3(30).
CONCATENATE P_PROGF '.html' into GV_HTML_FILE_NAME.
ELSE.
MESSAGE e001(AQ) WITH
'Function module does not exit'.
ENDIF.
ELSE.
SELECT SINGLE *
FROM TRDIR
WHERE name = P_PROG.
IF SY-subrc NE 0.
MESSAGE e001(AQ) WITH
'This Report does not exist'.
ELSE.
GV_PROG_NAME = P_PROG.
CONCATENATE P_PROG '.html' into GV_HTML_FILE_NAME.
ENDIF.
ENDIF.
ENDFORM. " selection_screen_validations
*&--------------------------------------------------------------------*
*& Form prepare_file_name
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* --> x_directory text
* --> x_program_name text
* --> y_file_name text
*---------------------------------------------------------------------*
FORM prepare_file_name USING X_DIRECTORY
X_FILE
CHANGING Y_FILE_NAME.
CONCATENATE X_DIRECTORY '\' X_FILE into Y_FILE_NAME.
ENDFORM. " prepare_file_name
*&---------------------------------------------------------------------*
*& Form download_html_file_on_pc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
FORM download_html_file_on_pc tables YT_DOWNLOAD
using X_OUTFILE type string.
* Use gui_download if file is located on the local PC.
* WS_download only works in foreground
IF SY-batch EQ 'X'.
MESSAGE e001(AQ) WITH
'This program cannot be executed in background'.
* ERROR: Unable to download locally stored files when running in
* background
ELSE.
WHEN OTHERS.
* Upload unsuccessful - error message
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDCASE.
ENDIF.
ENDFORM. " download_html_file_on_pc
*&---------------------------------------------------------------------*
*& Form convert_code_to_html
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> P_GT_REP_TABLE text
* --> P_GT_HTML text
*----------------------------------------------------------------------*
FORM convert_code_to_html TABLES XT_REP_TABLE
YT_HTML.
DEFINE add_html.
YT_HTML = &1.
APPEND YT_HTML.
END-OF-DEFINITION.
DATA : LV_NEXT_LINE_INDEX type i.
DATA : LV_REP_WA_CAPS type TY_REPORT_WO_INDEX,
LV_INLINE_COMMENT type TY_REPORT_WO_INDEX,
LV_FORM_COUNTER(4) type n,
LV_ANCHOR(4) type n.
DATA : LT_FORM_INDEX type standard table of TY_REPORT_WITH_INDEX,
LT_FORM_INDEX_WA like line of lt_form_index,
LV_FORM_NAME(72) type c,
LV_STRING(72) type c.
* Modify words in ABAP code which are tags for HTML.
REPLACE '< ' with '< ' into GV_REP_WA.
REPLACE '> ' with '> ' into GV_REP_WA.
* For Comments
IF GV_REP_WA(1) eq GC_ASTERIK.
concatenate '< FONT COLOR="BLUE"> ' GV_REP_WA ''
INTO YT_HTML.
add_html YT_HTML.
* For Code Lines.
ELSE.
* Remove inline comments
SPLIT GV_REP_WA at '"' into LV_REP_WA_CAPS LV_INLINE_COMMENT.
TRANSLATE LV_REP_WA_CAPS TO UPPER CASE.
SHIFT LV_REP_WA_CAPS LEFT DELETING LEADING SPACE.
* Replace Form routines and performs with anchors .
if LV_REP_WA_CAPS(7) eq 'PERFORM'.
SPLIT lv_rep_wa_caps+6 at SPACE
into LV_INLINE_COMMENT
LT_FORM_INDEX_WA-line LV_INLINE_COMMENT.
REPLACE '.' with '' into LT_FORM_INDEX_WA-line.
READ TABLE LT_FORM_INDEX into LT_FORM_INDEX_WA
with key LINE = LT_FORM_INDEX_WA-line.
if SY-subrc eq 0.
LV_ANCHOR = LT_FORM_INDEX_WA-index.
else.
* Populate form index table
LV_FORM_COUNTER = lv_form_counter + 1.
LV_ANCHOR = LV_FORM_COUNTER.
LT_FORM_INDEX_WA-index = LV_FORM_COUNTER.
append LT_FORM_INDEX_WA to lt_form_index.
endif.
CONCATENATE '< A HREF=' '"#F' LV_ANCHOR '"> '
INTO YT_HTML.
CONCATENATE YT_HTML GV_REP_WA into yt_html.
concatenate LT_FORM_INDEX_WA-line '< /A> ' into LV_STRING.
replace LT_FORM_INDEX_WA-line in YT_HTML
with LV_STRING IGNORING CASE .
add_html YT_HTML.
ELSE.
IF LV_REP_WA_CAPS(4) eq 'FORM'.
SPLIT lv_rep_wa_caps+3 at SPACE
into LV_INLINE_COMMENT LV_FORM_NAME lv_inline_comment.
READ TABLE LT_FORM_INDEX into LT_FORM_INDEX_WA
with key LINE = LV_FORM_NAME.
if SY-subrc eq 0.
LV_ANCHOR = LT_FORM_INDEX_WA-index.
CONCATENATE '< A NAME="F' LV_ANCHOR '"> '
INTO YT_HTML.
add_html YT_HTML.
endif.
endif.
add_html GV_REP_WA.
endif.
ENDIF.
ENDLOOP.
* Close HTML Tags
add_html '< /PRE> '.
add_html '< /BODY> '.
add_html '< /HTML> '.
*--------------------------------------------------------
* Write Anchors for Variables.
DATA : LT_VAR_LIST type standard table of RSYMB with header LINE.
DATA : LV_VAR_ANCHOR(200) type c,
LV_VAR_NUMBER(4) type n,
LV_VARIABLE(200) type c.
* Type for Report with line index
TYPES: BEGIN OF TY_VAR_INDEX,
INDEX TYPE i,
LINE(300),
FIRST_TIME,
END OF TY_VAR_INDEX.
DATA : LT_VAR_INDEX type standard table of TY_VAR_INDEX,
LT_VAR_INDEX_WA type TY_VAR_INDEX,
LV_FIRST_TIME type C,
LV_LENGTH type i,
LV_LINE_LENGTH type i.
LV_FIRST_TIME = 'X'.
* Get Variables list.
LOAD REPORT GV_PROG_NAME PART 'SYMB' INTO LT_VAR_LIST.
LOOP AT YT_HTML INTO GV_REP_WA.
LOOP AT LT_VAR_LIST.
SEARCH LT_VAR_LIST-TXOF FOR '%'.
if SY-subrc eq 0 or
GV_REP_WA(5) eq '< FONT'.
continue.
endif.
READ TABLE LT_VAR_INDEX into LT_VAR_INDEX_WA
with key LINE = LT_VAR_LIST-TXOF.
if SY-subrc eq 0.
LV_FIRST_TIME = LT_VAR_INDEX_WA-first_time.
LV_VAR_NUMBER = LT_VAR_INDEX_WA-index.
else.
LV_FIRST_TIME = 'X'.
DESCRIBE TABLE LT_VAR_INDEX lines LV_VAR_NUMBER.
LT_VAR_INDEX_WA-index = LV_VAR_NUMBER.
LT_VAR_INDEX_WA-line = LT_VAR_LIST-TXOF.
LT_VAR_INDEX_WA-first_time = 'X'.
APPEND LT_VAR_INDEX_WA to lt_var_index.
endif.
if LV_FIRST_TIME eq 'X'.
concatenate '< A NAME="' LV_VAR_NUMBER '"> ' LT_VAR_LIST-TXOF
'< /A> '
into LV_STRING.
else.
concatenate '< A HREF="#' LV_VAR_NUMBER '"> ' LT_VAR_LIST-TXOF
'< /A> '
into LV_STRING.
endif.
concatenate LT_VAR_LIST-TXOF ' ' into LV_VARIABLE
separated by SPACE.
SEARCH GV_REP_WA FOR LV_VARIABLE .
IF SY-subrc eq 0.
LV_LENGTH = SY-fdpos - 1.
IF LV_LENGTH > = 0 .
CHECK gv_rep_wa+lv_length(1) eq ' ' or
gv_rep_wa+lv_length(1) eq ':'.
ENDIF.
LV_LENGTH = strlen( LV_VARIABLE ) + SY-fdpos.
LV_LINE_LENGTH = strlen( GV_REP_WA ).
IF LV_LENGTH le LV_LINE_LENGTH .
CHECK gv_rep_wa+lv_length(1) eq ' ' or
gv_rep_wa+lv_length(1) eq '.' or
gv_rep_wa+lv_length(1) eq '(' or
gv_rep_wa+lv_length(1) eq '-' or
gv_rep_wa+lv_length(1) eq ','.
ENDIF.
CASE LV_VARIABLE.
WHEN 'BLOCK' OR 'BEGIN' OR 'END'.
SEARCH GV_REP_WA FOR 'OF BLOCK'.
CHECK SY-subrc ne 0.
WHEN 'WITH' OR 'FRAME' OR 'TITLE'..
SEARCH GV_REP_WA FOR 'WITH FRAME TITLE'.
CHECK SY-subrc ne 0.
WHEN 'LINE' OR 'BEGIN' OR 'END'.
SEARCH GV_REP_WA FOR 'OF LINE'.
CHECK SY-subrc ne 0.
SEARCH GV_REP_WA FOR 'LIKE LINE OF'.
CHECK SY-subrc ne 0.
WHEN 'PARAMETERS'.
SEARCH GV_REP_WA FOR 'PARAMETERS'.
CHECK SY-subrc ne 0.
ENDCASE.
REPLACE LT_VAR_LIST-TXOF in GV_REP_WA with LV_STRING
IGNORING CASE .
if SY-subrc eq 0.
LT_VAR_INDEX_WA-FIRST_TIME = ' '.
MODIFY LT_VAR_INDEX
from LT_VAR_INDEX_WA transporting FIRST_TIME
where LINE = LT_VAR_LIST-TXOF.
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.