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

Issue with varying

Former Member
0 Likes
1,149

Hi ABAPers,

I am new to this and would like a little help from you. I am going through the Teach yourself ABAP book and there are a few sample programs that I am trying to see work. But I constantly get and error saying

"P" and "C" are type-incompatible.

Here is the source code:

parameters p(20) default 'c::\\\xx\\yy'.
data: c type c,
       n type c.
      
       do 19 times varying c from p+0 next p+1
       varying n from p+1 next p+2.
check c ca ':\'.
if c = n.
   write: / 'duplicate', c, 'found', 'at position', sy-index.
   endif.
   enddo.

I am typing it exactly how it is n the book. Can someone tell me if there is a solution to this?

Look forward to hearing from you guys...

Thanks.

M

1 ACCEPTED SOLUTION
Read only

amy_king
Active Contributor
0 Likes
1,125

Hi Manish,

In my system, I get get this working by specifying an explicit number of characters to capture in the offset. My system also requires the RANGE addition, but depending on your release level, your system may not.

DO 19 TIMES VARYING c FROM p+0(1) NEXT p+1(1) RANGE p
                      VARYING n FROM p+1(1) NEXT p+2(1) RANGE p.

     ...

ENDDO.

To make life more interesting, the VARYING addition for DO...ENDO is now obsolete. Check out ASSIGN ... INCREMENT which replaces it.

Cheers,

Amy

Hi ABAPers,

I am new to this and would like a little help from you. I am going through the Teach yourself ABAP book and there are a few sample programs that I am trying to see work. But I constantly get and error saying

"P" and "C" are type-incompatible.

Here is the source code:

parameters p(20) default 'c::\\\xx\\yy'.
data: c type c,
       n type c.
      
       do 19 times varying c from p+0 next p+1
       varying n from p+1 next p+2.
check c ca ':\'.
if c = n.
   write: / 'duplicate', c, 'found', 'at position', sy-index.
   endif.
   enddo.

I am typing it exactly how it is n the book. Can someone tell me if there is a solution to this?

Look forward to hearing from you guys...

Thanks.

M

8 REPLIES 8
Read only

amy_king
Active Contributor
0 Likes
1,126

Hi Manish,

In my system, I get get this working by specifying an explicit number of characters to capture in the offset. My system also requires the RANGE addition, but depending on your release level, your system may not.

DO 19 TIMES VARYING c FROM p+0(1) NEXT p+1(1) RANGE p
                      VARYING n FROM p+1(1) NEXT p+2(1) RANGE p.

     ...

ENDDO.

To make life more interesting, the VARYING addition for DO...ENDO is now obsolete. Check out ASSIGN ... INCREMENT which replaces it.

Cheers,

Amy

Read only

Former Member
0 Likes
1,125

Thanks Amy. You suggestion of including the below:

p+0(1) next p+1(1)

has allowed the syntax check to complete and the program run successfully.

Can you tell me what the (1) after the p+0 and RANGE actually do?

Thanks again for the quick reply!

M

Read only

amy_king
Active Contributor
0 Likes
1,125

Hi Manish,

The (1) is a length specification and indicates how many characters to transfer in the assignment. Let's say we have two character variables:

DATA: lv_var_one TYPE char10,

          lv_var_two TYPE char10.

The statement...

lv_var_one = lv_var_two+3(7).

takes lv_var_two, skips the first 3 characters and assigns the next 7 characters to lv_var_one.

If you wrote...

lv_var_one = lv_var_two+3.

then the first 3 characters of lv_var_two would be skipped and the rest of the value of lv_var_two would be assigned to lv_var_one.

It can be useful when you want to capture just part of another variable value, like...

lv_current_month = sy-datum+4(2).

Here are a couple of documents about offset and length if you want to read more.

RANGE specifies an explicit memory area which the VARYING components may access.

Cheers,

Amy

Read only

Former Member
0 Likes
1,125

Thanks Amy!

This is a great help.

M

Read only

Former Member
0 Likes
1,125

Hi,

P is a packed data type that is numeric data type and you cannot use characters inside it because you cannot convert P to C and they are incompatible.

Read this link...

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2fcc358411d1829f0000e829fbfe/content.htm

also read this which tells about conversion rules.

http://help.sap.com/SAPHELP_470/Helpdata/EN/fc/eb3434358411d1829f0000e829fbfe/content.htm

thanks.

Read only

0 Likes
1,125

Hi Aswatha,

Actually, in Manish's code snippet, variable P is a character field of length 20.

parameters p(20) default 'c::\\\xx\\yy'.

Cheers,

Amy

Read only

0 Likes
1,125

Hi Amy,

thanks for waking me up here .... i didnt see that at all.......

thanks.

Read only

0 Likes
1,125

Fridays...