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

validate select-options ......?

former_member220286
Participant
0 Likes
3,630

when i am giving low and high values  in the slect-option.

select-options : order for vbak-vbeln.

then it must validate from a table that if the order no that user has entered exist or not..

i am giving range let say 4988 to 5100 and if an order no

4990 does not exist at backend then it  must return an error mesage..

how to validate here in ...select-options..............?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,710

Hi Deepak,

select-options : order for vbak-vbeln.

let say 4988 to 5100

TYPES: BEGIN OF TY_VBELN,

              VBELN TYPE EBELN,

               END OF TY_VBELN.

DATA : I_VBAK TYPE STANDARD TABLE OF TY_VBAK,

            I_Vvbak1 TYPE STANDARD TABLE OF TY_VBAK,

W_VBAK TYPE TY_VBAK,

W_VBAK TYPE TY_VBAK.

READ TABLE ORDER INDEX 1.

DO.

ORDER-LOW = ORDER-LOW + 1.

W_VBAK-VBELN = ORDER-LOW.

APPEND W_VBAK TO I_VBAK.

CLEAR W_VBAK.

IF ORDER-LOW = ORDER-HIGH.

EXIT.

ENDIF.

ENDDO.

above code contains all po number.

Now Select VBELN from VBAK table corresponding to the RANGE .

now use LOOP and READ

LOOP AT i_vbak into w_vbak.

NOW READ

READ TABLE I_VBAK1 INTO W_VBAK1 WITH KEY VBELN = W_VBAK-VBELN.

IF SY-SUBRC NE 0.

SHOW UR ERROR MESSAGE.

ENDIF.

ENDLOOP.

tRY THIS CODE.iT WILL WORK.

Thanks

Tarak

7 REPLIES 7
Read only

Former Member
0 Likes
1,710

hi,

          In this case, anyway you gonna get this value in variable order and put it in select query where condition..

check Sy-subrc for select query.. if it fails then throw an error message.. if it an ALV means it ll automatically move to next scrren for alv without values.. for stopping this..

SET SCREEN 0.

LEAVE SCREEN.

hope this helps,

Mathan R.

Read only

Former Member
0 Likes
1,710

Hi Deepak,

                If you want to check each number with-in the range the only possible way is to do a loop in the range, select values one-by-one and do a select query, but it is not feasible solution because you will have to hit database again and again.

Read only

satvik_panchal
Participant
0 Likes
1,710

Hello Deepak,

   U can do like this :

at selection-screen on order.
   if not order is initial.
     select vbeln from vbak up to 1 rows into vbak
                      where vbeln in order.
     endselect.


     if sy-subrc ne 0.
       message 'INVALID ORDER NO.' type 'E' display like 'I'.
     endif.
   endif.

Thanks and Regards,

Satvik

Read only

reachdebopriya
Active Participant
0 Likes
1,710

Hi Deepak,

Change the select-options as No-Extension/No-Intervals or else change it to parameter.

Otherwise we cannot validate all values as select options also involved exclusion or ranges.

OR

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_VBELN which is for plant.

  TYPE-POOLS sscr.

  DATA: ls_restrict TYPE sscr_restrict,

        ls_opt_list TYPE sscr_opt_list,

        ls_***      TYPE sscr_***.

  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_***-kind    = 'S'.

  ls_***-name    = 'S_VBELN'.

  ls_***-sg_main = 'I'.

  ls_***-sg_addy = ' '.

  ls_***-op_main = 'EQ'.

  ls_***-op_addy = 'EQ'.

  APPEND ls_*** TO ls_restrict-***_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'

    EXPORTING

      restriction = ls_restrict

    EXCEPTIONS

      OTHERS      = 1.

With Best Regards,

Debopriya Ghosh

Read only

Former Member
0 Likes
1,711

Hi Deepak,

select-options : order for vbak-vbeln.

let say 4988 to 5100

TYPES: BEGIN OF TY_VBELN,

              VBELN TYPE EBELN,

               END OF TY_VBELN.

DATA : I_VBAK TYPE STANDARD TABLE OF TY_VBAK,

            I_Vvbak1 TYPE STANDARD TABLE OF TY_VBAK,

W_VBAK TYPE TY_VBAK,

W_VBAK TYPE TY_VBAK.

READ TABLE ORDER INDEX 1.

DO.

ORDER-LOW = ORDER-LOW + 1.

W_VBAK-VBELN = ORDER-LOW.

APPEND W_VBAK TO I_VBAK.

CLEAR W_VBAK.

IF ORDER-LOW = ORDER-HIGH.

EXIT.

ENDIF.

ENDDO.

above code contains all po number.

Now Select VBELN from VBAK table corresponding to the RANGE .

now use LOOP and READ

LOOP AT i_vbak into w_vbak.

NOW READ

READ TABLE I_VBAK1 INTO W_VBAK1 WITH KEY VBELN = W_VBAK-VBELN.

IF SY-SUBRC NE 0.

SHOW UR ERROR MESSAGE.

ENDIF.

ENDLOOP.

tRY THIS CODE.iT WILL WORK.

Thanks

Tarak

Read only

Former Member
0 Likes
1,710

Hi,

use the event AT-SELECTION SCREEN, and there u want put the code for validation.Initially, you can select all the data for the input range , in an internal table, like;

select * from VBAK into IT_VBAK where vbeln in s_vbeln ( select option for VBELN)

Then, you can set a loop for the Range table and set a read check for each entry from the internal table IT_VBAK and display the error message accordingly.

BR

Nitin

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,710

If the table is small or the selection criteria are fine, there is no problem, else you should only perform some checks during actual execution (ie. when execution icon is pressed (or F8) and not when Enter pressed)

AT SELECTION-SCREEN ON so_range.

  CHECK sscrfields-ucomm EQ 'ONLI'

     OR sscrfields-ucomm EQ 'PRIN'.

  SELECT SINGLE field1 INTO workarea

    FROM table

    WHERE field1 IN so_range.

  IF sy-subrc NE 0.

    MESSAGE 'No data found for range'(900) TYPE 'E'.

  ENDIF.

In some cases you can even there select the whole data in an internal table.

Are you actually sure that you want to check gaps in number range in this kind of program. In this case for type numeric or type date fields (fields where data can be incremented via +1) you have to

- use FM SELECT_OPTIONS_RESTRICT to only allow values list and range

- sort the range, manage overlap (e.g. 1-10 +  5 =  1-10 and 1-10 + 5-12 =  1-12) can be done with a little logic and a loop (hint : new low value is lower or equal to previous high value)

- count the theoretical number or record to find

- execute the selection

- compare actual number of record extracted with theoretical number calculated

Regards,

Raymond