+ All Categories
Home > Documents > RFC Operation

RFC Operation

Date post: 16-Oct-2015
Category:
Upload: ricky-das
View: 93 times
Download: 1 times
Share this document with a friend
Description:
RFC Operation
Popular Tags:

of 13

Transcript

Step by Step development for CREATE_DEEP_ENTITY operationPosted bySyam BabuinSAP NetWeaver Gatewayon Apr 27, 2014 8:10:56 AMinShare3This blog I will explain creation of SAP NW GW OData service which will implement Create Deep Entityoperation.

SAP documentation for deep understanding.

Deep Insert - SAP NetWeaver Gateway - SAP Library

Create Custom RFC given below Structures.

Structure-1 - HeaderStructure-2 - ItemOStructure-3 - ItemT

Create Project in SEGWCreate three entity types and Entity Sets

Entity Type-1- HeaderEntity Type-2- ItemOEntity Type-3- ItemT

Entity Set-1- HeaderSetEntity Set-2- ItemOSetEntity Set-3- ItemTSet

Entity Type - Header

Entity Type - ItemO

Entity Type - ItemT

Entity Sets - HeaderSet,ItemOSet,ItemTSet

Create Associations given below

Association-1 - Header_ItemO (Without key fields mapping)Association-2 - Header_ItemT (Without key fields mapping)

Create Navigation given below

Navigation-1 - HeadItemONavigation-2 - HeadItemT

Now lets generate runtime artifacts. Click on generate runtime objects button. It will displaypopup . Keep the default class names as-is and click on enter button.Once generation is successful, you will get 4 classes. 2 for Data provider and 2 for Model provider.

Once registration done successfully .GotoGateway Client ( call transaction /IWFND/GW_CLIENT to open SAP NW Gateway client)Append $metatda to base service URL and press execute button. If everything is fine then you will HTTPResponse as below. Metadata provides information such as Entity type, key property, properties and Entity Setname and also check service document append ?$format=xml.

Build Types for Deep Entity

Code Snippet

*----------------------------------------------------------------------** CLASS ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT DEFINITION*----------------------------------------------------------------------***----------------------------------------------------------------------*CLASSzcl_zproj_gr_multideep_mpc_extDEFINITIONPUBLICINHERITING FROMzcl_zproj_gr_multideep_mpcCREATE PUBLIC.

PUBLIC SECTION.

TYPES:BEGIN OFts_deep_entity,id TYPEchar10,nameTYPEchar30,name2TYPEchar30,headitemoTYPE STANDARD TABLE OFts_itemoWITH DEFAULT KEY,headitemtTYPE STANDARD TABLE OFts_itemtWITH DEFAULT KEY,END OFts_deep_entity.

METHODS defineREDEFINITION.Redefine the DEFINE method of Extended Model Provider class ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT

Code Snippet

METHOD define.super->define( ).DATA:lo_annotationTYPE REF TO/iwbep/if_mgw_odata_annotation,lo_entity_typeTYPE REF TO/iwbep/if_mgw_odata_entity_typ,lo_complex_typeTYPE REF TO/iwbep/if_mgw_odata_cmplx_type,lo_propertyTYPE REF TO/iwbep/if_mgw_odata_property,lo_entity_setTYPE REF TO/iwbep/if_mgw_odata_entity_set.

************************************************************************************************************************************ ENTITY - Deep Entity***********************************************************************************************************************************

lo_entity_type=model->get_entity_type(iv_entity_name='Header')."#EC NOTEXT

lo_entity_type->bind_structure(iv_structure_name='ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT=>TS_DEEP_ENTITY')."#EC NOTEXT

ENDMETHOD.

Now we have create one custom method (CUSTOME_CREATE_DEEP_ENTITY) in classZCL_ZPROJ_GR_MULTIDEEP_DPC_EXT

IV_ENTITY_NAME Importing Type STRINGIV_ENTITY_SET_NAME Importing Type STRINGIV_SOURCE_NAME Importing Type STRINGIT_KEY_TAB Importing Type /IWBEP/T_MGW_NAME_VALUE_PAIRIT_NAVIGATION_PATH Importing Type /IWBEP/T_MGW_NAVIGATION_PATHIO_EXPAND Importing Type Ref To /IWBEP/IF_MGW_ODATA_EXPANDIO_TECH_REQUEST_CONTEXT Importing Type Ref To /IWBEP/IF_MGW_REQ_ENTITY_CIO_DATA_PROVIDER Importing Type Ref To /IWBEP/IF_MGW_ENTRY_PROVIDERER_DEEP_ENTITY Exporting Type ZCL_ZPROJ_GR_MULTIDEEP_MPC_EXT=>TS_DEEP_ENTITY

/IWBEP/CX_MGW_BUSI_EXCEPTION/IWBEP/CX_MGW_TECH_EXCEPTIONCode SnippetMETHODcustome_create_deep_entity.

DATA:lr_deep_entityTYPEzcl_zproj_gr_multideep_mpc_ext=>ts_deep_entity,lt_itemoTYPEzcl_zproj_gr_multideep_mpc=>tt_itemo,lt_itemtTYPEzcl_zproj_gr_multideep_mpc=>tt_itemt,ls_itemoTYPEzcl_zproj_gr_multideep_mpc=>ts_itemo,ls_itemtTYPEzcl_zproj_gr_multideep_mpc=>ts_itemt.

DATA:ls_general_dataTYPEzstr1_header,lt_itemo_dataTYPE STANDARD TABLE OFzstr1_itemo,ls_itemo_dataTYPEzstr1_itemo,lt_itemt_dataTYPE STANDARD TABLE OFzstr1_itemt,ls_itemt_dataTYPEzstr1_itemt.

FIELD-SYMBOLS:TYPEzcl_zproj_gr_multideep_mpc=>ts_itemo,TYPEzcl_zproj_gr_multideep_mpc=>ts_itemt.* Transform data into the internal structure

io_data_provider->read_entry_data(IMPORTINGes_data=lr_deep_entity).**********Collect the header fields herels_general_data-id=lr_deep_entity-id.ls_general_data-name1=lr_deep_entity-name.ls_general_data-name2=lr_deep_entity-name2.

********Collect itemO fieldsLOOP ATlr_deep_entity-headitemoASSIGNING.CLEARls_itemo_data.ls_itemo_data-id=-ido.ls_itemo_data-name=-nameo.APPENDls_itemo_dataTOlt_itemo_data.ENDLOOP.

*******Collect itemT fieldsLOOP ATlr_deep_entity-headitemtASSIGNING.CLEARls_itemt_data.ls_itemt_data-id=-idt.ls_itemt_data-name=-namet.APPENDls_itemt_dataTOlt_itemt_data.ENDLOOP.********Call RFCCALL FUNCTION'ZDEEP_RFC'EXPORTINGls_header=ls_general_dataTABLESlt_itemo=lt_itemo_datalt_itemt=lt_itemt_data.

er_deep_entity-id=ls_general_data-id.er_deep_entity-name=ls_general_data-name1.ENDMETHOD.

Now we have to Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

Code Snippet

METHOD/iwbep/if_mgw_appl_srv_runtime~create_deep_entity.

DATAcustome_create_deep_entityTYPEzcl_zproj_gr_multideep_mpc_ext=>ts_deep_entity.

CASEiv_entity_set_name.*-------------------------------------------------------------------------** EntitySet - HeaderSet*-------------------------------------------------------------------------*WHEN'HeaderSet'.* Call the entity set generated method* TRY.

CALL METHODme->custome_create_deep_entityEXPORTINGiv_entity_name=iv_entity_nameiv_entity_set_name=iv_entity_set_nameiv_source_name=iv_source_nameit_key_tab=it_key_tabit_navigation_path=it_navigation_pathio_expand=io_expandio_tech_request_context=io_tech_request_context io_data_provider=io_data_providerIMPORTINGer_deep_entity=custome_create_deep_entity.

copy_data_to_ref(EXPORTINGis_data=custome_create_deep_entityCHANGINGcr_data=er_deep_entity).ENDCASE.ENDMETHOD.

Coding Part done!!!....Let's move to Testing

Testing

Select HTTP method as POST Place the Request URI : /sap/opu/odata/sap/ZPROJ_GR_MULTIDEEP_SRV/HeaderSet Place the External Break point at METHOD CUSTOME_CREATE_DEEP_ENTITY Execute the Service (F8/Execute)

Request Payload

100TestTest Header2

10Test Item11

20Test Item12

10Test Item21

20Test Item22

Before executing methodread_entry_datavalues inlr_deep_entity is initial

After executing methodread_entry_datavalues inlr_deep_entity is not initial

Now RFC Will receive the threestructurevalues

Once come out from the debugger ...record will be created in Backend.

*************************** Your Done !!!**************************

Appreciate your suggestions and comments.


Recommended