Currently Being Moderated

Alternative title - I hate doco

 

http://www.wombling.com/wp-content/uploads/2013/08/run-from-doco-624x282.png

It’s kinda a mantra that I live a reasonable part of my life to. I think the above image is a not unjustifiable representation of my feelings about documentation:

But there are many good reasons that I should be doing doco. Most of them are supposed to save the customer money in the long run. And occasionally by doing the doco, I even find some small errors in my code that I hadn’t seen before.

InnoJam Sydney 2011

Before InnoJam had any of that fun fluffy design thinking aspect to it, we ran one in Sydney. It was good fun, and people could build whatever the heck they wanted.

In staying true to my aversion for writing doco, I came up with an idea about auto-generation UML diagrams from SAP code.

Here’s a video of the solution we came up with:

 

here’s a link to the Prezi that I presented in that video:

http://prezi.com/zri5q-ib4vzp/?utm_campaign=share&utm_medium=copy&rc=ex0share

 

 

 

 

 

I wrote a blog post about it:

"Programmers are lazy" - InnoJam them!

But it was long time ago and the move to a new version of SCN has kinda buggered it up.

Anyway, in short – Rui Nogueira never managed to get the terms and conditions of CodeExchange changed to a level where I’m happy to support it and put code in there. I’m pretty sure he tried though. So I didn’t do anything with the code.

 

Fast forward 3 years

I have a whiteboard in the office covered in post-it notes. They all represent at least one development that I’ve done for the current project I’m working on. At the beginning of the project, I was very good, and did all my doco as I went along. Then the poo hit the fan, and everyone wanted everything done yesterday, and didn’t care about doco.

So I now have a whiteboard full of post-it notes that represent potentially weeks of doco hell for me. So in my “free time” in the evening I decided to see if I could recreate the solution that we’d built in Sydney, and perhaps make it a little nicer.

 

UML output

The first thing I decided, was that I was NOT going to try to build the graphical output myself. Having had lots of fun in Sydney trying to make Gravity do something it really wasn’t designed for I thought I’d research how else I could get my interaction diagrams created.

If in doubt Wikipedia

http://en.wikipedia.org/wiki/List_of_UML_tools

There were loads there, and I’d pretty much decided on UMLet when I discovered something about interaction diagrams. Basically, interaction diagrams are supposed to show interaction between objects. Bit bloody obvious really. However, the thing is, if I’m documenting my code, I’d really like to show the interaction within my objects too. I.e. if I make a call to a private method of my class, I’d really like that to show up in my diagram. Given that interaction diagrams are only supposed to show external interaction it’s not surprising that most of the tools for creating the diagrams don’t really support this idea of internal object calls.

So a bit of browsing later and I found PlantUML. It has some awesome functionality for creating sequence diagrams, actually, most UML diagrams it seems, but it was the sequence diagrams that I was interested in.

Here’s a simple example:

http://www.wombling.com/wp-content/uploads/2013/08/simple_example.png

 

See how it’s quite possible to show “internal” calls of an instance and also show the life time of those calls. This feature I didn’t find on the other free UML tools that I looked at. There are a bunch of other formatting features that can be used too. If you’re interested check out their website: http://plantuml.sourceforge.net/sequence.html

 

Intercepting the SAP standard UML generation

So in transaction SAT there is the possibility to generate your own JNet UML sequence diagram (this exists as standard.)

http://www.wombling.com/wp-content/uploads/2013/08/press-the-button.png

 

However, it does not allow you to do things like filter out standard SAP routines (as far as I know! If anyone can tell me how to do this (without needing to list every method I call, please let me know!) When I was looking at one of my examples, where I ran a program to generate a performance review document for an employee, there were over 100,000 different routines called. Only about 400 of those calls involved my code, so you can imagine generating a UML diagram for the whole 100,000 calls would be a bit of overkill (not to mention an impossible to read diagram).

In customer systems there is a function module  ATRA_UML_DECIDER  that has been purposely handicapped. One does have to wonder why this has been done, but nevertheless it has.  It allows the user to chose from a list of potential UML extraction routines. All of these routines implement the IF_ATRA_UML_TOOL interface. There are classes for extracting to JNet, Borland Together and Altova. Now, I’m sure that Borland and Altova have good products, it’s just that I don’t really want to spend money on then when there are perfectly good (for my tasks) free and open source products out there.

There is a factory class/method CL_ATRA_UML_FACTORY  that creates an instance of a class implementing the interface. I overrode this method to use my particular extractor if it was me running the code. In the future, I might enhance this to check for a user role, or perhaps a user parameter, that’s trivial, the main point will be to allow others to access this logic too.

The guts of the code

Simply my implementation of the interface reads the table of data that is passed to the interface, removes all calls that aren’t to or from custom code and then builds a PlantUML representation of that code.

Here’s a very simple output that generates the diagram above.

@startuml

hide footbox

autonumber

participant "Instance 1 of Class\nZCL_HR_EMPLOYEE" as 1

1 -> 1: Call method GET_HELD_QUALIFICATIONS

activate 1

1 -> 1: Call method ZCL_HR_OBJECT->GET_RELATIONSHIPS

activate 1

create "Static Methods of Class\nCL_HRBAS_READ_INFOTYPE" as 2

1 -> 2: Call method GET_INSTANCE

activate 2

2 --> 1

deactivate 2

create "Instance 1 of Class\nCL_HRBAS_READ_INFOTYPE" as 3

1 -> 3: Call method IF_HRBAS_READ_INFOTYPE~READ_PLAIN_1001

activate 3

3 --> 1

deactivate 3

1 --> 1

deactivate 1

create "Instance 1 of Class\nZCL_HR_QUALIFICATION" as 4

1 -> 4: Create instance of class ZCL_HR_QUALIFICATION

activate 4

4 -> 4: Call method ZCL_HR_OBJECT->CONSTRUCTOR

activate 4

create "Function Group\nRHS0" as 5

4 -> 5: Call FM RH_GET_ACTIVE_WF_PLVAR

activate 5

5 --> 4

deactivate 5

4 --> 4

deactivate 4

4 --> 1

deactivate 4

deactivate 1

@enduml

 

A slightly less trivial example

The following code does some pretty simple stuff, it finds who is my manager, and finds out what required qualifications my position/job has.

DATA: lo_emp TYPE REF TO zcl_hr_employee,
lt_managers TYPE ztthr_employee_objects,
lt_required_quals TYPE ztthr_qualifications.

TRY.
lo_emp = zcl_hr_employee=>get_employee_by_user_id( sy-uname ).

lt_managers = lo_emp->get_position( )->get_managers_recursive( ).
lt_required_quals = lo_emp->get_position( )->get_required_qualifications( ).

CATCH zcx_hr_no_managing_pos_found  ” No managing position found
zcx_hr_no_holders_found  ” no holders for position found.
zcx_hr_no_position_found    ” no position found
zcx_hr_user_id_not_found.  ” cannot find user id for employee
ENDTRY.

 

So I thought I’d trace it:

it works out at around 200,000 different routines being called. 62 of those are my code, the rest standard.

http://www.wombling.com/wp-content/uploads/2013/08/run-through-1.png

First of all, I need to schedule a trace for myself…

run through 2

 

run through 3

 

Need to know which session I will be recording. If I left it as “Any” it will start recording this session, not very useful!

run through 4

 

Session 2 it is!

run through 5

run through 6

actually run it now!

and the schedule status changes to executed.

run through 7

 

I now need to delete the scheduled measurement. Despite the intimidating words, this does not delete my measurement, just the scheduling of it.

run through 8

 

now swapping to the “Evaluate” tab in SAT I can see my measurement, and I can click to output to UML

run through 9

 

Late breaking discovery! - Filter data using SLAD!

In a somewhat surprising discovery, I found that I can filter the results of the trace so that only the custom code bits get processed in UML handling routines. This speeds up the processing immensely. HOWEVER! This does mean that you will NOT see where your code calls the SAP standard code, but for some diagramming tasks this would be fine.

slad filter1.png

 

slad filter2.png

Clicking on the button triggers a bit of a pause whilst the system code chugs away and does loads of stuff it doesn’t need to do…

Then

run through 10

Save the data and PlantUML starts converting it immediately:

run through 11

and the result:

example

Would probably have been a little bigger if my employee had a job assigned to their position, but you can see how incredibly easy this now makes documenting the functionality I’ve built.

After checking the SCN T&C and finding similar (if not worse conditions for the upload of SAP derivative code (it uses an SAP standard interface, so it probably is)) and the same indemnity clauses that make me refuse to participate in Code Exchange, I've decided not to share the code here. That said if someone else is willing to put the code out there on Code Exchange I'm more than happy to provide it to them. Perhaps someone will put their hand up to load it into Code Exchange - Gregor Wolf ???


This content was previously published on my own blog, but the tip about the SLAD filter wasn't, and certainly the code wasn't published there. Some excellent points have been raised about how this isn't a replacement for actually documenting the functionality of the code that has been built. But, I have found at least one case where using this tooling has helped me write a better bit of code by sharing references to objects that I didn't realise were being instantiated multiple times. Could something like this help you with your doco? Do you have any thoughts?

Comments

Actions

Filter Blog

By author:
By date:
By tag: