Application Development 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: 

String Operatrors

raja_narayanan2
Active Participant
0 Kudos
371

Hi.... all

please help me....

My requirement is this....

If i use the first statement i am getting True statement.

1) IF 'EXAMPLE' CO SY-ABCDE. WRITE 'TRUE'. ELSE. WRITE 'FALSE'. ENDIF.

in second case am getting.....am getting false statement.....

2) PARAMETERS: FNAME TYPE PAD_VORNA.

START-OF-SELECTION.

  • example FNAME value is 'RAJA NARAYANAN' all CAPS letters.

IF FNAME CO SY-ABCDE. WRITE 'TRUE'. ELSE. WRITE 'FALSE'. ENDIF.

Please help me out...

i need to get if i enter small letters i should get false satement.

and cap means true statement... i should not change the type for fname....becaz that is my requirement.

Thanks in advance

Regards

Raja...

1 ACCEPTED SOLUTION

raja_narayanan2
Active Participant
0 Kudos
337

Hi....all

Thanks for your replies.....

i should not go for do loop for my scenario....i tried with do loop before itself and i got the answer.... but my client requirement is i have to use CO or CN like this string operators in IF..ENDIF. statements... and not in loop..

DATA STR TYPE STRING.

PARAMETERS: FNAME TYPE PAD_VORNA lower case.

str = fname.

IF STR CA 'SY-ABCDE'.

WRITE 'TRUE'.

ELSE.

WRITE 'FALSE'.

ENDIF.

i also tried with this statement... but... still i need some help....

if i enter in FNAME like this 'abc123#9'. i should get errors....

the FNAME should only accept character with only CAPS and not in small letters and also without any special charaters....

Please help.....me

Regards

Raja

13 REPLIES 13

Former Member
0 Kudos
337

Use the function module 2054_TRANSLATE_2_UPPERCASE

Former Member
0 Kudos
337

Hi,

instead of

PARAMETERS: FNAME TYPE PAD_VORNA,

use

PARAMETERS: FNAME TYPE PAD_VORNA lower case

Because, by default, whatever you will put in parameter input it is initialy converted into UPPERCASE. So internaly it is always compairing with to UPPERCASE STRINGs and you got 'TRUE ' as output.

Check your code now

PARAMETERS: FNAME TYPE PAD_VORNA  lower case.

IF FNAME CA 'SY-ABCDE'.
    WRITE 'TRUE'.
ELSE.
  WRITE 'FALSE'.
ENDIF.

Regards,

Anirban

Former Member
0 Kudos
337

Hi Raja,

Here is a simple example

data :loc_var type string value 'abcdefghijklmnopqrstuvwxyz'.

data :loc_test1 type string value 'MY NAME IS Raja'.

data :loc_test2 type string value 'MY NAME IS RAJA'.

if loc_test1 CA loc_var.

Message 'Small letters found' type 'I'..

endif.

if loc_test2 CA loc_var.

else.

Message 'Small letters not found' type 'I'.

endif.

Solution:

so the loc_var defines all variables in lower case and if any of the lowercase is found then we have the statement "if loc_test1 CA loc_var." as successful

Hope it helps

Regards

Byju

Former Member
0 Kudos
337

Hi

2 things

(1) There should not be space between words, if you pass 'RAJA NARAYANAN' to first statement also it will fail

(2) when you are passing thru parameter, write the parameter to different varaible and than check.

try this code

data : string type string.

PARAMETERS: FNAME TYPE PAD_VORNA.

START-OF-SELECTION.

translate fname to upper case.

string = fname.

*example FNAME value is 'RAJA NARAYANAN' all CAPS letters.

IF string CO SY-ABCDE. WRITE 'TRUE'. ELSE. WRITE 'FALSE'. ENDIF.

Regards

Madhan D

Edited by: Madhan Doraikannan on Nov 19, 2008 8:26 AM

Former Member
0 Kudos
337

>

> Hi.... all

>

> please help me....

> My requirement is this....

>

> If i use the first statement i am getting True statement.

>

> 1) IF 'EXAMPLE' CO SY-ABCDE. WRITE 'TRUE'. ELSE. WRITE 'FALSE'. ENDIF.

>

> in second case am getting.....am getting false statement.....

>

> 2) PARAMETERS: FNAME TYPE PAD_VORNA.

> START-OF-SELECTION.

> * example FNAME value is 'RAJA NARAYANAN' all CAPS letters.

> IF FNAME CO SY-ABCDE. WRITE 'TRUE'. ELSE. WRITE 'FALSE'. ENDIF.

>

>

>

> Please help me out...

> i need to get if i enter small letters i should get false satement.

> and cap means true statement... i should not change the type for fname....becaz that is my requirement.

>

> Thanks in advance

> Regards

> Raja...

Hi,

I think FALSE is coming in second case due to a sapce in between the name.

Thanks

NItesh

Former Member
0 Kudos
337

hi

the 'CO' operand can not work! it is sensible bewteen capitalization and lower.

you can try this

DATA:l_letter,

position TYPE i,

length TYPE i,

upper_counts TYPE i,

lower_counts TYPE i.

length = STRLEN( fname ).

DO length TIMES.

l_letter = fname+position(1).

IF l_letter >= 'A' AND

l_letter <= 'Z'.

upper_counts = upper_counts + 1.

ELSEIF l_letter >= 'a' AND

l_letter <= 'z'.

lower_counts = lower_counts + 1.

ENDIF.

position = position + 1.

ENDDO.

IF upper_counts = length.

WRITE 'TRUE'.

ELSEIF lower_counts = length.

WRITE 'FALSE'.

ENDIF.

raja_narayanan2
Active Participant
0 Kudos
338

Hi....all

Thanks for your replies.....

i should not go for do loop for my scenario....i tried with do loop before itself and i got the answer.... but my client requirement is i have to use CO or CN like this string operators in IF..ENDIF. statements... and not in loop..

DATA STR TYPE STRING.

PARAMETERS: FNAME TYPE PAD_VORNA lower case.

str = fname.

IF STR CA 'SY-ABCDE'.

WRITE 'TRUE'.

ELSE.

WRITE 'FALSE'.

ENDIF.

i also tried with this statement... but... still i need some help....

if i enter in FNAME like this 'abc123#9'. i should get errors....

the FNAME should only accept character with only CAPS and not in small letters and also without any special charaters....

Please help.....me

Regards

Raja

0 Kudos
337

Why r u making the code complecated

try

REPORT  ZTEST002.

PARAMETERS: FNAME TYPE PAD_VORNA  lower case.

IF FNAME CA SY-ABCDE.
    WRITE 'TRUE'.
ELSE.
  WRITE 'FALSE'.
ENDIF.

Regards,

Anirban

0 Kudos
337

HI...Anirban Bhattacharjee

Read my question and then reply for that

0 Kudos
337

i also tried with this statement... but... still i need some help....

if i enter in FNAME like this 'abc123#9'. i should get errors....

the FNAME should only accept character with only CAPS and not in small letters and also without any special charaters....

0 Kudos
337

REPORT ZSRK_068 .

PARAMETERS: FNAME TYPE PAD_VORNA.

DATA AL(27) VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '.

START-OF-SELECTION.

IF FNAME CO AL.

WRITE 'TRUE'.

ELSE.

WRITE 'FALSE'.

ENDIF.

0 Kudos
337

Check the code properly....... there will be no ' ' with SY-ABCDE and follow the RULE OF ENGAGEMENT regarding use of words in forum. I have read it and worked it out in my system.

matt
Active Contributor
0 Kudos
337

That's enough answers. Locked.

matt