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

Determine ITAB column dynamically

VenuAnumayam
Participant
0 Likes
511

Hello Experts,

I have an internal table like this:

types: begin of ty_mat,
            matnr type manr,
            descr type maktx,
            col_1 type mhdlg,
            col_2 type mddlg,
            col_3 type mhdlg,
            col_4 type mhdlg,
            col_5 type mhdlg,
          end of ty_mat.

data: t_mat type standard table of ty_mat,
      wa_mat like line of t_mat.

data: l_col(6) type c,
      l_var type mhdlg.

T_MAT has values like this:

MATNR DESCR COL_1 COL_2 COL_3 COL_4 COL_5
1235  ABADFC 0     0     0      0      0

For eg, During runtime, L_VAR value is determined as 5000 and L_COL value as COL_5 .

Now I have to update the internal table T_MAT like this:

MATNR DESCR COL_1 COL_2 COL_3 COL_4 COL_5
1235  ABADFC 0     0     0      0    5000

The value of L_VAR and L_COL changes dynamically all the times. Should I use the field-symbols? Can you please suggest how to code for that?

Thanks a lot.

Edited by: ravi kumar on Dec 21, 2009 2:27 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
481

Yes, you would use field-symbols

I supposse you are using wa_mat as the work area for t_mat and you know exactly which index you are going to modify

In that case it would be something like this


assign component L_COL of structure wa_mat to <fs>.
<fs> = l_var.
modify t_mat from wa_mat index whatver.

But can you be more specific? I´m pretty sure what you are trying to achieve would be easier if you assign a field-symbols to the line in t_mat you want to modify instead of using a work area

3 REPLIES 3
Read only

Former Member
0 Likes
482

Yes, you would use field-symbols

I supposse you are using wa_mat as the work area for t_mat and you know exactly which index you are going to modify

In that case it would be something like this


assign component L_COL of structure wa_mat to <fs>.
<fs> = l_var.
modify t_mat from wa_mat index whatver.

But can you be more specific? I´m pretty sure what you are trying to achieve would be easier if you assign a field-symbols to the line in t_mat you want to modify instead of using a work area

Read only

0 Likes
481

Thanks a lot. I knew the code until

assign component L_COL of structure wa_mat to <fs>

Didn't know how to pass the value after that.

Read only

Former Member
0 Likes
481

Yes, use field symbols.

Assuming your work area is populated with the correct line, following code should help.


field-symbols: <fs_field> type any.

assign component (L_COL) of wa_mat to <fs_field>

<fs_field> = l_var.

Now wa_mat-col_5 should have the value of 5000. I haven't tested the above code - so test it before relying on it.