Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
jahnavi_venati
Explorer

step1) Open TCode SEGW and create a project as shown in below screen shot.

Provide the following details


Then the components like

  1. 1. Data Model
  2. 2. Service Implementation
  3. 3. Runtime Artifacts
  4. 4. Service Maintenance

Gets displayed automatically.


step2. Create an entity type as follows

Provide as following.


Click on properties as shown below.

Add the following values for header as shown below

Same way create entity type PR_Item for the item also and give the following values

step3. Create an entityset as shown below.

Give the following details

Then Header Entityset is created.

     Same way create for Item Entityset is created.

step 4. Create a association as shown below.


And association set is automatically created.

step 5. Now Navigation is automatically created.

step 6.After completion of data model in Odata service in Service Implementation is filled automatically as shown in below screen shot.

step 7.Now we need to generate runtime artifacts ,for that you need to select Runtime Artifacts and click on

Click OK and save it.

We get the following in Runtime Artifacts .

step 8. We need write in ZCL_Z_PURCHASE_REQUISI_DPC_EXT so double click on it .

step 9 A.Then we need to right click on the methods and redefine required methods in following process.

And write following code  to get entity .


Code for Get Entity

method PRHEADERCOLLECTI_GET_ENTITY.

DATA: LS_KEY_TAB LIKE LINE OF IT_KEY_TAB.

     READ TABLE it_key_tab INTO ls_key_tab WITH KEY name ='PRNumber'.

ER_ENTITY-prnumber = LS_KEY_TAB-VALUE.

*    lv_pR_item = ls_key_tab-value.

**TRY.

*CALL METHOD SUPER->PRHEADERCOLLECTI_GET_ENTITY

*  EXPORTING

*    IV_ENTITY_NAME          =

*    IV_ENTITY_SET_NAME      =

*    IV_SOURCE_NAME          =

*    IT_KEY_TAB              =

**    io_request_object       =

**    io_tech_request_context =

*    IT_NAVIGATION_PATH      =

**  IMPORTING

**    er_entity               =

**    es_response_context     =

*    .

** CATCH /iwbep/cx_mgw_busi_exception .

** CATCH /iwbep/cx_mgw_tech_exception .

**ENDTRY.

endmethod.

9 B. Likewise redefine other required methods PRITEMCOLLECTION_GET_ENTITYSET and deep insert  also in same way  .

Code for GET_ENTITYSET

*** inactive new ***

METHOD PRITEMCOLLECTION_GET_ENTITYSET.

DATA:        ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,

            lv_pr_number TYPE BANFN,

            lv_pr_item TYPE BNFPO,

            lt_pr_items_bapi TYPE TABLE OF BAPIEBAN,

            ls_pr_item_bapi TYPE BAPIEBAN,

            IT_RETURN TYPE STANDARD TABLE OF BAPIRETURN.

TYPES:

BEGIN OF ts_pr_item,

     PRITEM type C length 5,

     PURGROUP type C length 3,

     MATERIAL type C length 18,

     SHORTTEXT type C length 40,

     PLANT type C length 4,

     MATERIALGROUP type C length 9,

     QUANTITY type P length 7 decimals 3,

     UNIT type C length 3,

     DOCUMENTTYPE type C length 4,

     DELIVERYDATE type TIMESTAMP,

     ITEMCATEGORY type C length 1,

     ACCTASSIGNCATEGORY type C length 1,

     PRNUMBER type C length 10,

END OF ts_pr_item.

*

DATA: es_entityset LIKE LINE OF ET_ENTITYSET.

*

READ TABLE it_key_tab INTO ls_key_tab WITH KEY name ='PRNumber'.

lv_pR_number = ls_key_tab-value.

*

READ TABLE it_key_tab INTO ls_key_tab WITH KEY name ='PRItem'.

lv_pR_item = ls_key_tab-value.

CALL FUNCTION 'BAPI_REQUISITION_GETDETAIL'

EXPORTING

number =  lv_pr_number

tables

requisition_items =   lt_pr_items_bapi

RETURN =   IT_RETURN

          .

*DELETE lt_pr_items_bapi WHERE preq_item NE lv_pr_item.

*

READ TABLE lt_pr_items_bapi INTO ls_pr_item_bapi INDEX 1.

*

LOOP AT lt_pr_items_bapi INTO ls_pr_item_bapi.

*

      es_entityset-PRITEM = ls_pr_item_bapi-PReq_ITEM.

      es_entityset-PURGROUP = ls_pr_item_bapi-PUR_GROUP.

      es_entityset-material = ls_pr_item_bapi-material.

      es_entityset-SHORTTEXT = ls_pr_item_bapi-short_text.

      es_entityset-plant = ls_pr_item_bapi-plant.

      es_entityset-MATERIALGROUP = ls_pr_item_bapi-mat_grp.

      es_entityset-quantity = ls_pr_item_bapi-quantity .

      es_entityset-UNIT = ls_pr_item_bapi-unit .

      es_entityset-DOCUMENTTYPE = ls_pr_item_bapi-doc_type .

      es_entityset-ITEMCATEGORY = ls_pr_item_bapi-item_cat .

      es_entityset-ACCTASSIGNCATEGORY = ls_pr_item_bapi-acctasscat .

      es_entityset-PRNUMBER = ls_pr_item_bapi-preq_no .

      es_entityset-DeliveryDate = ls_pr_item_bapi-deliv_date .

      APPEND es_entityset TO et_entityset.

      CLEAR: es_entityset.

*

ENDLOOP.

  1. ENDMETHOD.

CODE FOR CREATE_DEEP_ENTITY

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.

**TRY.

*CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

*  EXPORTING

**    iv_entity_name          =

**    iv_entity_set_name      =

**    iv_source_name          =

*    IO_DATA_PROVIDER        =

**    it_key_tab              =

**    it_navigation_path      =

*    IO_EXPAND               =

**    io_tech_request_context =

**  IMPORTING

**    er_deep_entity          =

*    .

** CATCH /iwbep/cx_mgw_busi_exception .

** CATCH /iwbep/cx_mgw_tech_exception .

**ENDTRY.

     DATA: lv_new_pr_no TYPE BAPIEBANC-PREQ_NO.

*             ls_new_pr_header TYPE BAPIMEREQHEADER.

DATA: ls_bapi_item TYPE bapiebanc,

          lt_bapi_item TYPE TABLE OF bapiebanc,

          lt_return TYPE TABLE OF bapiret2.

TYPES: ty_t_pr_items TYPE TABLE OF zcl_z_purchase_requisi_mpc=>ts_pr_item WITH DEFAULT KEY.

TYPES: BEGIN OF ts_pr_items.

            INCLUDE TYPE zcl_z_purchase_requisi_mpc=>ts_pr_header.

TYPES: PrItemCollection TYPE ty_t_pr_items,

           END OF ts_pr_items.

DATA: lt_items TYPE zcl_z_purchase_requisi_mpc=>tt_pr_header,

          ls_item  TYPE zcl_z_purchase_requisi_mpc=>ts_pr_item,

          lt1_items type ty_t_pr_items,

          ls_pritems TYPE ts_pr_items.

DATA: ls_data TYPE ts_pr_items.

CALL METHOD io_data_provider->read_entry_data( IMPORTING es_data = ls_data ).

*    ls_item-PRItemCollection  = ls_data-PrItemCollection.

lt1_items  = ls_data-PrItemCollection.

*append ls_item to it_items.

*clear ls_item.

*    LOOP AT lt_items INTO ls_item.

LOOP AT lt1_items INTO ls_item.

      ls_bapi_item-material = ls_item-material.

      ls_bapi_item-plant = ls_item-plant.

      ls_bapi_item-quantity = ls_item-quantity.

      ls_bapi_item-doc_type = ls_item-DocumentType.

      ls_bapi_item-DELIv_DATE = ls_item-DeliveryDate.

      ls_bapi_item-PUR_GROUP = ls_item-PURGROUP.

      ls_bapi_item-PREQ_ITEM = ls_item-PRITEM.

      ls_bapi_item-SHORT_TEXT = ls_item-SHORTTEXT.

      ls_bapi_item-MAT_GRP = ls_item-MATERIALGROUP.

      ls_bapi_item-UNIT = ls_item-UNIT.

      ls_bapi_item-ITEM_CAT = ls_item-ITEMCATEGORY.

      ls_bapi_item-ACCTASSCAT = ls_item-ACCTASSIGNCATEGORY.

      ls_bapi_item-PREQ_NO = ls_item-PRNUMBER.

*      ls_itemx-po_item = ls_item-item.

      APPEND ls_bapi_item TO lt_bapi_item.

*      APPEND ls_itemx TO lt_itemx.

      CLEAR ls_item.

ENDLOOP.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT         = lv_new_pr_no

IMPORTING

OUTPUT        = lv_new_pr_no

          .

CALL FUNCTION 'BAPI_REQUISITION_CREATE'

* EXPORTING

* SKIP_ITEMS_WITH_ERROR =

* AUTOMATIC_SOURCE = 'X'

IMPORTING

NUMBER = lv_new_pr_no

TABLES

requisition_items = lt_bapi_item

RETURN = lt_return

      .

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

        wait = 'X'.

*    MOVE-CORRESPONDING ls_headerdata TO ls_pritems.

ls_pritems-prnumber = lv_new_pr_no.

copy_data_to_ref(

      EXPORTING

        is_data = ls_pritems

      CHANGING

        cr_data = er_deep_entity ).

endmethod.

step10: Now Service Maintenance is automatically created but we need to register the service. So select the system i.e. EC7 and click on register.


Give the system Alias LOCAL_GW and click OK. Then Maintain The register

step 11.Test the service

Provide the following query

/sap/opu/odata/SAP/Z_PURCHASE_REQUISITION_TEST_SRV/PRHeaderCollection('0010003245')?$expand=PRItemcollection

Click on Use as Request.

Then you will get the response as request on left side

For Purchase Requisition creation you need to remove the Purchase Requisition number from left side.

/sap/opu/odata/SAP/Z_PURCHASE_REQUISITION_TEST_SRV/PRHeaderCollection() in gateway client and click on post

Purchase Requisition is created ‘0010017270’ as shown in below screen shot.


Check in Table level entries in EBAN we can find the Purchase Requisition '0010017270'


2 Comments
Labels in this area