You are on page 1of 8

Message Control using ABAP Objects

Hewitt Inc.
Beyond Technologies

Author: Alexandre Giguere

Message Control using ABAP Objects


Message control or output management are maintained with SAP transaction NACE. Message control are trigger by output type and other specific criteria like the language, application. Instead of having multiple output programs for each output type, we decided to have only one generic print program that will call an ABAP class. All business logic will be encapsulated inside ABAP classes. Inheritance will allow us to reause functionnality like emailing across all output types. The generic output program Z_P_SD_OUTPUT_DETERMINATION All IMG customizing should used this program. Source code FORM entry USING u_return_code TYPE i u_screen TYPE c. "#EC CALLED DATA: lr_output TYPE REF TO zif_output. * lx_output TYPE REF TO zcx_output. TRY. lr_output = zcl_output=>get_instance( nast ). lr_output->send( u_screen ). u_return_code = 0. CATCH zcx_output. " INTO lx_output. u_return_code = 1. ENDTRY. ENDFORM. "ENTRY

The get instance method is a factory pattern that will return us an instance of the corresponding output, however we will need to create our ABAP class following particular naming convention, we will see that later. Then we called the send method, this method is final and could not be redefined but internally this method is calling other methods that could be redefined. Last but not least, we need to set the return code to either 0 or 1.

Page 1 of 8

The Superclass
ZCL_OUTPUT Definition: Abstract class implementing the interface ZIF_OUTPUT with only one method SEND. This method will be called from the output / print program. The send method will call other protected method that must be redefined in the inheritance tree allowing polymorphism behaviour. The send method is raising the exception ZCX_OUTPUT if something goes wrong. This exception will be catch by the output program and set the valid return code to either 0 or 1 (error). Methods: GET_INSTANCE Public static method implementing the factory pattern. Returning interface ZIF_OUTPUT. FAX_PDF Protected method, under construction. Implementation missing. EMAIL_PDF Protected method for emailing all PDF. GET_EMAIL_SUBJECT Protected method, no implementation, should be redefined in sub-class to set your subject title. GET_EMAIL_ADDRESS Protected method getting the email address from the business partner (customer or vendor). Could be redefined in sub-class if logic is different. GET_FORM_DATA Protected method, abstract. This method will need to be implemented in all sub-classes. This is where you will put your code for gathering the data you need to output. GET_MESSAGE_HISTORY / READ MESSAGE_HISTORY Protected method, final. Utility method to read the current output type history, how many output have been printed yet . DO_SPECIAL_FUNCTION Protected method for transmission medium 5. Must be redefine for implementing business logic. GET_PDF_OUTPUT_PARAMS Protected method for setting default print parameters with SAP IFbA. GET_SSF_OUTPUT_PARAMS Protected method for setting default print parameters with Smart Forms. SEND_ADOBE_FORM Private method, main method for dispatching PDF output. SEND_SMART_FORM Private method, main method for dispatching Smart Form output. GET_PROCESSING_PROG Private method. Reading the IMG customizing for determining what is the output type (pdf or smart form).

Page 2 of 8

The subclasses (2nd level of the inheritance tree)


ZCL_OUTPUT_EF ZCL_OUTPUT_ME ZCL_OUTPUT_V1 ZCL_OUTPUT_V2 ZCL_OUTPUT_V3 -> -> -> -> -> Purchasing Inventory Management Sales Shipping Billing

Definition: The second level in the inheritance tree will be generic classes representing the application area. Output type are defined under specifc applications, these application area tells us if we are dealing with shipment, sales, billing The subclasses will always be abstract, that means they cannot be instantiated. They will be responsible to implement the constructor method and instantiating the business class related to the corresponding application area. Example: Application V1 is for Sales, that means the object key in table NAST will be a sales document. The constructor will instantiated the business class ZIF_SALES_DOCUMENT, so any subclasses could work with the instance. Methods: READ_LOGO Private method, not implemented in all sub-classes, read the hewitt logo in save in an xstring attribute.

Page 3 of 8

The subclasses (3rd and 4th level of the inheritance tree)


Purchasing ZCL_OUTPUT_EF_NEU Inventory Management ZCL_OUTPUT_ME_ZWE9 Sales ZCL_OUTPUT_V1_ZEOC ZCL_OUTPUT_V1_0146 o ZCL_OUTPUT_V1_ZCSA ZCL_OUTPUT_V1_0149 o ZCL_OUTPUT_V1_ZQTE ZCL_OUTPUT_V1_0303 o ZCL_OUTPUT_V1_ZCRL o ZCL_OUTPUT_V1_ZQRL ZCL_OUTPUT_V1_0304 o ZCL_OUTPUT_V1_ZBA0 ZCL_OUTPUT_V1_ZAME ZCL_OUTPUT_V1_ZAPR ZCL_OUTPUT_V1_ZBIL ZCL_OUTPUT_V1_ZEOC ZCL_OUTPUT_V1_ZQTT Shipping ZCL_OUTPUT_V2_1054 o ZCL_OUTPUT_V2_ZPL0 o ZCL_OUTPUT_V2_ZPLA ZCL_OUTPUT_V2_ZBIL ZCL_OUTPUT_V2_ZWE1 ZCL_OUTPUT_V2_ZWE2

Page 4 of 8

Billing ZCL_OUTPUT_V3_0144 o ZCL_OUTPUT_V3_ZAPN o ZCL_OUTPUT_V3_ZPCT o ZCL_OUTPUT_V3_ZPDT o ZCL_OUTPUT_V3_ZPQT o ZCL_OUTPUT_V3_ZPRF o ZCL_OUTPUT_V3_ZPRT ZCL_OUTPUT_V3_0145 o ZCL_OUTPUT_V3_ZECT o ZCL_OUTPUT_V3_ZEPF o ZCL_OUTPUT_V3_ZEQP ZCL_OUTPUT_V3_1048 o ZCL_OUTPUT_V3_ZSCT o ZCL_OUTPUT_V3_ZSPF o ZCL_OUTPUT_V3_ZSQT o ZCL_OUTPUT_V3_ZSRV o ZCL_OUTPUT_V3_ZSVL ZCL_OUTPUT_V3_0302 o ZCL_OUTPUT_V3_ZREN ZCL_OUTPUT_V3_1133 o ZCL_OUTPUT_V3_ZPLP ZCL_OUTPUT_V3_ZADE ZCL_OUTPUT_V3_ZCAB ZCL_OUTPUT_V3_ZCOR ZCL_OUTPUT_V3_ZTSR

Definition: The third level of classes will be used to gather all information for the output. Normally the third level is the last level of the inheritance tree, the name of the class is represented by the application and the output type. Example: ZCL_OUTPUT_V1_ZAME for output type ZAME under application V1 (sales). You must redefine and implement at least one of these 2 methods: DO_SPECIAL_FUNCTION (transmission medium 5) GET_FORM_DATA (transmission medium 2) However, its possible that there is a need where the functional has to configure 2 output types or more for the same form. In this case, it wont make sense to recopy the business logic to gather the form data in multiple classes. To remedy at this, we will create a fourth level representing the output type, and the third level will be used to gather the form data. The third level will have a different name, we used the RICEFW as the naming convention instead of the output type. Example: There is 5 output types for 1 smart form or adobe form. The business logic to gather the rd form data will be in the 3 level (ZCL_OUTPUT_V1_9999) and we will create 5 sub-classes of ZCL_OUTPUT_V1_9999 inheriting the business logic.

Page 5 of 8

The instantiation level should be set as private or protected depending if you are or not at the end of the inheritance tree. Remember that the GET_INSTANCE method from the superclass ZCL_OUTPUT will dynamically type the interface ZIF_OUTPUT according to a naming convention. Naming convention: ZCL_OUTPUT_Application_OutputType A wrong name could result in an unexpected behaviour or a system short dump.

Page 6 of 8

Refer to other classes for code examples:

Page 7 of 8

You might also like