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: 

identify number of blanks in a string or char field.

Former Member
0 Kudos
197

Hi Friends,

I have a issue, i have two fields of char30 and the users enters numeric values in that and i have to added the data.

i have to validate the data enter by users before adding.

there are chances that users may enter values like'80 0' then i have to throug an error , how to do that. i am unable to capture that sapce between 80 and 0.

is there any Function module ?

regards

Kumar M

1 ACCEPTED SOLUTION

Former Member
0 Kudos
133

Hi try this code.

DATA : char03 TYPE char30 VALUE '1234567890.',

char04 TYPE char30,

len1 type i,

len2 type i.

PARAMETER: char01 TYPE char30,

char02 TYPE char30.

len1 = strlen( char01 ).

len2 = strlen( char02 ).

replace ' ' with '$' into char01.

replace ' ' with '$' into char02.

search char01 for '$'.

if sy-fdpos lt len1.

write 'space available'.

endif.

search char02 for '$'.

if sy-fdpos lt len2.

write 'space available'.

endif.

Regards,

vicky.

9 REPLIES 9

sachin_mathapati
Contributor
0 Kudos
133

Hi ,

First find the string length using STRLEN.

Then check

If wf_field+0(strlen) CA space.

Raise error.

Endif.

Regards,

Sachin M M

Edited by: Sachin Mathapati on Nov 20, 2008 4:16 PM

SuhaSaha
Advisor
Advisor
0 Kudos
133

Hello Kumar,

Try this simple code:



v_string = '80 80 80'.

V_LEN1 = STRLEN( V_STRING ). "V_LEN1 = 8

CONDENSE V_STRING. "Now V_STRING = '808080'.

V_LEN2 = STRLEN( V_STRING ). "V_LEN1 = 6

IF V_LEN1 NE V-LEN2.
* Throw Error Message
ENDIF.

Hope this helps.

BR,

Suhas

Former Member
0 Kudos
133

May we know why you are using character field to get numeric values?

If you use numeric or integer type then this will be taken care by the system itself.

Regards

Karthik D

Former Member
0 Kudos
133

Hi,

Try this

IF p_fname CO '1,2,3,4,5,6,7,8,9,0' .

ELSE.

Error MEssage.

ENDIF.

Former Member
0 Kudos
133

Hi,

Check this out...



constant : c_space type space.

search variable for C_space.
if sy-subrc = 0.
"throw error.
endif.

Hope it was helpful...

Former Member
0 Kudos
133

REPORT ZSRK_073 MESSAGE-ID ZMSG .

PARAMETERS : P_F1(30),

P_F2(30).

DATA : L_F(30),

L_F1 TYPE I,

L_F2 TYPE I.

AT SELECTION-SCREEN.

L_F1 = STRLEN( P_F1 ).

L_F2 = STRLEN( P_F2 ).

IF P_F1+0(L_F1) CA SPACE.

MESSAGE E999 WITH 'Space exist in P_F1'.

ENDIF.

IF P_F2+0(L_F2) CA SPACE.

MESSAGE E999 WITH 'Space exist in P_F2'.

ENDIF.

START-OF-SELECTION.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = P_F1

IMPORTING

OUTPUT = P_F1.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = P_F2

IMPORTING

OUTPUT = P_F2.

L_F = P_F1 + P_F2.

WRITE : / L_F.

Former Member
0 Kudos
134

Hi try this code.

DATA : char03 TYPE char30 VALUE '1234567890.',

char04 TYPE char30,

len1 type i,

len2 type i.

PARAMETER: char01 TYPE char30,

char02 TYPE char30.

len1 = strlen( char01 ).

len2 = strlen( char02 ).

replace ' ' with '$' into char01.

replace ' ' with '$' into char02.

search char01 for '$'.

if sy-fdpos lt len1.

write 'space available'.

endif.

search char02 for '$'.

if sy-fdpos lt len2.

write 'space available'.

endif.

Regards,

vicky.

Former Member
0 Kudos
133

Hi Vicky,

I am really satisfied with your answer.

Edited by: Kumar M on Nov 20, 2008 1:57 PM

0 Kudos
133

But i think at first you addressed him( vicky ) as Chandu, didnt you?

Is that his pet name or you know him personally?

>

> Hi Chandu,

>

> I am really satisfied with your answer.

Regards

Karthik D