Monday, March 29, 2010

If 1 equals 2, what’s the purpose?

While debugging standard SAP ABAP code you might find for first look very strange code like following:

If 1 EQ 2.
MESSAGE W001(z100).
* plus do something else


Confusing? Of course! Based on the math this statement cannot be ever true. Then why do we need such an IF statement?

Actually there are certain situations when we need it. Just to name few of them. We need to make visible some parts of code which must not be executed under any circumstances. In this case we put it to such an IF. This can be make traceable usage of such a statement. E.g. message created in message’s transaction (TA SE91). In this way we just create reference point to “Where used” functionality of specific message. In case we would like to see where particular message 001 from message class Z100 is used we can achieve it. In general by this technique we can enhance ABAP code maintainability in larger scale.

This technique is often used in BW area as well. E.g. in data extraction ABAP function modules. See function modules called RSAX_BIW_GET_DATA_SIMPLE.