Application Development 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: 

Finding Dynamic no of Fields

Former Member
0 Kudos

Hi All,

I have a attendance Internal Table of Employees. This internal table is in following format.

Emp ID Date Project Hrs

Now an Employee can have any no of records per day and can book into different no of Project by dividing the no of hrs per day.

Now my requirement is i need to display Output in one line item for each employee for the data in attendance Internal table in the following manner.

EmpID Project1 Hrs1 Project2 Hrs2... ProjectN HrsN.

Here i am facing the problem in finding out the maximum no of Projects as it should be dynamic depending on a particular emp assigned to maximum no of projects.

Please do the needful help..If any Clarification in the Post Plese reply.

Thanks

Shashikanth Naram

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Shashikanth,

You can do like this. lets say you have your employee table in this reference lref_emp_tab.

DATA: lref_struct TYPE REF TO cl_abap_structdescr,

lref_emp_tab TYPE REF TO data,

ls_emp_wa TYPE REF TO data,

lv_line TYPE i.

FIELD-SYMBOLS:

<fs_tab> TYPE STANDARD TABLE,

<fs_wa> TYPE ANY.

ASSIGN lref_emp_tab->* TO <fs_tab>.

CREATE DATA ls_emp_wa LIKE LINE OF <fs_tab>.

ASSIGN ls_emp_wa->* TO <fs_wa>.

lref_struct ?= cl_abap_typedescr=>describe_by_data( <fs_wa> ).

DESCRIBE TABLE lref_struct->components LINES lv_line.

Now lv_line has number of coloumns in your internal table.

Regards

Abhijeet

3 REPLIES 3

bpawanchand
Active Contributor
0 Kudos

If i got you right then you want to know the number of columns in a table then , May be the class CL_ABAP_TABLEDESCR might help you to know the number of columns

Former Member
0 Kudos

Hi Shashikanth,

You can do like this. lets say you have your employee table in this reference lref_emp_tab.

DATA: lref_struct TYPE REF TO cl_abap_structdescr,

lref_emp_tab TYPE REF TO data,

ls_emp_wa TYPE REF TO data,

lv_line TYPE i.

FIELD-SYMBOLS:

<fs_tab> TYPE STANDARD TABLE,

<fs_wa> TYPE ANY.

ASSIGN lref_emp_tab->* TO <fs_tab>.

CREATE DATA ls_emp_wa LIKE LINE OF <fs_tab>.

ASSIGN ls_emp_wa->* TO <fs_wa>.

lref_struct ?= cl_abap_typedescr=>describe_by_data( <fs_wa> ).

DESCRIBE TABLE lref_struct->components LINES lv_line.

Now lv_line has number of coloumns in your internal table.

Regards

Abhijeet

Former Member
0 Kudos

you can use field symbols as explained above, or another way around can be:

define the max possible projects(if you know) columns.. and fill the data as them come.

and while creating field catalog(if using alv display) dont pass the fields which are not filled.