Show TOC

Generating Classes for Annotation Provider ClassLocate this document in the navigation structure

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:
  1. Create a project of type Annotation Model for Referenced Service.
  2. Import a vocabulary file.
  3. Reference a service to annotate the model.
  4. Create annotation.
  5. Right click on the project folder and select Generate Runtime. Alternatively, you can also select the project and click Generate Runtime Objects (Generate Runtime Objects) in tool bar. A dialogue box Annotation Model Definition appears.
    Note All the information in this dialogue box can be edited. You can provide a version for the annotated model in Model Version field.
  6. Click on Continue (Continue). Awindow Create Object Directory Entry appears.
  7. Click on Local Object or specify a package.
The APC is generated and stored in the Runtime Artifacts folder in the tree region. Also the message displaying the results of the generation is displayed in the mass edit view. Method DEFINE_VOCAB_ANNOTATIONS will be created in the APC to maintain the Vocabulary based Annotations. Inside this method vocabulary references will be created. The syntax is:
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:
  1. 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' ).
    
  2. 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' ).
  3. 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' ).
  4. 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' ).
  5. 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