Thursday 5 June 2014

Dynamic creation of component usage


Background: While working on one or other Webdynpro component, we all have come across the implementation of ALV. Interactive ALV is the type of ALV where after giving the input, user is first shown the primary list of ALV. A secondary list will be displayed on the click by user in one of the records of primary ALV. This secondary list will have more elaborated data of the selected record. 

For implementation of ALV in  ABAP Webdynpro, we have to create the component usage of one standard Webdynpro component named SALV_WD_TABLE. Further we have to do the external mapping of DATA node of SALV_WD_TABLE to our context node which is going to have the final value for display in ALV. We also have to embed the TABLE view of SALV_WD_TABLE into our ViewContainerUIElement of the respective view of our custom component, where we want to display the ALV. 

While working on one such ALV requirement, I came across one scenario where I need to implement the interactive ALV. As per the requirement both the ALVs must be displayed on the same screen (View).  

The usual approach to achieve this is to create as many separated usage of SALV_WD_TABLE as the number of ALVs you want to implement. In my case I could have to create 2 usages. The other approach is to implement the component usage dynamically. This approach can particularly be proved helpful when at design time you are not sure how many of component usage you need to create. 

So the component usage which we create at design time is called the static component usage, while the one created through program s called the dynamically created component usage 

Instead of following the static approach all the way, I created one component usage statically while other one I created through program (dynamic creation of component usage). 

Pre-requisite: Must have worked on normal Webdynpro application. Knowledge on static creation of component usage in own custom Webdynpro component.
Creation of Static Component Usage:
1. Create one Webdynpro component with main view and a window.
2. Now go to the webdynpro component -> Used component tab and create a static component usage of SALV_WD_TABLE.
3. Now go to component controller and create a new controller usage.
4. Now in context tab of component controller create 3 new node named sales_doc,    
    sales_header_data, sales_item_data with the below mentioned attribute and properties.


5. Go to Component Usage sub tree which is coming in left side panel and there click on INTERFACECONTROLLER_USAGE. There do the external binding of Sales_header_data context node to the DATA context node of SALV_WD_TABLE.
6. Now got to the window and there by right clicking on the ViewContainerUIElement Header_alv click on Embed_view and there choose the table view of SALV_WD_TABLE.
7. Now in layout tab of main view create appropriate UI element as shown in below screen shot. 
In the Input element we will be giving the VBELN as input and on clicking of button Show primary ALV will be displayed on ViewContainerUIElemenrt HEADER_ALV. 
On the onAction property of button ‘Show’ we have created an action named SHOW and a corresponding method names ONACTIONSHOW has been created automatically.
8. Go to the context tab of the view main and drag and drop the context node of component controller to the view’s context.
9. In attribute tab add one attribute as follows.
10. Now go to the method ONACTIONSHOW and write the below logic for fetching the data to be displayed.



11. By doing this till here your primary screen will be coming happily on clicking of ‘Show’ button. Create a webdynpro application and test it. It will look like below



Creation of Dynamic Component Usage:
12. Now if we want to click on one row of ALV and want the secondary list to be displayed we have to use the Hotspot technique of ALV. Hotspot technique is about creating one column in ALV as hotspot. By clicking on that column’s value ONCLICK event of ALV will be triggered and further defined code will trigger.
13. In order to define the hotspot in our ALV, we need to do further coding in ONACTIONSHOW method itself. Below is the screen shot of code which is pretty self explanatory

14. Now in Method list create a new event handler method and in even column pick ON_CLICK event of the interface controller of the component usage ALV_USAGE.
15. This method will automatically have one importing reference parameter named R_PARAM. This variable’s Value field will have the value of the clicked column of ALV list.
16. In this method we will first write the logic for fetching the data for secondary list for clicked value of primary list.

17. Below is the screen shot of the code which is meant for creating the component usage dynamically. For that we have first created a component usage group and then created a component usage. The code in screen shot is self explanatory. I have put a lot of comment there to make everything clear. And yes…put this code in ACTIONCLICK method itself.







18. Now test your application again. This time click on the Sales Doc. column’s value of primary list to get the secondary list. The result is like below.

                                                                                                              By: Reetika Patel

Wednesday 4 June 2014

Creation of new document object links in CV02N



In the SAP system, a large number of object links are provided to documents such as materials, equipment, and production resources/tools. You can find the complete list of SAP objects in Customizing for Document Management, under Control Data ® Maintain Screen for Object Link. In this activity you can also enter your own object links.  

The Business Add-In (BAdI) is defined so that you can integrate your own objects in transactions for document management (CV01N, CV02N, CV03N, CV04N) without modification.
1. One need to do some configuration changes in SPRO T-code. Location where changes needs to be done will be as per the below screen shot.


Here changes will be done in “Maintain screen for object link”. (Consult with functional consultant before doing this).

2. For development from technical side, we need to take help of BADI named DOCUMENT_OBJ. A fresh implementation will be created for this BADI using T-code SE19.




When we click on “Create Impl”  button screen comes where we will give the object name which we have already created in SPRO.
Go to tab Subscreens and we can see two rows with 2 fields to be filled.


We have to create 2 custom module pool programs. That module pool programs we need to specify here along with their screen no. This screen will be the same which we want under “Object link” tab in CV02N T-code.

For help we can always refer the other standard implementation of the same BADI given by SAP. To check this we need to go to T-code SE18 and open the BADI in display mode and go to below mentioned path. It will display all the existing implementation of this BADI.


                                                                                                             By: Reetika Patel