Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

dynamically generating colums

Former Member
0 Likes
462

Hi Experts,

i have one requirement.

just i will explain u with an example.

i have ekko header in selection screen .

i want to retrive ekko items for the selected ekko header and display the item data horizontally along with the header.

so the columns shud be generated dynamically.

now i want to fill itab with that values and generate extra colums for that .

so if anybody worked on such scenerio pls reply me with the solution as soon as possible.

Thanks & Regards,

Kranthi

3 REPLIES 3
Read only

Former Member
0 Likes
436

Hi Kranthi,

It is possible by the use of field symbols.

You can create dynamic columns of an internal table.

Cheers,

Nishant

Read only

0 Likes
436

Hi,

You can do this.

You create ALV Display with header Line display hyperlink on the document no.

On click on hyperlink you can at user command you receive the current row details using that thing you can display data into another alv over current one.

Try this it will work.

Rgds

Ravi Lanjewar

Read only

0 Likes
436

You can try for example something like this, to dynamically generate a table/structure:


DATA: struct_type TYPE REF TO cl_abap_structdescr,
      table_type TYPE REF TO cl_abap_tabledescr.
DATA: table TYPE REF TO data.
DATA: compontents TYPE COMPONENT_TABLE.
FIELD-SYMBOLS: <comp> LIKE LINE OF components.
FIELD-SYMBOLS: <table> TYPE ANY TABLE, <structure> TYPE ANY, <field> TYPE ANY.

* Create table/structure
INSERT INITIAL LINE INTO TABLE components ASSIGNING <comp>.
<comp>-name = 'field'.
<comp>-type = cl_abap_typedescr=>describe_by_name( 'CHAR50' ).

struct_type = cl_abap_structdescr=>create( components ).
table_type = cl_abap_tabledescr=>create(struct_type).

CREATE DATA table TYPE HANDLE table_type.

ASSIGN table->* TO <table>

* Fill table
INSERT INITIAL LINE INTO TABLE <table> ASSIGNING <structure>.

ASSIGN COMPONENT 'field' OF STRUCTURE <structure> TO <field>.

<field> = 'value'.

* Access table
LOOP AT <table> ASSIGNING <structure>.
  WRITE: 'Line:', sy-tabix.

  LOOP AT components ASSIGNING <comp>.
    ASSIGN COMPONENT <comp>-name OF STRUCTURE <structure> TO <field>.
    WRITE: / <comp>-name, ':', <field>.
  ENDLOOP.

  WRITE /.
ENDLOOP.

What you need to know is the components of your structure, before creating the data type. But you could use this table to store your data for display in the ALV.

You can also get the components of an existing structure and add your fields to that:


struct_type ?= cl_abap_typedescr=>describe_by_name( 'EKKO' ).
components = struct_type->get_components( ).

Edited by: Carsten Grafflage on Jun 2, 2010 1:16 PM