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

Re: Select-Option

hitesh2
Participant
0 Likes
1,264

Hi,

I have select-option and records in internal table. User inputs values in select-options. If value doesn't exist in internal table. i want to give error message. How can i do this.

Thanks,

Hitesh

8 REPLIES 8
Read only

Former Member
0 Likes
793

Hi Hitesh,

Try this option.

loop at <internal table> where not in <select option name>.

  • Generate an error message

message e000 with 'Selection screen values not available'.

endloop.

Selvapandian

Read only

0 Likes
793

Hi Selvapadian,

This Syntax " where not in " gives me error. Since select-options has low and high values.

loop at <internal table> where not in <select option name>.

  • Generate an error message

message e000 with 'Selection screen values not available'.

endloop.

Thanks,

Hitesh

Read only

0 Likes
793

Hi Hitesh,

Below is the sample code:

Let me know if any problem.

REPORT ZEXAM message-id <z>.

tables: mara.

select-options s_matnr for mara-matnr.

data: it like mara occurs 0 with header line.

select * from mara into table it.

loop at it where not matnr in s_matnr.

message e000.

endloop.

Read only

Former Member
0 Likes
793

Hi Hitesh,

I am not sure when you filled your internal table. If you filled your internal table in the INITIALIZATION event, then you can do the validation in AT SELECTION-SCREEN event. If you fill the internal table in START-OF-SELECTION event, you can validate it there.

Remember a select option can be a range of values or just single values or combination of both. So logically even if one value out of the select option values is valid, the user should not be given an error message. Only if all the values in the select-option are invalid, then the user should get the error message.

Now coming to the logic of validating the select option, you need to get all the possible values for the given select option into another internal table. Then you need to loop at both the internal tables to validate the select option. I don't see any other option unless your requirement is something else.

Does your select option refer to a database table? Please give more details about your select option type and the contents of the internal table.

Srinivas

Read only

0 Likes
793

Hi Srinivas,

My select option does not refer to a database table.

In my senario user inputs values in Select-option and my internal tables gets filled from custom RFC function.

Only way i can validate is by getting all possible values for given select option into another internal table. Can you give me example that will bring all the possible values into another internal table.

I appreciate your help.

Thanks,

Hitesh

-


Read only

0 Likes
793

Hi Hitesh,

How did you define your select-option? Is it char or numc or some other type and what length? It will be difficult to convert the range to a single value list if there is no database table associated with it. I would suggest that you change your select option to a select option with only single values. Here is how you define your select option.

select-options: s_abc for v_abc.

and then in your initialization event use this code.


  v_repid = <your program name>.
  clear s_opt_list_tab.
  move: 'JUST_EQ' to s_opt_list_tab-name,
        'X'       to s_opt_list_tab-options-eq.
  append s_opt_list_tab to s_restriction-opt_list_tab.

  clear s_ass_tab.
  move: 'S'        to s_ass_tab-kind,
        'S_ABC'    to s_ass_tab-name,
        'I'        to s_ass_tab-sg_main,
        ' '        to s_ass_tab-sg_addy,
        'JUST_EQ'  to s_ass_tab-op_main,
        'JUST_EQ'  to s_ass_tab-op_addy.
  append s_ass_tab to s_restriction-ass_tab.
*-- set the selection screen
  call function 'SELECT_OPTIONS_RESTRICT'
    exporting
      program                      = v_repid
      restriction                  = s_restriction
*     DB                           = ' '
   exceptions
      too_late                     = 1
      repeated                     = 2
      selopt_without_options       = 3
      selopt_without_signs         = 4
      invalid_sign                 = 5
      empty_option_list            = 6
      invalid_kind                 = 7
      repeated_kind_a              = 8
      others                       = 9.
  if sy-subrc <> 0.
    message id sy-msgid type 'W' number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

Required data declarations for the above code are

type-pools: sscr.

data: s_restriction type sscr_restrict,

s_opt_list_tab type sscr_opt_list,

s_ass_tab type sscr_ass,

v_repid like sy-repid.

This will restrict the user to just enter values in the select option low field.

Then you can validate it using the following code.

loop at s_abc.

read table itab with key field = s_abc-low.

if sy-subrc <> 0.

message.

endif.

endloop.

Hope this helps,

Srinivas

Read only

0 Likes
793

Srinivas,

Sorry, my select option do refer to database.

SELECT-OPTIONS s_del FOR likp-vbeln. this values i need to check against the values in internal table. This Internal table gets value from Custom RFC function.

Thanks,

Hitesh

Read only

0 Likes
793

In that case do something like this.


DATA: v_vbeln LIKE likp-vbeln.

SELECT-OPTIONS: s_vbeln FOR v_vbeln.

DATA: BEGIN OF itab OCCURS 0,
        vbeln LIKE likp-vbeln.
DATA: END OF itab.

DATA: BEGIN OF rfc_itab OCCURS 0,
        vbeln LIKE likp-vbeln.
DATA: END OF rfc_itab.

START-OF-SELECTION.

  SELECT vbeln INTO TABLE itab
               FROM likp
              WHERE vbeln IN s_vbeln.

  LOOP AT itab.
    READ TABLE rfc_itab WITH KEY vbeln = itab-vbeln.
    IF sy-subrc <> 0.
*-- delete the record
      DELETE itab.
    ENDIF.
  ENDLOOP.

*-- check if there is atleast one record left after validation
  READ TABLE itab INDEX 1.
  IF sy-subrc <> 0.
*-- none of the user selections are valid. Issue error message.
  ENDIF.