Unit 2: Creating Database Field Attributes

Use

In this unit you create and implement the database field attribute document date. This attribute contains the document date as a field value as it is stored on the database.

The system helps you implement this attribute by generating source text automatically.

Procedure

  1. Position the cursor on the entry Attributes.

  2. Choose and answer the query Create with ABAP Dictionary field proposals? with Yes. This simplifies the entry of the data type reference.

  3. Enter VBAK in the Table field.

    All database field attributes of an object type refer either to the table used to define its key fields or to a table with an identical key structure.

  4. Select the AUDAT field (document ) from the table fields displayed.

  5. Choose .

    The Create dialog box is then displayed.

  6. Check the proposed texts. You do not need to make any changes.

  7. Choose .

    The attribute is transferred into the object type definition with the automatically-proposed name DocumentDate.

Implementing attributes in the implementation program

Check the definition made so far. Select for this.

The system detects that the database field attribute has not been implemented in the program of the object type and allows you to generate a template automatically for the missing source text.

Make sure you choose this option.

The automatic generation of the implementation program has satisfactory results for database field attributes so that no revision is necessary.

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

Here, you can see additional program components that control access to the table with the attributes.

Do not change this part of the implementation!

Database field attribute

Database field attributes are implemented between the macro commands GET_TABLE_PROPERTY <table name> and END_PROPERTY.

To program one access for all attributes that refer to a table, the tables are buffered initially in an internal table. This internal table is created from the database table in the subroutine FORM SELECT_TABLE_<table name> USING SUBRC LIKE SY-SUBRC.

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

  • In the data declaration part, the variable OBJECT-_VBAK is declared as a structure VBAK (line 16).

  • The table access is implemented between the two macro command GET_TABLE_PROPERTY VBAK and END_PROPERTY (lines 21-28).

  • The automatically generated subroutine FORM SELECT_TABLE_VBAK that builds the internal table for buffering purposes is in lines 31-45.

Result

The object type must first be generated and released before it can be instantiated and tested.

  1. Choose .

    The system informs you if the object type still contains errors. Try to solve the error using the error overview (Start of the navigation pathGoTo Next navigation step Error ListEnd of the navigation path).

  2. Choose Start of the navigation pathEdit Next navigation step Change Release Status Next navigation step Object Type Next navigation step To ImplementedEnd of the navigation path.

The attributes created up to now can then be tested.

Testing the DocumentDate attribute

  1. Choose .

    You get to the Test Object Type <Object Name>: No instance connected.

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