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 strange behavior

Former Member
0 Likes
2,344

Hi All

I am facing a very interesting problem , like I have select options and I pass value as ‘001’, ‘003’, ‘005’, ‘006’, ‘008’, ‘011’ . I was checking this field in if condition , the value of checking variable in ‘0016’.

My statement is like that

If table-filed in s_field (select option)

If sy-subrc = 0 .

*Do something

Endif.

Endif.

The interesting thing is table-field = ‘0016’ which is not in selection-options table the value are ‘001’, ‘003’, ‘005’, ‘006’, ‘008’, ‘011’. But its still giving the subrc = 0 .

As when I am debugging I only can see these above value in s_field-low

Why? Its giving subrc = 0 and coming in …

Please explain as I am lost

Waiting

Bye

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,306

How is your select option defined?

How is your select option defined?

23 REPLIES 23
Read only

Former Member
0 Likes
2,306

Hi,

Why dont you do a loop at s_field rather than if condition.& regarding sy-sybrc ,the vaule might be stored from any previous statement.IF conditions doesnt return any sy-sybrc.

Or you can use a Check statement.

Read only

0 Likes
2,306

Yes it’s populated on screen.....

I have used the CHECK statement, it’s just a start of program and I am checking validation and I am more interested why it’s doing. I may use lot of other option but I am thinking why it’s doing?

I really appreciate your answer and Advise .

Thanks

Bye

Message was edited by: Suleman Javed

Read only

0 Likes
2,306

Sy-subrc is 0 ie initialized & it is showing that value.It has no effect from the IF condition,as it doesnt return any sy-subrc.

Read only

Former Member
0 Likes
2,306

HI,

How is the select-option populated? is it being populated on the selection screen ? or is it being populated programatically? if it populated programatically then for individuals values you need to do something like this...

S_field-sign = 'I'.

s_field-option = 'EQ'

s_field-low = '001'.

append s_field.

S_field-sign = 'I'.

s_field-option = 'EQ'

s_field-low = '002'.

append s_field. and so on..

if it was enetered on the sel. screen while running, then it is a mystery why it behaving this way...

btw...why did you have to check the sy-subrc value ? it will not be affected by the if condition.

IF you already did/knew this ..pls ignore my reply...

Thanks,

Renjith.

Read only

Former Member
0 Likes
2,307

How is your select option defined?

Read only

0 Likes
2,306

DATA :v_field like PERNR-WERKS.

select-options: s_field for v_field .

I much interested why it’s passing the selection even if it’s wrong

Read only

0 Likes
2,306

PERNR-WERKS is a character field and so 0016 is a value in the range 001 to 011. But if you have the select option values as single values, then it will fail.

See the code below.


REPORT zreport NO STANDARD PAGE HEADING MESSAGE-ID zfi
                                        LINE-COUNT 65
                                        LINE-SIZE 120.

DATA :v_field LIKE pernr-werks.

SELECT-OPTIONS: s_field FOR v_field .

INITIALIZATION.
  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '001'.
  APPEND s_field.

  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '002'.
  APPEND s_field.

  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '003'.
  APPEND s_field.

  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '005'.
  APPEND s_field.
  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '006'.
  APPEND s_field.

  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '008'.
  APPEND s_field.

  s_field-sign = 'I'.
  s_field-option = 'EQ'.
  s_field-low = '011'.
  APPEND s_field.

START-OF-SELECTION.

  IF '0016' IN s_field.
    MESSAGE i000 WITH 'I passed the test'.
  ELSE.
    MESSAGE i000 WITH 'I failed the test'.
  ENDIF.

This will result in the message 'I failed the test'. But if you delete my initialization selections and enter '001' in the 'from' field and '011' in the 'to' field, you will get the message 'I passed the test', because now you are giving a range of values and 0016 is in that range.

Hope this clarifies.

Srinivas

Read only

0 Likes
2,306

Hi Srinivas,

It will display the message 'I failed the test' only,

but if it is failing also SY_SUBRC = 0.

Read only

0 Likes
2,306

You explain it pretty good . I am populating values in selection screen , and all values are in s_field-low . When I debug the structure I can see it in low.

but as you said ...

START-OF-SELECTION.

IF '0016' IN s_field.

MESSAGE i000 WITH 'I passed the test'.

ELSE.

MESSAGE i000 WITH 'I failed the test'.

ENDIF.

<b>This will result in the message 'I failed the test'. But if you delete my initialization selections and enter '001' in the 'from' field and '011' in the 'to' field, you will get the message 'I passed the test', because now you are giving a range of values and 0016 is in that range.</b>

But its working in both cases if you are populating fields on screen..Strange?

Read only

0 Likes
2,306

The plant field in R/3 is a 4 character field and is always zero filled left. Meaning that plants are stored in the database as....

0001

0002

0011

0016

Since you are not putting the full value in the select-option fields, you are getting inconsistant results, in order to fix this problem, you should be entering 0001 in the from field and 0011 into the to field. Then the check will be consistant.

If you are concerned that the user will not enter these values correctly, you can convert them on the fly.



report  zrich_0001.

data :v_field type werks_d.

select-options: s_field for v_field .

initialization.

start-of-selection.

<b>  loop at s_field.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = s_field-low
      importing
        output = s_field-low.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = s_field-high
      importing
        output = s_field-high.

    modify s_field.

  endloop.</b>

  if '0016' in s_field.
    message i001(00) with 'I passed the test'.
  else.
    message i001(00) with 'I failed the test'.
  endif.


Regards,

Rich Heilman

Read only

0 Likes
2,306

Hi Suleman,

It seems to pass because you had been giving the value range as 'From 001 TO 011'. As it is a character field of 4 in length, it is taking the range as 'From 0010 TO 0110'. It is not just passing 0016 but it seems to pass all others upto 0109(I here mean from 0011 to 0109 and funniest part is it fails 0009 which it actually should pass. Enjoy!!!

Regards,

Srikanth

Message was edited by: Srikanth Lodd

Message was edited by: Srikanth Lodd

Read only

0 Likes
2,306

The Actual code is looks like

If table-filed in s_field. " (select option)

else.

Reject.

ENDIF.

Even if I am not populating value on selection screen '0016'. Still its not going to reject .But you guys give a nice overlook. Thanks to every body.

Read only

0 Likes
2,306

Hi Suleman,

I just worked on it & its working fine.Below is my code.

tables: mard.

select-options: s_werks for mard-werks.

DATA: V_FLED LIKE MARD-WERKS VALUE '0016'.

IF V_FLED IN S_WERKS.

WRITE:/ 'PLANT PRESENT'.

ELSE.

WRITE:/ 'PLANT NOT PRESENT'.

ENDIF.

Read only

0 Likes
2,306

You are populating values on screen?if you are giving value on selection screen as Single values '0001','0005',

'0007','0009','0012','0015'.

Then checking your code ?

DATA: V_FLED LIKE MARD-WERKS VALUE '0016'.

IF V_FLED IN S_WERKS.

WRITE:/ 'PLANT PRESENT'.

ELSE.

WRITE:/ 'PLANT NOT PRESENT'.

ENDIF.

Is it working?

Message was edited by: Suleman Javed

Read only

0 Likes
2,306

..

Message was edited by: Suleman Javed

Read only

0 Likes
2,306

Yes Absolutely...Its working fine for me..am getting "PLANT NOT PRESENT".

Read only

0 Likes
2,306

Thanks for you all...

I am done ..!!!

Thanks again...

Read only

0 Likes
2,306

Please close the post.

Thanks,

Srinivas

Read only

0 Likes
2,306

How I close the post Here ?

Read only

0 Likes
2,306

If you select the solved problem radio-button,then the posting will close.

Read only

0 Likes
2,306

You just did that and I think you reversed it.

Read only

govind_seenivasan
Participant
0 Likes
2,306

Hi,

Actullay the IF statement don't make any diffence in SY-SUBRC even the condition is true or false.

In your case is it processing the steps between "IF SY-SUBRC eq 0 and ENDIF"?

Thanks

Read only

former_member186741
Active Contributor
0 Likes
2,306

I'm guessing that your code fragment is inaccurate and the reason it's 'doing something' is because 'IF' does not set a non-zero RC when it fails. Is your code really like this?

.................

If table-filed in s_field. " (select option)

ENDIF.

If sy-subrc = 0 .

*Do something

Endif.

.................

I think it simply needs to be coded like this:

.................

If table-filed in s_field. " (select option)

*Do something

Endif.