Start of Content Area

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

Use

In this unit you create and implement the multiline object virtual attribute sales document positions. This attribute evaluates the items in the sales order, and returns a list with references to objects of the type VBAP ( sales document item).

A virtual attribute always requires an 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: Items
    Name:
    Order items
    Short description: Sales order items

  5. Select Virtual in the area Source.
  6. Select multiline in the area attribute property.
  7. Select Object type in the Data type reference area.
  8. Enter VBAP in the Object type field.
  9. Choose This graphic is explained in the accompanying text.

Implementing attributes 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 program of the object type, which determines the attribute value by evaluating the database contents at runtime.

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

Virtual attribute

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.

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

The structure VBAP_KEY is filled

An object reference ITEM is created

ITEM is appended to table OBJECT-ITEMS .

Result

Testing the virtual attribute items

  1. Position the cursor on the attribute just defined.
  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).

The attributes created up to now can then be tested.

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

Note: Object type VBAP (sales document item)

The object type VBAP describes the individual items of a sales document. The key fields of the object type VBAP are:

These key fields reference the key fields VBELN and POSNR in the table VBAP (sales document: item data).

Alternative implementation

An alternative implementation without an additional internal table is shown below.

Syntax

get_property items changing container.

  
tables vbap.
  
refresh object-items. clear object-items.

  
data item type swc_object.
  
data: begin of vbap_key,
         vbeln like vbap-vbeln,
         posnr like vbap-posnr,
       end of vbap_key.


  
vbap_key-vbeln = object-key-salesdocument.

  
select * from vbap where vbeln = object-key-salesdocument.
    
vbap_key-posnr = vbap-posnr.
    
swc_create_object item 'VBAP' vbap_key.
    
append item to object-items.
  
endselect.

  
swc_set_table container 'Items' object-items.
end_property.