Quantcast
Channel: SCN : Blog List - SAP CRM: Webclient UI - Framework
Viewing all articles
Browse latest Browse all 195

How to: Adding new row / element to context node collection in SAP CRM using ABAP

$
0
0

Sometimes performing even basics tasks in ABAP may confuse, especially if you are a newbie in ABAP.

Today I'm going to show how to add new row (line, element) to context node collection in SAP CRM using ABAP.

At the end of the post you can find the final code example, implementing the discussed task.

Feel free to copy, paste and run this code snippet.

 

Theory. In order to add new element to context node you have to:

1. Define a structure line of the context node element.

2. Create data reference, based on the structure line, defined at the previous step

3. Define the new context node object that will contain the new values, we're going to add to the context node

4. Fill the new context node object with the new values

5. Add new context node object, filled with the data to the context node.

 

Practice. The final code:

 

  1. " define structure line of the context node
  2. TYPES:
  3.         BEGIN OF line_struct_type,
  4.                 personID                TYPE numc5,
  5.                 firstName               TYPE char30,
  6.                 lastName                TYPE char30,
  7.         END OF line_struct_type.
  8. DATA:
  9.         cn_line_struct          TYPE REF TO DATA,
  10.         cn_single_element       TYPEREF TO cl_bsp_wd_value_node.
  11. " create data object, based on defined structure line
  12. CREATE DATA cn_line_struct TYPE line_struct_type.
  13. " create new data container object according to the context node structure line
  14. CREATE OBJECT cn_single_element
  15.         EXPORTING
  16.                 iv_data_ref = cn_line_struct.
  17. " fill the values into new data container object
  18. cn_single_element->set_property_as_string(
  19.         EXPORTING
  20.                 iv_attr_name ='personID'
  21.                 iv_value     ='222'
  22. ).
  23. " push the new data container object to the existed context node collection
  24. comp_controller_ref->typed_context->%context_node%->collection_wrapper->ADD(
  25.         EXPORTING
  26.                 iv_entity = cn_single_element
  27. ).

 

As you can see, even such basic stuff in ABAP SAP CRM may contain some «pitfalls».

 

Thanks.


Viewing all articles
Browse latest Browse all 195

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>