Show TOC

Procedure documentationUnit 6: Creating Multiline Virtual Attributes Locate this document in the navigation structure

 

In this unit you create and implement the multiline object virtual attribute sales document items. 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 more information on the macro commands provided, see:

Procedure

  1. Position the cursor on the entry Attributes.

  2. Choose and answer the query Create with ABAP Dictionary field proposals? with No.

  3. Enter the following texts for the attribute to be created:

    • Attribute: Items

    • Name: Order Items

    • Short text: Sales order items

  4. Select Virtual in the area Source.

  5. Select multiline in the area attribute property.

  6. Select Object type in the Data type reference area.

  7. Enter VBAP in the Object type field.

  8. Choose .

Implementing attributes in the implementation program

Check the definition of the object type so far. Select for this.

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.

  • As the attribute is to return a multiline list of object references, an internal table OBJECT-ITEMS with type SWC_OBJECT is declared (line 14 of the program, generated automatically).

  • Let the system create the template for the missing method. It must be done between the two macro commands GET_PROPERTY ITEMS CHANGING CONTAINER and END_PROPERTY (lines 65-96). The system inserts the macro command between these macro commands, with which the object reference to be created is written to the container.

  • Data declaration (lines 69-78)

    • Refresh table OBJECT-ITEMS

    • Auxiliary variable ITEM with type SWC_OBJECT to hold one object reference

    • Structure VBAP_KEY with the two fields VBELN and POSNR. These fields correspond to the key fields of the table VBAP (sales document: item data).

    • Internal table VBAP_TAB with structure VBAP. The items for an order are "collected" in this table.

  • Data selection (lines 81-91)

    • All items for the sales order identified by the key field of the object type are read from table VBAP and written to table VBAP_TAB (lines 81-82).

    • The entries in table VBAP_TAB are used in a loop (lines 87-91) as follows:

      The structure VBAP_KEY is filled

      An object reference ITEM is created

      ITEM is appended to table OBJECT-ITEMS.

  • Assignment (line 94)

    • The internal table OBJECT-ITEMS with the list of object references is assigned to the container element Items with the container macro SWC_SET_TABLE.

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 .

    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 .

    The Test Object Type <Object Name>: No Instance screen appears.

  2. Choose Instance.

    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.

  3. Choose .

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

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

  • SalesDocumentNo (sales document)

  • ItemNo (sales document item)

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 Syntax

  1. 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.
End of the code.