Application Development 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: 

Can you "combine" criteria for 2 or more fields on a Selection Screen?

former_member210148
Participant
0 Kudos

Good day everyone,

Here's my question: I understand that I can put fields on a Selection Screen and pre-fill them with data values. In this particular case, I want to pre-fill a couple of hidden fields with data values that will be used as criteria when I read data from the database; however, I need to pull back records that have this COMBINATION of data. For example:

WERKS BTRTL

Z002 Z001

Z002 Z002

Z003 Z001

Z003 Z002

So in my SQL, if I say "werks IN s_werks" and "btrtl IN s_brtrl", true, it will still work. But really, I need to say "if werks = 'z002' and btrtl = 'z001', or werks = 'z002' and btrtl = 'z002', etc. I can't rely on the simple "IN" functionality because it's possible a new value could be added in the future:

WERKS BTRTL

Z003 Z003

So if I use the "IN" logic and the record has werks = 'Z002' and btrtl = 'Z003', it would be returned. But I really don't want it returned, since a combination of werks = 'Z002' and btrtl = 'Z003' doesn't exist in my table of valid combinations.

Is this even possible to do in a Selection Screen? Do I go ahead and populate the fields separately, use the "IN" functionality, then spin through my resulting internal table and delete anything that doesn't match my "table" of valid combinations? Do I skip putting these on a Selection Screen completely and check the values in my SQL statement?

Thanks in advance -- points, as always, will be given.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Yuo can try to use FOR ALL ENTRIES option.

IF you have:

WERKS BTRTL

Z002 Z001

Z002 Z002

Z003 Z001

Z003 Z002

You should do something like that:

DATA: BEGIN OF <TAB_SEL> OCCURS 1,

WERKS TYPE WERKS,

BTRTL TYPE BTRTL,

END OF <TAB_SEL>.

WERKS BTRTL

<TAB_SEL>-WERKS = 'Z002'. <TAB_SEL>-BTRTL = 'Z001'.

APPEND <TAB_SEL>.

<TAB_SEL>-WERKS = 'Z002'. <TAB_SEL>-BTRTL = 'Z002'.

APPEND <TAB_SEL>.

<TAB_SEL>-WERKS = 'Z003'. <TAB_SEL>-BTRTL = 'Z001'.

APPEND <TAB_SEL>.

<TAB_SEL>-WERKS = 'Z003'. <TAB_SEL>-BTRTL = 'Z002'.

APPEND <TAB_SEL>.

SELECT * FROM <TABLE> INTO TABLE ITAB

FOR ALL ENTRIES IN <TAB_SEL>

WHERE WERKS = <TAB_SEL>-WERKS

AND BTRTL = <TAB_SEL>-BTRTL.

In this case you need to fill correctly the internal table <TAB_SEL> with the all combinations.

Max

8 REPLIES 8

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I think you may be confused. The IN functionality will definitly work for you.

  s_werks-sign   = 'I'.
  s_werks-option = 'EQ'.
  s_werks-low    = 'Z002'.
  append s_werks.
  s_werks-sign   = 'I'.
  s_werks-option = 'EQ'.
  s_werks-low    = 'Z003'.
  append s_werks.

  s_btrtl-sign   = 'I'.
  s_btrtl-option = 'EQ'.
  s_btrtl-low    = 'Z001'.
  append s_btrtl.
  s_btrtl-sign   = 'I'.
  s_btrtl-option = 'EQ'.
  s_btrtl-low    = 'Z002'.
  append s_btrtl.

where werks in s_werks
  and btrtl in s_btrtl.

By saying this the values of werks must be Z002 or Z003 and the BTRTL must either be Z001 or Z002. If you do not put anything in the S_BTRTL, then your concern would be valid. But since you are prefilling the S_BTRTL, it will work.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Dave,

In the selection screen u can supress the ranges by giving no-intervals.so instead of ranges u can give some values by clicking on the arrow at the end

SELECT-OPTIONS: S_WERKS FOR ZTAB-WERKS NO-INTERVALS.

or else

As u have said u can use IN and then delete the unwanted afterwards

Former Member
0 Kudos

Hi Dave,

Go for your first option.

That is:

Go ahead and populate the fields separately, use the "IN" functionality, then spin through my resulting internal table and delete anything that doesn't match my "table" of valid combinations.

This sounds good

Regs,

Venkat Ramanan

Former Member
0 Kudos

Hi

Yuo can try to use FOR ALL ENTRIES option.

IF you have:

WERKS BTRTL

Z002 Z001

Z002 Z002

Z003 Z001

Z003 Z002

You should do something like that:

DATA: BEGIN OF <TAB_SEL> OCCURS 1,

WERKS TYPE WERKS,

BTRTL TYPE BTRTL,

END OF <TAB_SEL>.

WERKS BTRTL

<TAB_SEL>-WERKS = 'Z002'. <TAB_SEL>-BTRTL = 'Z001'.

APPEND <TAB_SEL>.

<TAB_SEL>-WERKS = 'Z002'. <TAB_SEL>-BTRTL = 'Z002'.

APPEND <TAB_SEL>.

<TAB_SEL>-WERKS = 'Z003'. <TAB_SEL>-BTRTL = 'Z001'.

APPEND <TAB_SEL>.

<TAB_SEL>-WERKS = 'Z003'. <TAB_SEL>-BTRTL = 'Z002'.

APPEND <TAB_SEL>.

SELECT * FROM <TABLE> INTO TABLE ITAB

FOR ALL ENTRIES IN <TAB_SEL>

WHERE WERKS = <TAB_SEL>-WERKS

AND BTRTL = <TAB_SEL>-BTRTL.

In this case you need to fill correctly the internal table <TAB_SEL> with the all combinations.

Max

0 Kudos

Good suggestions, guys. I like Max's "FOR ALL ENTRIES" option, but I have a question as I'm not much of an SQL guru -- can I still put other criteria in the "WHERE" section of that statement? For example, adding to Max's example:

SELECT * FROM <TABLE> INTO TABLE ITAB

FOR ALL ENTRIES IN <TAB_SEL>

WHERE WERKS = <TAB_SEL>-WERKS

AND BTRTL = <TAB_SEL>-BTRTL

AND NACHM = 'Some Text...'

AND BPLAN = 'Some Criteria...'.

Or does the "FOR ALL ENTRIES" immediately "tie you down" to only comparing records to that table specified in the "FOR ALL ENTRIES" clause?

0 Kudos

Now I'm confused.

Regards,

Rich Heilman

0 Kudos

Hi

Yes you can.

Example: I want to select the vendor items of FI documents posted on 21/02/2006:

SELECT * FROM BKPF INTO TABLE BKPF

WHERE BUKRS = <MY_COMPANY>

AND BUDAT = '20060221'.

SELECT * FROM BSEG INTO TABLE T_BSEG

FOR ALL ENTRIES IN T_BKPF WHERE BUKRS = T_BKPF-BUKRS

AND BELNR = T_BKPF-BELNR

AND GJAHR = T_BKPF-GJAHR

AND KOART = 'K'.

Max

0 Kudos

Rich, I'm sorry if I confused things further. Perhaps I should have given a better example. Being new, I'm all too aware that I might not be phrasing my questions in the best way. I'll certainly strive to do that in every question I post.

Max -- sweet! I think your approach will work very well for me. Thanks so much for your help! Points awarded.