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

Error when field contains characters

Former Member
0 Likes
1,532

Hi All,

I have itab_output2-storeno field which usually gets store number in it but sometimes I get a string with characters in it. How can I send a error message when itab_output2-storeno has chracters.

Thanks,

Veni.

FORM FORMAT_STORENO.

IF itab_output2-storeno >= 1 AND itab_output2-storeno <= 9.

CONCATENATE '1012'

'00000'

itab_output2-storeno

INTO wa1-storeno.

ELSEIF itab_output2-storeno > 9 AND itab_output2-storeno < 100.

CONCATENATE '1012'

'0000'

itab_output2-storeno

INTO wa1-storeno.

ELSEIF itab_output2-storeno > 99 AND itab_output2-storeno < 1000.

CONCATENATE '1012'

'000'

itab_output2-storeno

INTO wa1-storeno.

ELSEIF itab_output2-storeno > 999 AND itab_output2-storeno < 10000.

CONCATENATE '1012'

'00'

itab_output2-storeno

INTO wa1-storeno.

ENDIF.

ENDFORM. " FORMAT_STORENO

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
1,462


IF itab_output2-storeno co sy-abcde
   message E999 with 'Error'.
endif.

or

IF itab_output2-storeno ca sy-abcde
   message E999 with 'Error'.
endif.

a®

14 REPLIES 14
Read only

former_member194669
Active Contributor
0 Likes
1,463


IF itab_output2-storeno co sy-abcde
   message E999 with 'Error'.
endif.

or

IF itab_output2-storeno ca sy-abcde
   message E999 with 'Error'.
endif.

a®

Read only

0 Likes
1,462

Hi ARS,

I tried the logic but it is giving me dump with error message 'Unable to interpret "IONS " as a number'.

IF itab_output2-storeno co sy-abcde.

WRITE: /01 'StoreNo provided', itab_output2-storeno, 'is not a number.'.

ELSEIF itab_output2-storeno >= 1 AND itab_output2-storeno <= 9.

CONCATENATE '1012'

'00000'

itab_output2-storeno

INTO wa1-storeno.

Store number came as 'IONS'.

Thanks,

Veni.

Read only

0 Likes
1,462

Check this example



report  zars no standard page heading
        line-size 170
        line-count 65(4).

data : v_text(10) type c value 'IONS'.
if v_text CA sy-abcde.
  write : 'Contains char'.
endif.

a®

Read only

0 Likes
1,462

Hi ARS,

The characters comming in to Store number is not constant. With the test data I have I saw 3(IONS, NYFL, ORES) different values for it. Is there any way I can catch this with out specifying the literal.

Thanks,

veni.

Read only

0 Likes
1,462

Check this example



report  zars no standard page heading
        line-size 170
        line-count 65(4).

if  i_output2-stroeno CA sy-abcde.
  write : 'Contains char'.
endif.

Read only

Former Member
0 Likes
1,462

Try this before all the IF statements

IF itab_output2-storeno CO '0123456789'.

  • Write all those IFs here

ELSE.

Write : "It is not a number".

ENDIF.

Read only

0 Likes
1,462

Hi Chandrasekhar,

I tried this logic also but it went into else condition when I have number also.

StoreNo provided 1795 is not a number.

StoreNo provided IONS is not a number.

Thanks,

Veni.

Read only

former_member156446
Active Contributor
0 Likes
1,462

I would have used a case statement for this:

case itab_output2-storeno.

when 1 .......

when others.

raise message.

endcase.

Read only

0 Likes
1,462

Hi Jay,

How can I specify store num Ranges in CASE stmt?

Thanks,

Veni.

Read only

former_member156446
Active Contributor
0 Likes
1,462

when GE '1' AND LE '9'.

CONCATENATE '1012' '00000' itab_output2-storeno INTO wa1-storeno.

when GR 9 AND LR 100.

CONCATENATE '1012' '0000' itab_output2-storeno INTO wa1-storeno.

.....

...

..

.

endcase.

to check if it had a character....

if itab-field ca sy-abcde.

Read only

0 Likes
1,462

Thank you ARS. IF itab_output2-storeno CA sy-abcde solved the problem.

Thank you Jay. I will implement CASE in my program.

Regards,

Veni.

Read only

0 Likes
1,462

Hi Jay,

Case stmt is not working as you mentioned. Can some one please help me, if can do this with ranges of values.

I am getting the error as 'Field "GE" is unknown. It is neither in one of the specified tables nor

defined by a "DATA" statement.'

CASE itab_output2-storeno.

when GE '1' AND LE '9'.

CONCATENATE '1012' '00000' itab_output2-storeno INTO wa1-storeno.

when GE 9 AND LE 100.

CONCATENATE '1012' '0000' itab_output2-storeno INTO wa1-storeno.

when GE 99 AND LE 1000.

CONCATENATE '1012' '000' itab_output2-storeno INTO wa1-storeno.

when GE 999 AND LE 10000.

CONCATENATE '1012' '00' itab_output2-storeno INTO wa1-storeno.

ENDCASE.

Thanks,

Veni.

Read only

0 Likes
1,462

Hi,

Just simplify the code

ifitab_output2-storeno GE '1' AND itab_output2-storeno LE '9'.

CONCATENATE '1012' '00000' itab_output2-storeno INTO wa1-storeno.

endif.

if itab_output2-storeno GE 9 AND itab_output2-storeno LE 100.

CONCATENATE '1012' '0000' itab_output2-storeno INTO wa1-storeno.

endif.

........

.......

......

.......

{code]

a®

Read only

0 Likes
1,462

Thank you again ARS.

Regards,

Veni.