Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Applies to:

   SAP CRM 6.0/7.0                        

   CRM Web UI              

   Model View Controller

Summary

                          You may sometimes need to find out the attributes of an internal table during runtime, that were not statically available. In this kind of situation, if you want to build an internal table, we can use ABAP RTTS ( Runtime Type Service) concept. Alternativly we can also create dynamic internal table by passing ALV field catalog to the class method -- cl_alv_table_create=>create_dynamic_table.   In this wiki I will describe the steps of creating dynamic  tableView using CRM Web UI MVC framework.

Author(s):  

   
Created on            :    03/03/3010
Author(s) Bio       :    Ranganatha Prasad Kurupati
                        I'm currently working as a CRM Consultant in Win IC, Web IC , Sales, Service and  Marketing areas. I have over 10 years of experience across SAP modules and specialized in SAP SRM, CRM, cProjects, Travel and Expense mgmt and Workflow. Previously worked on SAP projects across industry verticals -- Pharma, Hi-tech, Accounting, Agri-business and Oil&Gas).

Table of Contents

Introduction

               Before you start reading my blog, I would recommend you to read/practice a very nice blog written by Melanie Lauber-- How to display a z-table in an assignment block , which explains about displaying a custom table on WebUI. I don't want to duplicate all the steps here, but I want to describe the steps which are different from that blog. I will try to provide sample code where it is necessary. 

                 I'm assuming reader is expert in using Field Symbols, Dynmic internal tables, BSP, MVC, Web UI and writing custom Iterator class for tableView THTMLB tag..

Development steps


1. Database table design

Opportunity

Sales rep

Product

Commission%

100001

Rep1

P1

50

100001

Rep2

P1

50

100001

Rep2

P2

100

2. Create Internal Table during run-time

                 Create dynamic internal table from Sales reps and products in Opportunity. Create internal table during run-time with Sales reps as rows and Products as columns.Then Populate commission data from DB or allow user to enter it from UI. When user adds Sales reps or products, The UI screen need to be updated.

Internal table structure:

Sales rep

P1

P2

P..

Pn

Rep1

50

 

 

 

Rep2

50

100

 

 


 Sample code

DATA: gt_dyna_table TYPE REF TO DATA.
CALL METHOD cl_alv_table_create=>create_dynamic_table

3. Create View and Context node

            Follow the steps described in  How to display a z-table in an assignment block, But skip the Add Value Attributes to Context Node  step in Wizard.This step normally generates code in GET_TABLE_LINE_SAMPLE   method of Context node class.  

            In dynamic table scenario, we don't know the list of fields until run-time. So we have to manually implement GET_TABLE_LINE_SAMPLE  method which is detailed in Step-4. 

4. Implement GET_TABLE_LINE_SAMPLE method in the Table Node

            Create Table line sample from dynamic table.

 Sample code  

 METHOD GET_TABLE_LINE_SAMPLE

         FIELD-SYMBOLS:  <lt_dyna_table> TYPE TABLE.
        ASSIGN gt_dyna_table->* TO  <lt_dyna_table>.          " From the internal  table created in step-2
        CREATE DATA rv_sample LIKE LINE OF < lt_dyna_table >.
END METHOD.

5. Fill Table node from Dynamic table data

            Implement ON_NEW_FOCUS . Read the data from dynamic table and fill the Table context Node collection. This step is explained in detail in the blog I referred before.

Sample code

DATA: <ls_table_line> TYPE ANY,
LOOP AT gt_dyna_table assigning <ls_table_line> .        " loop thru the internal table from Step-2
    "...create line object
    create data lr_tabline.
    "...create value object with current line for colleciton
    create object lr_valuenode
      exporting
        iv_data_ref = lr_tabline.
    "...set current line data
    lr_valuenode->set_properties(<ls_table_line> ).
    "...add current line to collection
    lr_col->add( lr_valuenode ).
ENDLOOP.
 
me->set_collection( lr_col ).

6. Display the Data using model Binding

           Display the data using Model binding, so the context node gets updated from tableView with out any additional coding. We can not use CHTML tableView tag because the fields are not known during design time.

 Sample code  
<thtmlb:tableView   
  ............
  ............  
  ............
          table       = "//(Table context node)/table"
</thtmlb:tableView>

7. Make the tableView data Editable

          To make the tableView Editable , Implement View Iterator class by inheriting IF_HTMLB_TABLEVIEW_ITERATOR. Implement following methods as per your requirement.

 Sample code  
  IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS
  IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_ROW_START
  IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START
  CONSTRUCTOR

          Instantiate the View Iterator from controller method DO_VIEW_INIT_ON_ACTIVATION  by exporting Table context node.

 Sample code
 
 CREATE OBJECT gr_view_iterator
     EXPORTING
      ir_context_node = me->typed_context->(Table context node)       

          Include iterator in tableView tag in BSP.

   Sample code
<thtmlb:tableView  
          ............
          ............ 
          ............
        iterator = "<%= controller->gr_view_iterator %>"
        table   = "//(Table context node)/table"
</thtmlb:tableView>
 

8. Read data from Table node and Save to DB

         Implement the event handler method to read and Save the data.

Sample code
DATA: lr_bol_bo_col TYPE REF TO if_bol_bo_col,
(Table context node)->collection_wrapper>get_copy( RECEIVING rv_result = lr_bol_bo_col ).

Related Content

TableView Iterator

How to display a z-table in an assignment block

How to: Create a Context node of Dynamic table type.

3 Comments

  1. Guest

    Hi Ranganatha Prasad Kurupati,

    Sorry to disturb you. But i want your help.I am a fresher just passed out my B.Tech in 2010 and got job in sap crm as a fresher. My requirement is to do the same which u have discribe above. I mean i have to make result view of lead search editable so that the user can change 'status' and 'qualifation' form there itself. I have done upto status and qualification field as editable, but all the fields as in editable mode only, it is not checking perticullarly when user select any row. By default it is all in edit mode. Not return any code in CONSTRUCTOR and  DO_VIEW_INIT_ON_ACTIVATION method of IMPL class. If your can send coding how you have done, then it will be very helpful for me. This is my kind request with you. Please send ASAP.Specially i want CONSTRUCTOR code and how to save when user make a changes

    Thank You

    Regards,

    Nizamuddin

    +91-9989052354

  2. Hi Nizamuddin,

    I think you should not create a custom function to get this functionality. I don't know for the Leads, but in Activities and Opportunities when you have a search result list, there is a standard functionality to mark the objects that you want to change and then do an update on i.e. Status or Phase.

    Best regards
    Gregor

  3. Guest

    Hi Gregor Wolf,

              Thanks for your quick replay, The functionality which your telling is there as a buttons when we click on button pop-up will rise from there user can select select. But in my scenario the selection option is should from dropdown list of that field. That means it should be in editable mode. I have successfully made that field in editable mode and added dropdown list box to that fields and when user select new value from that it is rising event handler but new change value is not coming. Without that i can not go further. If you have worked such scenarios please help me.

                                                                                              Thanks you.

    Regards,

    Nizamuddin

    nizamshaik2006@gmail.com

    +91-9989052354