Sample Code

OData Read Call – DPC_EXT GET ENTITY method

This sample code read the incoming key (in this case, single result is returned) and filter(in this case, one to many results can be returned).

Read call with full key. Code is written in GET Method.


* Local Data Declaration
    DATA: lw_key_tab   TYPE /iwbep/s_mgw_name_value_pair,
          lv_message   TYPE bapi_msg,
          lv_lenum     TYPE lenum.
   
* StorageUnit is the name of the key element in the entityset.
* If order to get only one value GET method, fully key must be in the filter
    READ TABLE it_key_tab INTO lw_key_tab WITH KEY name = 'storageUnit'.

* Assign the value in proper variable
    lv_lenum = lw_key_tab-value.    
   
* Write your logic for processing
   
* Code for error handling
      mo_context->get_message_container( )->add_message_text_only(
                                    EXPORTING
                                      iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error
                                      iv_msg_text = CONV bapi_msg( lv_message )
                                    ).
      RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
        EXPORTING
          textid = /iwbep/cx_mgw_busi_exception=>business_error.

Read with a filter. Code is written in GET SET Method


* Local Data Declaration
    DATA: lw_filter TYPE /iwbep/s_mgw_select_option,
          lt_search    TYPE /iwbep/t_cod_select_options,
          ls_search    TYPE /iwbep/s_cod_select_option,
          lv_message   TYPE bapi_msg,
          lv_ebeln     TYPE ebeln.

* Read the filter table (a deep entity) with the filter variable. In this case purchaseOrder
* Then read the value passed in that filter variable. In this case, it is just a single variable is low
* The filter mimic the select option structure and can have BT or LE, GT etc as qualifier    
    READ TABLE it_filter_select_options INTO lw_filter WITH KEY
              property = 'purchaseOrder'.
    IF sy-subrc = 0.

      lt_search = lw_filter-select_options.
      IF lt_search IS NOT INITIAL.
        READ TABLE lt_search INTO ls_search INDEX 1.
        lv_ebeln = ls_search-low.
      ENDIF.  
   
* Write your logic for processing
   
* Code for error handling
      mo_context->get_message_container( )->add_message_text_only(
                                    EXPORTING
                                      iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error
                                      iv_msg_text = CONV bapi_msg( lv_message )
                                    ).
      RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
        EXPORTING
          textid = /iwbep/cx_mgw_busi_exception=>business_error.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter
LinkedIn
LinkedIn
Share