cancel
Showing results for 
Search instead for 
Did you mean: 

Success/Error/Info Message in return of Odata Service response from ECC

Former Member
0 Kudos

Hi All,

I am working on Odata services and want to return messages to front end application which is designed in HTML5, which provide status of update/delete or create operation. I want to return error type and description to front end.

I am using  class - /iwbep/if_message_container to return message and tried with following methods:

      lo_message_container = mo_context->get_message_container( ).

       ls_return-type = 'S'.

       ls_return-id   = 'ZTEST'.

       ls_return-number = '000'.

*      ls_return-log_no = '111'.

       ls_return-message = 'Data Available in Update Method'.

       APPEND ls_return TO lt_return.

***

       lo_message_container->add_messages_from_bapi(

         it_bapi_messages         = lt_return

         iv_determine_leading_msg = /iwbep/if_message_container=>gcs_leading_msg_search_option-first


Its not showing up in response of request to front end and response body is empty . if i raise exceptions /IWBEP/CX_MGW_BUSI_EXCEPTION or /IWBEP/CX_MGW_TECH_EXCEPTION response will come with error code - 404.


Please suggest any better way to send response to front end.


Regards,

Rajesh

raibin_raphy
Explorer

Hi Rajesh,

How are you? I was looking for sending custom success message. I able to send custom error message.

I wonder whether your issue is really solved. Please share the solution

Appreciate your help.

Raibin

Accepted Solutions (1)

Accepted Solutions (1)

RalfHandl
Product and Topic Expert
Product and Topic Expert

Hi Rajesh,

Gateway SP08 now has a standard mechanism for placing S, I, W messages in an SAP header SAP-Message: Map Message Container to Message Protocol Format - SAP NetWeaver Gateway - SAP Library.

To add a message to the header you get hold of the message container and add a message specifying that you want to add it to the response header:

lo_container = me->mo_context->get_message_container( ).

lo_container->add_message(

...

iv_add_to_response_header = abap_true

).

Regards

--Ralf

kammaje_cis
Active Contributor
0 Kudos

Hi Ralf,

Any idea when will this come to 740 stack?

Thanks

Krishna

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Krishna,

Gateway SP08 is contained in NW 7.40 SP06.

Hope this helps!

--Ralf

Former Member
0 Kudos

I need to get that working as well and tried the following code in the redefinition of a "get entity set" method:

DATA lo_container TYPE REF TO /iwbep/if_message_container.

****  " add to message container object

lo_container = me->mo_context->get_message_container( ).

CALL METHOD lo_container->add_message_text_only

   EXPORTING

     iv_msg_type               = /IWBEP/IF_MESSAGE_CONTAINER=>GCS_MESSAGE_TYPE-success

     iv_msg_text               = 'Success of ready entity set !'

     iv_error_category         = /IWBEP/IF_MESSAGE_CONTAINER=>GCS_ERROR_CATEGORY-PROCESSING

     iv_is_leading_message     = ABAP_TRUE

     iv_add_to_response_header = ABAP_TRUE

     .


this is not providing the message in the HTTP header as I expect from your description here. Perhaps you have a hint for me, thanks!


<?xml version="1.0" encoding="utf-8" ?>

- <HTTP_HEADER>
- <_-IWFND_-SUTIL_PROPERTY>
<NAME>~response_line</NAME>
<VALUE>HTTP/1.0 200 OK</VALUE>
</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>
<NAME>~server_protocol</NAME>
<VALUE>HTTP/1.0</VALUE>
</_-IWFND_-SUTIL_PROPERTY>
- <_-IWFND_-SUTIL_PROPERTY>
<NAME>~status_code</NAME>
<VALUE>200</VALUE>
</_-IWFND_-SUTIL_PROPERTY>
- <_-IWFND_-SUTIL_PROPERTY>
<NAME>~status_reason</NAME>
<VALUE>OK</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>
<NAME>set-cookie</NAME>
<VALUE>SAP_SESSIONID_P1D_100=xQ8y9gI_1LTf72WxxCSiYEtq0z2txRHjpVUAUFaAQpY%3d; path=/</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>
<NAME>content-type</NAME>
<VALUE>application/atom+xml;type=feed; charset=utf-8</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>

<NAME>content-length</NAME>
<VALUE>1909771</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>
<NAME>dataserviceversion</NAME>
<VALUE>2.0</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>

<NAME>sap-metadata-last-modified</NAME>
<VALUE>Mon, 10 Mar 2014 14:11:41 GMT</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>
<NAME>server</NAME>
<VALUE>SAP NetWeaver Application Server / ABAP 731</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

- <_-IWFND_-SUTIL_PROPERTY>
<NAME>RequestID</NAME>
<VALUE>0050568042961EE3ABB8A96D54728555</VALUE>

</_-IWFND_-SUTIL_PROPERTY>

</HTTP_HEADER>

former_member184867
Active Contributor
0 Kudos

Try the following code

data:  ls_header               TYPE ihttpnvp. 

ls_header-name = 'my-custom-message'

ls_header-value = '{msg_typ:S, desc: my custom message}'

/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

Message was edited by: Atanu Mallik

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Jörg,

I just tried your code snippet in a test system running NW 7.02 with GW SP08 and it worked for me. I see that your code ran on NW 7.31; it should also work on NW 7.31 with GW SP08.

Thanks!
--Ralf

Former Member
0 Kudos

Hi Ralf,

I got it working as well now on our NW 7.31 with GW SP08 with a NEW created oData service and model from scratch.

I was not able to get it working with my already existing/generated oData service by just adding the code snipped in a redefined and regenerated existing method...

Perhaps you have a hint for me what also could bring this to work to adapt existing methods.

thanks

Jörg

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Jörg,

That's odd. I pasted your code snippet into a playground service that I created way back on 2011-07-06, and it just worked.

Please open a CSS ticket.

Thanks!

--Ralf

Former Member
0 Kudos

Hello Atanu, i am using this code and i encounter problem with charasters coding. For example "ü" is showed in ui5 app as #

Additionally i see that "ü" is displyed ok when it is passed in normal xml/json response.

Any idea how to solve it ?

Former Member
0 Kudos

Hi Ralf,

I am trying to show the message on header in case of info or warning, so we dont need to raise exception and we continue to return the updated records back while post method is successful but return warning or info messages..

I am using method - add_message, As you suggested. I am appending messages using lo_container->add_message but nothing showing up in header. Do I need to raise any exception ?

I have declared variable - go_message_container is declared as type /IWBEP/IF_MESSAGE_CONTAINER

     go_message_container = mo_context->get_message_container( ).


      go_message_container->add_message(

         EXPORTING

           iv_msg_type               = 'W' "ls_msg-msgty

           iv_msg_id                 = ls_msg-arbgb

           iv_msg_number             = lv_num          " '001'

           iv_msg_text               = lv_text

           iv_msg_v1                 = ls_msg-msgv1

           iv_msg_v2                 = ls_msg-msgv2

           iv_msg_v3                 = ls_msg-msgv3

           iv_msg_v4                 = ls_msg-msgv4

           iv_add_to_response_header = abap_true          " Flag is set to show msgs on header

           ).

If I try to raise exception it is returning error in response body.. How msgs will show up in header.. I may have multiple msg to show.. Please assist..

Thanks

Rajesh

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rajesh,

the only difference between your code and mine that I can spot is that I provide the parameter

          iv_is_leading_message     = abap_true

Which Gateway SP are you using?

Thanks!

--Ralf

Former Member
0 Kudos

Thanks Ralf for responding

I tried my adding the iv_is_leading_message to method - ADD_MESSAGE but no response on header.

I am not sure if we need to raise the exception after adding messages to container. If I do - It give error in response body with only one message with request status 400.

***

I am raising exception as follow:

RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception

     EXPORTING

       message_container = io_message_container.

I have checked in class - /IWBEP/IF_MESSAGE_CONTAINER apart from method -

ADD_MESSAGE, Other message - ADD_MESSAGES_FROM_BAPI is also having IV_ADD_TO_RESPONSE_HEADER to show msg on header.


As I get from documents IV_ADD_TO_RESPONSE_HEADER is to show message on header,but not getting enough info to use it.

Even If I am not raising exception warnings are not coming op on header.

On our NW having SAP_GWFND/740/SP-004. 

Thanks & Regards,

Rajesh

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rajesh,

You don't have to raise an exception, but probably you have to upgrade to GW SP08.

Thanks!

--Ralf

Former Member
0 Kudos

Thanks Ralf for quick response,

I am debugging to find more about where I am losing the data.. else I will go for upgrade. One more question- can we return multiple messages to request header using method ADD_MESSAGE or ADD_MESSAGES_FROM_BAPI as both have IV_ADD_TO_RESPONSE_HEADER parameter?

Thanks

Rajesh

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rajesh,

you can have one leading message and an arbitrary number of detail messages. The detail messages will be in the "details" array:

sap-message: {"code":"BL/305","message":"Flight permission has not yet been granted","severity":"info","target":"FlightDate","details":[{"code":"BL/301","message":"Maximum weight exceeded","target":"","severity":"info"}]}


Regards!

--Ralf

raibin_raphy
Explorer
0 Kudos

Hi Ralf,

I tried the solution you gave and my code looks like below.

lo_message_container = me->mo_context->get_message_container( ).

lo_message_container->add_message(
EXPORTING
iv_msg_id = 'BL'
iv_msg_number = '001'
iv_msg_type = 'S'
iv_msg_text = 'STO successfully modified'
iv_is_leading_message = abap_true
iv_add_to_response_header = abap_true
).

I can see in debug that it is going through this code. But in my Fiori application, the custom message is not coming, but only standard message shows.

I try to send the message from /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_PROCESS.

We are using test system and learning Fiori. So, please let me know whether we can really send a custom success message from this method. Also not sure any configuration in Gateway system or backend ECC system we need to do.

The version of ECC is Netweaver 7.02 SP 20 (ECC 6 Ehp5 SP 17).

Really appreciate your help

thanks

Raibin

Answers (10)

Answers (10)

raibin_raphy
Explorer
0 Kudos

Hi All,
I am doing Update functionality and know how to send error message all discuss in this. But if I use /IWBEP/CX_MGW_BUSI_EXCEPTION to send success message from OData (as explained above), my Fiori application is thinking that as error message only.

So, can someone tell me how to send a custom success message.

All helps are really appreciated. thank you

pooja_g
Explorer
0 Kudos

Hi Rajesh,

Im facing same problem as to how do i pass success, info and warning messages to UI without raising it as an exception.

If i raise it as an exception , it goes to the error call and success function call is never triggered.

Please let me know in case you have found the solution.

Thanks in advance

Regards,

Pooja

Former Member
0 Kudos

hi all,

    I tried all what you guys described about this issue,but it didn't work, ,my version is NW 7.4 SP13, I'm not sure if any of you is using it, I really need to export message to front end with UI5, the problem is that i need to export message in method  entityname_get_entity & *_update_entity and so on,  and in this kind of method ,we have no related  field for message in this entity to export,please tell to how to export message in the method I said at above....thank you.

raibin_raphy
Explorer
0 Kudos

I also tried whatever whoever said. No error and I can see the program get executed in debug. But the Fiori front-end only shows the standard message. No issue to show custom error message. But I need to show custom success message as well.

So please let me know if you able to find a way. Appreciate your response

thanks

Raibin

0 Kudos

Hi all,

I would like to know if anyone knows how to "catch" this messages from an OData SDK. In case you may, I'll let the link to my discussion.

Handle NetWeaver Gateway message table ON Android SDK

Thanks in advance.

Best regards,

--

Ana Velásquez

Former Member
0 Kudos

I think guys you do a hibrid teori "u" was "u" and ui5 was abp,dont mix that, i can soupouse what you do and let me tell you something gone a have seriusly trouble.. And not whit me!! Dont reply

Former Member
0 Kudos

Hello All,

Lets talk about scenario when ui5 app want to call FM and of course wants to know about return status/message of FM.

Programmer wants to return this message to UI5 app.

How to do it in accordance with the best practices of odata ?

I did it with /iwbep/if_message_container and return status 400 but this solution is really far from ideal i guess.

Lucas

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Lucas,

If the call failed (no data retrieved), then HTTP 400 is the appropriate response, and the error messages are added to the message container which is attached to the exception that is thrown.

If the call succeeded in principle (data retrieved) but with some warnings, then HTTP 200 is the appropriate response, and the error messages should be added to the message container with parameter

  iv_add_to_response_header = ABAP_TRUE

In this case no exception is thrown, and Gateway will place the messages in the response header SAP-MESSAGE.

--Ralf

AshwinDutt
Active Contributor
0 Kudos

Hello Lukasz,

2 ways u can implement error handling based on ur use case ->

1. Implement Create_Entity and when create operation fails raise exception as i mentioned above by returning all the error messages and u get status 400 as response.


2. U can have one more entity in the GW model and create association and navigation with the parent entity with appropriate cardinality.

In DPC/DPC_EXT class capture all the error messages coming from the logic and store in an internal table in Create_Deep_Entity method and map back this as response. Here Response would be a deep structure.

U will get 201 status always irrespective of success/failure as we are not raising any exception here. Instead we are just capturing the error/success messages as part of response.

In the UI level, object containing error response has to be checked always based on Message Type ( E or S or W or A ) and corresponding message can be displayed.

U can decide which one u want to implement.

Regards,

Ashwin

Former Member
0 Kudos

Hello Ralf,

Thanks for answer.  In my case i want to return messages after create, status is 201.

As i understand you, i have to code like this:

lo_container->add_message(

exporting

iv_msg_type ='S'

iv_msg_text = 'XYZ'

..

  iv_add_to_response_header = ABAP_TRUE

).

Nothing else after this ? Do i have to export lo_container some how or framework will do it?

I did it like this and i cant see message in response header.

Am i doing it ok ?

Lucas

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Lucasz,

For me it works if I retrieve the message container via

lo_container = me->mo_context->get_message_container( ).

lo_container->add_message(

           iv_msg_type          = 'S'

           iv_msg_id            = 'BL'

           iv_msg_number        = 308

           iv_msg_v1            = 'Success'

           iv_is_leading_message     = abap_true

           iv_add_to_response_header = abap_true    

).

Then the message shows up in the response header.

Hope this helps!

--Ralf

Former Member
0 Kudos

Hi there, is there any possibility to tell the message container what http status code he should pass back? i only can raise exceptions with status codes but obviously i can't pass back 2xx status codes. Any suggestions?

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Mathias,

OData specifies which 2xx status code is to be used in which situation, so this is automatically handled by the framework:

  • 200 OK in most cases
  • 201 Created for successful CreateEntity requests
  • 202 Accepted for batch requests in OData 2.0 and for asynchronously processed requests in OData 4.0
  • 204 No Content for successful data modification requests

Which other 2xx status codes would you have liked to used, and for which purposes?

Thanks in advance!

--Ralf

Former Member
0 Kudos

Thanks Ralf,

unfortunatly it is a customer requirement, for different create actions he would like to have different 2xx codes. But if it is handled only by the framework i will adress it in the next meeting.

Thanks a lot

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Mathias,

I'm curious to learn about the scenario. There are only two standard 2xx codes not used by OData, see RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1):

  • 203 Non-Authoritative Information, and
  • 205 Reset Content

So far I hadn't considered those relevant in the OData context.

Thanks!
--Ralf

Former Member
0 Kudos

Hmm, i think it is a silly request. We have an entity which can have a parameter with two possible values. internaly to different actions will take place. Ths might sound not very odata like, but at the end i think from a design point of view it was ok. By now Backend was sending back success messages, but now the fronted should take care of it(don't ask me why...) but only in case of success(again don't ask why..) so to differentiate the two paramters the frontend guys would like to have two 2xx codes to distinguish between the two actions.. fubar....

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

If the client sending the request decides which action to take and puts this as a parameter in the request, then it already knows which action it has requested. No need to rely on the server response.

Also with a normal 201 response the client gets back an entity representation, so even if the server chose a different action, the action code is part of the response, assuming it is a property of the request entity.

Former Member
0 Kudos

Damn, you are right! haven't thought about that thanks you made my day

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

My pleasure!

Former Member
0 Kudos

Thanks for possible option suggested.. I will try to implement both and see which one work good with process..

Former Member
0 Kudos

Hi,

You need to add a parameter in the same entity for which you are using in Create operation and change the value after the successful creation and you can return the same entity to the front end.

Thanks,

Raju Bonagiri

former_member184867
Active Contributor
0 Kudos

Hello Rajesh,

Here is a snippet for you


DATA lo_message_container TYPE REF TO /iwbep/if_message_container.

" get message container object

lo_message_container->add_message

exporting

iv_msg_type = <>  "Refer to GCS_MESSAGE_TYPE

iv_msg_text = <>.

lo_message_container = me->/iwbep/if_mgw_core_srv_runtime~mo_context->get_message_container( ).

RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception

      EXPORTING

          message_container = io_message_container.

There are many other useful methods, you can have a look at the below link

SAP Library - SAP NetWeaver Gateway

Regards,

Atanu

Former Member
0 Kudos

Thanks Atanu,

by raising exception its returning error code 400.. I am looking for option were i can pass 'S' or 'I' messages.. without raising exception.

Regards,

Rajesh

former_member184867
Active Contributor
0 Kudos

Hi Rajesh,

You are right, the exception will return error code.

In HTTP world for success you need to depend on the status code, so if status code is 200,201,204 you can consider it to be successful for READ,CREATE,UPDATE/DELETE. However you can pass some more  informative text in such cases along with the HTTP response header.

Here is a snippet for you to achieve the same


data:  ls_header               TYPE ihttpnvp.

ls_header-name = 'my-custom-message' .

ls_header-value = '{msg_typ:S, desc: my custom message}'.

/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).


In RESPONSE header you will get

Regards,

Atanu

Former Member
0 Kudos

Hi Atanu,

We are trying to show msg as you told on header level.. But I am finding if we raise exception header msg didnt show up. Only in case if we dont raise exception, it will show at header custom tag...

Also can you advice best use of showing msg at header level... only exception are way to show error..

Thanks..

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rajesh,

When you raise an exception you can add the detail error/info/success messages directly to the exception, and they will show up in the normal OData error response body:

  lo_container = /iwbep/if_mgw_conv_srv_runtime~get_message_container( ).

  lo_container->add_message(

    ...

  ).


  raise exception type /iwbep/cx_mgw_busi_exception

    exporting

      textid            = /iwbep/cx_mgw_busi_exception=>business_error

      message_container = lo_container.

The header should only be used in success cases, and please use the mechanism I described below, available with Gateway SP08.

Hope this helps!
--Ralf

Former Member
0 Kudos

Hello Ralf,

Is it possible to add 2 messages ?

i am trying like this, but its not works .

any idea how to add 2 messages ?

lo_container->add_message(

exporting

iv_msg_type ='I'

iv_msg_text = 'XXXXXXXXXXXXXXXXXXXX'

iv_msg_id = '1'

**iv_msg_id = '1'

iv_msg_number = '0'

).

lo_container->add_message(

exporting

iv_msg_type ='S'

iv_msg_text = 'YYYYYYYYYYYYYYYYYY'

iv_msg_id = '2'

**iv_msg_id = '1'

iv_msg_number = '0'

).

AshwinDutt
Active Contributor
0 Kudos

Hello Lukasz,

U can use the below code to raise an exception with table of messages.

Where LT_RETURN_MSG is a table containing all ur messages.

data: ls_return_msg TYPE BAPIRET2.

data: lt_return_msg TYPE BAPIRET2_T


data: lo_message TYPE REF TO /IWBEP/IF_MESSAGE_CONTAINER.

data: lx_bus_ex TYPE REF TO /IWBEP/CX_MGW_BUSI_EXCEPTION.

  LO_MESSAGE = MO_CONTEXT->GET_MESSAGE_CONTAINER( ).

  LO_MESSAGE->ADD_MESSAGES_FROM_BAPI( IT_BAPI_MESSAGES = LT_RETURN_MSG ).

  create OBJECT lx_bus_ex

  exporting

    message_container = LO_MESSAGE.

    raise EXCEPTION lx_bus_ex.

Regards,

Ashwin

Former Member
0 Kudos

Hello,

Do you know if this sap-message is supported in the offline odata SDK as well? If so where and how can i access it?

Thanks,

Yohan