cancel
Showing results for 
Search instead for 
Did you mean: 

How to Read contact in ODATA Gateway Services

Former Member
0 Kudos

Hello Experts,

Please help it out me how to create odata gateway services for read contact person in SAP CRM and how to give multiple parameter with value range?

Expecting Soon reply urgently needed.

Thank's .

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hello Ashwin,

without child entity when i pass multiple parameters i got output, but when i add child entity facing problem? is there any chance to get ?

Former Member
0 Kudos

Hello Ashwin,

Yes, I am getting parent details & child Details from single FM.

Importing Parameters

Exporting Parameter

i got output from FM.

when i doing OData services i am unable do please help me.

how can i get child entity data in odata services?

please provide me some sample code also.

thanks & regards'

Tiru

AshwinDutt
Active Contributor
0 Kudos

Hello Tiru,

Does IT_SELECT_OPTIONS and IT_VALUE _PAIR holds multiple values when u send it as input?

Your use case has multiple table of inputs and multiple table of outputs. On top its a GET operation. I do not see any best way to implement this use case as of now.

If u had only input variables( not tables of inputs ) and multiple output tables, then we could have implemented Expand_Entity or Expand_EntitySet. But your use case is not fitting here also.

Have a look at the below :

If u can somehow mange to send IT_SELECT_OPTIONS & IT_VALUE _PAIR input values not as table of inputs to ur GW then u can implement the above way.

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

sorry for late reply,

Yas, i got finished thanks for  your support.

Requirement is to export FirstName, LastName, Accountname along with result structure. but those fields are not there in that result structure. but these fields there in child structure

can u please observe bellow screen shot

please help me how to achieve i wrote the code in bol programming

result



if i click on any entity it will disply like this

for this i need to achieve above two screen shots using bol programming and gateway services also

AshwinDutt
Active Contributor
0 Kudos

Hello,

Are u getting all your parent details & child details from a single FM ?

Can u share the FM input and output screen shot ?

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

thanks for ur reply, i did filtering for one parameter but i am unable to do same for multiple. i am new to bol programming. if u don't mind please provide me code for multiple. what should i take import parameter for multiple?

AshwinDutt
Active Contributor
0 Kudos

Hello Tirupati,

Could you please share few sample of inputs with range values for those parameters which u have shared in the previous mail? I want to know how u would exactly send inputs to ur RFC. It would be great if u can share ur use case with some sample of inputs with range values so that i can provide my comments.

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

Thanks for your reply i want to give import parameters like bellow i mentioned in screen shots..

For my RFC, if i give importing like this i want to get Result - OData.

Please guide me or else provide me code.

AshwinDutt
Active Contributor
0 Kudos

Hello Tirupati,

U need not to really code here.

If u have an RFC ready which can search as per your requirement based on different parameters just follow as below :

1. Import ur RFC.

2. select wat all fields u need in input & GW output response.

3. implement Get_Entity_Set method.

4. Provide mappings.

5. Generate Run-time Objects.

6. Register ur service in GW hub.

7. consume it in GW Client or Browser.

To do the above , Please follow the below which has got all the necessary steps :

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

I am getting trouble in Creating RFC itself how I can achieve this.Using BOL programming i achieved by passing single parameter but i want to pass multiple parameters and i want data in my function like mentioned in screen shots.

Please suggest me its urgent.

Thank's In Advance.

AshwinDutt
Active Contributor
0 Kudos

Hello Tirupati,

As per the screen shots u have shared, there can be parameters which can even repeat multiple times with a same operator. Handling these kind of use case if not possible via filters as GW wont support to send filters like that. So only i would suggest you to send your query string in search key word and send to GW.

In GW use that and pass to RFC so that u can straight away use that as ur query in RFC and return the response.

Pass all the filters parameters as a SEARCH string as below :

From UI build the query string and pass as below.

Sample ->

/sap/opu/odata/sap/xxxxxx/get_dataSet?search=QueryTable ge 'MARC' and QueryTable le 'MARC' and Fieldname le 'MATNR'

U get parameters sent in iv_search_string in GW. Use this in your logic appropriately so that u can  accommodate all possible combinations of operators with input parameters.


U can have ur RFC which can take a query string which u have got from GW and return data based on that.


Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

Yeah i am passing AccountId, ContactId, FirstName, Lastname or city1 as part of range values to RFC. for that i had created one structure for these parameters.

even i don't know how to do for multiple parameters. i am facing problem with filtering. i had done one import parameter i got output for these i will share what i did.

source code

DATA : lr_core      TYPE REF TO cl_crm_bol_core,

          lr_col       TYPE REF TO if_bol_bo_col,

          lr_dquery    TYPE REF TO cl_crm_bol_dquery_service,

          lr_entity    TYPE REF TO cl_crm_bol_entity,

          ls_contact   TYPE crmst_contact_person_obj_buil,

          lv_partner  TYPE string.


   lr_core = cl_crm_bol_core=>get_instance( ).

   lr_core->start_up('BP_APPL').

   IF iv_partner IS NOT INITIAL.

     lr_dquery  = cl_crm_bol_dquery_service=>get_instance('BuilContactAdvancedSearch').

     lr_dquery->add_selection_param( iv_attr_name = 'BP_NUMBER' iv_sign = 'I' iv_option = 'EQ' iv_low = iv_partner ).

     lr_col = lr_dquery->get_query_result( ).

     CHECK lr_col IS BOUND.

     lr_entity ?= lr_col->get_first( ).

     WHILE lr_entity IS BOUND.

       lr_entity->get_properties( IMPORTING es_attributes = ls_contact ).

       APPEND ls_contact TO et_contact.

*      MOVE-CORRESPONDING ls_contact TO ls_entity.

*      APPEND ls_entity TO et_entityset.

       CLEAR : ls_contact.

       lr_entity ?= lr_col->get_next( ).

     ENDWHILE.

   ELSE.

     lr_dquery  = cl_crm_bol_dquery_service=>get_instance('BuilContactAdvancedSearch').

     lr_dquery->set_property( iv_attr_name = 'MAX_HITS' iv_value = '30').

     lr_col = lr_dquery->get_query_result( ).

     CHECK lr_dquery IS BOUND.

     lr_entity ?= lr_col->get_first( ).

     WHILE lr_entity IS BOUND.

       lr_entity->get_properties( IMPORTING es_attributes = ls_contact ).

       APPEND ls_contact TO et_contact.

*      MOVE-CORRESPONDING ls_contact TO ls_entity.

*      APPEND ls_entity TO et_entityset.

       CLEAR : ls_contact.

       lr_entity ?= lr_col->get_next( ).

     ENDWHILE.

   ENDIF.

AshwinDutt
Active Contributor
0 Kudos

Hello Tirupati,

Ok as per the info u have shared, i understand that user from the UI has got all the flexibility to perform search on AccountId, ContactId, FirstName, Lastname or city1 parameters with different combination of operators. So u would like to have range value for each of those inputs.

So the Operators would be :

EQ Equals

LE Less than or equal to

GE Greater than or equal to

NE Not equal to

GT Greater than

LT Less than

But i do not know which what might be the combination of operators which u will be sending for a particular parameter/parameters as part of filters. But few operator combinations are not supported by GW which we need to be aware of.

In my previous reply, i have shared the operators supported by GW which u can pass as part of filters via URL.

The below are the things supported by GW where u can send some inputs as part of filters so that GW itself will convert into a range values so that u can straight away access those and use it in our logic.

Example 1: Supported

/sap/opu/odata/sap/xxxxxxxxx/get_dataSet?$filter=QueryParam1 ge 'abcd' and QueryParam1 le 'uvwx'

when u pass this GW itself will fill your IT_FILTER_SELECT_OPTIONS as follows with appropriate operator.

Example 2: Not Supported

/sap/opu/odata/sap/xxxxxxxxx/get_dataSet?$filter=QueryParam1 ge 'abcd' and QueryParam1 le 'uvwx' and QueryParam2 ge 'abcd' and QueryParam2 le 'uvwx'

Its not accepted by GW. U cannot send 2 different parameters as above.

Example 3 : Supported

/sap/opu/odata/sap/xxxxxxxxx/get_dataSet?$filter=QueryParam1 ge 'abcd' and QueryParam1 le 'uvwx' and QueryParam3 le '123'

U can use filters with different operators but note not all combination will work. That is the reason which i have given few example URL's for ur reference.

So like this u can send appropriate operators for different parameters as part of filters.

This way u can fit in some of the filter parameters with different operators.

One more way u can also try ->

If at all u have scenarios like i have shown in Example 2, GW will not accept.

To over come this,

for now i can think of a way where u can send all your filter parameters with any combination of operators as part of search key word.

Pass all the filters parameters as a SEARCH string as below :

From UI build the query string and pass as below.

Sample ->

/sap/opu/odata/sap/xxxxxx/get_dataSet?search=QueryTable ge 'MARC' and QueryTable le 'MARC' and Fieldname le 'MATNR'

U get parameters sent in iv_search_string. Use this in your logic appropriately so that u can  accommodate all possible combinations of operators with input parameters.

I am suggesting this way considering the below aspects -

1. ur scenario is involving different filter parameters and also different range values for each of those.

    Not all combination is possible via URL ( like Example 2 ).

2. BATCH is also not a suitable solution here.

So i am suggesting the above way.

Regards,

Ashwin

AshwinDutt
Active Contributor
0 Kudos

Hello,

To perform a READ operation u need to implement Get_Entity method.

READ operation needs KEY's to be passed.

Response can have a single entry as part of response or null.

To perform a QUERY operation u need to implement Get_Entity_Set method.

QUERY operation needs FILTER's to be passed.

Response can have either single/multiple entries or null as part of response.

Please follow the below to get detail info :

U can also use SEGW GW Service Builder to build your GW services.

To pass a RANGE Table as input , u need to operate on BATCH.

As we cannot pass a table of inputs to GW for QUERY/READ operations, so we need to use BATCH.

Please have a look at the below :

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

Thanks for your great reply, its very useful. I got the url but, i want to generate result through RFC and wants to pass value ranges to key parmaetres.

How can i, please brief me.

Appreciate your fast reply..

Thanks in Advance.

AshwinDutt
Active Contributor
0 Kudos

Hello Tirupati,

Since u would like to pass range values to those key parameters, there would be single/multiple or null entries as part of GW response based on your input value. Considering that the method which is to be implemented is Get_Entity_Set/QUERY operation.

1. Implement Get_Entity_Set / QUERY operation and map the fields accordingly in Service Builder and generate run-time objects.

2. In DPC_EXT class , Redefine below methods and just write ' EXIT ' and activate.

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END

3. As per my knowledge the below are the operators supported by GW through URL.

EQ Equals

LE Less than or equal to

GE Greater than or equal to

NE Not equal to

GT Greater than

LT Less than


Other operators like CP etc... has to be handled explicitly in GW level in DPC_EXT class in respective methods by checking whether the input value contains ' * ' .

If the input contains ' * ' then u need to pass CP operator explicitly in the code level.


4. U need to Create a PAYLOAD to BATCH all the different operations in a single request :


Headers to be passed :


Content-Type :  multipart/mixed; boundary=batch

x-csrf-token : < pass the value >


Method :


POST


Sample URL :


http://<Host with the Port Num>/sap/opu/odata/sap/<Your Service Name>/$batch


Sample Payload -> example when u have two operations in 1 single request.


If Get_Entity / READ is implemented then below is the PAYLOAD :


--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

GET get_data11(ImWhttype='C2',ImCountry='TH') HTTP/1.1

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

GET get_data11(ImWhttype='C1',ImCountry='TH') HTTP/1.1

--batch--

If Get_Entity_Set / QUERY is implemented then below is the PAYLOAD :

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

GET get_rec_types1?$format=json HTTP/1.1

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

GET get_order_details HTTP/1.1

--batch--

With this u must be able to implement what u r expecting.

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

     Thank's for reply, I want to do with RFC for multiple importing parameter(like AccountId, ContactId, FirstName, Lastname or city1) . I am getting with single parameter but unable to achieve with multiple parameter.

Its really helpful to me if I get guidance.

AshwinDutt
Active Contributor
0 Kudos

Hello Tirupati,

Could you please share some background info like how u will be sending importing parameters like AccountId, ContactId, FirstName, Lastname or city1 to your RFC ?

Are you passing AccountId, ContactId, FirstName, Lastname or city1 as part of range values to RFC ?

Could you please share the screen shot of RFC input and output structures so that i can suggest approach ?

Regards,

Ashwin