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

String Comparision

Former Member
0 Likes
1,412

I must restrict a field entry with letters from A-Z, a-z, 0-9, '-', '/' only.

if there is a charecter other than this, trigger a message and dont save the transaction.

I am doing all this in a exit.

how can i do this?

Thanks

Kiran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,379

>

> I am doing all this in a exit.

> Kiran

Though You dont need to selection screen and start of selection logic.if you are already working in Exit.

than i think Naimesh's solution would definaltely work for you but only you need :

IF P_TEXT NA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-/'."P_TEXT is your field on which you want put check
    WRITE: 'Error'."transaction not save
  ELSE.
    WRITE: 'string is ok'."should be save
  ENDIF.

11 REPLIES 11
Read only

naimesh_patel
Active Contributor
0 Likes
1,379

Try something like this:


PARAMETERS: P_TEXT TYPE CHAR30 LOWER CASE.

START-OF-SELECTION.

  IF P_TEXT NA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-/'.
    WRITE: 'Error'.
  ELSE.
    WRITE: 'string is ok'.
  ENDIF.

Regards,

Naimesh Patel

Read only

naveen_inuganti2
Active Contributor
0 Likes
1,379

Hi...

You wrote...

> dont save the transaction

Let me know this reuirement in which area...?

Is it screen programming?

Thanks,

Naveen.I

Read only

0 Likes
1,379

its in IE01.

am having a validation on the material serial number.

Is there any other way than to write such a big string from a to z twice??

Thanks

Kiran

Read only

0 Likes
1,379

If you are looking for special characters, you can use FM CHECK_STRING_SPEC_CHARACTERS

Read only

Former Member
0 Likes
1,380

>

> I am doing all this in a exit.

> Kiran

Though You dont need to selection screen and start of selection logic.if you are already working in Exit.

than i think Naimesh's solution would definaltely work for you but only you need :

IF P_TEXT NA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-/'."P_TEXT is your field on which you want put check
    WRITE: 'Error'."transaction not save
  ELSE.
    WRITE: 'string is ok'."should be save
  ENDIF.

Read only

0 Likes
1,379

I already did the same way as naimesh told:

Below is my code which is not working. I mean, message is not getting triggered when I entered Aa1-@ as SERNR value.

DATA: sernr TYPE equi-sernr.

MOVE data_equi-sernr TO sernr.

IF sernr NA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/'.

MESSAGE e001(00)

WITH 'Invalid Character in Serial Number.'

'Charaters from A-Z, a-z, 0-9 - / are only permitted'.

ENDIF.

Thanks

Kiran

Read only

0 Likes
1,379

Sorry. I used the wrong relational operator.


  IF P_TEXT CN 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-/ '.
    WRITE: 'Error'.
  ELSE.
    WRITE: 'string is ok'.
  ENDIF.

Make sure, you include one SPACE at the last. Otherwise, it will give an error event if the input is " ABAP".

Regards,

Naimesh Patel

Read only

0 Likes
1,379

Sorry i used now wrong relational oprator.

Edited by: Amit Gujargoud on Sep 3, 2008 5:04 PM

Read only

0 Likes
1,379

Naimesh, That was wonderful about the space catch.

But can you please explain why so?

Also, I would like to know if I can allow user to allow to make his changes when he enters a invalid charater instead of stopping by error message.

Awarded Very help ful points for now.

Shall give you full points when i close this thread.

Thanks

Kiran

Read only

0 Likes
1,379

>

> Awarded Very help ful points for now.

> Shall give you full points when i close this thread.

> Thanks

> Kiran

Voilation of rules.

>

> Naimesh, That was wonderful about the space catch.

> But can you please explain why so?

> Also, I would like to know if I can allow user to allow to make > his changes when he enters a invalid charater instead of stopping by error message.

>

reason is already given by Naimesh.

Use information message instead of error message to allow the user.

Read only

0 Likes
1,379

Allowing User to re-enter the string will depend on the place where you give the Error message.

If you would find the Enhancment / BADI which is being triggered at the PAI level in CHAIN.. ENDCHAIN than you can use the Error message and still system will open the field for input. But, unfortunatly we don't have much enhancment or BADI of this kind.

If you are in ECC 6 than you can very well use the Enhancement Spot.

Regards,

Naimesh Patel