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

regarding populating internal table

Former Member
0 Likes
566

i have created an internal table which is like...

data: begin of itab occurs 0,

col01 type string,

col02 type string,

col03 type string,

col04 type string,

col05 type string,

col06 type string,

col07 type string,

col08 type string,

col09 type string,

col10 type string,

col11 type string,

.........................

col31 type string,

end of itab.

.............................................

some code goes here..................

...................................

if fkdat + 7(2) = '01'

itab-col01 = .....

...............................

................................

if fkdat + 7(2) = '02'

itab-col02 = .....

...............................

................................

if fkdat + 7(2) = '03'

itab-col03 = .....

...............................

................................

if fkdat + 7(2) = '04'

itab-col04 = .....

...............................

................................

if fkdat + 7(2) = '05'

itab-col05 = .....

...............................

................................

if fkdat + 7(2) = '06'

itab-col06 = .....

...............................

................................

and so on like this.

can i append the internal table itab dynamically without doing the same thing for 31 times?? is there any way to increase the index of the fields of itab according to the if condition?? i think it might be done using field symbols......but i have confusion about that. i need help regarding this.

5 REPLIES 5
Read only

Former Member
0 Likes
541

Hi,

You can achieve this as follows:-

Please note that my table has 2 columns so I have looped twice.

You can loop as per your columns.

TYPES : BEGIN OF itab,

col01 TYPE c,

col02 TYPE c,

END OF itab.

DATA : itab TYPE STANDARD TABLE OF itab.

FIELD-SYMBOLS : <fs> TYPE char1.

DATA : wa TYPE itab.

DATA: var TYPE string,

cntr(2) TYPE n.

DO 2 TIMES.

cntr = cntr + 1.

CONCATENATE 'wa-col' cntr INTO var.

ASSIGN (var) TO <fs>.

if <fs> is assigned.

<fs> = 'A'.

endif.

ENDDO.

if sy-subrc eq 0.

append wa to itab.

endif.

Read only

0 Likes
541

does (variable) mean the content of the variable?? this is what i was missing in using the field symbol.

Read only

0 Likes
541

Hi,

Yes.

The statements

CONCATENATE 'wa-col' cntr INTO var.

ASSIGN (var) TO <fs>.

will actually point the field-symbol to the variable WA-COL01, WA-COL02 as you change the value of the counter.

The ASSIGN (var) TO <fs> means assign the value which is in var.

Regards,

Ankur Parab

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
541

Hi,

try using do varying

Read only

0 Likes
541

thank you a lot. i hope it will solve my problem. i learnt a new and very useful thing from you. i did not know how to point the content of the variable using pointer. that's why the internal table was not populating.

thanks again.