cancel
Showing results for 
Search instead for 
Did you mean: 

RAP unmanaged save, late numbering with draft

jaroslav_hrbacek
Participant
0 Kudos

Hi experts,

I have a scenario mentioned above, which should be in result creating sales order using standard BAPI. I´m using draft and late numbering. The key field sales order is assigned  in the adjust_numbers mehtod:

something like this:

  METHOD adjust_numbers.


    SELECT MAX( sls_doc ) FROM zcrm_quothead INTO @DATA(salesid_max).
    salesid_max += 1.


    READ ENTITIES OF ZI_CRM_QuotationHeader IN LOCAL MODE
     ENTITY QuotationHeader
      ALL FIELDS
       WITH CORRESPONDING #( mapped-quotationheader )
        RESULT DATA(pos_to_create).

   CLEAR mapped-quotationheader.
   LOOP AT pos_to_create INTO DATA(po_to_create).
    APPEND INITIAL LINE TO mapped-quotationheader
     ASSIGNING FIELD-SYMBOL(<mapped>).

    <mapped>-%pid = po_to_create-%pid.
    <mapped>-%key = salesid_max.
    <mapped>-SalesDocument = salesid_max.

   ENDLOOP.

  ENDMETHOD.

here is the behavior:

 

managed with unmanaged save implementation in class zbp_i_crm_quotationheader unique;
with draft;
//strict;

define behavior for ZI_CRM_QuotationHeader alias QuotationHeader
//persistent table ZCRM_QUOTHEAD
draft table zcrmd_quothead
lock master
total etag LocalLastChangedAt
etag master LocalLastChangedAt
authorization master ( instance )
late numbering

{

  create;
  update;
  delete;
  association _QuotationItem { internal create; with draft; }

  field ( readonly ) SalesDocument;
  field ( mandatory ) Description, QuotationDate, ContactUUID;
  // determination DefaultValues on modify { create;  }

  draft action Edit;
  draft action Activate;
  draft action Discard;
  draft action Resume;
  draft determine action Prepare;


  //BAPISDHD1
  mapping for bapisdhd01 corresponding
  {
    SalesDocument = doc_number;
    QuotationDate = req_date_h;
  }

  mapping for zcrm_quothead
  {
    SalesDocument = sls_doc;
    QuotationDate = quotdate;
    Description = descrpt;
    ContactUUID = conthd_uuid;
    LocalLastChangedAt = local_last_changed_at;
  }
}

define behavior for ZI_CRM_QuotationItem alias QuotationItem
draft table zcrmd_quotitem
late numbering
//persistent table <???>
lock dependent by _QuotationHeader
authorization dependent by _QuotationHeader
etag master LocalLastChangedAt

in draft tables there are the DraftUUID.:

define table zcrmd_quothead {
  key client         : abap.clnt not null;
  key salesdocument  : vbeln_va not null;
  key draftuuid      : sysuuid_x16 not null;
  contactuuid        : sysuuid_x16 not null;
  quotationdate      : abap.datn;
  description        : abap.string(1024);
  locallastchangedat : timestampl;
  "%admin"           : include sych_bdl_draft_admin_inc;

}

 

Testing my RAP in report list, I can create a draft in object page. I can edit draft, I can save draft to active instance. Howerver I can´t display active instance. There is an error: Unable to load the data. I found in the console, that it is calling get request: /QuotationHeader(SalesDocument='1',DraftUUID=00000000-0000-0000-0000-000000000000,IsActiveEntity=true). But the header entity has only one key field = Sales Document. DraftUUID is only in the draft table. 

 

what am I missing? 

thanks

Jarda

View Entire Topic
Ramjee_korada
Active Contributor
0 Kudos

Hi Jarda,

This topic is complicated and solution is described in the blog post -https://blogs.sap.com/2023/08/06/abap-rap-customizing-draft-behavior-in-a-fiori-application/

 

The root cause is that you want to implement draft but the draft implementation requires a guide as a key field in parent entity and it can be marked as numbering : managed.

My blog describes unmanaged implementation and you can ignore as you are using managed with unmanaged save.

 

Best wishes,

Ramjee Korada

 

jaroslav_hrbacek
Participant
0 Kudos
Thank you Ramjee. I will try it.