Annotation Provider Class
Service Builder generates the classes for Annotation Provider Class (APC) once you generate the project. APC will be generated only for the projects of type Annotation Model for Referenced Service.
Following APC classes are generated:
- Base Class
- Extension Class
| Class | Description | Naming Convention |
|---|---|---|
| Base Class | Generated by the system during the generation process. Do not modify this class manually | CL_<Project Name>_APC |
| Extension Class | This is the Implementation class that inherits the Base class. This class can be modified manually. | CL_<Project Name>_APC_EXT |
Procedure
To generate APC follow below steps:- Create a project of type Annotation Model for Referenced Service.
- Import a vocabulary file.
- Reference a service to annotate the model.
- Create annotation.
- Right click on the project folder and select Generate Runtime. Alternatively, you can also select the project and click (Generate Runtime Objects) in tool bar. A dialogue box Annotation Model Definition appears.
- Click on
(Continue). Awindow Create Object Directory Entry appears. - Click on Local Object or specify a package.
lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_CORE'
iv_vocab_version = '0001').
lo_reference->create_include( iv_namespace = 'Org.OData.Core.V1' ).Annotations can be of different types:
- Simple value can be any of the following types: String, Boolean, Integer, Path, Property path, Navigation property path. For simple value annotation, the code will look like:
lo_ann_target = vocab_anno_model->create_annotations_target( 'Musical/lyrics' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Org.OData.Core.V1.MediaType' ). lo_simp_value = lo_annotation->create_simple_value( ). lo_simp_value->set_string( 'test Desciption' ).
For Property Path, code will look like:lo_ann_target = vocab_anno_model->create_annotations_target( 'E1/P1' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Org.Mv.Core.V9.PropPath' ). lo_simp_value = lo_annotation->create_simple_value( ). lo_simp_value->set_property_path( 'TEST' ).
- Annotation with collection:
lo_ann_target = vocab_anno_model->create_annotations_target( 'Musical' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Org.OData.Core.V1.AcceptableMediaTypes' ). lo_collection = lo_annotation->create_collection( ). lo_simp_value = lo_collection->create_simple_value( ). lo_simp_value->set_string( 'entry1' ).
- Annotation with record:
lo_ann_target = vocab_anno_model->create_annotations_target( 'MusicalCollection' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Org.OData.Record.REC.UnitRecord' ). lo_record = lo_annotation->create_record( ). lo_property = lo_record->create_property( 'UnitRecord1' ). lo_simp_value = lo_property->create_simple_value( ). lo_simp_value->set_path( '32812387213987218232' ).
- Annotation with Enum Type Syntax Syntax:
lo_ann_target = vocab_anno_model->create_annotations_target( 'Musical/homepage' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Org.OData.Core.V1.Permissions' ). lo_simp_value = lo_annotation->create_simple_value( ). lo_simp_value->set_enum_member_by_name( 'Read' ).
- Annotation with Type Definition:
lo_ann_target = vocab_anno_model->create_annotations_target( 'Musical/MusicalID' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Org.OData.Core.V1.IsURL' ). lo_simp_value = lo_annotation->create_simple_value( ). lo_simp_value->set_boolean( ' ' ).
In the above syntax, the Type Definition with underlying type is Edm:Boolean