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

Assignment

Former Member
0 Likes
690

Hi Friends,

I have 10 fields in internal table , like

it_final-tsl01 , it_final-tsl02 ........ it_final-tsl10.

when i give 6 as input , it should add first 6 fields and store in a variable

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
664

Hi chandrasekhar,

1. just copy paste , and it will work as u require

2. we have to use field-symbols.

3.

report abc.

*----


data : begin of it_final occurs 0,

tls01 type i,

tls02 type i,

tls03 type i,

tls04 type i,

tls05 type i,

tls06 type i,

tls07 type i,

tls08 type i,

tls09 type i,

tls10 type i,

end of it_final.

*----


field-symbols : <FS>.

data : varname(15) type c.

data : num(2) type n.

data : tot type i.

*----


parameters : howmany type i default 6.

*----


start-of-selection.

*----


it_final-tls01 = 1.

it_final-tls02 = 2.

it_final-tls02 = 3.

append it_final.

loop at it_final.

do howmany times.

num = sy-index.

concatenate 'IT_FINAL-TLS' NUM INTO VARNAME.

assign (varname) to <FS>.

tot = tot + <FS>.

enddo.

write 😕 'Total : ' , tot.

endloop.

*----


regards,

amit m.

6 REPLIES 6
Read only

Former Member
0 Likes
664

You can try doing this.

data : counter(2) type n.

data : varname (15) type c.

counter = '01'

do n times.

counter = counter + 1.

concatenate 'IT_FINAL-TSL' counter into varname.

total = total + (varname)

enddo.

regards,

Ravi

Read only

0 Likes
664

Hi Ravi,

thx for the reply ,i had tried the samething but its short dump at line total = total + (varname), dump says

unable to interrupt IT_FINAL-TSL01 as a number.

Read only

0 Likes
664

If that is giving a short dump,

assign (varname) to <fs_any>

total = total + <fs_any>

Regards,

Ravi

Read only

Former Member
0 Likes
665

Hi chandrasekhar,

1. just copy paste , and it will work as u require

2. we have to use field-symbols.

3.

report abc.

*----


data : begin of it_final occurs 0,

tls01 type i,

tls02 type i,

tls03 type i,

tls04 type i,

tls05 type i,

tls06 type i,

tls07 type i,

tls08 type i,

tls09 type i,

tls10 type i,

end of it_final.

*----


field-symbols : <FS>.

data : varname(15) type c.

data : num(2) type n.

data : tot type i.

*----


parameters : howmany type i default 6.

*----


start-of-selection.

*----


it_final-tls01 = 1.

it_final-tls02 = 2.

it_final-tls02 = 3.

append it_final.

loop at it_final.

do howmany times.

num = sy-index.

concatenate 'IT_FINAL-TLS' NUM INTO VARNAME.

assign (varname) to <FS>.

tot = tot + <FS>.

enddo.

write 😕 'Total : ' , tot.

endloop.

*----


regards,

amit m.

Read only

Former Member
0 Likes
664

Hi Chandrasekhar,

u can do it field symbols.ucan go thru example below..

  • For Dynamic population of fields

loop at tb_final.

clear l_ctr.

loop at tb_fieldcat into x_fieldcat .

l_ctr = l_ctr + 1.

perform pass_dynamic using x_fieldcat- fieldname l_ctr.

endif.

endloop.

append tb_final1.

endloop.

form pass_dynamic using p_field p_ctr.

field-symbols : <f1> type any,

<f2> type any.

data : l_text(100).

clear: l_text.

concatenate 'TB_FINAL1-tsl' p_ctr into l_text.

assign (l_text) to <f1>.

clear l_text.

  • To pass Data of tb_final to tb_final1.

if g_heading <> gc_x.

concatenate 'TB_FINAL-' p_field into l_text.

assign (l_text) to <f2>.

<f1> = <f2>.

endif.

endform.

Regards,

Kiran b

Read only

Former Member
0 Likes
664

Hi,

check the code.

parameter : p_n(2) type i.

data : count(2) type i.

data : varname (15) type c.

do p_n times.

count = count + 1.

concatenate 'IT_FINAL-TSL' count into var.

sum = sum + var

enddo.