Application Development and Automation 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: 
Read only

type-incompatible in ABAP Code

TSG
Participant
0 Likes
2,840

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 ?


1 ACCEPTED SOLUTION
Read only

SharathYaralkattimath
Contributor
0 Likes
2,257

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

9 REPLIES 9
Read only

Former Member
0 Likes
2,257

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.

Read only

JanarthananE
Contributor
0 Likes
2,257

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

Read only

yogendra_bhaskar
Contributor
0 Likes
2,257

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

Read only

0 Likes
2,257

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

Read only

0 Likes
2,257

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

Read only

SharathYaralkattimath
Contributor
0 Likes
2,258

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

Read only

0 Likes
2,257

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.

Read only

0 Likes
2,257

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

Read only

0 Likes
2,257

thanks.