‎2012 Jul 23 10:56 AM
report ztx1012.
data: l,
t,
done.
parameters p(25) default ' Vendor Number'.
while done = ' '
vary l from p+0 next p+1
vary t from p+24 next p+23.
if l = ' ' and t = ' '.
l = t = '-'.
else.
done = 'X'.
endif.
endwhile.
write: / p.
I developed this code in ECC6.0. when executing this program getting error
l and P are Type incompatibility.
but i used the same type C for declaring I and P.
what is wrong ?
‎2012 Jul 23 11:32 AM
hi,
this code changes is working for me....
report ztx1012.
data: l,
t,
done.
parameters p(25) default ' Vendor Number'.
while done = ' '
vary l from p(1) next p+1(1) RANGE p
vary t from p+24(1) next p+23(1) RANGE p.
if l = ' ' and t = ' '.
l = t = '-'.
else.
done = 'X'.
endif.
endwhile.
write: / p.
Let me know if it is workin gfor you?
Thanks,
Sharath
‎2012 Jul 23 11:03 AM
in the above code the error is not saying about the data type. its saying about the variables you declared. please specify the variables declaration with proper data types and check.
‎2012 Jul 23 11:16 AM
Hi,
You can check with your variable declaration, and yes I and P are not compatibility, you can try n and p are compatible.
Regards
Jana
‎2012 Jul 23 11:17 AM
hi ,
try this ,
vary l from p+0(1) next p+1(1)
vary t from p+24(1) next p+23(1).
regards ,
Yogendra Bhaskar
‎2012 Jul 23 11:41 AM
hi ,
surely there will be range error after this , so add this :
vary l from p+0(1) next p+1(1) RANGE P
vary t from p+24(1) next p+23(1) RANGE P.
regards ,
Yogendra Bhaskar
‎2012 Jul 23 1:55 PM
Hi Yogendra,
but the range amendment will be necessary, since in this case the range can't be determined automatically.
while done = ' '
vary l from p+0(1) next p+1(1) range p
vary t from p+24(1) next p+23(1) range p.
if l = ' ' and t = ' '.
l = t = '-'.
else.
done = 'X'.
endif.
endwhile.
However, the WHILE ... VARY ... statement is obsolete and should be avoided.
Alternatives:
1) With regular expressions
data: lv_bound type string,
lv_body type string.
find regex '( *)(.*)\1' in p submatches lv_bound lv_body.
translate lv_bound using ' -'.
concatenate lv_bound lv_body lv_bound into p respecting blanks.
2) Exploiting the fact that the CO operator sets sy-fdpos in a reasonable way:
data: n type i, m type i.
if p co space or sy-fdpos ne 0.
n = 25 - sy-fdpos.
while n < 25 and p+n cn space.
add 1 to n.
endwhile.
if n < 25.
m = 25 - n.
translate p(m) using ' -'.
p+n = p.
endif.
endif.
Regards,
Rüdiger
‎2012 Jul 23 11:32 AM
hi,
this code changes is working for me....
report ztx1012.
data: l,
t,
done.
parameters p(25) default ' Vendor Number'.
while done = ' '
vary l from p(1) next p+1(1) RANGE p
vary t from p+24(1) next p+23(1) RANGE p.
if l = ' ' and t = ' '.
l = t = '-'.
else.
done = 'X'.
endif.
endwhile.
write: / p.
Let me know if it is workin gfor you?
Thanks,
Sharath
‎2012 Jul 23 4:22 PM
thanks sharath.
i am new to the ABAP development. but i want to know about why my solution is wrong and why you are using "Range" addition to your source code.
thanks best reagrds
Tithira.
‎2012 Jul 23 4:29 PM
Hi Tithira,
as the docu says, the range statement is necessary for DO ... VARYING and WHILE ... VARY, if the ABAP compiler can't determine the finish condition itself. This is the case here. In
vary l from p(1) next p+1(1)
the information that the basis gets for the "FROM" and "NEXT" field is only a pointer to the beginning of the field, and the length (1). From this, it can't derive when to stop the "vary" process. For this reason, the RANGE has to be passed. Then the runtime knows: As soon as it is leaving the 25 characters reserved for P, it has to stop the process.
But keep in mind that DO ... VARYING and WHILE ... VARY are obsolete and should not be used anyway.
Regards,
Rüdiger
‎2012 Jul 23 4:36 PM