Thursday, July 2, 2026

Simple RAP Application Development

 Steps for Simple RAP Application are as follows:

·         DATABASE TABLE

·         CDS DATA DEFINITION + CDS VIEW

·         CDS BEHAVIOR DEFINITION + IMPLEMENTATION CLASS

·         SERVICE DEFINITION

·         SERVICE BINDING

 

Example:

Create Sales Order Custom Table

With Search Options

Operations Like Create / Edit / Delete

Validate Currency

 

Starting with the Development:

1.      Create a Database Table

DATABASE TABLE

Create a New Package

Right click the package name and select New – Search Database Table

Add Name and Description
Finish









@EndUserText.label : 'Sales Order Master Table'

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table z2022_so {

 

  key client    : abap.clnt not null;

  key so_id     : abap.int4 not null;

  customer      : abap.char(256);

  @Semantics.amount.currencyCode : 'z2022_so.currency_code'

  gross_amount  : abap.curr(10,2);

  currency_code : abap.cuky;

  sales_org     : abap.char(4);

 

}


1.      Define Root CDS View

CDS DATA DEFINITION + CDS VIEW

SQL View Name provided (without the underscores) which we can see in the view list.

Right click the Database table and create New Data Definition





Add the SQLVIEWNAME and then Add  - Define ROOT view

Annotations for UI can be added now or later.


Annotations for GUI were added later

@AbapCatalog.sqlViewName: 'Z2022SOCDS'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Data Model for SO Table'

@Metadata.allowExtensions: true

define root view Z2022_SO_CDS as select from z2022_so

{

@UI.facet: [{

type: #IDENTIFICATION_REFERENCE,

label: 'Sales Order Maintenance',

purpose: #STANDARD }]

    @UI.identification: [{ position: 10 }]

    @UI.selectionField: [{ position: 10 }]

    @EndUserText.label: 'Sales Order'

    @Search.defaultSearchElement: true

    key so_id as SoId,

    @UI.identification: [{ position: 20 }]

    @UI.selectionField: [{ position: 20 }]

    @EndUserText.label: 'Customer'

    customer as Customer,

    @UI.identification: [{ position: 30 }]

    @UI.selectionField: [{ position: 30 }]

    @EndUserText.label: 'Gross Amount'

    @Search.defaultSearchElement: true

    gross_amount as GrossAmount,

    @UI.identification: [{ position: 40 }]

    @UI.selectionField: [{ position: 40 }]

    @EndUserText.label: 'Currency Code'

    @Search.defaultSearchElement: true

    currency_code as CurrencyCode,

    @UI.identification: [{ position: 50 }]

    @UI.selectionField: [{ position: 50 }]

    @EndUserText.label: 'Sales Org'

    @Search.defaultSearchElement: true

    sales_org as SalesOrg

}

 

1.      Create Behavior Definition

CDS BEHAVIOR DEFINITION + IMPLEMENTATION CLASS

Right click data definition and select Add Behavior Definition

Select Managed to auto create CRUD else you need to manually create everything.

In the behavior definition we provide the mandatory fields and also provide the method name for validation.





managed implementation in class zbp_2022_so_cds unique;

//strict ( 2 ); //Uncomment this line in order to enable strict mode 2. The strict mode has two variants (strict(1), strict(2)) and is prerequisite to be future proof regarding syntax and to be able to release your BO.

 

define behavior for Z2022_SO_CDS //alias <alias_name>

persistent table z2022_so

lock master

authorization master ( instance )

//etag master <field_name>

{

  create;

  update;

  delete;

    field ( readonly : update ) SoId;

    field (mandatory : create) Customer, GrossAmount, CurrencyCode;

    validation validateCurrencyCode on save {field CurrencyCode; create; }

 

  mapping for Z2022_SO{

  CurrencyCode = currency_code;

  SalesOrg = sales_org;

  GrossAmount = gross_amount;

  SoId = so_id;

  Customer = customer;

  }

}

 

1.      Implementation Class (only required when validation is needed, else we can skip this)

In the Behavior Definition, there is a class name on the top, Double click the class and the assistance will auto create the class. In the Class we will implement the class for validation.

%tky is a random unique value like a GUID which is used in runtime by the app.


CLASS lhc_Z2022_SO_CDS DEFINITION INHERITING FROM cl_abap_behavior_handler.

  PRIVATE SECTION.

 

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION

      IMPORTING keys REQUEST requested_authorizations FOR z2022_so_cds RESULT result.

    METHODS validatecurrencycode FOR VALIDATE ON SAVE

      IMPORTING keys FOR z2022_so_cds~validatecurrencycode.

 

ENDCLASS.

 

CLASS lhc_Z2022_SO_CDS IMPLEMENTATION.

 

  METHOD get_instance_authorizations.

  ENDMETHOD.

 

  METHOD validateCurrencyCode.

    READ ENTITIES OF z2022_so_cds IN LOCAL MODE

    ENTITY z2022_so_cds

    FIELDS ( CurrencyCode )

    WITH CORRESPONDING #( keys )

    RESULT DATA(lt_records).

 

    loop at lt_records into data(ls_records).

        if ls_records-CurrencyCode NE 'USD'.

        append value #( %tky = ls_records-%tky ) to failed-z2022_so_cds.

        APPEND value #( %tky = keys[ 1 ]-%tky

                        %msg  = new_message_with_text(

                          severity = if_abap_behv_message=>severity-error

                          text = 'Only USD is accepted' ) )

        to reported-z2022_so_cds.

        ENDIF.

    endloop.

  ENDMETHOD.

 

ENDCLASS.

 

 

1.      SERVICE DEFINITION

Right click data definition and create service definition




 

@EndUserText.label: 'Sales Order Service Definition'

define service Z2022_SO_SD {

  expose Z2022_SO_CDS as SalesOrder;

}

 

 

1.      SERVICE BINDING

Create Service Binding and Publish

Right click the service definition and choose service binding


Right Click the Entity Set and Association and Open Fiori Elements App Preview to Test




Screenshot of Application:


Create New Record



Data Validation




Update




Thanks for watching

No comments:

Post a Comment

AI-Powered Warehouse Temperature Automation Using IoT and SAP

  Overview In this project, we present a smart, scalable solution that leverages  AI ,  IoT , and  SAP technologies  to automate and optim...