Author: Rudramani Pandey

  • 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.

     

  • Navigate between Views in Web Dynpro

    Preface – This post is part of the SAP ABAP Web Dynpro series.

    Introduction

    In our previous articles we have already seen how to create a view in Web Dynpro. In Web Dynpro we can create multiple views under a component. It is also important to embed that view in the window to make it visible. In this article we will explore how to navigate between Views in Web Dynpro. Before jumping directly to the navigation concept, we will start with the concept of plugs in Web Dynpro.

    Navigate between Views in Web Dynpro

    A Web Dynpro application needs following to navigate between two views within a window:

    1. Views: At least two views which will have the navigation concept implemented.
    2. Navigation Links: A Navigation link is the connection between the above views.
    3. Plugs: A plug is the port that exists at both the ends of the Navigation link.

    The above concepts can be understood with the diagram shown below:

    Navigating between Views in Web Dynpro

    Plugs

    A plug is a junction used for accessing or existing a view. Either you will access a view or exist a view; and for both case we have two different plugs. These are:

    Inbound Plug

    This is a plug which is used to enter a view. Every inbound plug must be linked to an outbound plug else it produces errors.

    Outbound Plug

    This is a plug which is used to exit a view. Every outbound plug must be linked to an inbound plug else it produces errors.

    Navigation Link

    A Navigation link is the connection between two views. It needs plugs to execute a navigation.

    Step by step process to create a Navigation between views

    Step 1: Go to SE80, create a web Dynpro component ZTest_PLUGS.

    Step 2: Go to main view, insert a button, provide button text as ‘Press’, and create action method for button ON_PRESS.

    Step 3: Right click on component -> create -> view, provide name as DETAILS_VIEW and enter.

    Step 4: Go to “DETAILS_VIEW” view, insert a button, provide button text as ‘Back’, create action method for button ON_BACK.

    Step 5: Go to main view, outbound plugs tab, add outbound plug as GOTO_DETAILS_VIEW and inbound plugs tab add inbound plug as IN_MAIN.

    Step 6: Go to DETAILS_VIEW view, outbound plugs tab, add outbound plug as GOTO_MAIN and inbound plugs tab add inbound plug as IN_DETAILS.

    Step 7: Expand window, drag and drop MAIN, “DETAILS_VIEW” view into window.

    Step 8: Expand two views, right click on GOTO_ DETAILS_VIEW -> Create Navigation Link, press F4, select destination view as DETAILS_VIEW and enter.

    Step 9: Right click on GOTO_MAIN -> Create Navigation Link, press F4, select destination view as MAIN and enter.

    Step 10: Go to main view actions tab, double click on ON_PRESS method and add below code.

    wd_this->FIRE_GOTO_ DETAILS_VIEW_PLG( );

    Step 11: Go to DETAILS_VIEW view actions tab, double click on ON_BACK method and add below code.

    wd_this->FIRE_GOTO_MAIN_PLG( );

    Step 12: Save and Activate the components.

    Step 13: Run and Test the components.

  • Data Binding in Web Dynpro

    Preface – This post is part of the SAP ABAP Web Dynpro series.

    Introduction

    A Web Dynpro Application is developed using MVC (Model View Controller) Architecture. It means whatever data model is there that requires binding with the View elements (e.g. Input Field, Check box, Table, etc.). This binding can be achieved using view and controller. In this article we will explore data binding in Web Dynpro.

    Data Binding in Web Dynpro

    In Web Dynpro, we have multiple components. In our previous article, we have already discussed that we have something called Context which is a data container which stores data at runtime. A context can have multiple nodes e.g. Table nodes which will store table data. These nodes can have multiple Attributes that are the fields of the table.

    Definition

    Binding of the attributes or nodes of a context with UI elements (e.g. Table, Input Fields, etc.) is known as Data Binding in Web Dynpro.

    Data Binding in Web Dynpro

    Why we need Data Binding

    1. To show Customer Data on the Web Dynpro screen
    2. To auto fill the input fields based on pre-defined selections
    3. To provide search helps for an input element
    4. To maintain/provide conditions on UI based on backend data

    Types of Data Binding

    1. Internal Mapping
      It is a mapping between contexts of single component.
    2. External Mapping
      It is a mapping between multiple contexts using their interface controller.

    Setup and Coding for Data Binding

    In our previous articles we have already shared steps to create a Web Dynpro View and publish it as an application. You can follow steps and code mentioned here to convert that application in an Application which utilizes data binding.

  • Blockchain Implementation in ABAP

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

    Introduction

    With the introduction of Blockchain in SAP Cloud Platform, the important questions for SAP developers was its implementation in SAP ABAP. All the client information of SAP is mainly on premise based. The major amount of data is already stored in backend system and if we cannot push this data on blockchain then the Blockchain on SAP Cloud Platform is of no use. In this article we will explain the Blockchain Implementation in ABAP.

    Blockchain on SAP Cloud Platform

    In our previous articles we have already explained the blockchain services (mainly Hyperledger, Multichain and Quorum) on SAP Cloud Platform. These instances are connected with SAP Blockchain enablement services, which acts as an interface between these blockchain services and other SAP services.

    Blockchain Implementation in ABAP

    We can easily understand the blockchain implementation in ABAP using the given block diagram:

    Blockchain Implementation in ABAP

    In the diagram above, you can see that the SAP ABAP interacts with Blockchain Enablement services and the HANA Database. This application can be either displayed using Classical ABAP Report or using Fiori Application which will then use OData to interact with SAP ABAP methods.

    To call any service in SAP Cloud platform, we need to do the following:

    1. Get Token from the service using a read call.
    2. Perform CRUD operation on the service using the token received above.

    Let us understand these steps with respect to the blockchain services.

    Get Token from the Blockchain Service

    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.

     

    Get Proof history from the Blockchain Service

    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.

     

  • Components in Web Dynpro

    Preface – This post is part of the SAP ABAP Web Dynpro series.

    Introduction

    Web Dynpro is a SAP based technology which is used to create web-based Application. To develop a web based application we need multiple components and interfaces. In this article we will explain Components in Web Dynpro in detail.

    Components in Web Dynpro

    A Web Dynpro component is a reusable entity. The creation of Components in Web Dynpro is a mandatory process. A Web Dynpro component can even contain another Web Dynpro Component. The lifetime of Web Dynpro component begins at runtime of the application and end with the lifetime of Web Dynpro Application.

    Context

    It is a data container (or a temporary storage area) where we store data during runtime of Web Dynpro Application.

    UI Element

    It is the most important element of Web Dynpro. It is a display/screen element. Using it, we can display any information on the screen. It include Text View, Radio Buttons, Drop Down, Check Boxes, Tables, etc.

    View

    Like HTML websites, it is the screen that is visible on the browser. It is the same view that we have discussed in the MVC concept of Web Dynpro earlier.

    Window

    The window is the container that holds multiple view altogether.

    Methods

    It is the section that contains the business logic of our Web Dynpro Application. Like SAP ABAP, we include Select statements, Function Module, other code blocks here.

    Controller

    As we have discussed about MVC architecture of Web Dynpro, a controller is used to communicate between views and models (data). These models are extracted from the Methods.

    Navigation Plugs

    A navigation plug, as its name suggests is used to navigate between multiple views.

    Application

    Once we are done with all the component creation, modelling and coding, we need to get an executable link which is extracted from Web Dynpro Application.

    Advantage of Components in Web Dynpro

    Following are the advantages of Components in Web Dynpro:

    1. It helps in Structuring the programming
    2. It helps in creating blocks which are easily manageable
    3. It creates blocks which are reusable
  • Setup of SAP Web Dynpro Application

    Preface – This post is part of the SAP ABAP Web Dynpro series.

    Introduction

    Web Dynpro in SAP ABAP is a standard technology which is used to create web-based applications using ABAP programing language. Web Dynpro includes many graphical development tools which are included in ABAP workbench. Because of the use of a graphical tool, it seems to be more user-friendly. In this article we will learn about the setup of SAP Web Dynpro Application.

    Setup of SAP Web Dynpro Application

    Step 01: Goto the transaction SE80

    Step 02: Click Repository Browser

    web dynpro Object Navigator

    Step 03: Select Create web Dynpro component and assign it a name as shown above. On Clicking enter it will open a pop up as shown below:

    Create web dynpro App

    Step 04: Enter the description, chose the type and Assign Window and View name as shown below:

    web dynpro Connectivity browser

    Step 05: Now a view is created as shown below:

    web dynpro in SE80

    Step 06: Double click the view to open it, as shown below. Choose the layout option here:

    web dynpro layout

    Step 07: In the right hand side, you will see two options, choose Root Element Container, as shown below:

    web dynpro root

    Step 08: In above step, choose Insert Element:

    web dynpro Insert Element

    Step 09: Provide ID and TYPE of the element, as shown below:

    web dynpro Create Element

    Step 10: For the element “Page Header” you have just created, define the properties available in the right pane:

    web dynpro properties

    The title that we have provided above will be the header of the Web Dynpro Application. It is suggested to give a meaning title, unlike the one we have mentioned.

    Step 11: To save your application, click CTRL + S

    Step 12: Now activate your application, by right clicking the application name from left pane and clicking “Activate”, as shown below:

    web dynpro explorer

    Step 13: Whatever, we have done is just the creation of Web Dynpro Interface/Component. To get an executable Application, right click and under Create option, choose “Web Dynpro Application”.

    web dynpro Application

    Provide the name of the application and meaningful description. The application you have just created will appear just below the “Windows” option above. Now right click the Web Dynpro Application and click test to open your application. The application will open in Internet Explorer.

  • R3 Corda Platform Introduction

    Preface – This post is part of the Blockchain Basics series.

    Introduction

    Corda is an open source private blockchain platform, introduced by R3 that integrates the existing proven technologies such as relational database, Java Machine (JVM) in blockchain for ERP and business solutions.

    Corda has published a whitepaper to discuss the underline technologies; you can read the Corda: A distributed ledger Whitepaper here.

    How R3 Corda Works

    In Corda network, a node firstly undergoes a KYC process to obtain identity certificate. When this node joins the network, they publish this certificate including their legal name, their IP address, public key and some other information. Then the nodes communicate point-to-point using TLS encrypted messaging.

    R3 Corda Use Cases

    R3 Codra is one of the most used Enterprise based blockchain network. Following are some of the common use cases:

    1. International Bank Transaction

    To implement cross border payment without any third party involvement, a bank can use R3 Corda based network to implement it.

    1. Construction Industry

    To share information between multiple sub-contractors, we can submit the information related to construction on Corda Blockchain.

    1. Healthcare Industry

    Healthcare Industry has following two possible use cases to implement blockchain:

    1. Health records exchange
    2. Health Claims management

    Merits of Corda Blockchain

    Following are the merits of Corda Blockchain Network:

    1. Privacy
    2. Agile and flexible
    3. Interoperability
    4. Open development
    5. Open design

    Demerits of Corda Blockchain

    Following are the demerits of Quorum blockchain:

    1. Anonymity
    2. Questionable affair for many companies
  • Quorum Introduction

    Preface – This post is part of the Blockchain Basics series.

    Introduction

    Quorum is a private and permissioned blockchain developed on top of Go and Ethereum technology mainly for Enterprise based solution. An Ethereum is a decentralized platform which is used to run smart contracts. In this Quorum Introduction we will explore more about it.

    Quorum has its Whitepaper published here. Apart from Quorum Introduction, it discusses the core architecture and end to end implementation of Quorum technology.

    How Quorum Works

    Quorum Application are based on three layered structure. The initial layer is the go-Ethereum where all the transaction happens. The second layer is of Quorum where all the logics are implemented which also includes Transaction Manager, Crypto Enclave, consensus and network manager. The last layer includes the distributed blockchain applications.

    Quorum Use Cases

    With its permissioned blockchain paradigm, Quorum can be implemented easily in given use cases:

    1. Financial Applications

    To ensure the transactions between two parties and two financial institutions are secure, private and not revealed to any other financial institutions, then implementing it via a permissioned network like Quorum is a right decision. Quorum supports both client privacy as well as meet legal and regularity requirements.

    1. Payment Applications

    To implement payment across various parties based on various pre-defined conditions might include the implementation of smart contracts. The use of Quorum network helps us to implement the transaction on a common protocol.

    Merits of Quorum Blockchain

    Following are the merits of Quorum blockchain:

    1. Private and Permissioned Network
    2. Alternative Consensus Mechanism
    3. Peer permissioning
    4. Higher performance

    Demerits of Quorum Blockchain

    Following are the demerits of Quorum blockchain:

    1. Anonymity
    2. Questionable affair for many companies
  • Multichain Introduction

    Preface – This post is part of the Blockchain Basics series.

    Introduction

    Multichain is off-the-shelf private blockchain platform developed primarily for institutional financial sectors. It provides privacy, openness and control to the network administrator (that can be either miner of the first “genesis” block or a predefined miners set as Admin by previous Admin). Multichain has published a whitepaper to discuss the underline technologies; you can read the Multichain Private Blockchain Whitepaper here. In this article we will explore the Multichain Introduction with some of its use cases.

    How Multichain Works

    In a Multichain bases blockchain network, the administrator grants privileges to other users in the network. The mining (block validation) in a Multichain is just like a round robin schedule, which means each miner/user in the network must create blocks in rotation to generate an authentic blockchain.

    Multichain Use Cases

    Multichain is one of the widely used blockchain technologies that are being utilized by enterprises and small industries. Following are some of the accepted use cases by Multichain:

    1. Centralized Currency Settlement System

    This is a very generic use case where all the currency exchange system can be scrutinized under blockchain methodology.

    1. Bond Issuance System

    Issuance of bond in a systematic manner becomes a tedious job. Multichain can become a secure solution to this problem.

     

    1. Peer-to-peer Trading System

    Stock trading is not a peer-to-peer system but it can be like bitcoin trading system. This can be easily achieved with the help of Multichain.

     

    1. Consumer facing reward scheme

    It is also a generic scenario where blockchain can be used to win trust and bring fair results in the reward scheme.

     

     

    Merits of Multichain Blockchain

    Multichain Introduction on top of Bitcoin brings following merits:

    • Unlimited capacity
    • Very less or no transaction cost (based on subscription)
    • Relevant Data storage
    • Reduced Mining risks
    • Higher privacy features
    • Openness

    Demerits of Multichain Blockchain

    Although Multichain provides additional features on top of Bitcoin and is better than many permissioned blockchain technology, still it comes with following demerits:

    • No support to smart contracts
    • Typical consensus mechanism