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

WHILE Statement

Former Member
0 Likes
1,172

Can anyone help me please? The following program shows error "type L and T are  not compatible"

data: l,                         "leading  characters

        t,                         "trailing characters

        done.                      "done flag

  parameters p(25) default '    Vendor Number'.

  while done = ' '                 "the expression is evaluated first

      vary l from p+0  next p+1    "then vary assignments are performed

      vary t from p+24 next p+23.

      if l = ' ' and t = ' '.

         l = t = '-'.

     else.

         done = 'X'.

         endif.

     endwhile.

write: / p.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,088

The type incompatible error is because you have specified the offset, but not the length.

Correct usage would be like this:

    VARY l FROM p+0(1NEXT p+1(1RANGE p

    VARY t FROM p+24(1) NEXT p+23(1) RANGE p.

Refrain from using VARY keyword if your keyword documentation considers this as obsolete.

8 REPLIES 8
Read only

Former Member
0 Likes
1,088

Hello,

What is ur reqirement

Explain in detail......

thanks

Kranthi

Read only

0 Likes
1,088

Hello Kranthi,

I want to know why it shows the error. It is supposed to give the following out put

The code in Listing 10.12 produces this output:

    ----Vendor Number    ----

Please check the following link

http://www.sapnet.ru/abap21day/ch10/ch10.htm#UsingtheTTFONTSIZEwhileFONTTTFONTSIZEStatementFONT

Read only

Former Member
0 Likes
1,088

Hi,

You get the type compatible error because the variable ''l'' you have declared is of length 1 and parameter p is of length 25.  Tell us what you are trying to acheive from your above code so we could suggest something.

Best Regards,

Arun Krishnamoorthy

Read only

0 Likes
1,088

dear arun,

I have given 25 size to L but it shows the same error. Please check the following link.

http://www.sapnet.ru/abap21day/ch10/ch10.htm#UsingtheTTFONTSIZEwhileFONTTTFONTSIZEStatementFONT

Listing 10.12  An Example of the Use of the WHILE Statement

    1  report ztx1012.

    2  data: l,                         "leading  characters

    3        t,                         "trailing characters

    4        done.                      "done flag

    5  parameters p(25) default '    Vendor Number'.

    6  while done = ' '                 "the expression is evaluated first

    7      vary l from p+0  next p+1    "then vary assignments are performed

    8      vary t from p+24 next p+23.

    9      if l = ' ' and t = ' '.

    10         l = t = '-'.

    11     else.

    12         done = 'X'.

    13         endif.

    14     endwhile.

    15 write: / p.

It should produce the following output

The code in Listing 10.12 produces this output:

    ----Vendor Number    ----

Analysis     Lines 2 and 3 define two single character variables l and t. Line 3 defines a flag to indicate when processing is complete.     Line 5 defines p as character 25 with a default value.     On line 6, the expression on the while statement is first evaluated. It proves true the first time through the loop. The assignments on lines 7 and 8 are then performed. Line 7 assigns the first character from p to l and line 8 assigns the last character to t.     If l and t are both blank, line 10 assigns a dash to both. If they are not, line 12 assigns an 'X' to the done flag.     On line 14, endwhile copies the values from l and t back to p.     The while loop repeats again from line 6 as long as the done flag is blank.

Read only

0 Likes
1,088

Hi Prince,

Try this code,

data:   l(1) type c,                         "leading  characters

        t(1) type c,                         "trailing characters

        done.                      "done flag

  parameters p(25) default '    Vendor Number'.

  while done = ' '                 "the expression is evaluated first

      vary l from p+0(1) next p+1(1) RANGE P  "then vary assignments are performed


      vary t from p+23(1) next p+22(1) range p.

      if l = ' ' and t = ' '.

         l = t = '-'.

     else.


         done = 'X'.


         endif.

     endwhile.

write: / p.

Read only

0 Likes
1,088

This message was moderated.

Read only

Former Member
0 Likes
1,089

The type incompatible error is because you have specified the offset, but not the length.

Correct usage would be like this:

    VARY l FROM p+0(1NEXT p+1(1RANGE p

    VARY t FROM p+24(1) NEXT p+23(1) RANGE p.

Refrain from using VARY keyword if your keyword documentation considers this as obsolete.

Read only

0 Likes
1,088

Dear Manish Kumar,

Thank you very much. Can you please help me to solve the following?

I have used 3 tables. The details are -

Table Type -> Check Table

Table Name -> YCT

Fields -> Country, Region

Values -> 1 entry -> INDIA, MUMBAI

Table Type -> Foreign Key table

Table Name -> YFKT

Fields -> Country

Table Type -> Another Table

Table Name -> YADFKT

Fields -> Region

Values -> 1 entry -> MUMBAI

Since this is an adapted Foreign Key, So the relationships are -:

YCT-Country = YFKT-Country

AND

YCT-REGION = YADFKT-Region

That means i want Valid "Country" should be present in check table (YCT) and for that a valid "Region" must be there in "YADFKT".

But when I am trying to enter data "INDIA" in YFKT then it is saying "Entry is not present in Check Table".

Why this error is coming ?

I have seen someone faced the same problem but havent solved yet

Please see the following links

http://scn.sap.com/message/13998633#13998633

http://scn.sap.com/message/13997823#13997823

Thanks again.