‎2008 Jul 04 6:27 AM
i have written a simple prog that copies data from one itab to other
here's the prog
however im getting this error : alpha and it1-f1 are type incompatible
REPORT ZDAN_ITABDEMO3.
DATA: BEGIN OF IT1 OCCURS 10,
F1,
END OF IT1,
IT2 LIKE IT1 OCCURS 10 WITH HEADER LINE,
ALPHA(10) VALUE 'ABCDEFGHIJ'.
DO 10 TIMES VARYING IT1-F1 FROM ALPHA0 NEXT ALPHA1.
APPEND IT1.
ENDDO.
APPEND LINES OF IT1 FROM 2 TO 5 TO IT2.
LOOP AT IT2.
WRITE: IT2-F1.
ENDLOOP.
INSERT LINES OF IT1 FROM 8 INTO IT2 index 2.
SKIP.
LOOP AT IT2.
WRITE IT2-F1.
ENDLOOP.
LOOP AT IT2.
IF IT2-F1 >= 'E'.
INSERT LINES OF IT1 TO 1 INTO IT2.
ENDIF.
endloop.
SKIP.
LOOP AT IT2.
WRITE IT2-F1.
ENDLOOP.
SKIP.
IT2[] = IT1[].
LOOP AT IT2.
WRITE IT2-F1.
ENDLOOP.
please help
‎2008 Jul 04 6:41 AM
Hi,
you are trying to assign ALPHA with length 10 to the field IT1-F1 with length 1. So it should look little bit different.
DO 10 TIMES VARYING it1-f1 FROM alpha+0(1) NEXT alpha+1(1) RANGE alpha.
APPEND it1.
ENDDO.
Cheers
‎2008 Jul 04 6:34 AM
Hi Dan
By using this Syntax
... VARYING f FROM f1 NEXT f2
This will be useful if you have a series of fields of the same type and the same distance from each other.
f is a variable which you define in a DATA statement. On each loop pass, f contains a new value. The field f1 after "FROM" specifies the first value of the variable f, while the field f2 after "NEXT" specifies the value to be assigned to the variable f in the second pass. For each subsequent pass, the variable f contains the next value in the sequence determined by the distance between the fields f1 and f2 in memory.
The fields f1 and f2 should be type-compatible and convertible to f.
If the value of f changes during the loop pass, the new value is then placed in the appropriate field fn assigned to f (transfer type: pass by value and result). If the loop pass terminates because of a dialog message, the new value is not passed back if f changes.
The addition ... VARYING f FROM f1 NEXT f2 can be used several times in a DO statement.
Make the changes in your program as per given below code:
REPORT yh1073_test .
*REPORT ZDAN_ITABDEMO3.
DATA: BEGIN OF IT1 OCCURS 10,
F1,
END OF IT1,
IT2 LIKE IT1 OCCURS 10 WITH HEADER LINE.
*ALPHA(10) VALUE 'ABCDEFGHIJ'.
data:
begin of alpha occurs 0,
ONE VALUE 'A',
TWO VALUE 'B',
THREE VALUE 'C',
FOUR VALUE 'D',
FIVE VALUE 'E',
SIX VALUE 'F',
SEVEN VALUE 'G',
EIGHT VALUE 'H',
Nine VALUE 'I',
Ten VALUE 'J',
end of alpha.
DO 10 TIMES VARYING IT1-F1 FROM ALPHA-one NEXT ALPHA-two.
APPEND IT1.
IF IT1-F1 = 'J'.
EXIT.
ENDIF.
ENDDO.
APPEND LINES OF IT1 FROM 2 TO 5 TO IT2.
LOOP AT IT2.
WRITE: IT2-F1.
ENDLOOP.
INSERT LINES OF IT1 FROM 8 INTO IT2 index 2.
SKIP.
LOOP AT IT2.
WRITE IT2-F1.
ENDLOOP.
LOOP AT IT2.
IF IT2-F1 >= 'E'.
INSERT LINES OF IT1 TO 1 INTO IT2.
ENDIF.
endloop.
SKIP.
LOOP AT IT2.
WRITE IT2-F1.
ENDLOOP.
SKIP.
IT2 = IT1.
LOOP AT IT2.
WRITE IT2-F1.
ENDLOOP.Thanks nd regards
Anup.
‎2008 Jul 04 6:41 AM
Hi,
you are trying to assign ALPHA with length 10 to the field IT1-F1 with length 1. So it should look little bit different.
DO 10 TIMES VARYING it1-f1 FROM alpha+0(1) NEXT alpha+1(1) RANGE alpha.
APPEND it1.
ENDDO.
Cheers
‎2008 Jul 04 6:41 AM
here f1 having only 1 char where as alpha having 10 characters thats why u face the problem .
fi(10).
write this insted of f1 only .
‎2008 Nov 14 6:33 AM
Only one character should be specified in the loop for the size of the field (within the internal table) to match with the single character in the string 'ABCDE'. Please have a look at the code below for more clarity.
Data: Begin Of It1 Occurs 5,
f1,
End Of It1.
Data var(5) Value 'ABCDE'.
Do 5 Times Varying It1-f1 From var(1) Next var+1(1) Range var.
Append It1.
EndDo.
Loop At It1.
Write: / It1-f1.
EndLoop.
I am new to ABAP so please correct me if my understanding was wrong.