cancel
Showing results for 
Search instead for 
Did you mean: 

RAP Can't read entities with %tky enabling draft

Daniela_Piras
Newcomer
0 Kudos
132

Hi all!

I'm following SAP course "Building Apps with the ABAP RESTful Application Programming Model" but I'm trying to use OData V4 instead of V2.

I learnt that I need to activate the draft to enable Create option in the preview, so I create draft tables, entities and I adapted my behavior definition adding "with draft", total etag etc.

Before adding the draft, the following code worked, I had no syntax errors and I was able to activate the behavior implementation and open the preview:

METHOD calculateBookingID.

    DATA: max_booking TYPE /dmo/booking_id,
          update      TYPE TABLE FOR UPDATE zdp_cds_travel\\Booking.

    READ ENTITIES OF zdp_cds_travel IN LOCAL MODE
      ENTITY Travel BY \_Booking
      FIELDS ( TravelUUID )
      WITH CORRESPONDING #( keys )
      RESULT DATA(travels).

    LOOP AT travels INTO DATA(travel).

      max_booking = '0000'.
      READ ENTITIES OF zdp_cds_travel IN LOCAL MODE
        ENTITY Travel BY \_Booking
          FIELDS ( BookingID )
        WITH VALUE #( ( %tky = travel-%tky  ) )
        RESULT DATA(bookings).

      LOOP AT bookings INTO DATA(booking)
          WHERE BookingID IS INITIAL.

        max_booking += 10.

        APPEND VALUE #( %tky        = booking-%tky
                        BookingID   = max_booking )
          TO update.

      ENDLOOP.

    ENDLOOP.

    MODIFY ENTITIES OF zdp_cds_travel IN LOCAL MODE
      ENTITY Booking
      UPDATE FIELDS ( BookingID )
      WITH update
      REPORTED DATA(reported_update).

    reported = CORRESPONDING #( DEEP reported_update ).
  ENDMETHOD.

 After enabling the draft, line 18 rose this error:
The type of "TRAVEL-%TKY" cannot be converted to the type of "%TKY"

If I comment the draft, it works again.

Here the behavior definition:

managed;// implementation in class zbp_dp_cds_travel unique;
//strict; // ( 2 );
with draft;

define behavior for zdp_cds_travel alias Travel
implementation in class zbp_dp_i_travel unique
persistent table ztdp_travel
draft table ztdp_travel_d
lock master
total etag LastChangedAt
authorization master ( instance )
etag master LocalLastChangedAt //Optimistic Locking
{
  create;
  update;
  delete;
  field ( numbering : managed, readonly ) TravelUUID;
  field ( readonly ) TravelID, TotalPrice;
  field ( readonly ) LastChangedAt, LastChangedBy, CreatedAt, CreatedBy, LocalLastChangedAt;
  field ( mandatory ) AgencyID, CustomerID;
  association _Booking { create; }

  action ( features : instance ) acceptTravel result [1] $self;
  action ( features : instance ) rejectTravel result [1] $self;
  internal action recalcTotalPrice;

  determination setInitialStatus on modify { create; }
  determination calculateTotalPrice on modify { field BookingFee, CurrencyCode; }
  determination calculateTravelID on save { create; }

  validation validateAgency on save { field AgencyID; create; }
  validation validateCustomer on save { field CustomerID; create; }
  validation validateDates on save { field BeginDate, EndDate; create; }

  mapping for ztdp_travel
    {
      TravelUUID         = travel_uuid;
      TravelID           = travel_id;
      AgencyID           = agency_id;
      CustomerID         = customer_id;
      BeginDate          = begin_date;
      EndDate            = end_date;
      BookingFee         = booking_fee;
      TotalPrice         = total_price;
      CurrencyCode       = currency_code;
      Description        = description;
      CreatedBy          = created_by;
      CreatedAt          = created_at;
      LastChangedBy      = last_changed_by;
      LastChangedAt      = last_changed_at;
      LocalLastChangedAt = local_last_changed_at;
    }

}

define behavior for zdp_cds_booking alias Booking
implementation in class zbp_dp_i_booking unique
persistent table ztdp_book
draft table ztdp_book_d
lock dependent by _Travel
authorization dependent by _Travel
etag master LocalLastChangedAt  //Optimistic Locking
{
  update;
  delete;
  field ( numbering : managed, readonly ) BookingUUID;
  association _Travel;

  field ( readonly ) TravelUUID, BookingID;
  field ( readonly ) CreatedBy, LastChangedBy, LocalLastChangedAt;

  determination calculateBookingID on modify { create; }
  determination calculateTotalPrice on modify { field FlightPrice, CurrencyCode; }

  mapping for ztdp_book
    {
      BookingUUID        = booking_uuid;
      TravelUUID         = travel_uuid;
      BookingID          = booking_id;
      BookingDate        = booking_date;
      CustomerID         = customer_id;
      CarrierID          = carrier_id;
      ConnectionID       = connection_id;
      FlightDate         = flight_date;
      FlightPrice        = flight_price;
      CurrencyCode       = currency_code;
      CreatedBy          = created_by;
      LastChangedBy      = last_changed_by;
      LocalLastChangedAt = local_last_changed_at;
    }
}

 Any suggestions?

Thanks

View Entire Topic
patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello,

in line 10 you are actually reading "bookings", not "travels". Therefore you could add "BookingID" to the field list of line 8. 
In line 18 the %tky of entity Travel is expected. You can place the cursor on it and press F2. However, travel-%tky, which is actually booking-%tky, is not compatible.

I don't know why it would work w/o draft.

Regards,
Patrick