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

syntax

Former Member
0 Likes
562

Hi,

I need to check the first 2 places of a string and check if they are characters or numerical.

For example: ch1 = string

Ch2 = 20string

I need to differentiate them depending on their first 2 places.

Anyone please tell me the syntax

Thank you

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
503

You can check the first two characters for numeric values like so.

if str(2) CO '1234567890'.
* Yes, the first two are numeric
else.
* No, they are not numeric.
endif.

Regards,

Rich HEilman

3 REPLIES 3
Read only

ferry_lianto
Active Contributor
0 Likes
503

Hi,

You can use FM NUMERIC_CHECK to validate numeric or character by passing the first two character string.

DATA: WA_STRING TYPE STRING,

WA_HTYPE LIKE DD01V-DATATYPE.

MOVE CH1(2) TO WA_STRING.

CALL FUNCTION 'NUMERIC_CHECK'

EXPORTING

STRING_IN = WA_STRING

IMPORTING

HTYPE = WA_HTYPE.

IF WA_HTYPE = 'NUMC'.

WRITE: / 'numeric value'.

ELSE.

WRITE: / 'character value'.

ENDIF.

Regards,

Ferry Lianto

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
504

You can check the first two characters for numeric values like so.

if str(2) CO '1234567890'.
* Yes, the first two are numeric
else.
* No, they are not numeric.
endif.

Regards,

Rich HEilman

Read only

Former Member
0 Likes
503

Hi,

Check this...

DATA: CH1 TYPE STRING.

DATA: CH2 TYPE STRING.

CH1 = 'STRING'.

IF CH1+0(2) CO '01234567890'.

WRITE: / 'TRUE'.

ELSE.

WRITE: / 'FALSE'.

ENDIF.

Thanks,

Naren