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

Select Options

Former Member
0 Likes
969

I have declared a select option on the Selection screen . The user may enter value on the screen and can also enter multiple ranges with the help of pushbutton on screen . All the values have to be validated from a ztable ( any value entered shuld be present in the Ztable) .

*Now , to check each and every value i loop at the select table , check if option = 'EQ'/"BT' and accordingly check the calue in the ztable.

*The problem is :

  • when I enter a valid value on the screen , I am allowed to go ahead and enter the ranges in the push button option . Now , if there is an

*invalid value in that range , the error message is displayed after i press f8 . I want the error message to be displayed before coming

*out of pushbutton screen . Also, in my present code, the value from the current select table loop gets copied to the selection screen values,

*thus overwriting any value entered on screen .

I have written all my validations in "At selection screen"

The code goes like this :

LOOP AT S_C_CODE.

----


*If the Select Table contains only a Single value (Only for low not for high) , then check its presence in Table <>

----


IF S_C_CODE-OPTION = 'EQ'.

SELECT SINGLE * FROM ZMAXCODE INTO ZMAXCODE WHERE MX_COMP_CODE EQ S_C_CODE-LOW.

IF SY-SUBRC <> 0.

MESSAGE E001 with v_low.

ENDIF.

ENDIF.

----


*If the Select Table contains a range , then check for presence in Table <> for each value in the range.

----


IF S_C_CODE-OPTION = 'BT'.

V_LOW = S_C_CODE-LOW.

V_HIGH = S_C_CODE-HIGH.

WHILE V_LOW <= V_HIGH.

SELECT SINGLE * FROM ZMAXCODE WHERE MX_COMP_CODE EQ V_LOW.

IF SY-SUBRC <> 0.

MESSAGE E001 with v_low.

ENDIF.

V_LOW = V_LOW + 1.

UNPACK V_LOW TO V_LOW.

ENDWHILE.

CLEAR V_LOW.

CLEAR V_HIGH.

ENDIF.

ENDLOOP.

*I would appreciate if anyone can help me with their experiences?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
878

It is not advisable to validate ranges because they are meant to include some valid and some invalid values. A range is a range. The reason why users want a range is because sometimes they just don't know the exact values. All they know that it lies in certain range.

Instead of trying to validate each entry, all you have to do is select entries against the Z table and if you find <b>none</b>, then only issue an error message.

6 REPLIES 6
Read only

Former Member
0 Likes
878

Hi

Try to do this way,

declare an internal table and when ever, the value doesn't exist, append that value to internal table and say 'CONTINUE' in loop.

After loop is over,

if internal table is not initial,

display an error message.

refresh both internal table and the select-options table.

hope this will solve your problem.

shylesh

Read only

Former Member
0 Likes
879

It is not advisable to validate ranges because they are meant to include some valid and some invalid values. A range is a range. The reason why users want a range is because sometimes they just don't know the exact values. All they know that it lies in certain range.

Instead of trying to validate each entry, all you have to do is select entries against the Z table and if you find <b>none</b>, then only issue an error message.

Read only

0 Likes
878

Srinivas is correct - you really need to look at the entire table. Users can also enter exclusions and CP and NE. It's hard to validate things like that.

Rob

Read only

0 Likes
878

Hi Rob/Srinivas,

I too agree with both of you very much and even i also do the same way as srinivas said. But if customer insist in that way, what can we do?

I just gave the solution, based on that.

let me know if i am wrong.

regards,

shylesh

Read only

0 Likes
878

Well, if the customer wants it that way you can tell them that it will take this amount of time to do it that way and the results may not be exactly what they were expecting; but you can do it the simpler way and it will be done more quickly and their testing chore will be simplified and the final product will be easier to use.

But your right; in the final analysis, it's their call.

Rob

Read only

0 Likes
878

A compromise could be that you provide the user with only LOW option to fill in and remove the ranges and exclude conditions. That way user will be forced to enter single values and you can validate each of them by looping at the select option.

I think your customer will understand the reason. Let the customer know that it is possible to say either you found values or didn't find values, but not the way they want it. Explain it to them with several examples to showcase how many variations there can be and how difficult it will be to validate each of those variations. Tell them SELECT-OPTIONS gives them the flexibility of entering ranges, excluding ranges, single values etc. Such a powerful flexibility comes with a small price of not being able to validate each and every value.

If they still insist, then you have to restrict their ability to enter 'EXCLUSIONS', and may be even ranges. Look at the function module 'SELECT_OPTIONS_RESTRICT'. There is very good documentation associated with it.

Here is an example using this function module where I restrict the users to just multiple single values for a select option called S_EXWRK which is for plant.


  TYPE-POOLS sscr.
  DATA: ls_restrict TYPE sscr_restrict,
        ls_opt_list TYPE sscr_opt_list,
        ls_ass      TYPE sscr_ass.

  CLEAR ls_opt_list.
  MOVE 'EQ'  TO ls_opt_list-name.
  ls_opt_list-options-eq = 'X'.
  APPEND ls_opt_list TO ls_restrict-opt_list_tab.
  ls_ass-kind    = 'S'.
  ls_ass-name    = 'S_EXWRK'.
  ls_ass-sg_main = 'I'.
  ls_ass-sg_addy = ' '.
  ls_ass-op_main = 'EQ'.
  ls_ass-op_addy = 'EQ'.
  APPEND ls_ass TO ls_restrict-ass_tab.
  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
      restriction = ls_restrict
    EXCEPTIONS
      OTHERS      = 1.