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: 

Select-Options Validation

former_member194669
Active Contributor
0 Kudos

I have selection option like the following


data : v_acti type char4
select-options: s_acti for v_acti obligatory.

Here user can enter value from 0000 to 9999

My requirement is to validate this Here user needs to allow values only from 2000 to 9999.

I have find following to do this :-->

(1). I have created a domain and put the value range as 2000 to 9999 and used that data element. ( This is not working and not giving error message if user enter value as 1000 in s_acti-low)

I know it can validated in "at selection screen" event . But the issue is here user can enter values <2000 or >9999 or ne 2000 like that . I find these combinations validations in the "at selection screen" more tedious.

Other possible way i saw is create an internal table with value ranging from 0000 to 1999 and value the selection option

s_acti as

 
loop at itab.
if itab-acti in s_acti.
  message e000(v1) with "Wrong Input"
endif. 
endloop.

But don't want above like

Finally my requirement is to make validation in at selection screen event if user values as < 2000 combination i have give an error message.

Moderators : please do not lock this thread i have searched this forum for nearest one answers, but could not find.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ,

You can use the following syntax in your program.

AT SELECTION-SCREEN ON S_ACTI.

IF ( s_acti-low not between '2000' and '9999' ) AND ( s_acti-HIGH not between '2000' and '9999' ).

MESSAGE.

ENDIF.

19 REPLIES 19

Former Member
0 Kudos

hi,

as mentioned in a thread:this may help u:

<< Moderator message - Cut and paste response from removed. Plagiarism is not allowed in SCN >>

Thanks & regards,

Edited by: Rob Burbank on Oct 28, 2011 10:51 AM

Former Member
0 Kudos

Hi ,

You can use the following syntax in your program.

AT SELECTION-SCREEN ON S_ACTI.

IF ( s_acti-low not between '2000' and '9999' ) AND ( s_acti-HIGH not between '2000' and '9999' ).

MESSAGE.

ENDIF.

Former Member
0 Kudos

Hi,

try this short code with MARA.


TABLES: MARA.
*
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
*
AT SELECTION-SCREEN.
*
  SELECT * FROM MARA WHERE MATNR IN S_MATNR.
    IF MARA-MATNR LT '000000000000000200'.
      MESSAGE E010 WITH 'Range not allowed'.
      EXIT.
    ENDIF.
  ENDSELECT.
*
START-OF-SELECTION.
  WRITE: / 'TEST'.

END-OF-SELECTION.
*

Hope it helps.

Regards, Dieter

kesavadas_thekkillath
Active Contributor
0 Kudos

Just only allow the user to enter a low and high range and restrict all other options ( NP,CP,NE,LE etc )using SELECT_OPTIONS_RESTRICT.

Kesav

former_member194669
Active Contributor
0 Kudos

All,

Point #1 Here for s_acti selection there is no table entries ( like mara or makt ) so selecting a value then validating is not possible.

0 Kudos

Hi,

another way is like this:


DATA: V_ACTI TYPE CHAR4.
*
SELECT-OPTIONS: S_ACTI FOR V_ACTI OBLIGATORY.
*
AT SELECTION-SCREEN.
*
  DO 1999 TIMES.
    IF SY-INDEX IN S_ACTI.
      MESSAGE E010 WITH 'Range not allowed'.
      EXIT.
    ENDIF.
  ENDDO.

START-OF-SELECTION.
  WRITE: / 'TEST'.
END-OF-SELECTION.

Regards, Dieter

Edited by: Dieter Gröhn on Oct 28, 2011 1:39 PM

0 Kudos

Dieter,

You suggestions worked very well. Only thing i have bothered is DO loop.

But i didn't find any other solution to this.

Thanks for reply.

Former Member
0 Kudos

tables:vbak,vbap.

types:begin of x_vbak,

vbeln type vbak-vbeln,

end of x_vbak.

data:it_vbeln type standard table of x_vbak,

wa_vbeln type x_vbak,

it_posnr type table of vbap,

rt_vbak type range of vbak-vbeln,

wrt_vbak like line of rt_vbak.

select vbeln

from vbak

into table it_vbeln.

wrt_vbak-low = '0000002000'.

wrt_vbak-sign = 'I'.

wrt_vbak-high = '0000009999'.

wrt_vbak-option = 'BT'.

append wrt_vbak to rt_vbak.

select vbeln

posnr

from vbap

into table it_posnr

where vbeln in rt_vbak.

write:/ 'data'.

try this example and do the same of your requiremnt

i have done this example its working.

surajarafath
Contributor
0 Kudos

Hi,

for validating SELECT-OPTIONS.

you need to use the particular data base table inside LOOP..... ENDLOOP

for HIGH, LOW as well as SIGN = 'EQ'..

Check the below code. sure it will help...

LOOP AT S_LIFNR.
    CHECK S_LIFNR-OPTION = 'EQ'.
    SELECT SINGLE * FROM LFA1
           WHERE
           MANDT = SY-MANDT AND
           LIFNR = S_LIFNR-LOW.
    IF SY-SUBRC NE 0.
      MESSAGE E101(06) WITH S_LIFNR-LOW.
      EXIT.
    ENDIF.
  ENDLOOP.

  LOOP AT S_LIFNR.
    CHECK S_LIFNR-OPTION = 'BT'.
    SELECT SINGLE * FROM LFA1
            WHERE
           MANDT = SY-MANDT AND
           LIFNR = S_LIFNR-LOW.
    IF SY-SUBRC NE 0.
      MESSAGE E101(06) WITH S_LIFNR-LOW.
      EXIT.
    ENDIF.
  ENDLOOP.

  LOOP AT S_LIFNR.
    CHECK S_LIFNR-OPTION = 'BT'.
    SELECT SINGLE * FROM LFA1
          WHERE
           MANDT = SY-MANDT AND
           LIFNR = S_LIFNR-HIGH.
    IF SY-SUBRC NE 0.
      MESSAGE E101(06) WITH S_LIFNR-HIGH.
      EXIT.
    ENDIF.
  ENDLOOP.

surajarafath
Contributor
0 Kudos

Hi,

for validating SELECT-OPTIONS.

you need to use the particular data base table inside LOOP..... ENDLOOP

for HIGH, LOW as well as SIGN = 'EQ'..

Check the below code. sure it will help...

LOOP AT S_LIFNR.
    CHECK S_LIFNR-OPTION = 'EQ'.
    SELECT SINGLE * FROM LFA1
            WHERE
           MANDT = SY-MANDT AND
           LIFNR = S_LIFNR-LOW.
    IF SY-SUBRC NE 0.
      MESSAGE E101(06) WITH S_LIFNR-LOW.
      EXIT.
    ENDIF.
  ENDLOOP.

  LOOP AT S_LIFNR.
    CHECK S_LIFNR-OPTION = 'BT'.
    SELECT SINGLE * FROM LFA1
           WHERE
           MANDT = SY-MANDT AND
           LIFNR = S_LIFNR-LOW.
    IF SY-SUBRC NE 0.
      MESSAGE E101(06) WITH S_LIFNR-LOW.
      EXIT.
    ENDIF.
  ENDLOOP.

  LOOP AT S_LIFNR.
    CHECK S_LIFNR-OPTION = 'BT'.
    SELECT SINGLE * FROM LFA1
           WHERE
           MANDT = SY-MANDT AND
           LIFNR = S_LIFNR-HIGH.
    IF SY-SUBRC NE 0.
      MESSAGE E101(06) WITH S_LIFNR-HIGH.
      EXIT.
    ENDIF.
  ENDLOOP.

Thanks & Regards,

SUJI.

Former Member
0 Kudos

I cant really believe that allmighty a®s has a problem with this!

If i understand you right, user can only enter 0000 to 9999.

What i would do is:

Make myself an internal table with values 0000 to 1999.

like following:


data begin of ls_number.
data number type i.
data end   of ls_number.
data lt_numbers type table of ls_number.
DO 1999 TIMES.
  ls_number-number = sy-index.
  append ls_number to lt_numbers.
ENDDO.
"add 0
ls_number-number = 0.
append ls_number to lt_numbers.

"now simulate a select
loop at lt_number into ls_number where number in so_number.
  "if you get here you got unallowed entries in your select option
  "process error message
  exit.
endloop.

If sy-subrc = 4.
  "all is fine
endif.

hope you got my drift.

0 Kudos

Florian,

This day not my day.i am totally drained !!

In my Initial post i am given the same solution, but QM come up with queries related DO loop for 0000 to 1999 itrations

so that it would get some expert opinions regarding that

a®s

Other possible way i saw is create an internal table with value ranging from 0000 to 1999 and value the selection option

s_acti as


loop at itab.
if itab-acti in s_acti.
  message e000(v1) with "Wrong Input"
endif. 
endloop.

0 Kudos

if s_acti-low <= 1999 .

MESSAGE 'wrong input' TYPE 'E'.

endif.

if s_acti-low >= 2000.

write : 'working fine'.

ENDIF.

Try This

Former Member
0 Kudos

@a®s - the issue I have with this is that in your original post, you set out your requirements, stating what you do and do not want; then after a number of people try to solve your problem, you mark as solved an answer which gives a solution that you specifically say you don't want and then assign nothing to the others.

I think it would have been better to assign a yellow star to each answer and close the thread as "closed but unanswered".

Rob

former_member194669
Active Contributor
0 Kudos

Rob,

I think you misunderstood my question in the initial post.

Other possible way i saw is create an internal table with value ranging from 0000 to 1999 and value the selection option s_acti as


loop at itab.
if itab-acti in s_acti.
  message e000(v1) with "Wrong Input"
endif. 
endloop.

But don't want above like

and also i mentioned in my initial post

know it can validated in "at selection screen" event . But the issue is here user can enter values <2000 or >9999 or ne 2000 like that . I find these combinations validations in the "at selection screen" more tedious.

My requirement is to avoid internal table in some manner, and the given the maximum points to user who given the answer close to resolve the issue.

Now i have made question "Closed but answered" and given points to each user who answered.

My explnation here is not to hurt anybody's intensions, who are giving answers.

I really thankful Rob for pointing out

0 Kudos

I think you misunderstood my question in the initial post.

Well, it certainly wouldn't be the first time

I really didn't mean anything personal - I was more thinking about the point system in general. Moderators see a lot of posts where points are assigned (if at all) to posts that are incorrect or irrelevant (not saying that this is the case here). So this skews a system that is already not helpful in the long run.

Rob

PS Since you did mark this as closed but unanswered, I couldn't respond to it originally. I had to mark it as un answered. You can change it back at your convenience.

arseni_gallardo
Active Participant
0 Kudos

post deleted by myself... someone had already suggested my solution.

Edited by: Arseni Gallardo on Oct 29, 2011 4:24 PM

Clemenss
Active Contributor
0 Kudos

Hi a®s,

SELECT-OPTIONS defines a complex filter. If you do not apply the filter to data, you have little chance to validate the filter.

The only way, I think ABAP is fast enough, may be to check all distinct values outside the desired range, in your case value^s from 0000 to 1999:

DATA lv_numc4 TYPE NUMC4.
while  lv_numc4 < 2000.
  IF lv_NUMC IN s_acti.
    MESSAGE TYPE 'E' 'Invalid range used - please restrict to 2000 to 9999'.
  ENDIF.
  ADD 1 TO lv_numc4.
ENDWHILE.

I'm convinced that will take less time than the user is able to notice even if 1999 is in the range.

Regards

Clemens

former_member194669
Active Contributor
0 Kudos

I researched a lot for this issue. SCN members given the closest answer to this issue. So i am closing this thread.

Thanks