Instance Methods: Free Methods in Application DevelopmentLocate this document in the navigation structure

Use

As an application developer, you can create and implement your own methods for each controller. These methods are known as instance methods. These instance methods are normally used to procure and process data. These methods can be called within the controller by other methods, including methods implemented by application developers.

Parameters of Free Methods

Free methods in application development can, like event handlers, have mandatory or optional parameters.

Note

Note that the ABAP IS_SUPPLIED command is not supported for parameters in Web Dynpro ABAP.

More information: Special Features of Web Dynpro ABAP Programming

Free Methods in the Component Interface

Each method you create and define for the component controller can be added to the component interface. To do this, you select the Interface checkbox in the table on the Methods tab page of the component controller. Each method for which this checkbox is selected is part of the interface controller of the component and can be used by controllers of other components.

More information: Cross-Component Programming

Defining Exceptions

As of SAP NetWeaver 7.1, class-based exceptions can be defined for instance methods. The signature in the method editor allows you to switch between the display screen for the method's parameters and the method's exceptions.

In releases lower than SAP NetWeaver 7.1, we recommend defining a dynamic exception (derived from CX_DYNAMIC_CHECK) and raising this exception at the required location. The advantage of these exceptions is that you can catch them anywhere in the call hierarchy and do not have to catch them where the call is made.

Example

In the following example, the GET_FLIGHTS method has been implemented to read data from the back end for the current controller. This data is to be used in a second method in the same controller.

method GET_FLIGHTS .  
...
endmethod.


         
method FILL_CONTEXT_NODE . 
data: FLIGHTSTRUC type SPFLI.
      MY_NODE type ref to IF_WD_CONTEXT_NODE.
FLIGHTSTRUC = WD_THIS->GET_FLIGHTS( ).
MY_NODE = WD_CONTEXT->GET_CHILD_NODE( 'MY_CONTEXT_NODE' ).
MY_NODE->BIND_STRUCTURE( NEW_ITEM = FLIGHTSTRUC ).
endmethod.
         

Reference variable WD_THIS is used to call controller method GET_FLIGHTS and to pass the return value to internal variable FLIGHTSTRUC.

In the next step, context node MY_CONTEXT_NODE is passed to a second internal variable MY_NODE of type IF_WD_CONTEXT_NODE (see above, under WD_CONTEXT).

In the last step, internal variable FLIGHTSTRUC is bound to MY_NODE.