Category: ABAP

ABAP

  • Convert JSON to ABAP Internal Table

    Preface – This post is part of the ABAP Programs series.

     TYPES:
            BEGIN OF t_entry,
              access_token TYPE string,
              token_type   TYPE string,
              expires_in   TYPE n LENGTH 8,
              scope        TYPE string,
              jti          TYPE string,
            END OF t_entry .
          TYPES:
            t_entry_map TYPE SORTED TABLE OF t_entry WITH UNIQUE KEY access_token.
          DATA: m_entries TYPE t_entry.
    
          DATA: lr_instance  TYPE REF TO  /ui5/cl_json_parser.
          CREATE OBJECT lr_instance.
          CALL METHOD me->get_token.
          IF gv_token IS NOT INITIAL.
    
    *        data: itab TYPE TABLE OF string.
    *        data: access_tok type string.
    *        SPLIT gv_token at '"' INTO TABLE itab.
    *        try.
    *            lv_auth2 = itab[ 4 ].
    *          catch cx_sy_itab_line_not_found.
    *        ENDTRY.
    
            /ui2/cl_json=>deserialize(
            EXPORTING json = gv_token pretty_name = /ui2/cl_json=>pretty_mode-camel_case CHANGING data = m_entries ).
            lv_auth2 = m_entries-access_token.
            gv_token = gv_token+17.

     

  • Create Object History in SAP Blockchain

    Preface – This post is part of the Blockchain on SAP Cloud Platform and ABAP Programs series.

    In this article, we will learn how to create a block in Blockchain on the SAP Cloud Platform.

     METHOD create_object_history.
        DATA: lo_http_client TYPE REF TO if_http_client.
        DATA: response TYPE string,
              lv_url   TYPE string,
              lv_auth  TYPE string.
        CONSTANTS : lv_initial_url TYPE string VALUE '<Your_Service>'.
    
        IF iv_object_id IS NOT INITIAL.
    *** Getting Token
          TYPES:
            BEGIN OF t_entry,
              access_token TYPE string,
              token_type   TYPE string,
              expires_in   TYPE n LENGTH 8,
              scope        TYPE string,
              jti          TYPE string,
            END OF t_entry .
          TYPES:
            t_entry_map TYPE SORTED TABLE OF t_entry WITH UNIQUE KEY access_token.
          DATA: m_entries TYPE t_entry.
    
          DATA: lr_instance  TYPE REF TO  /ui5/cl_json_parser.
          CREATE OBJECT lr_instance.
          CALL METHOD me->get_token.
          IF gv_token IS NOT INITIAL.
    
            /ui2/cl_json=>deserialize(
            EXPORTING json = gv_token pretty_name = /ui2/cl_json=>pretty_mode-camel_case CHANGING data = m_entries ).
            DATA lv_auth2 TYPE string.
            lv_auth2 = m_entries-access_token.
    *        gv_token = gv_token+17.
    
            CONCATENATE 'Bearer' lv_auth2 INTO lv_auth SEPARATED BY space.
    
          ENDIF.
          DATA lv_object_id TYPE string.
          lv_object_id = iv_object_id.
          TRANSLATE lv_object_id TO LOWER CASE.
    
          CONCATENATE lv_initial_url lv_object_id INTO lv_url. "Appending Fix URL and the Object ID to get the Request URL
    
          "create HTTP client by url
          CALL METHOD cl_http_client=>create_by_url
            EXPORTING
              url                = lv_url
            IMPORTING
              client             = lo_http_client
            EXCEPTIONS
              argument_not_found = 1
              plugin_not_active  = 2
              internal_error     = 3
              OTHERS             = 4.
    
          "Available API Endpoints
          "https://blockchain-service.cfapps.sap.hana.ondemand.com/blockchain/proofOfHistory/api/v1
          "https://blockchain-service.cfapps.eu10.hana.ondemand.com/blockchain/proofOfHistory/api/v1
          "https://blockchain-service.cfapps.us10.hana.ondemand.com/blockchain/proofOfHistory/api/v1
    
          IF sy-subrc <> 0.
            "error handling
          ENDIF.
    
          "setting request method
          lo_http_client->request->set_method('POST').
    
          "adding headers
          lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded' ).
          lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ).
          lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth ).
    
          "Available Security Schemes for productive API Endpoints
          "OAuth 2.0
    
          CALL METHOD lo_http_client->send
            EXCEPTIONS
              http_communication_failure = 1
              http_invalid_state         = 2
              http_processing_failed     = 3
              http_invalid_timeout       = 4
              OTHERS                     = 5.
    
          IF sy-subrc = 0.
            CALL METHOD lo_http_client->receive
              EXCEPTIONS
                http_communication_failure = 1
                http_invalid_state         = 2
                http_processing_failed     = 3
                OTHERS                     = 5.
          ENDIF.
    
          IF sy-subrc <> 0.
            "error handling
            response = lo_http_client->response->get_cdata( ).
            ev_response = response.
          ELSE.
            response = lo_http_client->response->get_cdata( ).
            IF response IS NOT INITIAL.
              ev_response = response.
            ELSE.
              ev_response = 'Block created successfully'.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDMETHOD.
    

     

  • Get Proof history from the Blockchain Service using SAP ABAP

    Preface – This post is part of the Blockchain on SAP Cloud Platform and ABAP Programs series.

    In this step, we will call the blockchain service again using the token that we have stored in above step. And then we will receive the history of transactions from blockchain.

    METHOD get_proof_history.
        DATA: lo_http_client TYPE REF TO if_http_client.
        DATA: response TYPE string,
              lv_url   TYPE string,
              lv_auth  TYPE string,
              lv_auth2 TYPE string.
        CONSTANTS : lv_initial_url TYPE string VALUE '<Your Service>'.
        IF iv_object_id IS NOT INITIAL.
    *** Getting Token
          TYPES:
            BEGIN OF t_entry,
              access_token TYPE string,
              token_type   TYPE string,
              expires_in   TYPE n LENGTH 8,
              scope        TYPE string,
              jti          TYPE string,
            END OF t_entry .
          TYPES:
            t_entry_map TYPE SORTED TABLE OF t_entry WITH UNIQUE KEY access_token.
          DATA: m_entries TYPE t_entry.
          DATA: lr_instance  TYPE REF TO  /ui5/cl_json_parser.
          CREATE OBJECT lr_instance.
          CALL METHOD me->get_token.
          IF gv_token IS NOT INITIAL.
    *        data: itab TYPE TABLE OF string.
    *        data: access_tok type string.
    *        SPLIT gv_token at '"' INTO TABLE itab.
    *        try.
    *            lv_auth2 = itab[ 4 ].
    *          catch cx_sy_itab_line_not_found.
    *        ENDTRY.
            /ui2/cl_json=>deserialize(
            EXPORTING json = gv_token pretty_name = /ui2/cl_json=>pretty_mode-camel_case CHANGING data = m_entries ).
            lv_auth2 = m_entries-access_token.
            gv_token = gv_token+17.
            CONCATENATE 'Bearer' lv_auth2 INTO lv_auth SEPARATED BY space.
          ENDIF.
          DATA lv_object_id TYPE string.
          lv_object_id = iv_object_id.
          TRANSLATE lv_object_id TO LOWER CASE.
          CONCATENATE lv_initial_url lv_object_id INTO lv_url. "Appending Fix URL and the Object ID to get the Request URL
          "create HTTP client by url
          CALL METHOD cl_http_client=>create_by_url
            EXPORTING
              url                = lv_url
            IMPORTING
              client             = lo_http_client
            EXCEPTIONS
              argument_not_found = 1
              plugin_not_active  = 2
              internal_error     = 3
              OTHERS             = 4.
          "Available API Endpoints
          "https://blockchain-service.cfapps.sap.hana.ondemand.com/blockchain/proofOfHistory/api/v1
          "https://blockchain-service.cfapps.eu10.hana.ondemand.com/blockchain/proofOfHistory/api/v1
          "https://blockchain-service.cfapps.us10.hana.ondemand.com/blockchain/proofOfHistory/api/v1
          IF sy-subrc <> 0.
            "error handling
          ENDIF.
          "setting request method
          lo_http_client->request->set_method('GET').
          "creatung Auth value
    *       lv_auth2 = 'Basic <Your Login Credentials>'.
          "adding headers
    *      lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded' ).
          lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ).
          lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth ).
    *      lo_http_client->request->set_header_field( name = 'APIKey' value = 'zBoCpDtkaT9jexRjtMk0J98Rs8izmQi1' ).
          "Available Security Schemes for productive API Endpoints
          "OAuth 2.0
          CALL METHOD lo_http_client->send
            EXCEPTIONS
              http_communication_failure = 1
              http_invalid_state         = 2
              http_processing_failed     = 3
              http_invalid_timeout       = 4
              OTHERS                     = 5.
          IF sy-subrc = 0.
            CALL METHOD lo_http_client->receive
              EXCEPTIONS
                http_communication_failure = 1
                http_invalid_state         = 2
                http_processing_failed     = 3
                OTHERS                     = 5.
          ENDIF.
          IF sy-subrc = 1.
            "error handling
            ev_response = 'http_communication_failure'.
          ELSEIF sy-subrc = 2.
            ev_response = 'http_invalid_state'.
          ELSEIF sy-subrc = 3.
            ev_response = 'http_processing_failed'.
          ELSEIF sy-subrc = 0.
            response = lo_http_client->response->get_cdata( ).
    *WRITE: 'response: ', response.
            ev_response = response.
          ELSE.
            ev_response = 'Unknown Error'.
          ENDIF.
        ENDIF.
      ENDMETHOD.

     

  • Get Token from SAP Cloud Platform Service

    Preface – This post is part of the ABAP Programs series.

    In this step we will call the service to get the token and store that token in a global variable for later use.

    METHOD get_token.
        DATA: lo_http_client TYPE REF TO if_http_client.
        DATA: response TYPE string,
              lv_url   TYPE string.
        CONSTANTS: lv_initial_url TYPE string VALUE '<Blockchain Service Link>',
                   lv_auth        TYPE string VALUE 'Basic <your login credentials>'.
        "create HTTP client by url
        CALL METHOD cl_http_client=>create_by_url
          EXPORTING
            url                = lv_initial_url
          IMPORTING
            client             = lo_http_client
          EXCEPTIONS
            argument_not_found = 1
            plugin_not_active  = 2
            internal_error     = 3
            OTHERS             = 4.
        "Available API Endpoints
        "https://blockchain-service.cfapps.sap.hana.ondemand.com/blockchain/proofOfHistory/api/v1
        "https://blockchain-service.cfapps.eu10.hana.ondemand.com/blockchain/proofOfHistory/api/v1
        "https://blockchain-service.cfapps.us10.hana.ondemand.com/blockchain/proofOfHistory/api/v1
        IF sy-subrc <> 0.
          "error handling
        ENDIF.
        "setting request method
        lo_http_client->request->set_method('GET').
        "adding headers
        lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth ).
        "Available Security Schemes for productive API Endpoints
        "OAuth 2.0
        CALL METHOD lo_http_client->send
          EXCEPTIONS
            http_communication_failure = 1
            http_invalid_state         = 2
            http_processing_failed     = 3
            http_invalid_timeout       = 4
            OTHERS                     = 5.
        IF sy-subrc = 0.
          CALL METHOD lo_http_client->receive
            EXCEPTIONS
              http_communication_failure = 1
              http_invalid_state         = 2
              http_processing_failed     = 3
              OTHERS                     = 5.
        ENDIF.
        IF sy-subrc <> 0.
          "error handling
        ENDIF.
        response = lo_http_client->response->get_cdata( ).
       GV_TOKEN = response. "Global Variable
      ENDMETHOD.

     

  • Calculate a hash in ABAP

    Preface – This post is part of the ABAP Programs series.

    In ABAP we can perform the following:

    calculate_hash_for_raw

    METHOD calculate_hash_for_raw.
    
        TRY.
            cl_abap_message_digest=>calculate_hash_for_raw(
              EXPORTING
                if_algorithm = 'SHA256'
                if_data      = iv_data
              IMPORTING
                ef_hashstring = ev_sha256
            ).
          CATCH cx_root.
            " Eh, what're you gonna do?
        ENDTRY.
      ENDMETHOD.

    calculate_hash_for_string

    METHOD calculate_hash_for_string.
    
        TRY.
            cl_abap_message_digest=>calculate_hash_for_char(
              EXPORTING
                if_algorithm = 'SHA256'
                if_data      = iv_data
              IMPORTING
                ef_hashstring = ev_sha256
            ).
          CATCH cx_root.
            " Eh, what're you gonna do?
        ENDTRY.
      ENDMETHOD.

     

  • 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

  • How to Register SAP OData Service in /IWFND/MAINT_SERVICE

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

    Introduction

    Once we have created an OData in SEGW. The very next step is to register the OData. After registering only we can access the SAP OData service. By registering, we mean we open our service to the internet. We can Register the service in two ways:

    • From the transaction SEGW
    • From the transaction /n/IWFND/MAINT_SERVICE

    Steps to Register an OData service using SEGW

    Once the OData is generated, now it is the time to register the service. Once the service is registered, then only it can be used anywhere.

    To generate an OData, follow the given steps:

    1. Double click the node Service Maintenance
    2. Select any System and click Register as shown below:
      OData Service Register
    3. Enter an Alias, if asked as shown below:
      OData System Alias
    4. Now, in the next screen you get following options:
    Field Description
    Technical Service Name This is auto generated service name
    Service Version It is auto generated service version
    Description It is the Description of the OData you have mention earlier
    External Service Name It is same to the auto generated service name
    Namespace It is by default bank
    External Mapping ID It is by default Empty
    External Data Source Type It is by Default set to source type C
    Technical Model Name It is auto generated Model Name
    Model Version It is auto generated Model Version
    Package Assignment Assign your package name here, or just choose Local Object from the button below. It will be then $TMP
    ICF Node It is by default “Standard Mode”
    oAuth Enablement It provides option to add extra authentication, in case you need oAuth2 enablement choose it, else leave it blank

     

    In our case, we just need to choose package and click confirm, as shown below:
    OData Service Registration

    Once the service is registered, the Registration will turn green, as shown below:
    OData Service Status

    Test the OData service

    1. To test the OData service, click the SAP Gateway Client button, as shown below:
      OData Test Service
    2. It will open a new screen, here click Add URI Option as shown below:
      OData Add URI Option
    3. Choose $metadata, here:
      OData $metadata
    4. Click Execute as shown below:
      OData Service Status 200

    If the status is 200, as shown above, then it means your OData is working fine.

    Steps to Register an OData service using /IWFND/MAINT_SERVICE

    1. Open the Service Maintenance Screen using the transaction /IWFND/MAINT_SERVICE. The given screen will open:
      Open the Service Maintenance Screen
    2. Click “Add Service” button. It will open “Add Selective Services” popup.
      Click “Add Service”
    3. Filter your service by entering it in the field “External Service Name” as shown below and click the search icon.
      Filter your service
    4. Now, the above search will return your OData Service name. Select your service and click Add Selected Service
      Select your service
    5. Now, assign your package name to the Service as shown below. In case, you don’t have package name, either click on “Local Object” or write $TMP in the package assignment. Then, save the above settings.
      Assign your package name to the Service
    6. Now, a pop up will open saying “Service <your service name> was created and its metadata was loaded successfully
    7. Now, go back to the transaction /iwfnd/maint_service and filter your service again. This time select your service and select SAP Gateway client
      select SAP Gateway client

    The Filter will open this popup, enter your details here and click execute (the green button).

    enter your details

    Then, follow these steps:

    follow these steps

    1. Here, test your service by following the steps given below:
      1. To test the OData service, click the SAP Gateway Client button, as shown below:
        OData Test Service
      2. It will open a new screen, here click Add URI Option as shown below:
        OData Add URI Option
      3. Choose $metadata, here:
        OData $metadata
      4. Click Execute as shown below:
        OData Service Status 200

    If the status is 200, as shown above, then it means your OData is working fine.

    Error Resolution

    In case you get an error while testing. It might be due to the wrong configuration, or a few nodes are inactive.

    To activate nodes, you need to visit T-Code SICF and search your service. Whatever result you will get, right-click on each and click “Activate”.

    In case you are still getting the same error of Node Activation “Check the ICF nodes in Tx SICF: At least one node is inactive.”, that might be because your server doesn’t have HTTPS enabled. To configure that, you need to visit T-Code RZ10. Check these blogs for the same: Error Explanation, Error Resolution.

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://youtu.be/2rEZrFj2haE?list=PLlZBMkVFeev4mdT2qpbUHTmZh4JMwrLqe&t=691[/embedyt]
  • How to perform OData Query and CRUD operation in OData

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

    Introduction

    In previous articles, we have discussed What is an OData and how to create an OData in SAP. We have also shown how to test an OData if it is working fine or not. Now, we need to learn how to read a table using an OData Query and also perform operations like Insert, Update and Delete on that table. In this article we will also learn basic queries of reading data.

    How it works

    In case of OData, there are three phases of data transfer. These are:

    1. Sending Data from Frontend

    Data is sent from UI (Client) to OData (Server) in form of query

    2.      Taking Data from Frontend

    At OData we receive data from Frontend using data provider (Code implemented in CRUD Operation section)

    io_data_provider->read_entry_data(IMPORTING es_data= ls_entity).

    3.      Sending Data to Frontend

    From OData we send data to UI using et_entityset or er_entity after data manipulation (Code implemented in CRUD Operation section)

    The above steps are shown in the image below:

    How to perform OData Query and CRUD operation in OData

    Operations in ODATA

    In this section, we will explore all the methods generated automatically, once you generate an OData. In last article, we have already instructed to write all your CRUD operations related code in DPC_EXT class. Hence, we will follow the same concept here.

    SAP ABAP OData provides different methods for CRUD operations, these are:

    Method SQL Operation Description
    GET_ENTITY Select This method is used to read a single data based on table keys
    GET_ENTITYSET Select This method is used to read entire data of a table
    CREATE_ENTITY Insert This method is used to create/insert a new data in table
    UPDATE_ENTITY Update/Modify This method is used to update an existing data in table
    DELETE_ENTITY Delete This method is used to delete an existing data in table

     

    Query in SAP OData

    In this section, we will explore all the Query we can perform while reading data from OData. In above section, we have learnt how to do read calls using GET_ENTITY and GET_ENTITYSET. Sometimes, we need to filter out data according to our requirement, or to get total number of data counts or to get data in specific order. These all SAP OData Queries are explained below:
    Here, let us suppose <your service name>  = https://isd.sap.com/<OData Service Name>

    Query Description Example
    $metadata It gives the metadata detail of your service. By metadata we mean it will provide information about all the entity sets with their field names and their attributes <your service name>/$metadata
    $FILTER It is mainly used during Read Entity Set call. During Read, we can send some filter value in backend that can be later used in where condition of Select queries <your service name>/$FILTER
    $top and $skip It is mainly used to get limited data in the UI, in case you are reading all the data, and the table is having a very large data <your service name>/$top and $skip
    $orderby This is used to order the data in ascending or descending order for a specific key <your service name>/$orderby
    $format=json This returns the data in form of JSON format. By default, the result is in XML format. <your service name>/$format=json
    $inlinecount This returns the number of data of a table that will appear in the UI <your service name>/$inlinecount
    $expand This is used to bind the association and navigation data together <your service name>/$expand
    $value This is used to return the media data <your service name>/$value

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=2rEZrFj2haE[/embedyt]
  • Difference between a Static Breakpoint and Dynamic Breakpoint

    Preface – This post is part of the Differences in ABAP for Interviews series.

    Introduction

    Before jumping to the difference between a Static Breakpoint and Dynamic Breakpoint, let’s have a short introduction of the two.

    What is a Breakpoint in SAP ABAP?

    A Breakpoint is a signal in a specific line of the ABAP program that interrupts the normal execution of the program and the control is transferred to the Debugger. A breakpoint can be active or passive at runtime and can be set for the specific users, all users or based on checkpoints. Breakpoints help in debugging and analysing ABAP Objects, ABAP programs and evaluating only the concerned sections of ABAP code, while skipping the rest of the areas.

    Static Breakpoint

    Static Breakpoints are recommended for use only during the development of an application where the program execution needs to be interrupted at the same point for analysis. These must be deleted once the development phase is over. These are set by an ABAP statement and can be of the following types:

    • User non-specific: These are inserted by the ABAP keyword BREAK-POINT. These are applied to all users and the system interrupts the execution for all the users.
    • User-specific: These are inserted by the ABAP keyword BREAK <USERNAME>. These are applied to the specified user and the system interrupts the execution for the specified user.

    Dynamic Breakpoint

    Dynamic Breakpoints are triggered when the program that you are running reaches a particular ABAP statement or exception class. These are user-specific and gets automatically deleted when the user logs off. A total 30 dynamic breakpoints can be set without changing source code.

    Dynamic Breakpoints are more flexible than Static Breakpoints as the former can be created, deactivated or deleted at runtime. Dynamic breakpoints can be set even when the program is locked by another user.

    Now, let’s have a look at their difference.

    Difference between a Static Breakpoint and Dynamic Breakpoint

    Static Breakpoint Dynamic Breakpoint
    They can be set using statement “BREAK-POINT” and “BREAK <USERNAME>” in ABAP code. They can be set in ABAP editor and in debugging mode.
    These are not normally user specific; but can be set for specific users. These are user specific.
    These cannot be set when the program is locked by another user These can be set even if the program is locked by another user.
    These needs to be deleted manually. These are deleted automatically when you log-off from SAP.

  • How to Create SAP OData

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

    Introduction

    In our previous article, we have already discussed what an OData is. In this article we will go through step by step process to create a SAP OData service. Later on, we will register our service and also test if it is working fine. In this article, we will not write any code related to CRUD (create, write, update and delete). To learn CRUD in OData, click here.

    Step by Step Process to create SAP OData service

    In this section we will follow multiple predefined steps to create an OData, these are:

    1. We will use SAP Service Gateway Builder (SEGW) to create a new project
    2. We will Import DDIC/CDS or other Structure to create an OData Model
    3. We will Generate our OData
    4. We will Register and test our Service

    Create a new Service Builder project

    To create a new project, follow the given steps:

    1. Go to transaction code SEGW, it will start the Gateway Service Builder.
    2. Click on the Create Project button, as shown below:
    3. Enter the given information
    Field Description Example
    Project It is the name of your SAP OData Service. It will start with Z or Y ZPROJECT_NAME
    Description Enter a description for your OData Demo OData Project
    Project Type SAP Provides given four Project Options:

    1.       Service with SAP Annotations

    2.       Service with Vocabulary-Based Annotations

    3.       Annotation Model for Referenced Service

    4.       OData 4.0 Service

    We will learn about them in details, later.

    Service with SAP Annotations

     

    Generation Strategy It will be preloaded as Standard which means, it has all standard configurations. Standard
    Package Enter your project package or temporary package i.e. $TMP $TMP
    Person Responsible It will be preloaded with your User ID/ User Name barryAllen

    OData creation

    1. Press Continue and Save.

    Import a DDIC structure

    To use an OData Service, it should be designed in such way that it will read/update one or more table. Therefore, we need to import any table, structure or view. These are part of DDIC structure. We can also import Data model from file, RFC/ BOR Interface or a search help. But in this section, we will learn how to import a DDIC structure:

    1. Click on the Data Model under the project we have recently created to expand it.
    2. Right Click on Data Model and click Import and then click DDIC Structure
      OData DDIC Import
    3. Now, a Wizard will open. Enter the following details, there:
    Field Description Example
    Name Enter a name of Model. It should be explanatory. CustomerData
    Type We have two options here:

    1.       Entity Type: This means a simple DDIC structure/table/view will be imported

    2.       Complex Type: This means a complex DDIC structure/table/view will be imported

    Choose Entity Type
    ABAP Structure Choose your required table or structure name. Just copy and paste the name of your DDIC table/structure/view zcustomer_data
    Create Default Entity Set It will create an Entity Type with the same fields as of Entity. Also, the name will remain same. We recommend you to leave it check marked. Leave it check marked

     

    The above details are shown below:
    OData Entity Set Creation

    1. In the next step, the wizard will show all the fields of the imported table. Just select them all and click next as shown below:
      OData Entity Set Creation2
    2. In the next step, the wizard will show all the checked fields. Here you need to check the primary keys and finish, as shown below:
      OData Entity Set Creation3

     

    Generate OData Service

    Now, we have created an OData object with a model. Now to use this Object we need to generate all the required classes. To generate, press the Generate Runtime Objects  OData Generate Icon button, as shown below:

    OData Generate Runtime Objects

    Note: The Generate Runtime Objects button automatically saves the project before generating classes.

    Pressing the above button, will open a dialog box as shown below:

    OData Class Generation

    Just press Continue, as shown above. The above process will generate following classes:

    Class Name Description
    MPC Class MPC stands for Model Provider Class. This is generated and refreshed every time, we generate a class. It is not recommended to extend this class for Model Annotations, because all the methods are deleted whenever the OData is generated.
    MPC EXT Class This is the Extended MPC class, and all the methods are conserved even the OData is generated.
    DPC Class DPC stands for Data Provider Class. This is generated and refreshed every time, we generate a class. It is not recommended to extend this class for CRUD operation, because all the methods are deleted whenever the OData is generated.
    DPC EXT Class This is the Extended DPC class, and all the methods are conserved even the OData is generated.
    MDL Class The is the Model Class.
    SRV Class This is the Service Class.

     

    Just click on Lock Object to generate the classes, as shown below:

    OData Service Generation

    Register SAP OData using the Gateway client

    Once the OData is generated, now it is the time to register the service. Once the service is registered, then only it can be used anywhere.

    To generate an OData, follow the given steps:

    1. Double click the node Service Maintenance
    2. Select any System and click Register as shown below:
      OData Service Register
    3. Enter an Alias, if asked as shown below:
      OData System Alias
    4. Now, in the next screen you get following options:
    Field Description
    Technical Service Name This is auto generated service name
    Service Version It is auto generated service version
    Description It is the Description of the OData you have mention earlier
    External Service Name It is same to the auto generated service name
    Namespace It is by default bank
    External Mapping ID It is by default Empty
    External Data Source Type It is by Default set to source type C
    Technical Model Name It is auto generated Model Name
    Model Version It is auto generated Model Version
    Package Assignment Assign your package name here, or just choose Local Object from the button below. It will be then $TMP
    ICF Node It is by default “Standard Mode”
    oAuth Enablement It provides option to add extra authentication, in case you need oAuth2 enablement choose it, else leave it blank

     

    In our case, we just need to choose package and click confirm, as shown below:

    OData Service Registration

    Once the service is registered, the Registration will turn green, as shown below:

    OData Service Status

    Test the OData service

    1. To test the OData service, click the SAP Gateway Client button, as shown below:OData Test Service
    2. It will open a new screen, here click Add URI Option as shown below:
      OData Add URI Option
    3. Choose $metadata, here:
      OData $metadata
    4. Click Execute as shown below:
      OData Service Status 200

    If the status is 200, as shown above, then it means your OData is working fine.

    In upcoming articles, we will learn how to perform CRUD operation using OData.

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=2rEZrFj2haE[/embedyt]