Problem in Code
Dear Group,
Here is the simple code taken from SAMs.
*&---------------------------------------------------------------------*
*& Report ZWHILE_LOOPGPK *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZWHILE_LOOPGPK.
data: l,
t ,
done.
parameter v(25) default ' Praveen '.
while done = ' '
vary l from v+0 next v+1
vary t from v+24 next v+23.
if l = ' ' and t = ' '.
l = t = '-'.
else.
done = 'X'.
endif.
endwhile.
write: / 'Value of the input variable is : ',
/, v.
The error I get is V and L are type incompatible. Can you guys please let me know, where the problem exists.
Regards,
Praveen
It's strange, I generated your code and all was ok.
Result:
" Value of the input variable is :
-PRAVEEN - "
Try change definition:
DATA: l TYPE c,
t TYPE c,
done TYPE c.
PARAMETER v(25) TYPE c DEFAULT ' Praveen '.
Dear Sir,
I tried even that way by giving the datatype, but yet it didnt work. It still gave the same error.
Regards,
Praveen.
Sorry, I don't have any more idea...
v+0(1) next v+1(1).
Dear Group,
Solution:
The error is not in the code. The error is in the configuration of some parameters, in the attributes. They are Fixed Point Arithmetic and Unicode Check Active.
In order to uncheck these:
Step 1: Goto the ABAP Editor.
Step 2: Click on GOTO in the menu bar and select the option "Attributes".
Step 3: Uncheck the fields,
Fixed Point Arithmetic
Unicode Check Active.
Step 4: Click on the Save Button.
Step 5: Execute.
But till now I didnt understand why exactly this made the change and how is that these are inter linked. If any one could answer this, it would be great.
Regards,
Praveen.
'Fixed Point Arithmetic' doesn't matter, but 'Unicode Check Active' does.
The syntax error " 'V' and 'L' are type-incompatible" comes from it.
ABAP help, built-in SE38, explains it. Help tree is ABAP-By theme -> ABAP Unicode -> Constraints in Unicode programs -> Other changes -> 3. Loops with the VARY and VARYING additions.
By the way, what a tricky program to display PARAMETER back.
I was truly confused why variable V is modified in the WHILE loop.
It looks like VARY option creates hidden pointers for T, L. At the start of 2nd iteration, the values of V+0(1) and V+24(1) becomes '-' ! That must be side effect of the assignment l = t = '-'. in the 1st iteration.
I checked it by coding below, which is a modified conding sample of ABAP help.
REPORT zwhile_loopgpk2.
DATA: BEGIN OF WORD,
ONE VALUE 'E',
TWO VALUE 'x',
THREE VALUE 'a',
FOUR VALUE 'm',
FIVE VALUE 'p',
SIX VALUE 'l',
SEVEN VALUE 'e',
EIGHT VALUE '!',
filler(2) value space,
END OF WORD,
LETTER1, LETTER2.
write: / '*', word, '*'.
skip.
WHILE LETTER2 <> '!'
VARY LETTER1 FROM WORD-ONE NEXT WORD-THREE
VARY LETTER2 FROM WORD-TWO NEXT WORD-FOUR.
if sy-index = 5.
skip.
write: / '*', word, '*'.
exit.
endif.
WRITE: LETTER1, LETTER2.
clear : LETTER1, LETTER2.
ENDWHILE.
The result is below. the structure word gets blanked.
* Example! *
E x a m p l e !
* *
T.Yamagiwa
thanks for all the info.
Yamagiwa, i have a question , there is a option in attributes called 'start with variant', what does it do ? i have a requirement , Myprog. should start with the Variant...plz. suggest me.
thanks in advance.
sushmi
Eh? I understand "Start using variant" flag enforces the program to 'Execute with variant' (shift-F6, not F.
T.Yamagiwa
Hey Group,
Thanks for the response. Especially I should thank Yamagiwa for his effort.
Regards,
Praveen.