SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Restrict SELECT-OPTIONS



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 22, 2007 6:32 pm    Post subject: Restrict SELECT-OPTIONS Reply with quote

Code:
REPORT sy-repid.
*Sample code to show how to use FM to restrict SELECT-OPTIONS.
*bt cp eq ge gt le lt nb ne np are the 10 options to choose from.
*To use in Dialog, put in PBO. For ABAP, put in initialization.

*This FM is quite well documented. Most of the comments here are from
*the online doco. There is also sample code in the doco.
TABLES: kna1.
TYPE-POOLS: sscr.
selection-screen begin of block AA with frame.
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr,
                s_land1 for kna1-land1.
selection-screen end of block AA.
selection-screen begin of block BB with frame.
SELECT-OPTIONS: s_name1 FOR kna1-name1,
                s_name2 for kna1-name2.
selection-screen end of block BB.

DATA: l_restrict TYPE sscr_restrict.
DATA: l_opt_list TYPE sscr_opt_list.
DATA: l_ass TYPE sscr_ass.

INITIALIZATION.
  CLEAR l_opt_list.
* You can call 'name' anything. Can be descriptive such as EQ_ONLY or
* NO_INTERV Max 10. Can do multiple names for different combos if req'd.
  l_opt_list-name = 'EQ_ONLY'.
  l_opt_list-options-eq = 'X'.
  APPEND l_opt_list TO l_restrict-opt_list_tab.

* l_ass-kind            A(ll), B(lock), S(elect-Option)
* A - Applies to all sel options. B all sel options within the block
* (name of block goes into NAME). S - specific sel option named.
* l_ass-name           Blank for A(ll). Block name or Sel Option name
* l_ass-sg_main  'I': Only sign 'I' allowed on the main selection screen
*                '*': No restriction for main scren
* l_ass-sg_addy  ' ' Apply same restriction to multiple selection screen
* ^Optional^     '*' No restriciton for multiple selection screen
*                'N' Multiple selections not allowed
* l_ass-op_main        The field with the restrictions
* l_ass-op_addy        Name of field with option list for multi select
* ^Optional^

  CLEAR l_ass.
  l_ass-kind = 'B'.
  l_ass-name = 'AA'.
  l_ass-sg_main = '*'.
  l_ass-op_main = 'EQ_ONLY'.
  APPEND l_ass TO l_restrict-ass_tab.

  l_ass-kind = 'B'.
  l_ass-name = 'BB'.
  l_ass-sg_main = 'I'.                "'I' will override 'NB' option
  l_ass-op_main = 'EQ_ONLY'.
  APPEND l_ass TO l_restrict-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
       EXPORTING
            restriction = l_restrict
       EXCEPTIONS
            OTHERS      = 1.


START-OF-SELECTION.
  WRITE: / s_kunnr.


The function module SELECT_OPTIONS_RESTRICT can be used for restricting possible selection options and signs. By calling this function module, we can restrict the number of selection options available for a field. For more information,refer to the function module documentation.

Code:
REPORT selectoptionsrestrict.

* Author   :  Lakshmi Sunitha
* Date     :  February 19, 2003

* Include type pool SSCR
TYPE-POOLS sscr.

TABLES :
  marc.

* defining the selection-screen
select-options :
  s_matnr for marc-matnr,
  s_werks for marc-werks.

* Define the object to be passed to the RESTRICTION parameter
DATA restrict TYPE sscr_restrict.

* Auxiliary objects for filling RESTRICT
DATA : optlist TYPE sscr_opt_list,
           ass type sscr_ass.

INITIALIZATION.

* Restricting the MATNR selection to only EQ and 'BT'.
  optlist-name = 'OBJECTKEY1'.
  optlist-options-eq = 'X'.
  optlist-options-bt = 'X'.
  APPEND optlist TO restrict-opt_list_tab.

  ass-kind = 'S'.
  ass-name = 'S_MATNR'.
  ass-sg_main = 'I'.
  ass-sg_addy = space.
  ass-op_main = 'OBJECTKEY1'.
  APPEND ass TO restrict-ass_tab.

* Restricting the WERKS selection to CP, GE, LT, NE.
  optlist-name = 'OBJECTKEY2'.
  optlist-options-cp = 'X'.
  optlist-options-ge = 'X'.
  optlist-options-lt = 'X'.
  optlist-options-ne = 'X'.
  APPEND optlist TO restrict-opt_list_tab.

  ass-kind = 'S'.
  ass-name = 'S_WERKS'.
  ass-sg_main = 'I'.
  ass-sg_addy = space.
  ass-op_main = 'OBJECTKEY2'.
  APPEND ass TO restrict-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
   EXPORTING
    restriction                  = restrict
   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 SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.