Context

Purpose of this document: it describes a way to create a simple Web DynPro application that contains an ALV grid with dynamic columns (and thus also dynamic data). This explanation is based on a simple example coming from the HR world.

Business example

The web application will show all the competences/qualifications of the team members of a manager. As columns, we’ll have a list of persons; and as rows, the competences required to work in the manager’s team. Depending on the manager, the number of team members will change, so the number of columns is dynamic (that is: computed by the application during runtime).

/wp-content/uploads/2015/01/image1_630722.jpg

Part 1: get data

The main component controller will contain, as it should, the business logic to get the data. The basic data will then be shared between elements of the component via the context: the node “GLOBAL_DATA” will be used for this purpose. We will find a copy/mirror version of this node (and all its data) in the main view for example.  Context mapping will be used to share/expose the “GLOBAL_DATA” context node.

/wp-content/uploads/2015/01/image2_630723.jpg

  • (a)  Read SAP data
  • (b)  Bind data to the context of the component
  • (c)  Share part of the component controller context to subcomponent contexts (context mapping)

Part 2: create dynamic structure

  So the idea is to create during the runtime, this kind of structure:

/wp-content/uploads/2015/01/image3_630725.jpg

How to do that? Via the RTTI (Run-time type information) objects provided by the abap stack! Especially the classes CL_ABAP_DATADESCR and CL_ABAP_STRUCTDESCR will be used. The dynamic structure will be firstly represented /materialized via the object of type CL_ABAP_STRUCTDESCR.

/wp-content/uploads/2015/01/image4_630726.jpg


Part 3: create dynamic context (based on dynamic structure)

To create a new context node based on a structure, the procedure is quite simple: the RTTI class holding the structure definition will be passed to a dedicated method of the context node information object.

/wp-content/uploads/2015/01/image5_630727.jpg

Remark: the dynamic context node will be create on context of the view

Part 4: append data to the context

To add data to the context, we will do it the usual way: create an internal table with the same structure as the context node that will hold the data.

To create the internal table, we need also to do it dynamically using …

  1. RTTI classes to create a compatible table type and an “instance/variable” of it
  2. “CREATE DATA” statement to create data row based on  a dynamic structure
  3. Add that data row object to the internal table

STEP 01:

/wp-content/uploads/2015/01/image6_630734.png

STEP 02:

/wp-content/uploads/2015/01/image7_630735.png

STEP 03:  APPEND <FS_ROW> TO <FS_TABLE>



Finally : bind internal table to the context.

/wp-content/uploads/2015/01/image8_630736.png

/wp-content/uploads/2015/01/image9_630740.jpg


Part 5: ALV life cycle

Once the data ready on the context, the binding to the (ALV) grid is quite usual… so, in the method “wddomodifyview” of the view containing the ALV view:

/wp-content/uploads/2015/01/image10_630741.jpg

That’s all folks! All the plumbing stuff has been explained… it’s your turn to write this kind of application!

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply