Custom BO creation:
A BOL entity is a business object whose structure is same as the structure you want to display in your view. A BOL entity is of type CL_CRM_BOL_ENTITY.
How to create a BOL entity if there does not exist one with the structure you need?
1. First create a DB table in SE11, with all the fields you need in your view.
2. Then create a lock object for this view with the kind of lock you need.
3. Now assign a BO to this table and lock object in the view CRMV_TBLOBJ_OBJ
4. Now in SPRO->CRM->CROSS APP COMP->GENIL COMP->SPECIAL SETTING->DEFINE BO, mention your BO, DB table, Interface details.
This completes creation of a BO.
Creating a table view:
1. Create a table view with the desired context node.
2. Create the buttons in the controller class, and set the CONFIG TABLE details in the .htm page to set the table config.
3. Create buttons CREATE, EDIT, DELETE in the DO_PREPARE_OUTPUT method of the view controller class.
4. Add event handler methods for each of the buttons.
Code details:
You use the component controller(CoCo) of the component to access the context nodes of other views in the component. CoCo basically acts like a global place holder and context nodes assigned to component controller can be accessed from any view's controller class.
How to access a context node of some other view from your custom view?
lr_comp ?= me->comp_controller
lr_comp->typed_context->campaign->collection_wrapper->get_current( ).
5. Create a ON_NEW_FOCUS method which acts as a event handler for NEW_FOCUS event.
This method is used to determine the BOL entities of dependent model nodes as a collection at run time and to assign them to the collection wrapper of the dependent model node. In other words, if the focus of the collection of the leading context node changes, its collection wrapper sends a NEW_FOCUS event to the dependent collection node which updates its context structure accordingly. This event is triggered by the publish_current method of the collection_wrapper of your leading context node.
The ON_NEW_FOCUS method is created in the context node class of your view and set that as an event handler method for the class CL_BSP_WD_COLLECTION_WRAPPER and event NEW_FOCUS.
Go to CTXT class of Order and in the CONNECT_NODES method set the handler to activate
coll_wrapper = campaign->get_collection_wrapper
set HANDLER me->order->on_new_focus for coll_wrapper ACTIVATION iv_activate.
6. For the SAVE action:
You have used the component controller to access other views context node, now for other views to access your context node your context node has to be tied up to the component controller. The save is in the over view page, and to inform the Save button that there is an other view which it has to save and commit, we tie the data/context nodes to the component controller.
In the create_order method of your context class, after the binding call the ON_NEW_FOCUS method so that we can pass the entity or the FOCUS_BO parameter to the ON_NEW_FOCUS method.
In the save action:
get, the current entity and add it to the transaction context and transaction manager saves and commits all the bol collection at a time.
A transaction context is like a buffer where all the bol entities are stored, and after the save action all the bol entities are together saved and committed to the DB.
At the end also call the publish_current method from the collection wrapper class.
7. ON_NEW_FOCUS method: In here you write the query method to get the query result and display your output. In addition to this you can also set conditions to inform the view about when it has to fetch the data.