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

SELECT-OPTIONS with single value

Former Member
0 Likes
10,194

Hello Experts,

Im having trouble in making my requirement, im just new in abap so please help me.

I have 3 SELECT-OPTIONS where in i need to put the values into my Internal table,,

my code works if i fill up both FROM and TO textboxs for example in POSITION. but if i will just fill the POSITION-LOW and leave blank to POSITION-HIGH,

it doesnt get the data that i need.

IF POSITION IS NOT INITIAL AND EMPSUB IS INITIAL AND EMPGROUP IS INITIAL.   "POSITION

       SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

         WHERE PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

     ELSEIF POSITION IS INITIAL AND EMPSUB IS NOT INITIAL AND EMPGROUP IS INITIAL. "EMPLOYEE SUB GROUP

       SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

         WHERE PERSK BETWEEN EMPSUB-LOW AND EMPSUB-HIGH.

     ELSEIF POSITION IS INITIAL AND EMPSUB IS INITIAL AND EMPGROUP IS NOT INITIAL.   "EMPLOYEE GROUP

       SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

         WHERE PERSG BETWEEN EMPGROUP-LOW AND EMPGROUP-HIGH.

     ELSEIF POSITION IS NOT INITIAL AND EMPSUB IS NOT INITIAL AND EMPGROUP IS NOT INITIAL.

       SELECT PERNR PERSK BEGDA

               INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

               FROM PA0001

               WHERE PERSG BETWEEN EMPGROUP-LOW AND EMPGROUP-HIGH

               AND PERSK BETWEEN EMPSUB-LOW AND EMPSUB-HIGH

               AND PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

     ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,241

Hi Jepoy,

"IN" is best option in your case , but if you want to use "BETWEEN" then write your code as below

IF POSITION-HIGH IS INITIAL .

  

    POSITION-HIGH = POSITION-LOW .

  

        SELECT PERNR PERSK BEGDA

          INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

          FROM PA0001

          WHERE PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

         

   ELSE.

        SELECT PERNR PERSK BEGDA

          INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

          FROM PA0001

          WHERE PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

            

ENDIF.

Note :

Still i suggested you go with "IN" Operator , Unnecessary "IF/ELSE" Increase in your code .

Regard's

Smruti

11 REPLIES 11
Read only

FredericGirod
Active Contributor
0 Likes
5,241

Hi,

SELECT-OPTIONS ...  NO-EXTENSION  NO INTERVALS

extension : no multiple value

intervals : no High value

regards

Fred

Read only

former_member188827
Active Contributor
0 Likes
5,241

Why dont you use "IN" in your where clasue.

  SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

WHERE PLANS IN POSITION.

Regards

Read only

former_member209120
Active Contributor
0 Likes
5,241

Hi Jepoy.

Try line this.....

While using select-option's we should use in

if you use between statement  low or high values, if you not enter any thing it will show error values

IF POSITION IS NOT INITIAL AND EMPSUB IS INITIAL AND EMPGROUP IS INITIAL.   "POSITION

       SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

         WHERE PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

         WHERE PLANS in POSITION.

     ELSEIF POSITION IS INITIAL AND EMPSUB IS NOT INITIAL AND EMPGROUP IS INITIAL. "EMPLOYEE SUB GROUP

       SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

         WHERE PERSK BETWEEN EMPSUB-LOW AND EMPSUB-HIGH.

         WHERE PERSK in EMPSUB.

     ELSEIF POSITION IS INITIAL AND EMPSUB IS INITIAL AND EMPGROUP IS NOT INITIAL.   "EMPLOYEE GROUP

       SELECT PERNR PERSK BEGDA

         INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

         FROM PA0001

         WHERE PERSG BETWEEN EMPGROUP-LOW AND EMPGROUP-HIGH.

WHERE PERSG in EMPGROUP.

     ELSEIF POSITION IS NOT INITIAL AND EMPSUB IS NOT INITIAL AND EMPGROUP IS NOT INITIAL.

       SELECT PERNR PERSK BEGDA

               INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

               FROM PA0001

               WHERE PERSG BETWEEN EMPGROUP-LOW AND EMPGROUP-HIGH

               AND PERSK BETWEEN EMPSUB-LOW AND EMPSUB-HIGH

               AND PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

          WHERE PERSG in EMPGROUP

               AND PERSK in EMPSUB

               AND PLANS in POSITION.


     ENDIF.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
5,241

The "most expected" SELECT for those select-options would be a single (read WHERE - sql_cond)

SELECT pernr persk begda
   INTO  CORRESPONDING FIELDS OF TABLE it_pa0001
   FROM pa0001
   WHERE plans IN  position
     AND persk IN empsub
     AND persg IN empgroup.

Of course you should also put those select-options in a SELECTION-SCREEN BLOCK and check AT SELECTION-SCREEN ON BLOCK that they are not initial.

Regards,

Raymond

Read only

Former Member
0 Likes
5,242

Hi Jepoy,

"IN" is best option in your case , but if you want to use "BETWEEN" then write your code as below

IF POSITION-HIGH IS INITIAL .

  

    POSITION-HIGH = POSITION-LOW .

  

        SELECT PERNR PERSK BEGDA

          INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

          FROM PA0001

          WHERE PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

         

   ELSE.

        SELECT PERNR PERSK BEGDA

          INTO  CORRESPONDING FIELDS OF TABLE IT_PA0001

          FROM PA0001

          WHERE PLANS BETWEEN POSITION-LOW AND POSITION-HIGH.

            

ENDIF.

Note :

Still i suggested you go with "IN" Operator , Unnecessary "IF/ELSE" Increase in your code .

Regard's

Smruti

Read only

Former Member
0 Likes
5,241

Thank you for the replies.

I did change my code to 'IN'

Read only

0 Likes
5,241

Hi Jepor,

Why my answer is not correct? Can I know the reason..

Read only

0 Likes
5,241

Hi ramesh,

I didnt say your answer was incorrect, it's just that most of the answers are the same.

Your answer is very helpful to me. thanks with that.

Read only

0 Likes
5,241

Hi Jepoy.

First you marked my answer as helpful after that you unmarked for that I questioned?

Read only

0 Likes
5,241

oh sorry with that, it's just my first time here and im exploring things

Read only

RaymondGiuseppi
Active Contributor
0 Likes
5,241

I would insist on IN operatot, try to input a wildcard in LOW value, what will happen, and if a user add an exclustion, or multiple lines...

You could use FM SELECT_OPTIONS_RESTRICT, so user will only be allowed to input ranges or single values, else that may and will generate errors, add in INITIALIZATION a code like :

* - ALL as default, everything allowed
CLEAR opt_list.
MOVE 'ALL' TO opt_list-name.
MOVE 'X' TO: opt_list-options-bt,
              opt_list-options-cp,
              opt_list-options-eq,
              opt_list-options-ge,
              opt_list-options-gt,
              opt_list-options-le,
              opt_list-options-lt,
              opt_list-options-nb,
              opt_list-options-ne,
              opt_list-options-np.
APPEND opt_list TO restrict-opt_list_tab.
* - Only single values and ranges allowed
CLEAR opt_list.
MOVE 'RAN' TO opt_list-name.
MOVE 'X' TO: opt_list-options-eq,
              opt_list-options-bt.
APPEND opt_list TO restrict-opt_list_tab.

* Affecting "modes" to select-options
* ALL by default
CLEAR ass.
MOVE: 'A' TO ass-kind,
       '*' TO ass-sg_main,
       'ALL' TO ass-op_main.
APPEND ass TO restrict-ass_tab.
* RAN to your criteria
CLEAR ass.
MOVE: 'S' TO ass-kind,
        'I' TO ass-sg_main, " No exclude
        'RAN' TO ass-op_main. " exact values and range
MOVE 'POSITION' TO ass-name.
APPEND ass TO restrict-ass_tab.
MOVE 'EMPSUB' TO ass-name.
APPEND ass TO restrict-ass_tab.
MOVE 'EMPGROUP' TO ass-name.
APPEND ass TO restrict-ass_tab.

* Execute FM
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
   EXPORTING
     restriction = restrict
   EXCEPTIONS
     OTHERS      = 1.

Regards,

Raymond