Start of Content Area

Procedure documentation Unit 8: Creating the ExistenceCheck Method Without Parameters  Locate the document in its SAP Library structure

Use

In this unit, you will create and implement the method ExistenceCheck as a method without a parameter.

You must implement this method if your object type supports the SAP standard interface.

Prerequisites

The ExistenceCheck method checks whether the object identified by the key fields actually exists. The ExistenceCheck method is one of the methods inherited by every object type from the SAP standard interface (technical name: IFSAP) .

This method is not yet implemented for the interface. The implementation program must be extended correspondingly.

The following properties and exceptions of the method ExistenceCheck are inherited from the interface IFSAP :

The ExistenceCheck method is a synchronous method, which runs without dialog, is instance-dependent and does not return a result. If the object does not exist, the method is terminated with an exception.

The exception The object does not exist is defined for the method ExistenceCheck with the number 0001 .

This exception must be implemented at the appropriate point in the source text. Use the macro command EXIT_RETURN 0001 SPACE SPACE SPACE SPACE for this purpose.

Defining exceptions

Exceptions can be defined for each method. For each exception, you must specify whether a temporary error or an application or system error is involved. Each exception is identified by a 4-digit number and linked to a message text that is supplemented by up to four variables at runtime. You can use the following number ranges:

Implementing exceptions

You trigger the exception within the implementation of the method, that is within the macro commands BEGIN_METHOD and END_METHOD , if an error occurs when the method is processed. Use the macro command with the call: EXIT_RETURN Code Variable1 Variable2 Variable3 Variable4.

As the code (ABAP Dictionary reference SWOTINVOKE-CODE), enter the four-digit number of the exception which was specified when the exception was defined. The four variables (maximum) are determined from the definition of the message that is linked to the exception.

For more information, see Programming Exceptions.

Procedure

  1. Position the cursor on the method ExistenceCheck .
  2. Choose This graphic is explained in the accompanying text.
  3. The color of the entry changes.

  4. Double-click the method name to open the method definition. You do not need to change anything here for this example. Choose This graphic is explained in the accompanying text.
  5. Position the cursor on the method ExistenceCheck .
  6. Choose Program. Let the system create the template for the missing method.
  7. The actual implementation must be carried out manually between the two macro commands BEGIN_METHOD EXISTENCECHECK CHANGING CONTAINER and END_METHOD . There is no additional source text initially.
  8. Add the implementation program of the ExistenceCheck method, which you can take from the implementation program in the appendix (lines 104-111), to the program. The VBAK table, which contains the header data of a sales order, is scanned with the key entered. If this was not successful, exception 0001 is triggered.

  9. Choose This graphic is explained in the accompanying text and exit the program editor.

Result

Testing a method without parameters

  1. The object type must first be generated so that it can be instantiated and tested. To do so, choose This graphic is explained in the accompanying text.
  2. The system informs you if the object type still contains errors. Try to correct these errors in the error overview (Goto ® Error list).

  3. To test the method, choose This graphic is explained in the accompanying text.
  4. The Test Object Type <Object Name>: No Instance screen appears.

  5. Choose This graphic is explained in the accompanying text Instance.
  6. Identify an object of the type sales order by entering the number of a sales order of your choice. Use the F4 input help if necessary.

  7. Choose This graphic is explained in the accompanying text.

The Test Object Type <Object Name> screen then appears, in which you can test your object type (execute methods, check attribute values).