2015 May 30 9:11 AM
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?
2015 Jun 02 1:07 AM
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.
2015 May 30 10:19 AM
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 .
2015 May 30 10:25 AM
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 .
2015 May 30 3:39 PM
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 .
2015 May 30 3:38 PM
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.
2015 May 30 7:59 PM
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
2015 May 30 8:36 PM
2015 Jun 01 2:19 PM
Look at FM SELECT_OPTIONS_RESTRICT. It's documented and released.
Rob
2015 Jun 02 1:07 AM
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.