Sap - if 1=2. What is This Code About?

By: Suresh Kumar Parvathaneni

This article is SAP related.
We all might have seen the code "IF 1=2. ....do this...EndIF" and we also know that this code never turns true. The main purpose of such code is for "Maintainability" of the program. Confused?? Read the following:
Depending upon the scenario, we would either issue the messages in the program using MESSAGE statement or sometimes might have to call the standard function module MESSAGE_PREPARE to prepare the whole message and use it wherever required.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
msg_id = msg_id
msg_no = msg_no
MSG_VAR1 = sy-msgv1
MSG_VAR2 = sy-msgv2
MSG_VAR3 = sy-msgv3
MSG_VAR4 = sy-msgv4
IMPORTING
MSG_TEXT = tdoc-text
EXCEPTIONS
FUNCTION_NOT_COMPLETED = 1
MESSAGE_NOT_FOUND = 2
OTHERS = 3.

Assume that we have defined custom message class for issuing the messages.

If we have to modify certain message in this message class, we first need to check for the where-used list of the message to study the impact of the message change. If the message is issued using the MESSAGE statement in any program, then that program would appear in the where-used list. But if the message is used in the program using the FM MESSAGE_PREPARE or any similar function module, then this program would not appear in the where-used list. So in order to have this program include in the where-used list, we would code the following after the call to the function module MESSAGE_PREPARE.
IF 1=2.
Message E003(xx).
ENDIF.
Since the check "IF 1=2" never gets true, the message would never trigger in the program and this program would appear in the where-used list of that message.

Top Searches on
Technology
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Technology