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

Input restriction selection option

Former Member
0 Likes
2,751

Hi All

I want to restrict Selection-option for mseg-werks.

now we have requirement that user can enter only the plant that start with either 24 or 25(this can be changed in future)

now since this can be change, we are getting it dynamicaly and making it as range i.e.User can enter value which is available in range (say r_werks )

so r_werks contains pattern like 24* or 25*.

now i want to put validation on selection-option so that only plant that satisfy the pattern in r_werks should be entered otherwise non satisfied plant number should be shown with error message.

How to do this?

1 ACCEPTED SOLUTION
Read only

former_member186741
Active Contributor
0 Likes
2,324

isn't this just a case of having the select-option and the range you require and the just selecting with an AND joining the two?

REPORT  ZNRW_TEST.
data: gv_werks type mseg-werks,
      gr_werks type range of mseg-werks,
      gs_werks like line of gr_werks,
      gt_werks type standard table of mseg-werks.

select-options s_werks for gv_werks.

initialization.
gs_werks-low = '72*'.
gs_werks-sign = 'I'.
gs_werks-option = 'CP'.
APPEND gs_werks TO gr_werks.

gs_werks-low = '10*'.
APPEND gs_werks TO gr_werks.

at selection-screen.
select werks from t001w
into table gt_werks
  where werks in s_werks
    and werks in gr_werks.

if sy-dbcnt = 0.
MESSAGE E086(ZC) WITH 'No valid plants found.'.
endif.

start-of-selection.

8 REPLIES 8
Read only

rosenberg_eitan
Active Contributor
0 Likes
2,324

Hi,

You can use SAP authorization.

Use or create authorization object that have WERKS as a parameter .

Sample code:

The code needs to go as part of "AT SELECTION-SCREEN ." event .

Regards .

Read only

0 Likes
2,324

Thanks Eitan  Rosenberg  for replying.

I can create authority check but I already put authority check for different validation on same and i want to do this validation by manual code how it is possible by coding .

Read only

0 Likes
2,324

Hi,

Another option:

Create a range table (R_werks) that will contain the allowed range .

put in R_werks the allowed range .

Select into internal table (it_T001W_1) from T001W based on R_werks .

Select into internal table (it_T001W_2) from T001W based on s_werks (the user input) .

Check that the values in it_T001W_2 must be in it_T001W_1 ("read table transporting no fields" can do the trick) .

Regards .

Note: The range table (R_werks) can be stored in a ztable or FI sets .

Read only

former_member185054
Active Participant
0 Likes
2,324

Hi Zubin,

in at selection screen event you can use this code.


REPORT  ZSAM_SCN_3749117.

tables t001w.

SELECT-OPTIONS s_werks for t001w-werks NO-EXTENSION.

loop at s_werks.

   IF s_werks-low+0(2) ne '10'.

     MESSAGE 'error' TYPE 'E'.

   ENDIF.

   IF s_werks-high+0(2) ne '10'.

     MESSAGE 'error' TYPE 'E'.

   ENDIF.

endloop.


with regards,

sampath kumar.

Read only

former_member184158
Active Contributor
0 Likes
2,324


Hi

can you try this , I have tested and it works for me, if I have understood your question as well.,


try to enter any number other 24* and 25*


it is allowed only 24* and/or 25* , others you will get an Error. or information message.











TABLES mseg.

SELECT-OPTIONS werk FOR  mseg-werks.

DATA lt_r_werks TYPE range_t_werks.

DATA lt_r_werks2 TYPE range_t_werks.

DATA ls_r_werks TYPE range_s_werks.

DATA lt_ltab TYPE TABLE OF ltap.

ls_r_werks-low = '24*'.

ls_r_werks-sign = 'I'.

ls_r_werks-option = 'CP'.

APPEND ls_r_werks TO lt_r_werks.

CLEAR ls_r_werks.

ls_r_werks-low = '25*'.

ls_r_werks-sign = 'I'.

ls_r_werks-option = 'CP'.

APPEND ls_r_werks TO lt_r_werks.

lt_r_werks2 = werk[].

START-OF-SELECTION.

   LOOP AT lt_r_werks2 INTO ls_r_werks.

     IF ls_r_werks-low CP '24*'

       OR ls_r_werks-low CP '25*'.

       CONTINUE.

     ELSE.

       MESSAGE 'It is allowed only plant 24* or 25*' TYPE 'I'.

       RETURN.

     ENDIF.

   ENDLOOP.

   SELECT * FROM ltap INTO TABLE lt_ltab

     WHERE werks IN werk.



Regards

Ibrahim


Read only

Former Member
0 Likes
2,324

This message was moderated.

Read only

Former Member
0 Likes
2,324

Look at FM SELECT_OPTIONS_RESTRICT. It's documented and released.

Rob

Read only

former_member186741
Active Contributor
0 Likes
2,325

isn't this just a case of having the select-option and the range you require and the just selecting with an AND joining the two?

REPORT  ZNRW_TEST.
data: gv_werks type mseg-werks,
      gr_werks type range of mseg-werks,
      gs_werks like line of gr_werks,
      gt_werks type standard table of mseg-werks.

select-options s_werks for gv_werks.

initialization.
gs_werks-low = '72*'.
gs_werks-sign = 'I'.
gs_werks-option = 'CP'.
APPEND gs_werks TO gr_werks.

gs_werks-low = '10*'.
APPEND gs_werks TO gr_werks.

at selection-screen.
select werks from t001w
into table gt_werks
  where werks in s_werks
    and werks in gr_werks.

if sy-dbcnt = 0.
MESSAGE E086(ZC) WITH 'No valid plants found.'.
endif.

start-of-selection.