In this unit you create and implement the objectvirtual attribute sales group. This attribute returns the sales group of the sales order as an object reference.
Objects of the type sales group have only one key field. Therefore, it is not actually necessary to implement this attribute as a virtual attribute. You could also create it as an object database field attribute.
This basic example is simply intended to demonstrate how a virtual attribute is implemented.
A virtual attribute always requires an implementation in the implementation program.
You use the macro commands provided by the system to implement these attributes.
For further information on the macro commands provided, see:
Implementing attributes in the implementation program
Check the definition of the object type so far. To do so, choose .
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 goes to the implementation program.
A virtual attribute is implemented between the macro commandsGET_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 create an object reference. To create an object reference with given key fields and a known object type, use the following macro command:
The variable<Object> must first be declared with:
This data declaration is already in the automatically-generated source text.
Analyze the implementation program as it stands. You can use theimplementation program in the appendix as a comparison.
Add the following two lines to the implementation program:
SELECT SINGLE * FROM VBAK WHERE VBELN = OBJECT-KEY-SALESDOCUMENT.
SWC_CREATE_OBJECT OBJECT-SALESGROUP 'TVKGR' VBAK-VKGRP.
Testing the virtual attribute SalesGroup
The system informs you if the object type still contains errors. Try to correct these errors in the error overview (Goto ® Error list).
Test the attributes created so far.
The Test Object Type <Object Name>: No Instance screen appears.
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.
The Test Object Type <Object Name> screen then appears, in which you can test your object type (execute methods, check attribute values).