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

/wp-content/uploads/2016/05/1_952378.png

Provide the following details


/wp-content/uploads/2016/05/2_952670.png

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

/wp-content/uploads/2016/05/4_952672.png

Provide as following.


/wp-content/uploads/2016/05/5_952679.png

/wp-content/uploads/2016/05/6_952680.png

Click on properties as shown below.

/wp-content/uploads/2016/05/7_952681.png

Add the following values for header as shown below

/wp-content/uploads/2016/05/9_952683.png

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

/wp-content/uploads/2016/05/10_952684.png

step3. Create an entityset as shown below.

/wp-content/uploads/2016/05/11_952685.png

Give the following details

/wp-content/uploads/2016/05/12_952686.png

Then Header Entityset is created.

/wp-content/uploads/2016/05/13_952687.png

     Same way create for Item Entityset is created.

/wp-content/uploads/2016/05/14_952688.png

step 4. Create a association as shown below.

/wp-content/uploads/2016/05/15_952689.png


/wp-content/uploads/2016/05/16_952690.png

/wp-content/uploads/2016/05/17_952701.png

/wp-content/uploads/2016/05/18_952703.png

/wp-content/uploads/2016/05/19_952705.png

And association set is automatically created.

step 5. Now Navigation is automatically created.

/wp-content/uploads/2016/05/20_952710.png

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

/wp-content/uploads/2016/05/21_952711.png

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

/wp-content/uploads/2016/05/22_952715.png

Click OK and save it.

/wp-content/uploads/2016/05/24_952718.png

We get the following in Runtime Artifacts .

/wp-content/uploads/2016/05/25_952719.png

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

/wp-content/uploads/2016/05/27_952721.png

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

/wp-content/uploads/2016/05/28_952722.png

And write following code  to get entity .


/wp-content/uploads/2016/05/29_952723.png

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.


/wp-content/uploads/2016/05/30_952730.png

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

/wp-content/uploads/2016/05/33_952732.png

Click on Use as Request.

/wp-content/uploads/2016/05/34_952739.png

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.

/wp-content/uploads/2016/05/35_952741.png

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


/wp-content/uploads/2016/05/36_952757.png

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


To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. sivakumar M

    Dear ,

    I have tried above as it is but Its not working.

    /sap/opu/odata/sap/ZPR_CREATE_SRV/PRHeaderCollection(‘0010017240’)?$expand=PRItemcollection

    below error is coming

    <?xml version=”1.0″ encoding=”utf-8″ ?>

    <error xmlns=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata>

    <code>005056A509B11EE1B9A8FEC11C21D78E</code>

    <message xml:lang=”en>Resource not found for the segment ‘PRItemcollection’.</message>

    </error>

    (0) 

Leave a Reply