Category: ODATA

  • Delete an Entity using SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Delete operation is used when you want to remove a record from the database. For example, you have created one quotation and now you no longer want it. So you will delete the quotation using the DELETE request.

    This article describes the step-by-step procedure to implement and test delete operation in SAP OData.

    Context

    Delete entity can be implemented by redefining the DELETE_ENTITY method.

    Procedure

    1. Open *DPC_EXT class artifact of OData and redefine *DELETE_ENTITY method.
    2. Reimplement the delete method.
      Delete an Entity using SAP OData
      IT_KEY_TAB holds the values from the frontend.
    3. Activate the class and register the service.
    4. Execute and test the OData.
      1. Select Entity set
      2. Select DELETE option
      3. Add the key value to be deleted in the request URL
      4. Execute the request
        Delete an Entity using SAP OData Testing
      5. Status 204 represents success.
      6. Verify in the table the record is successfully deleted.

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=2rEZrFj2haE[/embedyt]
  • Update an Entity using SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Many times, we come across a scenario where we want to update the data records, for example, we want to update the phone number or address.

    This article describes the step-by-step procedure to implement and test update operations in SAP OData.

    Context

    Update entity can be implemented by the redefining UPDATE_ENTITY method.

    1. Using PUT HTTP method.
    2. Using PATCH HTTP method.

    Difference between PUT and PATCH HTTP method

    • PUT: The request body is considered as the updated version of the original data stored in the database. When using PUT, we need to send the full payload in our request.
    • PATCH: It is used for the partial modification of the resource. When using PATCH, we only send the data to be modified in the request body.

    Procedure

    1. Open *DPC_EXT class artifact of OData and redefine *UPDATE_ENTITY method.
    2. Reimplement the method for the update.
      UPDATE_ENTITY method
    3. Activate the class and register the service.
    4. Execute and test the OData.
      1. Select Entity set
      2. Get the data to be updated using the GET request
      3. Click on Use as Request to copy the HTTP response to HTTP request which works as input.
        Execute and test the OData
      4. Change the field value Carname and URL in HTTP Request
      5. Select PUT option
      6. Add the key value to be updated in the request URL
      7. Execute the request
        Execute and test the OData PUT Request
      8. Status code 204 represents success
        PUT Request response
      9. Verify-in the table data is successfully updated.
        verify the updated data

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=2rEZrFj2haE[/embedyt]
  • Create an Entity using SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Context

    Create entity can be implemented in two ways:

    1. Using CREATE_ENTITY method for single entity creation.
    2. Using CREATE_DEEP_ENTITY method to create a single entity as well as parent and child entity together.

    Procedure

    1. Open *DPC_EXT class artifact of OData and redefine *CREATE_ENTITY method.

    2. Reimplement the method.

    method PARTNERS_CREATE_ENTITY.
    
      data: lv_id                type          snwd_partner_id,
            ls_id                type          bapi_epm_bp_id,
            ls_header            type          bapi_epm_bp_header,
            lt_return            type 	      table of bapiret2,
            error_msg            type          string,
            ls_message           type          scx_t100key,
            lt_keys              type          /iwbep/t_mgw_tech_pairs,
            ls_snwd_bpa          type          snwd_bpa,
            lv_timestamp         type          timestamp.
    
      io_data_provider->read_entry_data( importing es_data = ls_header ).
    
      CALL FUNCTION 'BAPI_EPM_BP_CREATE'
        EXPORTING
          HEADERDATA        = ls_header " EPM: BP header data
        IMPORTING
          BUSINESSPARTNERID = ls_id
        TABLES
          RETURN     = lt_return.     
    
      if lt_return is not initial.
        loop at lt_return reference into data(lr_return).
          err_msg = lr_return->message .
        endloop.
    
        ls_message-msgid = 'SY'.
        ls_message-msgno = '002'.
        ls_message-attr1 = error_msg.
    
        raise exception type /iwbep/cx_mgw_busi_exception
          EXPORTING
            textid = ls_message.
      endif.
    
      CALL FUNCTION 'BAPI_EPM_BP_GET_DETAIL'
        EXPORTING
          BP_ID             = ls_id
        IMPORTING
          HEADERDATA        = er_entity
    endmethod. 
    

    The input data is passed in es_data structure and captured in ls_header. The structure ls_header is then used as the input parameter of BAPI ‘BAPI_EPM_BP_CREATE’ to create data in the database. Then BAPI ‘BAPI_EPM_BP_GET_DETAIL’ will retrieve the created data and capture it in er_entity which will be passed to the response body.

    3. Activate the class.

    4. Create Deep Entity (To create Header with Item): Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

    5. Reimplement the method.

    method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.
    
     types: ty_t_soitem type standard table of  zcl_z_epm_rkt_mpc=>ts_salesorderitem with default key.
     types: begin of ty_s_so.
              include type zcl_z_epm_rkt_mpc=>ts_salesorder.
               types: items type ty_t_soitem,
             end of ty_s_so.
    
      data: ls_sales_order     type ty_s_so,
            lv_compare_result  type /iwbep/if_mgw_odata_expand=>ty_e_compare_result.
    
      data: lv_so_id    type BAPI_EPM_SO_ID,
            ls_so_hdr    type BAPI_EPM_SO_HEADER,
            ls_so_hdr2   type BAPI_EPM_SO_HEADER,
            ls_so_item   type BAPI_EPM_SO_ITEM,
            lt_so_item   type standard table of BAPI_EPM_SO_ITEM,
            lt_so_item2  type standard table of BAPI_EPM_SO_ITEM,
            lt_return   type bapirettab,
            ls_return   TYPE bapiret2,
            ls_message  type scx_t100key,
            error_msg     type string.
    
      constants: lc_so_itm TYPE string VALUE 'Items'.
    
    * Validate whether data matches
      lv_compare_result = io_expand->compare_to( lc_so_itm ).
    
    * Access data from IO_DATA_PROVIDER
      if lv_compare_result EQ /iwbep/if_mgw_odata_expand=>gcs_compare_result-match_equals.
    io_data_provider->read_entry_data( IMPORTING es_data = ls_sales_order ).
    
    *   Move header Sales order data into BAPI structure
        move-corresponding ls_sales_order to ls_so_hdr.
    
    *   Move Sales Order items into BAPI table structure
        loop at ls_sales_order-items into ls_so_item.
           append ls_so_item to lt_so_item.
        endloop.
    
        CALL FUNCTION 'BAPI_EPM_SO_CREATE'
          EXPORTING
            HEADERDATA          = ls_so_hdr
          IMPORTING
            SALESORDERID        = lv_so_id
          TABLES
            ITEMDATA            = lt_so_item
            RETURN              = lt_return.
    
        if lt_return is not initial.
          loop at lt_return into ls_return.
            err_msg = ls_return-message .
          endloop.
    
          ls_message-msgid = 'SY'.
          ls_message-msgno = '002'.
          ls_message-attr1 = error_msg.
    
          raise exception type /iwbep/cx_mgw_busi_exception
            exporting
              textid = ls_message.
        else.
    
          CALL FUNCTION 'BAPI_EPM_SO_GET_DETAIL'
            EXPORTING
              SO_ID            = lv_so_id
            IMPORTING
              HEADERDATA       = ls_so_hdr2
            TABLES
              ITEMDATA         = lt_so_item2.
          move-corresponding ls_so_hdr2 to ls_sales_order.
          ls_sales_order-items = lt_so_item2.
    
          copy_data_to_ref(
          EXPORTING
            is_data = ls_sales_order
          CHANGING
            cr_data = er_deep_entity ).
        endif.
      endif.
    endmethod. 
    

    The structure of incoming data contains parent and child entity nested structure. This is defined with type ty_s_so.

    6. Activate the class

    7. Execute the Create request.

    • Select Entity Set
    • Select HTTP method as POST
    • Add the data in the request body
    • Click Execute

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=2rEZrFj2haE[/embedyt]
  • Testing SAP OData CRUD operations using Postman

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Introduction

    Postman is an API development tool that helps developers to create, test, share and document the APIs. It has various HTTP requests like GET, POST, PUT, PATCH and the ability to save the environment.

    In this article, we will learn how to set up the POSTMAN and then we will test OData CRUD operations using POSTMAN.

     

    Installing POSTMAN

    To install POSTMAN on your device you can use the link go.postman.co/home and download the latest version for your platform.

    For more details on installing and updating POSTMAN, you can refer to the link https://learning.postman.com/docs/getting-started/installation-and-updates/

     

    Components of POSTMAN

    Postman UI is made up of various components.
    Components of POSTMAN

    • Left sidebar provides the navigation to Collections, APIs, Environments, Mock Servers, Monitors and History.
    • Header provides the access to Workspace, Reports, and Search option.
    • Center area is where we work with requests.
    • Right sidebar provides the link to Comments, Request Info’s, Code and Documentations.

     

    Variables

    We will use the variables to store our data which will be reused multiple times.

    You can create variables by clicking ENVIRONMENT in the left panel and selecting GLOBAL.

    Variables in Postman

    Here you create variables and provide initial and current value. In case you need to change the value of the variable you only need to update the CURRENT VALUE field. This is the field from where the data is picked up.

    Scope of variables:

    Scope of variables

    • Global scope: Enable you to use data between the Collection, requests, test scripts and environment.
    • Collection: Enable you to use data in different requests under the same collection.
    • Environment: Enables to tailor the processing to different environments.
    • Data: Comes from external files like CSV, JSON.
    • Local: The scope is temporary and can only be used in the defined requests.

    Create variable

    1. Select data and click on Set as Variable.
      Create variable
    2. Select Set as new Variable.
      Set as new Variable
    3. Provide name, value and scope.
      Save Variable

     

    Format to use variables in request: {{variable_name}}

    Example:  .Example of variable in postman

     

    HTTP requests

    There are various HTTP methods available that are used to make a request to APIs. Some of the frequently used HTTP methods are:

    • GET: Used to retrieve data from APIs (Read scenario)
    • POST: Used to send new data to API (Create scenario)
    • PUT or PATCH: Used to update existing data (Update scenario). PUT request modifies the entire resource in the database whereas PATCH request modifies only the supplied resource. So, while using PUT we need to send the entire data in request URI and by using PATCH we need to send only the updatable field.
    • DELETE: Used to remove existing record (Delete scenario)

    It supports various addition methods. Refer to the below snip.
    HTTP requests in Postman

    Creating requests

    You can create a request by clicking on the NEW tab and selecting HTTP Request. Also, you can create a request by clicking + button.

    Creating requests

    After selecting HTTP Request, a screen will open. Provide relevant name, description to your HTTP request.

    Specify the relevant details for your requests (like HTTP method, URL, parameters, body data).

    Get request in Postman

    Click on SEND button to save your call. You can create a collection to save all your related requests under one folder.

     

    Collection

    A collection is a folder that groups the number of API requests. There can be n number of collections in Postman. Generally, an API request belonging to the same business object is saved under  the same Collection. You can even share your API requests with your team via collection.

    Authentication

    Authentication is verifying the client’s identity who is accessing the request whereas authorization is verifying the client’s action of permission. Some APIs require authorization details act.

    To provide authorization details, click on the Authorization tab and select auth Type. Provide the relevant details and SAVE.

    There are various auth types, for more details check out Authorizing requests.

    Authentication in Postman

    Instead of adding an authorization in each request individually, you can add your authorization details directly to your Collection.

    Steps:

    1. Select TYPE as Inherit auth from parent.
      Type of Authorization
    2. Click Collection and add authorization details there.
      Basic Authentication in Postman

    Sending requests

    GET request

    Steps to follow:

    1. Click on the NEW button and select HTTP request
      New GET request

     

    1. Select HTTP request GET and enter OData service URL in URL field
      Enter URL

     

    1. Click on the Send button
      Send Request

     

    At the bottom, you can see the output and status code.

     

    Fetch x-csrf-token

    An x-csrf-token is used to prevent cross-site request forgery attacks. While making a call for Create/Update/Delete we must need to send x-csrf-token value via Header.

    Steps to fetch the x-csrf-token value.

    1. Create a GET
    2. Add in HEADERS: key = x-csrf-token and value = fetch.
      Fetch x-csrf-token
    3. Execute the request by clicking on SEND
    4. Below you will get the result. In the Header section of the result you can find fetched x-csrf-token value. Get that value and paste it in HEADERS section of CUD requests.

     

    POST request

    1. Select HTTP request POST and enter OData service URL for create in URL field. (Do not provide the key field and its value in URI)
      POST request in Postman
    2. Provide x-csrf-token parameter in HEADERS (To fetch x-csrf-token refer How to fetch x-csrf-token?).
      Provide x-csrf-token
    3. Provide the data to be created in the BODY tab and select the relevant data type. Here, we have selected raw.
      Provide the data to be created in the BODY
    4. Save and click on Send to execute the request.

     

    PUT/PATCH request

    To know which request URI to use please read HTTP requests.

    1. Select HTTP request PUT/PATCH and enter OData service URL for create in URL field. ( Add key field and its value which is to be updated)
      Select HTTP request PUT
    2. Provide x-csrf-token parameter in HEADERS (To fetch x-csrf-token refer How to fetch x-csrf-token?).
      Provide x-csrf-token parameter in HEADERS tab
    3. Provide the data to be created in the BODY tab and select the relevant data type. Here, we have selected raw.
      For Put Provide the data to be created in the BODY tab
    4. Save and click on Send to execute the request.

     

    DELETE request

    1. Select HTTP request DELETE and enter OData service URL for create in URL field. ( Add key field and its value which is to be deleted)
      Select HTTP request DELETE
    2. Provide x-csrf-token parameter in HEADERS (To fetch x-csrf-token refer How to fetch x-csrf-token?).
      Provide x-csrf-token for Delete
    3. For DELETE requests we don’t have to provide any input in BODY.
      No body required for Delete
    4. Save and click on Send to execute the request.

    Sharing API requests

    To share your API requests with your team or other people follow the below steps.

    1. Save your requests in Collection.
    2. Click on Collection that you want to share.
    3. Click on the Share button
      Sharing API requests
    4. There are three ways you can share.
      Share Quota

    Best practices

    1. If a parameter or value is used at multiple places. Always try to create its variable in the Environment section and use the variable in your requests.
      Example: If api.getpostman.com is used in all your requests URL.
      Postmand Best practices 1
      Create a variable with value api.getpostman.com and use the variable everywhere.
      The positive aspect is in case your domain is changed, you only need to change the value in one place and all your requests will adapt it.
      Postmand Best practices 2
      Postmand Best practices 3

     

    1. If you are adding Authorization, never provide your password directly in your Request or Collection level.

    The mishappening is, if you provide your password directly at a collection level or in request and you share the collection with your team or other people, the password will also get shared with them. So, everyone with that collection will get to know your password.

    Postmand Best practices 4

    The best approach is to create a variable for your password in the environment section and use that variable in the password field. This way only the variable name will be shared and your password will be safe.

    Postmand Best practices 5

    1. Instead of fetching x-csrf-token value and adding it to request every time manually, you can create a variable for x-csrf-token in the environment and add a script code to automatically update the x-csrf-token value in the environment.
  • MIME handling in SAP OData (File Media handling)

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    This article will give a bare minimum to read and upload media files or MIME in SAP OData service.

    Procedure

    1. Create OData service
    2. Register service
    3. Execute service

    Steps

    1. Create OData
    2. Select EntityType and select checkbox ‘Media’
      Enable MIME in OData
    3. Generate runtime artifact. In MPC ext class redefine the DEFINE method.
      Generate MIME runtime artifact ODATA
    4. Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM .
      Create Stream
    5. Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM .
      Get Stream
    6. Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~UPDATE_STREAM .
      Update Stream

     

    1. Redefine method FILESET_GET_ENTITYSET.
      FILESET_GET_ENTITYSET
    2. Register OData service
    3. Execute
      1. GET_STREAM is used to download the media
      /sap/opu/odata/sap/ZMIMEFILE_SRV/File(Mandt=’100′,Filename=’mobile.jpg’)/$value.
      Download the media
       

      2. CREATE_STREAM is used to upload the media
      /sap/opu/odata/sap/ZMIMEFILE_SRV/File
      Upload the media

     

    Features

    List of supported MIME Types that can be stored in MIME Repository:

    Category/Subcategory File Extension Description
    texts text/css css CSS stylesheet file
    text/html html, htm HTML file
    text/javascript js JavaScript file
    text/plain txt, c, cc, g, h, hh, m, f90 Plain text file
    text/richtext rtx MIME rich text
    text/xml xml XML file
    Images image/gif gif GIF graphic
    image/ief ief Exchange Format
    image/jpeg jpeg, jpg, jpe JPEG graphic
    image/x-rgb rgb RBG graphic
    image/x-windowdump xwd X-Windows dump
    image/tiff tiff, tif TIFF graphic
    image/bmp bmp Icon
    image/ico ico Icon (Windows)
    Audio audio/basic au, snd AU and SND sound files
    audio/x-aiff aif, aiff, aifc AIFF sound file
    audio/x-aiff midi, mid MIDI file
    audio/x-pn-realaudio ram, ra RealAudio file
    audio/x-pn-realaudio-plugin rpm RealAudio plug-in file
    Video video/mpeg mpeg, mpg, mpe MPEG video
    video/x-msvideo avi Microsoft AVI video
    video/x-sgi-movie movie Microsoft SGI video
    video/quicktime qt, mov Quicktime video
    Applications application/acad (NCSA) dwg AutoCAD file
    application/dxf (CERN) dxf AutoCAD file
    application/mif mif Maker Interchange Format (Adobe FrameMaker)
    application/msword doc, dot MS Word file
    application/mspowerpoint ppt, ppz, pps, pot MS PowerPoint file
    application/msexcel xls, xla MS Excel file
    application/mshelp hlp, chm MS Windows help file
    application/octet-stream com, exe, bin, dll, class Executable file or program code file
    application/pdf pdf PDF file (Adobe Acrobat Exchange/Reader)
    application/postscript ai, eps, ps Postscript file (Adobe)
    application/rtf rtf RTF file (Microsoft)

     

  • $ORDERBY Query in SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    In this article, we will learn how to use $orderby query in our SAP OData services.

    What is the use of $orderby query?

    There are many query options to control the amount and order of data. One of the query options provided is $orderby. It adds the sorting capability to OData services. You can order the collection based on the fields available.

    System version

    SAP NetWeaver Gateway Release 2.0 Support Package >=03

    Syntax

    http://<server>:<port>/sap/opu/odata/sap/<service_name>/EntitySet?$orderby=<fieldname> <sortorder>

    where,

    • <fieldname> :is the name of the field.
    • <sortorder>: desc/asc

     

    Business Example

    An OData service has retrieved all the Product details, but you want the details in some specified order say, you want the details in descending order by price. Here you can use the $orderby query to achieve the desired output.

    You want to fetch the Product details in order by its Price in descending.

    Implementation

    In this section, we will implement $orderby on our Product Entity Set.

    Step 1: After the creation of the OData service, right Click on Entity Set under Service Implementation, go to ABAP workbench.

    SAP OData Implementation

    Step 2:

    Adjust your code for $orderby query. The orderby query option is available in the method by accessing importing parameter IT_ORDER.

    $ORDERBY Query in SAP OData

     

    In the GetEntitySet method, first, we retrieve all the products and get orderby “fieldname”, “sortorder” and apply them to the BAPI result data to get the required sort order.

    Step 3:

    Execute the service. If we don’t add $orderby in our service URL, we will get all the results from the system. If we add $order by in-service URL we will get the result based on the sort order provided.

    Service URL: /sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$orderby=Price asc’.

    $ORDERBY Query in SAP OData Output

  • $TOP and $SKIP Query in SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    In this article, we will learn how to use $top and $skip query in our OData services.

    What is the use of $top $skip query?

    The OData query $top and $skip are used to restrict the data from the backend.

    To achieve the client-side pagination, we can use $top = n query and $skip = m is used in coordination with $top. $top query fetches the top n records skipping first m records.

    System version

    SAP NetWeaver Gateway Release 2.0 Support Package >=03

    Syntax

    • http://<server>:<port>/sap/opu/odata/sap/<service_name>/EntitySet?$top=5
    • http://<server>:<port>/sap/opu/odata/sap/<service_name>/ EntitySet?$top=5&skip=3

     

    Business Example

    • You want the first 5 records of Products. Or we want the first 10 roll number students in our result.
    • Teach wants first 10 roll number students skipping first 5.

    Implementation

    In this section, we will implement $top and $skip on our Product Entity Set.

    Step 1: After the creation of OData service, right Click on Entity Set under Service Implementation, go to ABAP workbench.

    SAP OData Implementation

    Step 2:

    Adjust your code for $top and $skip query.

    $TOP and $SKIP Query in SAP OData

    In the above code, we retrieved all the product details and applied $top and $skip query to get the required output.

    Step 3:

    Add $top and $skip query in OData URL and execute the service.

    Service URL: /sap/opu/odata/sap/ZProduct_Srv/ProductsSet?$top=5

    $TOP and $SKIP Query in SAP OData Output

  • $FILTER in SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    In this section, we will learn the concept of the $filter query in SAP OData and its usage.

    Supported System Version

    SAP NetWeaver Gateway Release 2.0 Support Package >=03

    Syntax

    http://<server>:<port>/sap/opu/odata/sap/<service_name>/EntitySet?$filter=ProductId eq ‘HP-101’

    Business Example

    The shopping site, say, Amazon is displaying all the products but you want some specific category to be displayed. So, you will apply filters (select category phones or laptops)  to display the data of your choice.

    Implementation

    In this section, we will implement $filter on our Product Entity Set.

    Step 1: After the creation of the OData service, right Click on Entity Set under Service Implementation, go to ABAP workbench.

    SAP OData Implementation

    Step 2:

    Adjust your code for $filter query.

    $FILTER in SAP OData

    The filter query option is available by accessing the parameter IT_FILTER_SELECT_OPTIONS.

    In the above code, we first retrieved the filter options passed from the frontend by reading IT_FILTER_SELECT_OPTIONS. And then passed the select-option range to BAPI to get the desired filtered output.

    Step 3:

    If we do not pass any filter option, we will get all the products from the system.

    Add $filter query in OData URL and execute the service. You can add one or more filter options.

    Service URL: /sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$filter=Name eq ‘Notebook Basic 15.

     

    Operators used with $filter

    Logical Operators

    Logical Operator Description Example
    eq Equal https://<API-Server>/odata/v2/User?$filter=gender eq ‘F’ .
    ne Not Equal hhttps://<API-Server>/odata/v2/User?$filter=place ne ‘’London’
    gt Greater than https://<API-Server>/odata/v2/PicklistLabel?$filter=amount gt 200
    ge Greater than or equal https://<API-Server>/odata/v2/PicklistLabel?$filter=amount ge 200
    lt Less than https://<API-Server>/odata/v2/PicklistLabel?$filter=amount lt 200
    le Less than or equal https://<API-Server>/odata/v2/PicklistLabel?$filter=amount le 200
    and Logical and https://<API-Server>/odata/v2/PicklistLabel?$filter=amount le 200 and amount ge 300
    or Logical or https://<API-Server>/odata/v2/PicklistLabel?$filter=amount le 200 or amount ge 300
    not Logical not https://<API-Server>/odata/v2/PicklistLabel?$filter=amount le 200 not amount ge 300

     

    Arithmetic Operators

    Arithmetic Operator Description Example
    add Addition https://<API-Server>/odata/v2/PicklistLabel?$filter=amount add 5 gt 10
    sub Subtraction https://<API-Server>/odata/v2/PicklistLabel?$filter= amount sub 5 gt 10
    mul Multiplication https://<API-Server>/odata/v2/PicklistLabel?$filter= amount mul 5 gt 10
    div Division https://<API-Server>/odata/v2/PicklistLabel?$filter= amount div 5 gt 10
    mod Modulus https://<API-Server>/odata/v2/PicklistLabel?$filter= amount mod 5 gt 10

     

    Grouping Operators

    Grouping Operator Description Example
    ( ) Precedence grouping https://<API-Server>/odata/v2/PicklistLabel?$filter=(number sub 20) gt 30

     

  • Constructor in a Class

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Introduction

    Focusing on the concept of the constructors in a class, we will discuss what is a constructor and its type with an example. So, a constructor can be understood as a special method in a class that is automatically called when an object is created. It does not require any explicit method call.

    Definition

    A constructor is a special method in a class that is invoked at the time object is created or instantiated.

    Type of Constructors

    Constructors are of two types:

    • Instance constructor
    • Static constructor

    Instance Constructors

    The instance constructor is the predefined instance method of the class called constructor. There are few points to consider while declaring the constructor. They are:

    • The name of the constructor method, irrespective of the class name or type, must be always CONSTRUCTOR.
    • It is declared using a method statement in the visibility section of the class.
    • The method signature can only have importing parameters or exceptions. There are no exporting parameters included.
    • The instance method can be used to set default values in the class.
    • The instance method anyhow can access both instance as well as static variables.
    • It is called each time the object is created.

    Static Constructors

    The static constructor is the predefined static method of the class called as class_constructor. There are few points to consider while declaring the static constructor. They are:

    • The name of the class_constructor method must be CLASS_CONSTRUCTOR.
    • It is declared using CLASS_METHODS statement in the public section of class.
    • The method signature cannot contain importing or exporting parameters or exceptions.
    • The static method can be used to set default values globally.
    • The static method can only access the static variables.
    • It is called exactly once before the class is accessed for the first time.

     

    Example

    Let’s spot one simple example:

    CLASS  demo DEFINITION.
    
           PUBLIC SECTION.
    
                 METHODS:  CONSTRUCTOR.                                                         “Instance Constructor”
    
                 CLASS_METHODS: CLASS_CONSTRUCTOR.                             “Static Constructor”
    
    END CLASS.
    
    CLASS  demo IMPLEMENTATION.
    
           METHOD CONSTRUCTOR.
    
                    WRITE: “Instance Constructor is initiated”.
    
           END METHOD.
    
           METHOD CLASS_CONSTRUCTOR.
    
                    WRITE: “Static Constructor is initiated”.
    
           END METHOD.
    
    END CLASS.
    
    **class object creation**
    
    DATA: demo_obj TYPE REF TO demo.
    
    CREATE  OBJECT  demo_obj.

    OUTPUT

    Static Constructor is initiated

    Instance Constructor is initiated

     

    In the definition part of the class, the CONSTRUCTOR is the instance constructor defined using Methods and static constructer is defined as CLASS_CONSTRUCTOR using class_methods. And their implementations are given the IMPLEMENTATION part. When the object  demo_obj is created, the instance and static constructor is called.

    As we can see that the output displays static constructer implementation before the instance constructor, this is because the CLASS_CONSTRUCTOR method is triggered before the CONSTRUCTOR method.

  • How to Activate Services in SICF: SAP Transaction Guide

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Introduction

    SAP provides Internet Communication Framework (ICF) services that needs to be activated after your OData Service is registered and active. The ICF is an API service enables an ABAP program to communicate with the Internet. In our last article, we have activated our OData services, let us explore more about SICF nodes in this article.

    Steps to Activate OData Services

    1. Go to the transaction SICF (Maintain Services) and search for your OData Service Name as shown below:
      Go to the transaction SICF
    2. Now, activate the following service nodes (if available):
      1. /default_host/sap/bc/ui5_ui5
      2. /default_host/sap/bc/ui5_ui5/sap/<your service name>
      3. /default_host/sap/bc/bsp/sap/<your service name>
      4. /default_host/sap/opu/odata/sap/<your service name>
    3. To activate an ICF service, select the required service node in the ICF tree.
    4. Activate the ICF service in one of the following ways:
      1. In the menu, select option Service/Host  Activate
      2. In the context menu select Activate Service. (By Right Clicking on the node as shown below)

    Activate the ICF service

    Steps to Activate Services for Fiori Launchpad

    1. Go to the transaction SICF (Maintain Services) and search for your OData Service Name as shown below:
      Go to the transaction SICF
    2. Now, activate the following service nodes (if available):
      1. /default host/sap/bc/ui2/nwbc/
      2. /default_host/sap/bc/ui2/start_up
      3. /default_host/sap/bc/ui5_ui5/sap/ar_srvc_launch
      4. /default_host/sap/bc/ui5_ui5/sap/ar_srvc_news
      5. /default_host/sap/bc/ui5_ui5/sap/arsrvc_upb_admn
      6. /default_host/sap/bc/ui5_ui5/ui2/ushell
      7. /default_host/sap/public/bc/ui2
      8. /default_host/sap/public/bc/ui5_ui5
    3. To activate an ICF service, select the required service node in the ICF tree and choose hierarchy icon to activate all the child nodes under the chosen service.
    4. Activate the ICF service in one of the following ways:
      1. In the menu, select option Service/Host Activate
      2. In the context menu select Activate Service (By Right Clicking on the node as shown below)

    Activate Services for Fiori Launchpad

    Steps to Activate Services for Web Dynpro ABAP

    1. Go to the transaction SICF (Maintain Services) and search for your OData Service Name as shown below:
      Go to the transaction SICF
    2. Now, activate the following service nodes (if available):
      1. /default_host/sap/bc/webdynpro [Activate only the node and not the subnodes]
      2. /default_host/sap/public/bc [This node will be activated automatically once the given subnodes are activated]
        1. /default_host/sap/public/bc/ur
        2. /default_host/sap/public/bc/icons
        3. /default_host/sap/public/bc/icons_rtl
        4. /default_host/sap/public/bc/webicons
        5. /default_host/sap/public/bc/pictograms
        6. /default_host/sap/public/bc/webdynpro/* (ssr, mimes, etc.)
        7. /default_host/sap/public/myssocntl

    3. To activate an ICF service, select the required service node in the ICF tree.

    4. Activate the ICF service in one of the following ways:

    1. In the menu, select option Service/Host Activate
    2. In the context menu select Activate Service (By Right Clicking on the node as shown below)

    Activate Services for Web Dynpro ABAP