cancel
Showing results for 
Search instead for 
Did you mean: 

RAP API with custom static action: How can I set optional parameters?

10-23-2025 5:30 PM
emalelez15 Explorer
2039 views 5 comments
0 Likes
SAP Managed Tags
Labels
ABAP RAP custom actionABAP RAP(RESTful Application Programming)
Subscribe

Hi everyone,

I defined a API using RAP. Here below all the details.

ROOT ENTITY

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Sales Report (SLSRPT from Lobster)'
@Metadata.ignorePropagatedAnnotations: true
define root view entity ZLBSR_R_SALES_DATA
  as select from zsd_lbstr_slsrpt
{
  key uuid               as UUID,
      erdat              as CreationDate,
      erzet              as CreationTime,
      ernam              as CreationUser,
      status             as Status,
      bstkd              as CustomerReference,
      bstdk              as CustomerReferenceDate,
      ean11              as ArticleEAN11,
//      @Semantics.quantity.unitOfMeasure: 'QuantityUnitOfMeasure'
      kwmeng             as Quantity,
      vrkme              as QuantityUnitOfMeasure,
      vdatu              as RequestedDeliveryDate,
      sold_to_party_gln  as SoldToPartyGLN,
      ship_to_party_gln  as ShipToPartyGLN,
      @Semantics.systemDateTime.localInstanceLastChangedAt: true
      local_last_changed as LocalLastChanged,
      @Semantics.systemDateTime.lastChangedAt: true
      last_changed       as LastChanged
}

BEHAVIOUR DEFINITION

managed implementation in class zbp_lbsr_r_sales_data unique;
strict ( 2 );

define behavior for ZLBSR_R_SALES_DATA alias SalesData
persistent table zsd_lbstr_slsrpt
lock master
authorization master ( instance )
etag master LastChanged
{
  field ( readonly )
  UUID,
  CreationDate,
  CreationTime,
  CreationUser,
  Status,
  LastChanged,
  LocalLastChanged;
  field ( numbering : managed )
  UUID;

  create;
  update;
  delete;

  determination fill_administrative_data on save { create; }

  static action deleteWithFilters parameter ZLBSR_D_DELETION_FILTERS;

  mapping for zsd_lbstr_slsrpt
    {
      UUID                  = uuid;
      CreationDate          = erdat;
      CreationTime          = erzet;
      CreationUser          = ernam;
      Status                = status;
      CustomerReference     = bstkd;
      CustomerReferenceDate = bstdk;
      ArticleEAN11          = ean11;
      Quantity              = kwmeng;
      QuantityUnitOfMeasure = vrkme;
      RequestedDeliveryDate = vdatu;
      SoldToPartyGLN        = sold_to_party_gln;
      ShipToPartyGLN        = ship_to_party_gln;
      LocalLastChanged      = local_last_changed;
      LastChanged           = last_changed;
    }
}

ABSTRACT ENTITY ZLBSR_D_DELETION_FILTERS

@EndUserText.label: 'Sales Report - Filters for deleteWithFilters action'
define abstract entity ZLBSR_D_DELETION_FILTERS
{
  CustomerReference : bstkd;
  SoldToPartyGLN    : zlbstr_slsrpt_sold_to_prty_gln;
  ShipToPartyGLN    : zlbstr_slsrpt_ship_to_prty_gln;
}

The 3 fields CustomerReference, SoldToPartyGLN and ShipToPartyGLN are all character fields with different lenghts.

When I send a POST request for the action deleteWithFilters I have always to declare the value for all the 3 parameters. I could always declare the ShipToPartyGLN as empty (like "ShipToPartyGLN""") and that works but I'd like to set the ShipToPartyGLN as optional in order to avoid the caller to set this parameter everytime. How can I do that?

emalelez15_0-1761233096857.png

 

Thanks!

 

 

 

0 Likes
View Entire Topic
Oleg_Vokh
Product and Topic Expert
Product and Topic Expert

Hi @emalelez15 ,
Try using Abstract Behavior Definition as shown in the screenshots below,

Oleg_Vokh_0-1761564189654.png
mandatory:execute: Marks CustomerReference and SoldToPartyGLN as required in the request body,
ShipToPartyGLN is not marked, so it should be optional

Oleg_Vokh_1-1761564231876.png

I hope this helps you.

emalelez15
Explorer
0 Likes

Hi @Oleg_Vokh,
Thanks for your response. In order to create a behaviour, I had to change the definition of the abstract entity adding "root".

@EndUserText.label: 'Sales Report - Filters for deleteWithFilters action'
define root abstract entity ZLBSR_D_DELETION_FILTERS
{
  CustomerReference : bstkd;
  SoldToPartyGLN    : zlbstr_slsrpt_sold_to_prty_gln;
  ShipToPartyGLN    : char100;
}

Then I create the behaviour:

abstract;
strict ( 2 );
with hierarchy;

define behavior for ZLBSR_D_DELETION_FILTERS alias DeletionFilters
with control
{
  field ( mandatory : execute )
  CustomerReference,
  SoldToPartyGLN;
}

 I unpublished the service, the published it, cleaned the cache, but I still get this error:

emalelez15_0-1761566546553.png

Any other suggestions?

Oleg_Vokh
Product and Topic Expert
Product and Topic Expert

@emalelez15 
I just published the service and was able to test it. Everything works for me.

Oleg_Vokh_0-1761585419000.png

Oleg_Vokh_0-1761589349846.png

I think this might be because in Behavior Definition you just specified a parameter, but you need a deep parameter.

Oleg_Vokh_0-1761589777402.png

 

Oleg_Vokh
Product and Topic Expert
Product and Topic Expert
0 Likes
@emalelez15 I tested and changed my previous comment
Rhythm_Wang
Explorer
0 Likes
@Oleg_Vokh, is this only working for Action not for Function? Since function use the HTTP Get and Query parameter instead of HTTP Post and Body, or it's currently not supported?