Start of Content Area

Procedure documentation Unit 4: Creating Virtual Attributes  Locate the document in its SAP Library structure

Use

In this unit you create and implement the virtual attribute TextWithDocumentNo. This attribute returns the text sales order <order number> of <date> . This text must be combined in the implementation program of the object type.

A virtual attribute always requires a supplement to the proposed implementation in the implementation program.

Prerequisites

You use the macro commands provided by the system to implement these attributes.

For further information on the macro commands provided, see:

Procedure

  1. Position the cursor on the entry Attributes.
  2. Choose This graphic is explained in the accompanying text and answer the query Create with ABAP Dictionary field proposals? with No.
  3. Enter the following texts for the attribute to be created:
  4. Attribute: TextWithDocumentNo
    Name:
    Text and number
    Short description: Text and number of sales order

  5. Select Virtual in the area Source.
  6. Select Dictionary for the area Data type reference.
  7. Enter SYST in the Reference table field.
  8. Enter TITLE in the field Reference field.
  9. (You could also specify any character field with the required length here. Note that it is not the content of the field that is of interest, but its data type.)

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

Implementing attribute in the implementation program

Check the definition of the object type so far. To do so, choose This graphic is explained in the accompanying text.

The system detects that the implementation is missing and allows you to generate a template automatically for the missing source text.

Make sure you choose this option.

The source text generated automatically for implementing virtual attributes is always incomplete and restricted to setting the relevant container element. You must make changes here and implement the read procedure in the implementation program, which determines the attribute value by evaluating the database contents at runtime.

The system then automatically goes to the implementation program of the object type you created.

Virtual attributes

A virtual attribute is implemented between the macro commands GET_PROPERTY <attribute name> CHANGING CONTAINER and END_PROPERTY . The program code here determines how the value of the virtual attribute is derived at runtime.

The value determined is then stored in a container. This container forms the interface of the object type.

When you implement a virtual attribute, you must write the attribute value determined to the container of the object. Use one of the following macros for this purpose:

These macro commands are already in the automatically-generated source text.

Analyze the implementation program as it stands. You can use the implementation program in the appendix as a comparison.

Result

Testing virtual attributes

In order to test the attribute, it must first be released and then the object type must be generated.

  1. Position the cursor on the attribute TextWithDocumentNo .
  2. Choose Edit Change Release Status Object Type Component ® To Implemented.
  3. Choose This graphic is explained in the accompanying text.

The system informs you if the object type still contains errors. Try to correct these errors in the error overview (Goto ® Error list).

You can now test the attributes created up to now:

  1. Choose This graphic is explained in the accompanying text.
  2. The Test Object Type <Object Name>: No Instance screen appears.

  3. Choose This graphic is explained in the accompanying text Instance.
  4. 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.

  5. 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).