cancel
Showing results for 
Search instead for 
Did you mean: 

How to bind several structures in Gateway Service class?

Former Member
0 Kudos

Hi Colleagues,

I know how to bind one structure for a new created data object in Gateway Service class as below, but I don't know how to bind several structures if there are several tables as export parameters in one function module, could you please tell me how to define them?

Kind Regards

Andie

Accepted Solutions (1)

Accepted Solutions (1)

former_member184867
Active Contributor
0 Kudos

You can bind one structure with one entity.

If your are fields coming from multiple structures/tables you might consider a local type or a dictionary object comprising of all the required fields. Then you can bind it to the entity ..

Former Member
0 Kudos

Hi Atanu,

Do you mean it is impossible to bind several structures to one entity? If putting all the required fields into one local type, it would be very complicated and difficult to distinguish.

Kind Regards

Andie

former_member184867
Active Contributor
0 Kudos

Yes, I think you need to create local types or a zstructure to achieve this..

Yes it becomes a bit complicated but it gives more flexibility

Former Member
0 Kudos

okay, I will try to do it. Thanks for your reply.

arunchembra1
Participant
0 Kudos

Hi Andie,

If these structures or table have any relationship like Parent - Child relationship you can go for Deep Entity using Association and Navigation. Otherwise you can follow Atanu's Replay, create one common structure and expose only required fields,

Thanks,

Arun

Former Member
0 Kudos

Hi Atanu,

I define a new structure and write some coding as below in Gateway Service class, if I use the folloiwng hyperlink which the logic includes two search conditions(i.e., I = 230431 and I = 193626), then set breakpoint in the coding below and do debugging, one variant it_filter_select_options in the following coding can only get 'I = 193626'. Do you know how to change something in the hyperlink to make two search conditions included into this variant? I guess it would need to add brackets or something like this, but I don't know where to add them?

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/MonitorActivityList?$filter=sign_objec...

Kind Regards

Andie

SyambabuAllu
Contributor
0 Kudos

Hi Andie,

Can you try below code snippet for above URI.

You have to declare the filter reference variable using MPC(ex : z_cl_mpc) class

Data im_sign_object_id type z_cl_mpc=>sign_object_id.

Data im_option_object_id type z_cl_mpc=> im_option_object_id.

Data im_low_object_id type z_cl_mpc=> im_low_object_id.

                                  

  IF it_filter_select_options IS NOT INITIAL.

* Maps filter table lines to function module parameters
LOOP AT lt_filter_select_options INTO ls_filter.

LOOP AT ls_filter-select_options INTO ls_filter_range.
CASE ls_filter-property.
WHEN 'sign_object_id'.
IF sy-subrc = 0.
im_sign_object_id = ls_filter_range-low.
ENDIF.
WHEN 'option_object_id'.
IF sy-subrc = 0.
im_option_object_id = ls_filter_range-low.
ENDIF.
WHEN 'low_object_id'.
IF sy-subrc = 0.
im_low_object_id = ls_filter_range-low.
ENDIF.
WHEN OTHERS.
" Log message in the application log
me->/iwbep/if_sb_dpc_comm_services~log_message(
EXPORTING
iv_msg_type   = 'E'
iv_msg_id     = '/IWBEP/MC_SB_DPC_ADM'
iv_msg_number = 020
iv_msg_v1     = ls_filter-property ).
" Raise Exception
RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception
EXPORTING
textid = /iwbep/cx_mgw_tech_exception=>internal_error.
ENDCASE.
ENDLOOP.

ENDLOOP.

ENDIF

Thanks,

Syam

Former Member
0 Kudos

Hi Syam,

How to define class z_cl_mpc? Is there any class as reference?

Kind Regards

Andie


SyambabuAllu
Contributor
0 Kudos

Hi Andie,

In your model if there above three fields or not.Otherwise you can create some reference variables using data element for above three fields.

Thanks,

Syam

Former Member
0 Kudos

Hi Syam,

My problem is not related to this class but the variant it_filter_select_options as below in the first statement cannot get two search conditions when using the above hyperlink.

  • IF it_filter_select_options IS NOT INITIAL.

Kind Regards    

Andie

SyambabuAllu
Contributor
0 Kudos

Hi Andie,

Can you paste here the code of method GET_ENTITYSET.

I will check and modify it.

Thanks,

Syam

Former Member
0 Kudos

Hi Syam,

Please see the below.

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

In My Opinion, the way which you would like to send filter parameters according to the shared URL by you is not something GW supports.

You cannot send $filter multiple times.

Kindly perform BATCH operation for QUERY to accomplish this, where you can send multiple operations in a single request to GW.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashywin,

Could you please give me one example of how to use BATCH operation for QUERY?

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Please have a look at the blog described by Arun to accomplish your scenario

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashywin,

For performing BATCH operation for QUERY,  could we use uncertain $filter as search conditions multiple times. 

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Yes. You can send multiple filter parameters in a single request. Kindly have a look at the below blog.

Batch Request in Netweaver Gateway(Multiple Operations into a Single Request)

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashywin,

I notice one statement used in the above web page you mentioned. Could you please explain 'ABCCollection' and do I need to define it in Gateway Service class and where to define it?

  • GET ABCCollection/?$filter= EMP_ID eq '10000030' HTTP/1.1

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

' ABCCollection ' is the EntitySet name which you would have defined/created while creating your GW service in the Service Builder.


Regards,

Ashwin

Former Member
0 Kudos

Hi Ashywin,

I use Firefox to do test, and got error when using the following way to fetch Token. And already redefined two methods below in Gateway Service class.

  • /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_BEGIN
  • /IWBEP/IF_MGW_CORE_SRV_RUNTIME~CHANGESET_END

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

To get the Token the URL which you have to use should be something like this ( any GET Service )

http://<XXXXXX>/sap/opu/odata/sap/<Your_Service_Name>/<Your_Entity_Set_Name>

Once you get the Token, then fire the BATCH with the below URL using $batch by sending the Payload.

http://<XXXXXX>/sap/opu/odata/sap/<Your_Service_Name>/$batch

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

I use the following URL but get Interal Server Error.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/MonitorActivityList

  • Status Code: 500 Internal Server Error

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Could you please share error logs ?

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

Error log cannot be found via t-code /IWFND/ERROR_LOG, only display error message as below on web page.

  • RFC Error: The current application triggered a termination with a short dump.

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Could you please put a break point in DPC and debug ?

Check if RFC is working fine.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

This error has been fixed and I can get Token now, but there is another error message below displayed when doing batch as below.

  • The specified HTTP method is not allowed for the resource identified by the Data Service Request URI
  • Status Code: 405 Method Not Allowed

The BODY is as below:

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id%20eq%20'I'and%20option_object_id%20eq%20'EQ'and%20low_object_id%20eq%20'230431' HTTP/1.1

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/jsonxml

GET MonitorActivityList/?$filter=sign_object_id%20eq%20'I'and%20option_object_id%20eq%20'EQ'and%20low_object_id%20eq%20'193626' HTTP/1.1

--batch--

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

The error is because you are using GET method .

Please change the Method to POST and add $batch at the end of the URL as below.

Kindly be careful with the spaces in the Payload.

Please use the below payload.

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id%20eq%20'I'and%20option_object_id%20eq%20'EQ'and%20low_object_id%20eq%20'230431' HTTP/1.1

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/xml


GET MonitorActivityList/?$filter=sign_object_id%20eq%20'I'and%20option_object_id%20eq%20'EQ'and%20low_object_id%20eq%20'193626' HTTP/1.1

--batch--

Check again by doing all the above.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

No any response and no any error message, see the below. POST is used to Create operation, is it correct?

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Please put break point in DPC and check if call is coming till your DPC.

Just reminding you again be careful with the spaces maintained in the payload which i shared.

Maintain the same spacing.

If you are getting 202 accepted and there is no response the check the Body and the spacing between the operation in side it.

Kindly share the response code and the details so that it will help to locate the problem.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

It cannot jump into breakpoint, I use the following Body and get error messages as below.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id%20eq%20'I'and%20option_object_id%20eq%20'EQ'and%20low_object_id%20eq%20'230431' HTTP/1.1

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id%20eq%20'I'and%20option_object_id%20eq%20'EQ'and%20low_object_id%20eq%20'193626' HTTP/1.1

--batch--

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Error message:

  • Status Code: 400 Bad Request
  • The Data Services Request could not be understood due to malformed syntax

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Could you please share the URL you are sending ?

Please try with the below Body .

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id eq 'I' and option_object_id eq ''EQ' and low_object_id eq '230431' HTTP/1.1

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id eq 'I'and option_object_id eq 'EQ'and low_object_id eq '193626' HTTP/1.1

--batch--

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

I got the same error message.

  • Status Code: 400 Bad Request
  • The Data Services Request could not be understood due to malformed syntax

[ Body ]

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id eq 'I' and option_object_id eq 'EQ' and low_object_id eq '230431' HTTP/1.1

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id eq 'I' and option_object_id eq 'EQ' and low_object_id eq '193626' HTTP/1.1

--batch--

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Can you check each filter operation individually once ? to just make sure URI is correct and its working when fired individually in browser.

Check with the below body again please.

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id eq 'I' and option_object_id eq 'EQ' and low_object_id eq '230431' HTTP/1.1

--batch

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/xml

GET MonitorActivityList/?$filter=sign_object_id eq 'I' and option_object_id eq 'EQ' and low_object_id eq '193626' HTTP/1.1

--batch--

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

I only use one search filter condition in the following body, but still get the same error message.

///////////////////////////////////////////////////////////////////////////////////////////////////

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=low_object_id eq '230431' HTTP/1.1

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/xml

GET MonitorActivityList/?$filter=low_object_id eq '193626' HTTP/1.1

--batch--

///////////////////////////////////////////////////////////////////////////////////////////////////

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Please check the following things in the browser first and make sure below are working.

http://XXXXXX/sap/opu/odata/sap/<Service_Name>/<Entity_Set_Name>?$filter=sign_object_id eq 'I' and option_object_id eq 'EQ' and low_object_id eq '230431'


http://XXXXXX/sap/opu/odata/sap/<Service_Name>/<Entity_Set_Name>?$filter=sign_object_id eq 'I' and option_object_id eq 'EQ' and low_object_id eq '193626'


if the above 2 URL's are not working then try below.


http://XXXXXX/sap/opu/odata/sap/<Service_Name>/<Entity_Set_Name>?$filter=sign_object_id eq '' and option_object_id eq '' and low_object_id eq '230431'


http://XXXXXX/sap/opu/odata/sap/<Service_Name>/<Entity_Set_Name>?$filter=sign_object_id eq '' and option_object_id eq '' and low_object_id eq '193626'


If the above things are working , then please try as shown below first and check if you are getting response.


If you are getting response for the above mentioned body , then please add filter parameters in the body and check again ( filter parameters which you would have tested individually in the browser as mentioned at the starting ).


Please check the above mentioned things and share the details.


Regards,

Ashwin


Former Member
0 Kudos

Hi Ashwin,

There is no problem to open the following URL directly in browser, but I got error message as below.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/MonitorActivityList?$filter=sign_objec...

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Did you pass x-csrf-token while firing?  Can you please test the same in rest client once ?

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

Token cannot be added as shown below, could you please tell me how to pass it while firing?

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

We need not to pass as GW Client itself will handle CSRF Token.

Please follow the below steps.

1. Get the metadata of your service.

2. Click on Use as Request button.

3. Now delete metadata and paste your body in the place of that.

4. Fire the service in the way how you used to trigger by giving correct URL and with Method as POST.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

I got the same error when getting the metadata in SAPGUI, but it works well in Firefox browser.

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Its not always necessary to test in gateway client. You can test in rest client / advanced rest client as well.

Please check things which i said last time in rest client / advanced rest client ( refer to May 7, 2014 8:53 AM reply of mine ).

Please check those and revert.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

There is no problem to open the following URL directly in browser, but fails when put it in the body using batch as I mentioned above.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/MonitorActivityList?$filter=sign_objec...

Kind Regards

Andie

Former Member
0 Kudos

Hi Ashwin,

Now I can get successful status code:202 Accepted using Firefox RESTClient based on the folloiwng body, and can jump into breakpoint set in method GET_ENTITYSET, but variant it_filter_select_options cannot get any values. Do you know how to solve this issue?

//////////////////////////////////////////////////////////////////////////////////////

--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET MonitorActivityList/?$filter= low_object_id eq '117172' HTTP/1.1


--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET MonitorActivityList/?$filter= low_object_id eq '117182' HTTP/1.1

--batch--

//////////////////////////////////////////////////////////////////////////////////////

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Can you please try removing ' / ' in GET MonitorActivityList/?$filter= low_object_id eq '117182' & GET MonitorActivityList/?$filter= low_object_id eq '117172' ?

Just send GET MonitorActivityList?$filter= low_object_id eq '117172'   & GET MonitorActivityList?$filter= low_object_id eq '117182'.

Can you please try this way and check ?

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

Now I set two search conditions and the variant it_filter_select_options can get one entry each time, and jump to breakpoint twice, how can I know how many search conditions in batch job to define loop times?

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Could you please explain the problem which you are facing much more in detail ? Can you share the URL and the body as well ?

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

The URL and body is as below.

------------------------------[ URL ]-------------------------------------------------- 

https://pgdmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS
https://pgdmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/$batch

------------------------------[ Body ]--------------------------------------------------
--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET MonitorActivityList?$filter=activity_id%20eq%20'117172' HTTP/1.1


--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET MonitorActivityList?$filter=activity_id%20eq%20'117182' HTTP/1.1

--batch--
-----------------------------------------------------------------------------

In the Gateway Service class, I use the following coding and set breakpoint there, program can jump to there twice and the variant it_filter_select_options can get one entry each time. How can I know how many search conditions in batch job to define loop times? 

................................

WHEN 'MonitorActivityList'.

       lt_filter_select_options = it_filter_select_options.

................................

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Andie,

Thanks for sharing information.

In your case call is going twice to your Data Provider Class ( 1st call will be filling your lt_filter_select_options with activity_id property & value ' 117172 ' . 2nd call will be filling your lt_filter_select_options with activity_id property & value ' 117182 '  ).

This is the expected behavior. This is how BATCH works Andie.

Here you need not to know how many search conditions in batch job to define loop times as GW itself will handle delegating calls based on the number of operation you are performing in your single request. I mean to say, here in your body , you have 2 operation with different filter values in a single request. So GW knows that it has to call your BE logic 2 times.


All you need to do is just loop through the lt_filter_select_options table and extract the property and its corresponding value and pass it to your logic which is performing search.

With this you would be able to perform Query operation in BATCH mode and get the response in the order with which you would have specified in the body of the BATCH.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

I know the logic you said, but I have to collect all the search conditions before invoking one funtion module of doing search within GW class, so how can I know which time I need to invoke this function module in the coding? The function module for doing search can be invoked each time.

Kind Regards

Andie

AshwinDutt
Active Contributor
0 Kudos

Hello Anide,

You want to collect all the filter parameters and call FM only once rather than calling FM each and every time right ?! This i have not done Andie. I too need to think about this .

Regards,

Ashwin

Answers (0)