Tuesday 17 November 2015

Container in BO and parameter passing in BO methods


In earlier 2 posts we have seen about the creation of business object and it’s component and how to trigger a workflow through a BO event. In this post we will see the concept of container in BO and how to pass the parameters in BO methods and events.


If we see closely the function module 'SWO_INVOKE' and 'SWE_EVENT_CREATE' we can see the table parameter named ‘CONTAINER’ and ‘EVENT_CONTAINER’ respectively used in the FMs. These parameters are of structure ‘SWCONT’. These parameters are responsible for the exchange of data from and to the function module and in turn using those parameters we can pass the data in methods and events of BO. If you see the structure ‘SWCONT’ it looks something like below.


So before calling the function module we will make an internal table of type SWCONT and will fill the required data and then pass on the table to FM.

Now another important point here is to fill the data in container table. There are standard FM and macros also which will help us in this. So below is the list of macros which will be used for this purpose. Also we have to include <CNTN01> in our program in order to use these macros. 

SWC_SET_ELEMENT  : Used for setting the normal parameter into container
SWC_GET_ELEMENT : Used for getting the normal parameter from container
SWC_SET_TABLE        : Used for setting the multi-line parameter into container
SWC_GET_TABLE       : Used for getting the multi-line parameter from container

So now we will look into a demo program. We will take the example of BO we have created in creation of business object and it’s component post. So there we have created one BO named ZDEMO and it has one method named “test_report” which has parameters like below.


So we can see 3 parameters are of import type ad one is of export type. Means we will be sending 3 parameters to the method and method will return 1 parameter.
So after using function module named 'SWO_CREATE' for creating instance of BO, we will be doing coding like below to fill the container.


Also because method is returning one parameter we have to do modification in BO program also. We will set the parameter ‘CreatedBy’ there in container using SWC_SET_ELEMENT. Then we can fetch the value of ‘CreatedBy’ parameter from container in our report using SWC_GET_ELEMENT.

 
In example I am just setting some random string value to the parameters. In real life cases, we have to do coding in order to get the right value to pass to the method and inside method we have to do calculation to get the right parameter to return back to report.

Now we will be putting break point at 2-3 places and will check the value of container to check if it is taking parameters value perfectly and if control is going inside method or not. Below is some screen shots of debugging.










We can clearly that value which method has returned back to report through container, have been fetched and stored in variable lv_CreateBy.

Same way we can fill the container and pass on to the events of the BO.

Happy Learning :)