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

regarding alpha numeric check

Former Member
0 Likes
1,728

hey i used below code to check my input file name has

alpha numric check (0-9,A-Z,-) or not..

CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.

if fname CA alphanumeric.

else.

MESSAGE E002.

endif.

was my check is correct...i guess i am lacking something here...

if i enter other than this(0-9,A-Z,-) it should give me error..

how to do this..ppls correct me..

ambichan

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
1,640

Hi.

try:

IF fname CO alphanumeric.

regards Andreas

14 REPLIES 14
Read only

andreas_mann3
Active Contributor
0 Likes
1,641

Hi.

try:

IF fname CO alphanumeric.

regards Andreas

Read only

0 Likes
1,640

hey sorry for my poor explanation.

actually my requirement is..if user input

other than number,Alphabets,and hyphen it should display me error.

CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.

if fname CO alphanumeric.

else.

MESSAGE E002.

endif.

ABove code allows ABC$% input without displaying error.

(Except Alphanumeric, even if you enter 1 special character also it should display me error..)

ambichan

Message was edited by: ambi chan

Read only

0 Likes
1,640

try this

parameters: fname(50) .

data: an(50) .

CONCATENATE '0123456789' sy-abcde '_' INTO an.

if fname Co an.

else.

MESSAGE i398(00) with 'error' .

endif.

Regards

Raja

Read only

0 Likes
1,640

Hi,

Try the option CS(Contains String) as this is not case sensitive,

if fname cs alphanumeric.

endif.

Hope this helps,

Rgds,

Read only

0 Likes
1,640

sorry , i don't understand ?!

do you mean s.th like that:

AT SELECTION-SCREEN ON fname.
  CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.
  IF fname CN alphanumeric.
    MESSAGE e001(00) WITH 'error'.
  ENDIF.

regards Andreas

Read only

0 Likes
1,640

Hey guys,

I am really confused with all tests.

First let me try to put the question properly here.

I have parameter taking Input as Fname.ie FILE NAME.

Here if i wrongly enter input Fname as any special character,say ( !@#$%^&*()_+.)it should throw me error.

Wrong input options can be for example as below.

1-ABC*%

2-*123'(

3- "#123ABC

Correct inputs are

1-ABC123

2-123ABC_

3-ABC_123

etc

i hope now i am clear with my question explaining what i want...does all answer posted here matches my question.?.pls correct me..

ambichan.

Message was edited by: ambi chan

Read only

0 Likes
1,640

Hi Ambi,

Did you test the solution provided by Andreas, it seems to work fine, no ?

regards,

Erwan.

Read only

0 Likes
1,640

No.its not working.

First i checked this

CASE-1

AT SELECTION-SCREEN ON fname.

CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.

if fname CN alphanumeric.

MESSAGE E002.

endif.

Above code allows me to input both 'ABC' and 'ABC&('.

CASE-2

AT SELECTION-SCREEN ON fname.

CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.

if fname CN alphanumeric.

MESSAGE E002.

endif.

here it gives error even if i Enter only alphabets..

what to do...

just struck up..here

Read only

0 Likes
1,640

I've checked the following code and it works fine :

REPORT  ZTEST_3                                 .

data : alphanumeric(70).

parameters: fname(50) .


AT SELECTION-SCREEN ON fname.
  CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.
  IF fname CN alphanumeric.
    MESSAGE e001(00) WITH 'error'.
  ENDIF.


  start-of-selection.

  write:/ 'OK'.

ABC is OK, but not ABC& .

Regards,

Erwan.

Read only

0 Likes
1,640

well. I accept it works with your program.

Could you pls check out my code..where the bug is..

TYPES: MSGTEXT_T(700).

DATA REC(400) type c.

DATA FOUT(90) type C.

DATA FPATH(200) TYPE C.

DATA FORMAT LIKE FILENAME-FILEFORMAT.

DATA FLAG(20) TYPE C.

CONSTANTS: VAR_PART_LG TYPE I VALUE 64.

CONSTANTS: ZCLIENT LIKE SY-MANDT VALUE '800'.

CONSTANTS: ZENV LIKE SY-OPSYS VALUE 'NT'.

DATA : BEGIN OF ENTRIESTAB OCCURS 2000.

INCLUDE STRUCTURE RSLGETAB.

DATA : END OF ENTRIESTAB.

DATA: BEGIN OF AUX_slgproc. " LIKE rslgpid

INCLUDE STRUCTURE RSLGPID.

DATA END OF AUX_slgproc.

DATA: BEGIN OF GEN_OUTLINE "generic

, TSKNA(3) "new taskname

, TSKNU(2). "tasknumber

DATA: END OF GEN_OUTLINE.

DATA : HIDE_PARAMS LIKE RSLGTYPE-PARAMARRAY. " C(620)

DATA : BEGIN OF DISPLAY_TAB occurs 0

,DIS_DATE(10) TYPE C

,DIS_TIME(8) TYPE C

,DIS_TSKNA(3) TYPE C

,DIS_TSKNU(2) TYPE C

,DIS_SLGMAND(3) TYPE C

,DIS_SLGLTRM(8) TYPE C

,DIS_SLGUSER(12) TYPE C

,DIS_SLGTC(10) TYPE C

,DIS_MSGID(4) TYPE C

,DIS_MSGTXT(316) TYPE C.

DATA : END OF DISPLAY_TAB.

DATA : alphanumeric(37) TYPE C.

DATA: BEGIN OF CUR_SYSLOGTAB. " struct, not table ! !

INCLUDE STRUCTURE RSLGTCACHE.

DATA: END OF CUR_SYSLOGTAB.

Data : BEGIN OF TA.

INCLUDE STRUCTURE RSLGSEL.

Data : END OF TA.

Data : BEGIN OF INFO_AFTERFILE.

INCLUDE STRUCTURE RSLGFINFO.

Data : END OF INFO_AFTERFILE.

DATA: L11_CATCHED_ERRNO(6)

, L11_CATCHED_T100(5)

, HIDE_TEXT TYPE MSGTEXT_T " Long.

, HIDE_TEXT_LG TYPE I.

DATA: BEGIN OF AN_ENTRY. " LIKE RSLGENTR.

INCLUDE STRUCTURE RSLGENTR.

DATA: END OF AN_ENTRY.

SELECTIOn-SCREEN BEGIN OF BLOCK BLK1 with FRAME TITLE text-ex0.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex1.

PARAMETERS : SDATE LIKE SY-DATUM OBLIGATORY.

selection-screen comment 35(10) text-ex2.

PARAMETERS : STIME LIKE SY-UZEIT OBLIGATORY.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex3.

PARAMETERS : EDATE LIKE SY-DATUM.

selection-screen comment 35(10) text-ex4.

PARAMETERS : ETIME LIKE SY-UZEIT.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex8.

PARAMETERS : E_FILE LIKE FILENAME-FILEINTERN DEFAULT 'ZLOGICFILE'

OBLIGATORY.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex5.

PARAMETERS : FNAME(36) TYPE C OBLIGATORY.

PARAMETERS : FTXT(3) TYPE C DEFAULT 'TXT'.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK BLK1.

TYPES: MSGTEXT_T(700).

DATA REC(400) type c.

DATA FOUT(90) type C.

DATA FPATH(200) TYPE C.

DATA FORMAT LIKE FILENAME-FILEFORMAT.

DATA FLAG(20) TYPE C.

CONSTANTS: VAR_PART_LG TYPE I VALUE 64.

CONSTANTS: ZCLIENT LIKE SY-MANDT VALUE '800'.

CONSTANTS: ZENV LIKE SY-OPSYS VALUE 'NT'.

DATA : BEGIN OF ENTRIESTAB OCCURS 2000.

INCLUDE STRUCTURE RSLGETAB.

DATA : END OF ENTRIESTAB.

DATA: BEGIN OF AUX_slgproc. " LIKE rslgpid

INCLUDE STRUCTURE RSLGPID.

DATA END OF AUX_slgproc.

DATA: BEGIN OF GEN_OUTLINE "generic

, TSKNA(3) "new taskname

, TSKNU(2). "tasknumber

DATA: END OF GEN_OUTLINE.

DATA : HIDE_PARAMS LIKE RSLGTYPE-PARAMARRAY. " C(620)

DATA : BEGIN OF DISPLAY_TAB occurs 0

,DIS_DATE(10) TYPE C

,DIS_TIME(8) TYPE C

,DIS_TSKNA(3) TYPE C

,DIS_TSKNU(2) TYPE C

,DIS_SLGMAND(3) TYPE C

,DIS_SLGLTRM(8) TYPE C

,DIS_SLGUSER(12) TYPE C

,DIS_SLGTC(10) TYPE C

,DIS_MSGID(4) TYPE C

,DIS_MSGTXT(316) TYPE C.

DATA : END OF DISPLAY_TAB.

DATA : alphanumeric(37) TYPE C.

DATA: BEGIN OF CUR_SYSLOGTAB. " struct, not table ! !

INCLUDE STRUCTURE RSLGTCACHE.

DATA: END OF CUR_SYSLOGTAB.

Data : BEGIN OF TA.

INCLUDE STRUCTURE RSLGSEL.

Data : END OF TA.

Data : BEGIN OF INFO_AFTERFILE.

INCLUDE STRUCTURE RSLGFINFO.

Data : END OF INFO_AFTERFILE.

DATA: L11_CATCHED_ERRNO(6)

, L11_CATCHED_T100(5)

, HIDE_TEXT TYPE MSGTEXT_T " Long.

, HIDE_TEXT_LG TYPE I.

DATA: BEGIN OF AN_ENTRY. " LIKE RSLGENTR.

INCLUDE STRUCTURE RSLGENTR.

DATA: END OF AN_ENTRY.

SELECTIOn-SCREEN BEGIN OF BLOCK BLK1 with FRAME TITLE text-ex0.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex1.

PARAMETERS : SDATE LIKE SY-DATUM OBLIGATORY.

selection-screen comment 35(10) text-ex2.

PARAMETERS : STIME LIKE SY-UZEIT OBLIGATORY.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex3.

PARAMETERS : EDATE LIKE SY-DATUM.

selection-screen comment 35(10) text-ex4.

PARAMETERS : ETIME LIKE SY-UZEIT.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex8.

PARAMETERS : E_FILE LIKE FILENAME-FILEINTERN DEFAULT 'ZLOGICFILE'

OBLIGATORY.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1.

*ファイル名設定

SELECTION-SCREEN BEGIN OF LINE.

selection-screen comment 5(15) text-ex5.

PARAMETERS : FNAME(36) TYPE C OBLIGATORY.

PARAMETERS : FTXT(3) TYPE C DEFAULT 'TXT'.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK BLK1.

AT SELECTION-SCREEN.

CONCATENATE sdate(4) sdate4(2) sdate6(2) stime(2) stime+2(2)

stime+4(2) '00' INTO TA-STARTDATE.

if Edate = '00000000'.

CONCATENATE sy-datum(4) sy-datum4(2) sy-datum6(2) sy-uzeit(2)

sy-uzeit2(2) sy-uzeit4(2) '00' INTO TA-STOP_DATE.

else.

CONCATENATE edate(4) edate4(2) edate6(2) etime(2) etime+2(2)

etime+4(2) '00' INTO TA-STOP_DATE.

endif.

IF SDATE >< ' ' AND SDATE >< '00000000'

AND STIME >< ' ' AND STIME >< '000000'

AND EDATE >< ' ' AND EDATE >< '00000000'

AND ETIME >< ' ' AND ETIME >< '000000' .

"All four fields given.

IF SDATE > EDATE.

MESSAGE E001.

ELSEIF SDATE = EDATE

AND STIME > ETIME.

MESSAGE E001.

ENDIF.

ELSEIF SDATE >< ' ' AND SDATE >< '00000000'

AND EDATE >< ' ' AND EDATE >< '00000000'

.

"Two date fields given.

IF SDATE > EDATE.

MESSAGE E001.

ENDIF.

ENDIF.

<b>AT SELECTION-SCREEN ON fname.

CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric.

if fname CN alphanumeric.

MESSAGE E002.

endif.</b>

PERFORM GETFPATH.

FORM GETFPATH.

CONCATENATE FNAME FTXT INTO FOUT SEPARATED BY '.'.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

CLIENT = ZCLIENT

LOGICAL_FILENAME = E_FILE

OPERATING_SYSTEM = ZENV

PARAMETER_1 = FOUT

  • PARAMETER_2 = ' '

  • PARAMETER_3 = ' '

  • USE_PRESENTATION_SERVER = ' '

  • WITH_FILE_EXTENSION = ' '

  • USE_BUFFER = ' '

IMPORTING

EMERGENCY_FLAG = FLAG

FILE_FORMAT = FORMAT

FILE_NAME = FPATH

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE E004.

EXIT.

ENDIF.

Read only

0 Likes
1,640

Hi Ambichan,

I don't know why your code doesn't work. but can you just try to do something like this -

parameters : p_test(100).

data: len          type i,
      alphanumeric type string.


initialization.
  concatenate sy-abcde
              '0123456789'
              '_'
         into alphanumeric.

at selection-screen.
  len = strlen( p_test ).
  if ( p_test cn alphanumeric ).
    if len ne sy-fdpos.
      message i888(bctrain) with 'Error!!'.
    endif.
  endif.
 

Regards,

Anand Mandalika.

Read only

0 Likes
1,640

I've checked your code.

It is possible that it check for the "space" value.

Try this :

data : alphanumeric(38)

AT SELECTION-SCREEN ON fname.

  CONCATENATE '0123456789' sy-abcde '_' INTO alphanumeric+1(37).
  IF fname CN alphanumeric.
    MESSAGE e002.
  ENDIF.

Moreover, of topic but a tip, when you check for the date value :

Instead of using

SDATE >< ' ' AND SDATE >< '00000000'

,

you can try

SDATE ne space

.

Regards,

Erwan.

Message was edited by: Erwan LE BRUN

Message was edited by: Erwan LE BRUN

Read only

0 Likes
1,640

Hi Erwan,

Don't we <i>usually</i> (not necessarily) make the date field obligatory in such cases ?

Regards,

Anand Mandalika.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,640

Hi,

Just try the following.It is meeting your requirement[allowed alphabets,letters,-].

parameter fname(37) type c.

data alphanumeric(37).

data ch(37).

data l type i.

AT SELECTION-SCREEN ON fname.

CONCATENATE '0123456789' sy-abcde INTO alphanumeric.

if fname CN alphanumeric .

l = strlen( fname ).

ch = fname.

do l times.

replace '-' with '0' into ch.

enddo.

if ch cn alphanumeric.

MESSAGE E005 with 'error'.

endif.

endif.