cancel
Showing results for 
Search instead for 
Did you mean: 

Functions in SAP ABAP RESTful Application Programming Model ?

Ramjee_korada
Active Contributor
0 Kudos
3,568

Hello Experts,

Did any one try on "how Functions work in ABAP RESTful Application Programming Model" ?

I found below information theoretically but no examples to try ..

If yes, please share examples.

https://help.sap.com/viewer/923180ddb98240829d935862025004d6/Cloud/en-US/d401150cfdb1454d9f55d80aead...

justin_nikles
Participant
0 Kudos

Hi Ramjee,

This isn't exactly an answer to your question, so I am posting it as a comment. In case you missed this part of the documentation, there are two sections which might help you in defining and implementing a function for your OData service:

Function Definition - SAP Help Portal

Function Implementation - SAP Help Portal

Both sections are pretty good at covering how you'd define and implement these. If you have a specific use-case that you're looking to implement, maybe you could give some background, and we could have a discussion around how you might implement that with a function. I don't have any examples on hand though.

Best,

Justin

Accepted Solutions (1)

Accepted Solutions (1)

Ramjee_korada
Active Contributor
0 Kudos

I have published a blog post with E2E scenario to use RAP Functions in Fiori App

ABAP RAP / FUNCTIONS: Defaulting fields during new object creation in "Unmanaged Scenario without Dr...

Answers (1)

Answers (1)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Ramjee,

I found the following code that might help you (though it only works in an on premise system since it uses the "old" sflight model:

CDS view

@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
@EndUserText.label: 'spfli view'
define root view entity DEMO_SPFLI_Flights
  as select from spfli
  composition [0..*] of DEMO_SFLIGHT as _Flights
  {
    key spfli.carrid    as Carrid,
    key spfli.connid    as Connid,
        spfli.countryfr as Countryfr,
        spfli.cityfrom  as Cityfrom,
        spfli.airpfrom  as Airpfrom,
        spfli.countryto as Countryto,
        spfli.cityto    as Cityto,
        spfli.airpto    as Airpto,
        spfli.fltime    as Fltime,
        spfli.deptime   as Deptime,
        spfli.arrtime   as Arrtime,
        spfli.distance  as Distance,
        spfli.distid    as Distid,
        spfli.fltype    as Fltype,
        spfli.period    as Period,
        _Flights
  }

Behavior Definition

managed implementation in class bp_demo_spfli_flights unique;


define behavior for DEMO_SPFLI_Flights
persistent table SPFLI
lock master


{
  create;
  update;
  delete;
  association _Flights { create; }
  function FunctionResultEntity result [0..*] entity DEMO_SPFLI_Flights;
}


Behavior Implementation

CLASS lhc_demo_spfli_flights DEFINITION INHERITING FROM cl_abap_behavior_handler.


  PRIVATE SECTION.


    METHODS FunctionResultEntity FOR READ
      IMPORTING keys FOR FUNCTION DEMO_SPFLI_Flights~FunctionResultEntity RESULT result.


ENDCLASS.


CLASS lhc_demo_spfli_flights IMPLEMENTATION.


  METHOD FunctionResultEntity.
    DATA(lt_keys) = keys.
    CHECK lt_keys IS NOT INITIAL.


    READ ENTITIES OF demo_spfli_flights IN LOCAL MODE
      ENTITY demo_spfli_flights
        FIELDS ( Carrid Connid Airpfrom Cityfrom Airpto Cityto )
        WITH CORRESPONDING #( lt_keys )
      RESULT DATA(lt_item)
      FAILED DATA(read_failed).


    failed = CORRESPONDING #( DEEP read_failed ).


    LOOP AT lt_item ASSIGNING FIELD-SYMBOL(<fs_item>).
      APPEND VALUE #( %tky   = <fs_item>-%tky
                      %param = CORRESPONDING #( <fs_item> ) ) TO result.
    ENDLOOP.


  ENDMETHOD.




ENDCLASS.
Ramjee_korada
Active Contributor
0 Kudos

Thank you for useful examples