2007 Jan 04 10:03 PM
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.
2007 Jan 05 4:06 PM
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
2007 Jan 04 10:08 PM
Hi,
Use the LOOP AT..
LOOP AT ITAB2.
MOVE THE VALUES FOR EACH COLUMN.
ITAB3-ONE = ITAB2-FIRST.
ITAB3-..
APPEND ITAB3.
ENDLOOP.
Thanks,
Naren
2007 Jan 04 10:26 PM
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.
2007 Jan 04 10:10 PM
2007 Jan 04 10:17 PM
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.
2007 Jan 04 10:31 PM
hi Prashanth,
can you please write a snippet to demonstrate it concretely ?
regards
Ilhan
2007 Jan 04 10:31 PM
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
2007 Jan 04 10:54 PM
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.
2007 Jan 04 11:02 PM
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
2007 Jan 04 11:12 PM
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
2007 Jan 05 8:39 AM
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
2007 Jan 05 9:04 AM
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?
2007 Jan 05 4:06 PM
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