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: 

How to prevent the use of wild cards in select-option

Former Member
0 Kudos

Hello experts,

Is it possible to prevent the use of wild cards in a select-option? If yes, how is it done please?

I have a

SELECT-OPTIONS: o_comp  FOR dbtab-field OBLIGATORY DEFAULT 'FI'.

and, I want to prevent the users for giving in some thing like FI* with the wildcard bc it would lead to dump.

I want an error message to display and prevent the users for making such entry.

Please I need your help and I would be very grateful.

Thanks

Nadin

12 REPLIES 12

Former Member
0 Kudos

Hi,

U can give Conditions for not giving Wildcard Characters.

For Eg,

IF o_comp co '*'.

MESSAGE 'U should not Use Wildcard Characters for Input' TYPE 'I'.

else.

Select ....

endif.

Regards,

Padmam.

raymond_giuseppi
Active Contributor
0 Kudos

You have to use SELECT_OPTIONS_RESTRICT to restrict input allowed. Call this FM in INITIALIZATION or SELECTION-SCREEN OUPUT sections.

Sample :

TYPE-POOLS: sscr.

INITIALIZATION.

* Restrict SELECT-OPTIONS
  PERFORM restrict_select.

* (...)

FORM restrict_select.
  DATA: restrict TYPE sscr_restrict,
        opt_list TYPE sscr_opt_list,
        ass TYPE sscr_ass.
* Défine select-options modes (aka option list)
* - ALL standard - all options allowed
  CLEAR opt_list.
  MOVE 'ALL' TO opt_list-name.
  MOVE 'X' TO: opt_list-options-bt,
               opt_list-options-cp,
               opt_list-options-eq,
               opt_list-options-ge,
               opt_list-options-gt,
               opt_list-options-le,
               opt_list-options-lt,
               opt_list-options-nb,
               opt_list-options-ne,
               opt_list-options-np.
  APPEND opt_list TO restrict-opt_list_tab.
* - EQU only equality allowed (list of values)
  CLEAR opt_list.
  MOVE 'EQU' TO opt_list-name.
  MOVE 'X' TO opt_list-options-eq.
  APPEND opt_list TO restrict-opt_list_tab.
* Affect modes to parameters or block of parameters
* ALL by default
  CLEAR ass.
  MOVE: 'A'          TO ass-kind,
        '*'          TO ass-sg_main,
        'ALL'        TO ass-op_main.
  APPEND ass TO restrict-ass_tab.
* EQU to internal material number
  CLEAR ass.
  MOVE: 'S'          TO ass-kind,
        'S-MATNR'    TO ass-name,
        'I'          TO ass-sg_main, " no exclusion
        'EQU'        TO ass-op_main. " only value list
  APPEND ass TO restrict-ass_tab.
* Call  FM
  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
       EXPORTING
            restriction = restrict
       EXCEPTIONS
            OTHERS      = 1.
ENDFORM.                    " restrict_select

In the sample, only select-options for matnr is restricted to single value list.

For your request build a mode with all options except "pattern" ones : CP and NP.

Regards

0 Kudos

Hi Raymond,

could you please explain what comes here:

* EQU to internal material number
  CLEAR ass.
  MOVE: 'S'          TO ass-kind,
        'S-MATNR'    TO ass-name,
        'I'          TO ass-sg_main, " no exclusion
        'EQU'        TO ass-op_main. " only value list

and how I could implement this in my case.

Thank you

Nadin

Former Member
0 Kudos

Try this: -

AT SELECTION-SCREEN on o_comp.

if o_comp-low ca '' or o_comp-high ca ''.

message i000 with 'No * please!'.

endif.

Former Member
0 Kudos

hi

good

you cant give a default value for the select-options as you have given here,you must have to give the default value within the single cotes.

thanks

mrutyun^

Former Member
0 Kudos

Hi,

You can use like below :

SELECT-OPTIONS: o_comp  FOR dbtab-field OBLIGATORY DEFAULT 'FI'.

at selection-screen.

if o_comp-low CP '*' or o_comp-high CP '*'.

message 'Should not input wild cards' type 'E'.

Endif.

Thanks,

Sriram Ponna.

0 Kudos

Thank you Padman, Thank you Raymond, Thank Sriram,

I have used some of the options provided like:

AT SELECTION-SCREEN ON o_comp.
  IF o_comp-low CP '*' OR o_comp-high CP '*'.
*  IF o_comp-low CA '*' OR o_comp-high CA '*'.
* exit.
    MESSAGE 'This form is not supported' TYPE 'I' DISPLAY LIKE 'E'.   
  ENDIF.

But still the program is executed after the message is displayed. I have even use an exit but the program is still executed after the message is displayed and I click the ok button on the message. This is not good. I would like to try Raymond's option with the FM but could you please explain what you mean by mode? how is the mode built in my case? Thank you all for the input.

0 Kudos

Hi

Try this. It will work for sure.

AT SELECTION-SCREEN on o_comp.

Loop at o_comp where option = 'CP'.

message e000 with 'Patterns not allowed'.

Endloop.

Regards

Navneet

0 Kudos

For your request build a "no pattern" like

* - NOP - No pattern - no wildcard allowed
  CLEAR opt_list.
  MOVE 'NOP' TO opt_list-name.
  MOVE 'X' TO: opt_list-options-bt,
               opt_list-options-eq,
               opt_list-options-ge,
               opt_list-options-gt,
               opt_list-options-le,
               opt_list-options-lt,
               opt_list-options-nb,
               opt_list-options-ne.

Create this option list and the ALL one of my sample and affect ALL to all select-options and NOP to o_comp.

Also SELECT-OPTIONS are RANGEs, internal tables in fact, so you have to LOOP AT them and check each and every records...

Regards

0 Kudos

Thank you all for have provided your expert knowledge. I used Sriram idea and it worked perfectly. The only statement lacking was Leave Screen after the message so that the program should not continue to execute. I had a couple of trouble implementing Raymond's FM. I think it's because i am still a freshman in ABAP. I would continue to exploit and test Raymond's idea with the FM still it works.

I have therefore provided points to Sriram bc his idea was the closest in solving my problem.

This is the coding:

SELECT-OPTIONS: o_comp  FOR dbtab-field OBLIGATORY DEFAULT 'FI'.

AT SELECTION-SCREEN ON o_comp.
  PERFORM restrict_select.

FORM restrict_select .
DATA w_comp LIKE LINE OF o_comp.
  LOOP AT o_comp WHERE option = 'CP'.
    MESSAGE comes here.
    LEAVE SCREEN.
  ENDLOOP.
ENDFORM.                    " restrict_select

Once more thank you all.

Nina

0 Kudos

Don't forget wildcard exclusion

LOOP AT o_comp WHERE option = 'CP' OR option = 'NP'.

Regards

0 Kudos

Hi

The solution you had used was given by me and also the points were awarded to me and not sriram as mentioned.

LEAVE SCREEN is not required as I have given an error message and not Information messgae. So, the program will never go to Start-of-selection.

Regards

Navneet