cancel
Showing results for 
Search instead for 
Did you mean: 

How to access request object in Model Provider Class?

jzeifang
Participant
0 Kudos

Dear specialists,

as my previous post is located in the wrong area (),

I repost my question here:

I want to define the data model of my OData service dynamically depending on an URI paramter of my HTTP request. But so far I did not find any possibility to access the request object in the model provider class.

Does anybody has a hint for me?

Many thanks in advance.

Best regards,

Juergen

Accepted Solutions (1)

Accepted Solutions (1)

former_member388328
Active Contributor
0 Kudos

Hi Juergen,

I did not understand your question clearly. What i understood is , you want access a data model based on your Http request. If this is right , then without enhancing any code we can achieve this , option 1 is you can achieve by creating multiple odata service ,  create you models based on requirements. Option 2 create a Model  and create multiple entity sets based on single model in same odata service, use different multiple entity sets in your URI  . 

This is not your requirement , please give details about your business requirement , we can discuss further.

Thanking you

Vengaiah

jzeifang
Participant
0 Kudos

Hi Vengaiah,

correct, I want to create the model depending on the http request. But this shall be very generic, since there might be new parameter values very often. To create a new model or a new entity set every time I have new requirements is not an option for us.

So the idea is to create one model with one entity set which contains just the key fields (these are always the same). In a customizing table I define the DDIC structure per URI paramater which contains the fields of the model.

Based on the URI parameter value I will read the name of the DDIC structure and create the model dynamically. But to receive this I need to get access to the request in the DEFINE method of the model provider class.

I hope my requirements are a little bit clearer now 😉

Thank you!

Best regards,

Juergen

former_member388328
Active Contributor
0 Kudos

Hi Juergen,

I hope I understood your requirement.

1) create a odata service with your ddic structure . redefine the define method in *MPC_EXT Class with  and include the below statement

lo_entity_type->ADD_AUTO_EXPAND_INCLUDE( iv_include_name   = '<yourAbap Structure name>'

                                 iv_bind_conversions = 'X' ).


     Now this will give a new model as soon as you change the ddic structure.


2) Go class /IWBEP/CL_MGW_LOCAL_HANDLER, in the class goto method  GET_ENTITY_SET ( provided if are doing get request in your HTTP).

In Line 26 , you can see a  BADI mo_mgw_runtime->/iwbep/if_mgw_core_srv_runtime~read_entityset.


  Before this line put a enhancement spot and use the function modules to DDIF_TABL_PUT and   DDIF_TABL_ACTIVATE to update your ddic structure as per your requirement .


First put a breakpoint in the class /IWBEP/CL_MGW_LOCAL_HANDLER in method GET_ENTITY_SET and see that URI is giving all the required parameters for appending the ddic structure. Then go ahead with enhancement.


Thanking you

Vengaiah

jzeifang
Participant
0 Kudos

Hi Vengaiah,

thank you very much. This was exactly the hint I needed, now I manage to create the data model dynamically based on the URI parameter.

Best regards,

Jürgen

Answers (1)

Answers (1)

jzeifang
Participant
0 Kudos

Hi Vengaiah,


now I have a new problem. Whenever the model cache is cleared the model needs to be re-created (which sounds quite logical )


In this case before calling method GET_ENTITY_SET of class /IWBEP/CL_MGW_LOCAL_HANDLER the method GET_META_DATA of the same class is called. And from this method the method DEFINE of my *MPC_EXT class is called to create the new model.


The problem is, that in the method GET_META_DATA I do not see any information regarding the URI. This means that at this point in time I do not have any information on how to update my ddic structure.


I hope you understand what I mean.


Do you have any idea how to resolve this.


Thanks!


Best regards,

Jürgen


former_member388328
Active Contributor
0 Kudos

Hi Jurgen,

Yes, i have seen you are not getting the URI in method GET_META_DATA.

Thanking you

Vengaiah

former_member388328
Active Contributor
0 Kudos

Hi Jurgen,

Can you please check the structure IS_REQUEST_CONTEXT in GET_META_DATA  method.   will this be of any help for you.

Thanking you

Vengaiah

jzeifang
Participant
0 Kudos

Hi Vengaiah,

thank you for your help.

Finally I found a way to get the information I need:

In the gateway system I enhanced method CREATE_REQUEST_CONTEXT of class /IWFND/CL_MGW_REQUEST_MANAGER. In this enhancement I added the information to  ES_REQUEST_CONTEXT-PARAMETERS. And the I can read it in the backend system in methods mentioned above.

Best regards,

Jürgen