Skip to content

Latest commit

 

History

History
297 lines (253 loc) · 11.7 KB

optional_parameters.md

File metadata and controls

297 lines (253 loc) · 11.7 KB

Optional parameters for workshops or other advanced scenarios

The follwoing parameters have been implemented so that it is possible to create RAP business objects including a mapping (if CDS views are used as a data source) and including assocations and value helps.

This is usefull if identical objects shall be created for trainings.

The RAP Generator has and is used for SAP events such as the openSAP courses about RAP and SAP Fiori as well as for hands on sessions in SAP user group events or SAP TechEd.

Here I got the following requirements:

  • Add additional fields to the generated CDS views (e.g. fields based on an association such as '_Travel.Customer' )
  • Change the field names of the generated artefacts (e.g. use the field name 'Customer' instead of 'PartnerID' which would be used if the field of the database table would be 'PARTNER_ID'.

When using this parameters the json files will become more complicated. As a result the use of these parameters is not recommended if you want to develop a single RAP object. As said they will typically be used in workshops such as TechEd sessions, CodeJams or OpenSAP courses where there is the need to provide participants with complete RAP business objects as a starting point.

Please note
When creating JSON files in general and complicated JSON files in particular it is strongly recommended to use an appropriate JSON editor of your choice.

I personally can recommend Visual Studio Code.

mapping

Using this parameter you can provide the mapping between the field names of the CDS view and the field names used by the legacy business logic if CDS views are used as a data source. When using tables as data sources this mapping is generated by the generator. When CDS views are used as a data source such a mapping has be created manually by the developer if it has not been set.

{
  "implementationType": "unmanaged_semantic",
  "namespace": "Z",
  "suffix": "_####",
  "prefix": "RAP_",
  "package": "ZRAP_####",
  "datasourcetype": "cds_view",
  "hierarchy": {
    "entityName": "Travel",
    "dataSource": "/DMO/I_Travel_U",
    "objectId": "TravelID",
    "persistenttable": "/dmo/travel",    
    "lastchangedat": "lastchangedat", 
    "mapping": [
      {
        "dbtable_field": "TRAVEL_ID",
        "cds_view_field": "TravelID"
      },
      {
        "dbtable_field": "AGENCY_ID",
        "cds_view_field": "AgencyID"
      },
      {
        "dbtable_field": "CUSTOMER_ID",
        "cds_view_field": "CustomerID"
      },
      {
        "dbtable_field": "BEGIN_DATE",
        "cds_view_field": "BeginDate"
      },
      {
        "dbtable_field": "BOOKING_FEE",
        "cds_view_field": "BookingFee"
      },
      {
        "dbtable_field": "TOTAL_PRICE",
        "cds_view_field": "TotalPrice"
      },
      {
        "dbtable_field": "CURRENCY_CODE",
        "cds_view_field": "CurrencyCode"
      },
      {
        "dbtable_field": "DESCRIPTION",
        "cds_view_field": "Description"
      },
      {
        "dbtable_field": "STATUS",
        "cds_view_field": "Status"
      },
      {
        "dbtable_field": "LASTCHANGEDAT",
        "cds_view_field": "Lastchangedat"
      }
    ],   
    "children": [
      {
        "entityName": "Booking",
        "dataSource": "/DMO/I_Booking_U",
        "objectId": "BookingID",
        "persistenttable": "/dmo/booking"      
      }
    ]
  }
}

“associations” and “valuehelps”

On node level it is also possible to set information to generate valuehelps and associations. These properties have been introduced mainly for setups in courses where one would like to be able that participants can generate a business object that contain exactly those associations and value help definitions that are required for the course. Though it might also be useful for other scenarios as well, you see that the complexity of your JSON file will grow and it might be simpler to code this manually in the CDS views that are generated by the RAP generator.

“associations”

Associations is an array of objects where each object represents one association. An association needs the several properties

  • "name" is the name of the association and its name must start with an underscore '_'.
  • "target" is the name of the CDS view that is the target of your associaton
  • "cardinality" here you can enter one of the following values
    • "zero_to_one" [0..1]
    • "one" [1]
    • "zero_to_n" [0..n]
    • "one_to_n" [1..n]
    • "one_to_one" [1..1]
  • "conditions" is again an array of objects with two properties
    • "projectionField" this is the field ´"$projection.AgencyID = _Agency.AgencyID"´
    • "associationField" this is the field ´"$projection.AgencyID = _Agency.AgencyID
    "associations": [
      {
        "name": "_Agency",
        "target": "/DMO/I_Agency",
        "cardinality": "zero_to_n",
        "conditions": [
          {
            "projectionField": "AgencyID",
            "associationField": "AgencyID"
          }
        ]
      },
      {
        "name": "_Customer",
        "target": "/DMO/I_Customer",
        "cardinality": "zero_to_n",
        "conditions": [
          {
            "projectionField": "CustomerID",
            "associationField": "CustomerID"
          }
        ]
      }
    ]

valueHelps

Valuehelps is also an array of objects where each object represents a value help. Each object may contain an addiitional array that contains the information for the additional binding.

  • "alias" is the alias of the value help used in the service definition.
  • "name" is the name of the CDS view used as a value help
  • "localelement" this denotes the field name in your projection view. Since this is already the CDS field name you have to be aware about the naming convertions that are used by the generator when it creates cds fields from the underlying ABAP field names, namely by using the conversion into camelCase notation.
      @Consumption.valueHelpDefinition: [{ entity : {name: '/DMO/I_Agency', element: 'AgencyID'  } }]
      AgencyID,
  • "element" this is the field name in the CDS view that is used as a value help.
      @Consumption.valueHelpDefinition: [{ entity : {name: '/DMO/I_Agency', element: 'AgencyID'  } }]
      AgencyID,
  • "additionalBinding" is again an array of objects with two properties
  • "localElement" these are the following fields
      @Consumption.valueHelpDefinition: [ {entity: {name: '/DMO/I_Flight', element: 'ConnectionID'},
                                                 additionalBinding: [ { localElement: 'FlightDate',   element: 'FlightDate'},
                                                                      { localElement: 'AirlineID',    element: 'AirlineID'},
                                                                      { localElement: 'FlightPrice',  element: 'Price', usage: #RESULT},
                                                                      { localElement: 'CurrencyCode', element: 'CurrencyCode' } ] } ]
  • "element" these are the following fields
      @Consumption.valueHelpDefinition: [ {entity: {name: '/DMO/I_Flight', element: 'ConnectionID'},
                                                 additionalBinding: [ { localElement: 'FlightDate',   element: 'FlightDate'},
                                                                      { localElement: 'AirlineID',    element: 'AirlineID'},
                                                                      { localElement: 'FlightPrice',  element: 'Price', usage: #RESULT},
                                                                      { localElement: 'CurrencyCode', element: 'CurrencyCode' } ] } ]
                                                                      
  • "usage" these are the following (optinonal) fields in a valuehelp
      @Consumption.valueHelpDefinition: [ {entity: {name: '/DMO/I_Flight', element: 'ConnectionID'},
                                                 additionalBinding: [ { localElement: 'FlightDate',   element: 'FlightDate'},
                                                                      { localElement: 'AirlineID',    element: 'AirlineID'},
                                                                      { localElement: 'FlightPrice',  element: 'Price', usage: #RESULT},
                                                                      { localElement: 'CurrencyCode', element: 'CurrencyCode' } ] } ]
                                                                      

In order to generate a value help as mentioned above the following entry would have to be added to a node object, here the booking entity.

      
    "valueHelps": [
          {
            "alias": "Flight",
            "name": "/DMO/I_Flight",
            "localElement": "ConnectionID",
            "element": "ConnectionID",
            "additionalBinding": [
              {
                "localElement": "ConnectionID",
                "element": "ConnectionID"
              },
              {
                "localElement": "CarrierID",
                "element": "AirlineID"
              },
              {
                "localElement": "ConnectionID",
                "element": "ConnectionID",
                "usage": "RESULT"
              }
            ]
          },
          {
            "alias": "Currency",
            "name": "I_Currency",
            "localElement": "CurrencyCode",
            "element": "Currency"
          }
        ]
      }
    ]

objectswithadditionalfields

When using the RAP Generator in workshops it turned out that CDS views should also contain fields that are not part of the underlying data source such as fields that are retrieved via an association.

_Customer.LastName as CustomerName,

If additional fields are added this has to be done at various locations namely

  • cds_interface_view
  • cds_projection_view
  • draft_table

One has to specifiy the field name, the alias and optionally the key word localized.

So the JSON file must contain an array objectswithadditionalfields. For each object type an additional array called "additionalfields" has to be filled that contains the additional fields for each object.

Please note that the field names for additional fields in the draft table must match the field name (or the alias name) of the field in the interface view.

 "objectswithadditionalfields": [
      {
        "object": "cds_projection_view",
        "additionalfields": [
          {
            "fieldname": "_HolidayTxt.HolidayDescription",
            "alias": "HolidayDescription",
            "localized": true
          },
          {
            "fieldname": "_DeprecationText.ConfignDeprecationCodeName",
            "alias": "DeprecationDescription",
            "localized": true
          },
          {
            "fieldname": "Criticality",
            "alias": "Criticality"
          }
        ]
      },
      {
        "object": "cds_interface_view",
        "additionalfields": [
          {
            "fieldname": "case overall_status when ' ' then 2  when 'N' then 2  when 'I' then 0   when 'P' then 0   when 'D' then 3   when 'X' then 1   else 0    end",
            "alias": "Criticality"
          }
        ]
      },
      {
        "object": "draft_table",
        "additionalfields": [
          {
            "fieldname": "Criticality",
            "builtintype": "int1"
          }
        ]
      }
    ],