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.
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).
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.
- (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:
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.
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.
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 …
- RTTI classes to create a compatible table type and an “instance/variable” of it
- “CREATE DATA” statement to create data row based on a dynamic structure
- Add that data row object to the internal table
STEP 03: APPEND <FS_ROW> TO <FS_TABLE>
Finally : bind internal table to the context.
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:
That’s all folks! All the plumbing stuff has been explained… it’s your turn to write this kind of application!