ZICDOC is an ABAP program, which ties to analyze source code of other ABAP program and create then HTML documentation. It is based mainly on comments extracted from source code, but it also recognize a few simple objects like database tables, forms, classes and similar code blocks and tries to assign comments to these objects. As a result, you can receive HTML file describing analyzed program. The level of details depend on what programmer "left" in source code.
Documenting source code of any program is crucial for it's later maintenance and extending. There are many tools for storing documentation (from word processors and file systems to advanced and sophisticated databases with version management, workflows and other wonderful functionalities). But programmers don't like to use them. After several program's modification, such a documentation is typically outdated and sooner or later - useless. I see, that the only place where programmers eventually leave additional information is source code (comments).
Suppose, that you have wonderful, detailed and up-to-date information inside source code of your program. That's great, but it isn't the end of you problems. You probably write a program not for yourself. Very soon your manager, quality controller or customer will ask you for any kind of documentation of your work...
It would be nice to have any tool which will automatically create such a documentation based on information in source code. There are several such a tools on the market - JAVADOC is good example, which solves problem of Java programmers. Unfortunately, I have not found such a generator for ABAP (I mean freeware, I heard some time ago about similar tool for ABAP, but it was very expensive).
I have been thinking about automatic documentation generator for several months, but I have had no motivation do it. I have started programming it, but never finished. About one year ago, I have decided finally to go into object-oriented ABAP (learn it) and it was turning point. I was looking for any real task for implementing (not just simple report displaying data from several tables) and I reminded about the generator.
After a few weeks, I had a class analyzing source code and storing results in internal tables. The next step was preparing any solution for displaying these results. At the beginning, I considered creation of XML files and then preparing XML transformations for converting XML data into more readable HTML, PDF or any other format. But, when I looked into details of XMLT - I gave up. It is so complex like new programming language. Finally, I did not decide to learn XML, XMLT and HTML, but just only HTML (it was also new for me). I only introduced CSS (cascade style sheets) to be more flexible with formatting output information.
Now, if you know that the ZICDOC project was for me the first contact with object-oriented ABAP, HTML and CSS, I hope that you will be more patient reading source code of the generator. It still needs some improvements or corrections, but at he moment I have no time to do it.
Program was tested mainly on WAS 6.40 and WAS 7.0, but it should work on all versions of WAS. It was also tested a little on 4.6C (I started on this version), but It offers oldest version of statement SCAN ABAP-SOURCE. It has different syntax and results. Source code of the generator contains part described with word COMPATYBILITY (for 4.6C), so it is probably possible to adjust program to that version.
ATTENTION!
Due to size limit of single Weblog, I had to put source code of programs in part II, III and IV of the blog.
I tried not to use any nonstandard dictionary objects. You can even find, that I haven't used program text for HTML tags, but created them as constants. So, it should be enough just to create all ABAP programs and then activate them. If you want to understand what fields are on selection screen of the main program, copy texts from source code (they are at the beginning ) to selection texts.
Additionally, you have to create file ZIcDocStyle.css.
You should create the following programs:
The main program of generator is ZICDOC. Selection screen is below:
It allows entering the path to generated output HTML file.
As a input you have two options:
Additionally, you can influence the content of generated file (see also section 4). The meaning of options is the following:
After starting program, and waiting several seconds, you will (hopefully) see message, that NNNN bytes transferred. It means that your program has been analyzed and you can see results.
Attention!
To see correctly HTML file, you must place in the same folder file with styles: ZIcDocStyle.css. You can find additional information in section 2.6).
Before you can create with ZICDOC documentation for any program, the analyzed source code:
The generator triesto find comments I source code and assign them to code units (like programs, forms, classes, etc). This information is later used to create documentation for these units. Program recognizes the following types of statements:
I tried to write documentation of the ZICDOC in the source code. Try to generate HTML file for the program (it can be the first exercise). Additional information you will find directly in source code.
In general, the generator is based on built-in keyword SCAN ABAP-CODE (see online help for ABAP). It performs decomposition of source code into single statements and tokens. They can be later analyzed by your own program.
Generation of output HTML file is based on CSS. It allows using simple HTML tags in generated document and storing formatting information in separate file. You can, for instance, have several CSS files with different formatting, and depending on which one is used, different result will be displayed. You can experiment with CSS file and change different options. You can receive quite interesting results.
The name of CSS file is inside HTML file (in the header). The name of file is ZIcDocStyle.css and it must be located in the same directory as the main HTML file. Of course, you can edit HTML file and easy change the name of used CSS file.
CSS files can be edit with dedicated editors (which show you formatting options in dialog windows) or just any plain text editor (like Notepad). In the file, you can assign formatting options (like font name and size, color, table cell width) to specific HTML tags. For instance, headers are displayed with style H1 (in HTML document:
I have used three basic forms of defining styles (it was an exercise for me):
. If tag is nested inside | (inside tables cell) then width of a cell must be equal 25ex. By nesting, I understand: | Any text in cell |
Text |
Generated documentation is based mainly on comments entered by programmer. This section describes rules, which should be considered.
Source code comments are very important for understanding usage of functions, forms, objects and individual lines of code. Therefore, program reads comments and places them in output file as description of specific objects.
Depending on a context, comments can describe code before or after it. To assign comments to right objects, strict rules must be applied by a programmer. The most important are described below.
Comments can contain variables (tags) starting with character @. They can be any single word. There are several predefined (assumed to be used) but other are treated in the same way - a special formatting cab be applied in output file.
List of examples:
The following tags are treated in different way. The generator use the word following the tag as its special parameter (like in: * @Param I_MATNR Material number). Parameters can be issued with different formatting options (font). Only the following predefined variables can have parametrs (it is hard-coded):
At the beginning of each main program or include it is possible to write comment describing this unit. This comment is recognized by beginning characters: *&. It is not required, that all lines of this part begins with these 2 characters. It is enough, that the first line begins with them. All following lines can begin with single character *.
Program comment can start in any line of code, even at the end of program. I suggest to enter it at the beginning, because Pretty Printer generates form's header comments beginning wit *&, so it can lead to unexpected results. Program comment ends with the firs blank line or statement (just no-comment). Example:
*&---------------------------------------------------------------------*
*& Report ZICDOC_TEST1
*&
*&---------------------------------------------------------------------*
*& @Author Ireneusz Cwir
*& @Date 18.01.2008
*& @Info Program for testing documentation generation by ZICDOC
*&---------------------------------------------------------------------*
* This comment, although doesn't begin with '*&' belong to program's
* description part. It is because there is no empty line between
* above section and this section.
It will start in new line -
* thanks to HTML tag: <br>
* Line with horizontal separator is ignored.
*
* This comment also belongs to above section, because line above
* starts with '*', so it is no really blank line.
* This doesn't belong to previous section, because there is really
* empty line above.
Comments for forms, list events and other similar code units are placed before the unit. The last continuous section of comment (without blank line) before unit is assigned to that unit.
Comments can contain special tags using for marking special sections of comments (like author, date, parameters - see point 3.1.2).
If you want to output comment from inside form or method, you must use comment starting with*".
Output HTML file can contain different sections. Selection screen parameters control this. Sections are describe below.
Section lists all includes used in the program. They are printed as subnodes of the analyzed program. This section contains also macros called from the program. If source code of include has been available for analysis and detailed section should be generated, nodes are created as links to detailed descriptions of each include.
Section lists database tables used in the program (covers includes). The following information is displayed for each table:
This section contains the following information for each program (include):
Section contains more detailed information about classes defined and implemented in analyzed program:
Section contains more detailed information about code units in each program (include):
The section contains hierarchy of calls of forms, function modules and other code units. It is intended for documenting reports. Then, list events are roots of calls. Other program types have not been tested. For instance, it does not list calls made from class methods.
ZICDOC does not recognize methods calls if short version are used.