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: 

Validating Multiple select-options entries against records maintained in DB Table

shubh7767
Explorer
1,552

I want to Validate multiple select-options entries (can be single value/ can be Range) against the Database table field having 2.5 million records. If select-options inputs successfully validate against the DB Table field particular logic should trigger. That logic will be different for each select-options entry. What should be my approach? I'm transferring select-options entries to the range table and looping it to get multiple select-options entries and using a select query separately to fetch data from the DB table providing the "where" condition for select-options entries.

15 REPLIES 15

1,358

Hi Bhagat, Here is a Sample Code to Validate the Multiple Select-options entries.

*Local Reference Structure.

TYPES: BEGIN OF gty_ekko,

ebeln TYPE ebeln,

bukrs TYPE bukrs,

bstyp TYPE ebstyp,

bsart TYPE esart,

ernam TYPE ernam,

END OF gty_ekko.

*"Declarations.

DATA: gv_ebeln TYPE ebeln,

gv_bukrs TYPE bukrs,

gs_ekko TYPE gty_ekko,

gt_ekko TYPE TABLE OF gty_ekko.

*"Selection Screen For MUltiple Select-Options

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_ebeln FOR gv_ebeln, s_bukrs FOR gv_bukrs.

SELECTION-SCREEN END OF block b1.

*Validating Ebeln Field

AT SELECTION-SCREEN on s_ebeln.

DATA lv_ebeln TYPE ebeln.

SELECT SINGLE ebeln

FROM ekko

INTO lv_ebeln

WHERE ebeln IN s_ebeln.

IF sy-subrc <> 0.

MESSAGE 'Invalid Purchase Order' TYPE 'E'.

ENDIF.

*Validating BUKRS Field

*"To Validate Multiple Input Select-Options, We can Use At Selection Screen event. but here Iam Validating Each Field Separately, So I have Taken At Selection On Event.

AT SELECTION-SCREEN on s_bukrs.

DATA lv_bukrs TYPE bukrs.

SELECT SINGLE bukrs

FROM ekko

INTO lv_bukrs

WHERE bukrs IN s_bukrs.

IF sy-subrc <> 0.

MESSAGE 'Invalid Company Code' TYPE 'E'.

ENDIF.

*Start Of Selection Event"

START-OF-SELECTION.

SELECT ebeln

bukrs

bstyp

bsart

ernam

FROM ekko

INto TABLE gt_ekko

WHERE ebeln in s_ebeln

AND bukrs in s_bukrs.

*End Of Selection Event.

*Printing Using Classic Report

END-OF-SELECTION.

LOOP AT gt_ekko INTO gs_ekko.

WRITE:/ gs_ekko-ebeln,

gs_ekko-bukrs,

gs_ekko-bstyp,

gs_ekko-bsart,

gs_ekko-ernam,

sy-uline.

ENDLOOP.

0 Kudos
1,358

Let me tell you in a more simple manner, in a nutshell I need to validate multiple entries of a select-options against a db table.

Sandra_Rossi
Active Contributor
0 Kudos
1,358

I think that the complexity of this question deserves more details to clarify what your issue is.

shubh7767
Explorer
0 Kudos
1,358

Hey Sandra, just have a look on my newly added comment to have more Clarity.

matt
Active Contributor
0 Kudos
1,358

This makes little sense.

SELECT * FROM table WHERE field IN range INTO TABLE itab.

Either returns sy-subrc 4 if there are no matches, or 0 if they are.

What exactly is your requirement? Don't simply repeat "Validate select options" - why are you needing to validate selection options? What is the end purpose of the program?

roberto_forti
Contributor
0 Kudos
1,358

Hi,

Using range[] "... table-field in s_xpto[]". In some cases, the report can display "error/dump" when retrieving (select) data because the data inserted into the range.

1,358

Hi Roberto, in my case it's working fine.

shubh7767
Explorer
0 Kudos
1,358

Hey Matthew, my requirement is if user enters any entry in select-options it should check against the records in db table. Select-options entry can be multiple and for each entry their individual logic should trigger. Any more specific you want from this please let me know!!!

matt
Active Contributor
0 Kudos
1,358

Thanks for the effort, but it's still sounds like "Validate select options"

What is wrong with:

SELECT * FROM table WHERE field IN range INTO TABLE itab.
IF sy-subrc IS NOT INITIAL.
" Your choices are not valid
ELSE.
" Your choices are valid
ENDIF.

Sure, you could loop over the select-option and check each condition individually, but select-options are to be considered as a whole - not individually.
What would you do with a select-option like this?

SIGN OPTION LOW HIGH
I EQ X
E EQ Y
I BT A* B*

matt
Active Contributor
0 Kudos
1,358

Also, once you've done the validation - if all is valid, what happens. What is the full purpose of your program?

shubh7767
Explorer
0 Kudos
1,358

validating select-options is done Matthew. but for each valid entry of select-options their own specific logic should trigger. to achieve this functionality, I'm struggling.

matt
Active Contributor
1,358

What exactly do you mean "For each valid entry their own specific logic should trigger"? Can you give some kind of example? I'm trying to help here, but the lack of information is making it difficult.

shubh7767
Explorer
0 Kudos
1,358

Sure, Matthew. Thanks for your efforts. Let me give you an example. I have a DB table having 100k to 2.5 million records. If from select-options I'm entering range e.g, 300k9low) to 500k(high) and 600k(low) to 900k(high) so for the first entry i.e. 300k-500k logic1 will trigger as it falls under the total records range maintained in DB Table(100k-2.5 million records) and for 600k-900k logic2 will also get trigger as this also maintained in DB Table. logic1 will differ from logic2, I'll going to write it later on.

matt
Active Contributor
1,358

So your select option looks like this:

I BT 300000 500000
I BT 600000 900000

I guess something like:

LOOP AT range ASSIGNING FIELD-SYMBOL(<range_line>).
  DATA(index) = sy-tabix.
  DATA(single_range) = VALUE #( <range_line> ).<br>  SELECT count( * ) INTO @DATA(count) FROM dbtable.
  DATA(counts) = VALUE ty_table_of_integers( ( count ) ).
  IF counts IN single_Range AND sy-tabix EQ 1.
    " logic 1
  ELSE.
    " logic 2
  ENDIF. 
ENDLOOP.

shubh7767
Explorer
0 Kudos
1,358

Hi Matthew, Thanks for your inputs. This will be going to help me for sure.