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: 

assigning

Former Member
0 Kudos
161

Hi!

Suppose itab2 contains lots of values lets say about 20.

How can I assign its values to itab3' s all components.

Hopefully, somebody can give helpful idea.

Regards

itab3-one= itab2-firstvalue

itab3-two= itab2-secondvalue

itab3-three= itab2-thirdvalue

itab3-four= itab2-fourthvalue

append itab3

TYPES: begin of typ1, 
       one(10) type c, 
       two(10) type c, 
       three(10) type c, 
       four(10) type c, 
       end of typ1. 
        
TYPES: begin of typ2, 
       first(10) type c, 
       end of typ2. 


data itab type ALSMEX_TABLINE occurs 0 with header line. 
data itab2 type typ2 occurs 0 with header line . 
data itab3 type typ1 occurs 0 with header line .


LOOP AT ..
...
ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
128

Hi,

Sorry for the syntax error..This is one of possibility..You can also write four read statements to do that..Instead of DO..ASSIGN COMPONENT..ENDDO...Then you can insert after 4 reads.

DATA: V_INDEX TYPE SYINDEX.

DATA: V_MOD TYPE SYINDEX.

V_INDEX = 1.

DO.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-ONE = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-SECOND = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-THIRD = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-FOURTH = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

APPEND ITAB3.

ENDDO.

Thanks,

Naren

12 REPLIES 12

Former Member
0 Kudos
128

Hi,

Use the LOOP AT..

LOOP AT ITAB2.

  • MOVE THE VALUES FOR EACH COLUMN.

ITAB3-ONE = ITAB2-FIRST.

ITAB3-..

APPEND ITAB3.

ENDLOOP.

Thanks,

Naren

0 Kudos
128

Hello Naren,

I think thats wrong. Please note within the LOOP iteration

you will assign always the same values for all itab3' s

components.

According to your suugestion it looks as follows:

LOOP AT ITAB2.

  • MOVE THE VALUES FOR EACH COLUMN.

ITAB3-ONE = ITAB2-FIRST.

ITAB3-TWO = ITAB2-FIRST.

ITAB3-THREE = ITAB2-FIRST.

ITAB3-FOUR = ITAB2-FIRST.

APPEND ITAB3.

ENDLOOP.

Former Member
0 Kudos
128

Ignore my answer.

Message was edited by:

Venkat Muthyala

Former Member
0 Kudos
128

Hi Ilhan,

This should be the best and simple way of doing this, according to me.

<code>

append lines of itab2 to itab3.

</endcode>

Remember to reward points, if you are satisifed with this answer.

Rgds,

Prashanth.

SAP.

0 Kudos
128

hi Prashanth,

can you please write a snippet to demonstrate it concretely ?

regards

Ilhan

Former Member
0 Kudos
128

Hi,

Since ITAB2 is declared with a header line..

And I am looping at ITAB2..For each iteration the header line will be populated..

<b>So according to this logic..ITAB3 will have the values of ITAB2..And not the same values...</b>

LOOP AT <b>ITAB2</b>.

  • MOVE THE VALUES FOR EACH COLUMN.

ITAB3-ONE = ITAB2-FIRST.

ITAB3-TWO = ITAB2-FIRST.

ITAB3-THREE = ITAB2-FIRST.

ITAB3-FOUR = ITAB2-FIRST.

APPEND ITAB3.

ENDLOOP.

Thanks,

Naren

0 Kudos
128

Dear Narendran,

TYPES: begin of typ1,

one(10) type c,

two(10) type c,

three(10) type c,

four(10) type c,

end of typ1.

TYPES: begin of typ2,

first(10) type c,

end of typ2.

data itab2 type typ2 occurs 0 with header line .

data itab3 type typ1 occurs 0 with header line .

itab2-first = '2'.

itab2-first = '5'.

itab2-first = '6'.

itab2-first = '12'.

itab2-first = '32'.

itab2-first = '35'.

itab2-first = '40'.

itab2-first = '12'.

itab2-first = '45'.

itab2-first = '48'.

itab2-first = '58'.

itab2-first = '60'.

append itab2.

LOOP AT ITAB2.

ITAB3-ONE = ITAB2-FIRST.

ITAB3-TWO = ITAB2-FIRST.

ITAB3-THREE = ITAB2-FIRST.

ITAB3-FOUR = ITAB2-FIRST.

APPEND ITAB3.

ENDLOOP.

LOOP AT itab3.

write:/ itab3.

ENDLOOP.

*purpose -> RESULT SHOULD LOOK LIKE see below

*2 5 6 12

*32 35 40 12

*45 48 58 60

  • this logic doesn't provide desired result

  • I get only

  • 60 60 60 60

*LOOP ....

  • Firsttime of iteration

*ITAB3-ONE = ITAB2-FIRST. 2

*ITAB3-TWO = ITAB2-FIRST. 5

*ITAB3-THREE = ITAB2-FIRST. 6

*ITAB3-FOUR = ITAB2-FIRST. 12

*ENDLOOP.

0 Kudos
128

Sorry I have to make correction.

instead

  • this logic doesn't provide desired result

  • I get only

  • 60 60 60 60

please consider

  • this logic doesn't provide desired result

  • I get only

2 2 2 2

5 5 5 5

6 6 6 6

12 12 12 12

32 32 32 32

35 35 35 35

40 40 40 40

12 12 12 12

45 45 45 45

48 48 48 48

58 58 58 58

60 60 60 60

Former Member
0 Kudos
128

Hi,

Okay ..I got it..

Try this..

DATA: V_INDEX TYPE SYINDEX.

FIELD-SYMBOLS: <FS>.

V_INDEX = 1.

DO.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

DO 4 TIMES.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ASSIGN SY-INDEX COMPONENT OF STRUCTURE ITAB3 TO <FS>.

<FS> = ITAB2-FIRST.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

V_INDEX = V_INDEX + 1.

ENDDO.

APPEND ITAB3.

ENDDO.

Thanks,

Naren

0 Kudos
128

Hi Naren,

I'm working with R/3 4.6 C and I have got the following

syntax error when I did check your addtional code.

-> COMPONENT OF STRUCTURE ITAB3 ist not expected

any idea whats wrong

friendly reagrds

Ilhan

0 Kudos
128

Ok Naren I got it too.

excuse the oversight you wrote:

ASSIGN SY-INDEX COMPONENT OF STRUCTURE ITAB3 TO <FS>.

instead of

ASSIGN COMPONENT SY-INDEX OF STRUCTURE ITAB3 TO <FS>.

It doesn't greatly matter. I thank you very much for your kindly efforts

to help me. It provides the desired result now.

Is that really the sole possibility to solve that problem?

Former Member
0 Kudos
129

Hi,

Sorry for the syntax error..This is one of possibility..You can also write four read statements to do that..Instead of DO..ASSIGN COMPONENT..ENDDO...Then you can insert after 4 reads.

DATA: V_INDEX TYPE SYINDEX.

DATA: V_MOD TYPE SYINDEX.

V_INDEX = 1.

DO.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-ONE = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-SECOND = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-THIRD = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

READ TABLE ITAB2 INDEX V_INDEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITAB3-FOURTH = ITAB2-FIRST.

V_INDEX = V_INDEX + 1.

APPEND ITAB3.

ENDDO.

Thanks,

Naren