Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Thursday, February 21, 2008

Restricting the selection screen using sap abap

When you create a select-option for an input to your program, for each field, the default selection screen looks like this:

And the default possible selections are:

but sometime you don't want to give the user the possibility to select a range, select values "greater than", etc.
     
Here is a small example on how to do it:
     
REPORT ZDANY_RESTRICT_SELECTION.
     
* Include type pool SSCR
    TYPE-POOLS sscr.
    TABLES : sflight.
     
* defining the selection-screen
    select-options :
        s_carrid for sflight-carrid,
        s_connid for sflight-connid.
     
* 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 carrid 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_carrid'.
    ass-sg_main = 'I'.
    ass-sg_addy = space.
    ass-op_main = 'OBJECTKEY1'.
    APPEND ass TO restrict-ass_tab.
     
* Restricting the connid 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_connid'.
    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.
     
when you execute this piece of code, you will notice that for carrid, the selection screen is now restricted :


When you create a select-option for an input to your program, for each field, the default selection screen looks like this:

And the default possible selections are:

but sometime you don't want to give the user the possibility to select a range, select values "greater than", etc.
     
Here is a small example on how to do it:
     
REPORT ZDANY_RESTRICT_SELECTION.
     
* Include type pool SSCR
    TYPE-POOLS sscr.
    TABLES : sflight.
     
* defining the selection-screen
    select-options :
        s_carrid for sflight-carrid,
        s_connid for sflight-connid.
     
* 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 carrid 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_carrid'.
    ass-sg_main = 'I'.
    ass-sg_addy = space.
    ass-op_main = 'OBJECTKEY1'.
    APPEND ass TO restrict-ass_tab.
     
* Restricting the connid 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_connid'.
    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.
     
when you execute this piece of code, you will notice that for carrid, the selection screen is now restricted :

No comments:

Post a Comment

Content

Recent Topics