Show TOC

Background documentationInstance Methods: Free Methods in Application Development Locate this document in the navigation structure

 

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

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

End of the note.
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.10, you can define class-based exceptions 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.10, we recommend that you define a dynamic exception (derived from CX_DYNAMIC_CHECK) and raise 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.

Syntax Syntax

  1. method GET_FLIGHTS .  
  2. ...
  3. endmethod.
End of the code.

Syntax Syntax

  1. method FILL_CONTEXT_NODE . 
  2. data: FLIGHTSTRUC type SPFLI.
  3.       MY_NODE type ref to IF_WD_CONTEXT_NODE.
  4. FLIGHTSTRUC = WD_THIS->GET_FLIGHTS( ).
  5. MY_NODE = WD_CONTEXT->GET_CHILD_NODE( 'MY_CONTEXT_NODE' ).
  6. MY_NODE->BIND_STRUCTURE( NEW_ITEM = FLIGHTSTRUC ).
  7. endmethod.
End of the code.

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.