cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a service with deep insert input but output a single entity?

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

     I have created a service which has 2 entities.

     DeliveryHeader

     DeliveryItems

     StatusOutput

     

     Association has been defined for DeliveryHeader and  DeliveryItems.

    My input request message is:

    {

       "DN_No" : "123",

       "ShipTo" : "CNZ",

        "DeliveryItems" : [{

            

        "DN_No": "123",

        "Item_No": "1",

        "Quantity": "10'

       }]

  }

I want my output to be different entity structure that is of StatusOutput.

{

    "StatusOutput" : {

         "Code": "100",

         "Text" : "Successfully created DN"

}

}

But I am getting output same as input.

What I have to do to get the desired output? Please help!

In my create_deep_entity I have coded like this:

TYPESBEGIN OF t_output.

           TYPES: StatusOutput TYPE ycl_prj_create_dn_mpc_ext=>TS_STATUSOUTPUT,

          END OF t_output.


x_output-StatusOutput-code = "100".

x_output-StatusOutput-text = "Successfully created DN".


    copy_data_to_ref(

       EXPORTING

         is_data = x_output

       CHANGING

         cr_data = er_deep_entity ).

          

Thanks

Gopal

Accepted Solutions (0)

Answers (1)

Answers (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Gopal,

Have you created association to the StatusOutput entity as well ?

You would have already Created association with some cardinality ( 1 to N ) between DeliveryHeader & DeliveryItems entities right !?

Now create association between DeliveryHeader & StatusOutput ( say 1 to N OR 1 to 1 .. based on your requirement ). But here if as per my understanding since u need  only success message and corresponding success message type, u need to create association with 1 to 1 cardinlity between

DeliveryHeader & StatusOutput entities.

Now after successful creation send back the message and its code in the deep structure ( structure which can hold DeliveryHeader , DeliveryItems , StatusOutput details )  which you would be already defined to hold all the DeliveryHeader and DeliveryItems details and StatusOutput details.

This way you can return your message and code as separate entity in the response ( But remember you will be having data in other entities of your DeliveryItems & DeliveryHeader )

This is what you are expecting if i understand your problem well.

If at all you want only that specific entity in the response alone,

As per my knowledge u cant restrict your response like how you are expecting ( only single entity alone with success message ) . Since we are sending back the same input deep structure as part of response you cannot restrict that way.

At the most you can empty your response forcefully excluding your data structure/table having the success message. However this will not make any sense.

Regards,

Ashwin

gopalkrishna_baliga
Participant
0 Kudos

I have not created any association between Header and output. In the output I don't want header and item. I just want the OutputStatus only. As you said this may not be possible.

one way I am thinking is: can I call get entity method for outputStatus entity in my deep insert code? And I will not call copy_data_to_ref.

AshwinDutt
Active Contributor
0 Kudos

Hello Gopal,

You can give it a try Gopal.

I do not know if its a correct way to call that way like how you are thinking.

I have never tried that way.I really doubt if it will work or not.

In my opinion i think you will face problems while returning the response after u call get_entity_set / get_entity in ur create_deep method.

However u can check once.

Regards,

Ashwin