cancel
Showing results for 
Search instead for 
Did you mean: 

Display success message in GW Response

Former Member
0 Kudos

Hi experts,

After a POST operation executes, the GW response shows the payload of get_entity method for the created item, if the creation is successful.

If the creation is unsuccessful, the error caught in the return table of the BOR/RFC is thrown and it comes up in the response.

Is it possible to display the success message from the Return table of BOR/RFC in the GW Response?

If yes, how do we do it? What needs to be done while redefining the create_entity method?

Consider my example, I am creating a sales order. When the creation is successful, the GW response shows the sales order that has been created. What i want is just the message "The Order with Number xxxxxxxxx has been created" (I have added that in my RFC's Return Table).

Thank You in advance,

-Nimish Kate

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor

Hello Nimish,

Yes its possible and can be done.

Before suggesting approach can you please give details of the present set up of your POST Operation ?

Have you implemented Create_Entity and Get_Entity using wizard of SEGW by creating mapping to the RFC's ?

or Just Model is created using SEGW and manually Create_Entity is implemented  in the DPC_EXT class ?

However irrespective of implementation, my thoughts on this is no message has to be built manually like ' The Order with Number xxxxxxxxx has been created ' from back-end and send to the front end application. This message can be built in the front end as well once SO Number is sent to the application from GW. On successful POST and successful READ only then that newly created SO would have been retrieved from backend.

If at all your BAPI or Standard FM is giving such a formulated standard success message and you would like to show the same in front end then its fine.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin,

Thanks for the quick response.

For your first point, Yes GET is getting called which has response only when POST is successful.

For the second point, I have implemented it using the mapping wizard, but i did check inside it, where there are lines of code (which i have now commented)-

*-------------------------------------------------------------------------*

*             - Read After Create -

**-------------------------------------------------------------------------*

*CREATE OBJECT lo_tech_read_request_context.

*

** Create key table for the read operation

*

*         ls_key-name = 'VBELN'.

*         ls_key-value = i_recpt-vbeln.

*         if ls_key is NOT INITIAL.

*         APPEND ls_key TO lt_keys.

*         endif.

*

** Set into request context object the key table and the entity set name

*lo_tech_read_request_context->set_keys( EXPORTING  it_keys = lt_keys ).

*lv_entityset_name = io_tech_request_context->get_entity_set_name( ).

*lo_tech_read_request_context->set_entityset_name( EXPORTING iv_entityset_name = lv_entityset_name ).

*lv_entity_name = io_tech_request_context->get_entity_type_name( ).

*lo_tech_read_request_context->set_entity_type_name( EXPORTING iv_entity_name = lv_entity_name ).

*

**Display message after create

*

*

** Call read after create

*/iwbep/if_mgw_appl_srv_runtime~get_entity(

*  EXPORTING

*    iv_entity_name     = iv_entity_name

*    iv_entity_set_name = iv_entity_set_name

*    iv_source_name     = iv_source_name

*    it_key_tab         = it_key_tab

*    io_tech_request_context = lo_tech_read_request_context

*    it_navigation_path = it_navigation_path

*  IMPORTING

*    er_entity          = ls_entity ).

*

** Send the read response to the caller interface

*  ASSIGN ls_entity->* TO <ls_data>.

*  er_entity = <ls_data>.


I dont know what to replace this code with, in order to get the success message.

OR, like you said, there is some other approach as well.


Thanks,

-Nimish

AshwinDutt
Active Contributor
0 Kudos

Hello Nimish,

Thanks for the information.

Based on the present set up I would suggest the below and check:

Add 2 more additional properties ' Message ' and ' MsgType' to the existing Entity.

Re-generate the run-time artifacts.

Clear the model cache in the GW system - /iwfnd/cache_cleanup

Now coming to DPC_EXT class.

Make sure you have added all the code needed for Create and Read operations inside the DPC_EXT class. Here redefine the appropriate methods and add code ( This step would be basically copy-pasting of the code which is already present in DPC class to DPC_EXT class )

Inside DPC_EXT class, inside Create_Entity Method, Uncomment the Code which you have already commented ( the code which is inserted by the frame work - Read after Create ). Keep this code as it is.

After Read is successful, your <ls_data> will have all the fields and also fields associated with the properties Message and MsgType that you newly added in the first step in the GW model for the Entity.

Before the below line gets executed, for the existing details inside <ls_data>, manually add the formulated text as you already mentioned like

' The Order with Number XXXX XXXX has been created ' to the <ls_data> and also the Message Type as 'S' to <ls_data>.


er_entity = <ls_data>.

Now you final response will have all the details fetched as part of READ after CREATE and along with the Message and MsgType.

In Front end application they can Read the MsgType and if its 'S' then they can show the message and the other details.

Regards,

Ashwin

Former Member
0 Kudos

Hi Ashwin

Thanks a lot for this suggestion.

But there seems to be a slight problem here.

<ls_data> is not defined until runtime so we cannot know for sure what the structure of <ls_data> will be until the previous line is executed.

So it is not possible to go <ls_data>-Message = RETURNTAB-Message.


Also, I've just realized another doubt here.

What if I don't have a valid READ mapping? or if i dont have a READ mapping at all?

Consider i want to post a document for cash receipt. There is no list or detail for the document (lets say the cash receipt screen is a custom screen, hence a custom FM).


Then the POST operation will be executed correctly, but the response will probably say method get_entity not executed in data provider class.


How do we get the success message from the FM in the response here?


Thanks,

-Nimish

AshwinDutt
Active Contributor
0 Kudos

Hello Nimish,


But there seems to be a slight problem here.

<ls_data> is not defined until runtime so we cannot know for sure what the structure of <ls_data> will be until the previous line is executed.

For the above, Yes after assigning statement executed ( ASSIGN ls_entity->* TO <ls_data>. ), only then you will be able to add Message and MsgType.

Once its assigned you can add these and map back to er_entity.


What if I don't have a valid READ mapping? or if i dont have a READ mapping at all?

Consider i want to post a document for cash receipt. There is no list or detail for the document (lets say the cash receipt screen is a custom screen, hence a custom FM).


Then the POST operation will be executed correctly, but the response will probably say method get_entity not executed in data provider class.


How do we get the success message from the FM in the response here?

For the above,

Before we decide to use SEGW Mapping Option, we should always have an RFC ready for Create and another RFC ready to Read the created data. Then only we should go for Mapping for Create and Read operations in SEGW and generate the run-time artifacts.

If only Create FM is there and no Logic to Read, then we always go for Manual coding of the Create_Entity Method inside the DPC_EXT class.

We will Model the Service for Create by just Creating the Entities in SEGW then generate the Run-Time Artifacts. Now use the generated DPC_EXT class to write the code manually inside the Create_Entity Method.


To keep simple, we can just add additional properties Message and MsgType inside the Entity which is already created for Create Operation in SEGW at the time of modelling the service.

Once FM Returns the SO Number indicating Create is successful, then the formulated message can be added to the input structure and then map back the same to er_entity. This will have the Success Message, MsgType and also the other details ( basically the details sent as input for the SO creation ) and same will come as part of GW response.


I believe you would have already done error handling in case of error and raise the exceptions with all the error messages. This handling you can keep as it is.


Regards,

Ashwin

Answers (1)

Answers (1)

former_member184867
Active Contributor
0 Kudos

The simplest option would be to pass the success message through http header without touching the entity.

SAP Gateway provides Message Container APIs to achieve this. Sample Code would look like

DATA: lo_container TYPE REF TO /iwbep/if_message_container.
lo_container
= me->mo_context->get_message_container( ).


lo_container
->add_message( iv_msg_type = 'S'
iv_msg_id
= 'ZZZ
iv_msg_number
= 45
iv_msg_text
= 'SO Created Successfully'
iv_is_leading_message
= abap_false
iv_add_to_response_header
= abap_true
).


Once you do it, you can get sap-message header in the HTTP response. So the payload of SO creation does not change, but you get an additional response header with the success message.

Former Member
0 Kudos

Hi Atanu,

I did try out what you suggested.

Unfortunately, it doesn't work out.

I have to either attach contents of lo_container to er_entity or else response has 2 options to come out-

1. the input payload as output response.

2. a big red message "METHOD GET_ENTITY NOT IMPLEMENTED IN DATA PROVIDER CLASS".


Either way, not what i'm looking for.


Nevertheless, Ashwin helped me achieve what i was looking for.

Thank you for your input though.


Cheers,

-NK