English 中文(简体)
如何将多种条件纳入选举考试?
原标题:How to include multiple conditions in a SELECT?

我正在使用5个参数,以收集亚洲开发银行表格(mara, makt, marc, mard)的细节。

 PARAMETERS :number TYPE matnr MATCHCODE OBJECT MAT1 ,
             type TYPE MTART MATCHCODE OBJECT H_T134 ,
             sector TYPE MBRSH MATCHCODE OBJECT H_T137 ,
             group TYPE MATKL MATCHCODE OBJECT H_T023 ,
             unit TYPE MEINS MATCHCODE OBJECT H_T006 .

首先,我尝试利用<> 座标/>查询表取用数据。 为了检索具体记录,我必须使用<>WHERE条件。 但我陷入困境。 我们可以使用<<>INITIAL条件,检查哪些参数具有价值。

但是,有2/3/4/5参数具有价值的机会。 对于每个案件,我们必须写出某些问询(如果会导致履约问题),或者在选择询问中是否有任何使用动态条件部分?

最佳回答

您可使用<条码>。

TABLES MARA.  

SELECT-OPTIONS:
  s_matnr FOR mara-matnr MATCHCODE OBJECT MAT1 ,
  s_mtart FOR mara-MTART MATCHCODE OBJECT H_T134 ,
  s_mbrsh FOR mara-MBRSH MATCHCODE OBJECT H_T137 ,
  s_matkl FOR mara-MATKL MATCHCODE OBJECT H_T023 ,
  s_meins FOR mara-MEINS MATCHCODE OBJECT H_T006 .

* [...]  

SELECT * FROM MARA where 
  matnr in s_matnr and
  mtart in s_mtart and
  mbrsh in s_mbrsh and
  matkl in s_matkl and
  meins in s_meins.

如果是这样的话,你的筛选将允许数据具有多重价值和幅度。

如果您需要诸如<代码>参数-command等单一数值,则您必须为<代码>设定临时选择。 西欧和其他国家:

  • NO INTERVALS to allow only single values
  • NO-EXTENSION to allow only one value.
  • OBLIGATORY if an empty value is not allowed (As far I understand your question, you have the opposite situation, so you don t need it).

因此,选择:

SELECT-OPTIONS:
  s_matnr FOR mara-matnr NO-EXTENSION NO INTERVALS,
  s_mtart FOR mara-MTART NO-EXTENSION NO INTERVALS,
  s_mbrsh FOR mara-MBRSH NO-EXTENSION NO INTERVALS,
  s_matkl FOR mara-MATKL NO-EXTENSION NO INTERVALS,
  s_meins FOR mara-MEINS NO-EXTENSION NO INTERVALS.

说明:

  • MARA must be defined as a TABLE if you use SELECT-OPTIONS
  • Do you really need the MATCHCODE OBJECT? Normally the usage of the FOR already defines the correct matchcode object (via data element/domain).

申斥:

  • I have no SAP-system available yet, so the code may contain syntax errors. - I will check it tomorrow.
问题回答

I think the easiest way to do this is to use select-options instead. You can then use the select-option value with the in expression in your query.
That way, when the value is empty, it will automatically be ignored (which won t happen when you use an empty parameter in your query), so you won t have to create a separate WHERE expression for each possible combination. An example:

tables: mara.
select-options number for mara-matnr matchcode object mat1 no-extension no intervals.
select-options type for mara-mtart matchcode object h_t134 no-extension no intervals.
select-options sector for mara-mbrsh matchcode object h_t137 no-extension no intervals.
select-options group for mara-matkl matchcode object h_t023 no-extension no intervals.
select-options unit for mara-meins matchcode object h_t006 no-extension no intervals.

select distinct mara~matnr makt~maktx marc~werks mard~lgort into table ta_materials
  from mara
  inner join makt on makt~matnr = mara~matnr
  inner join marc on marc~matnr = mara~matnr
  inner join mard on mard~matnr = mara~matnr
  where makt~spras = sy-langu and
        mara~matnr in number and
        mara~mtart in type and
        mara~mbrsh in sector and
        mara~matkl in group and
        mara~meins in unit
  order by mara~matnr.





相关问题
using the where clause + new constraint with args?

I have a piece of code that looks like this: public static T CreateSomething<T>(SomeType a) where T : SomeMicrosoftBaseClass, new() { var newElement = new T { SomeProperty = a}; ...

Strange .Where() behaviour. Somebody has an explanation?

Original I don t get why the Where() clause doesn t give me the right results in the last example. It isn t any different is it? Why does C# behaves differently? transactions = IEnumerable<...

Linq To Sql Where Or operator

I need to create a query which checks if a field (string) contains one or more words supplied at run time. Basically I need to be able to ask a WhereOr question. This seems like it should be a ...

C# Beginner: Where has my IList.Where() method gone?

I ve got another simple one (I think) that s stumping me. I have written a method in one of my controls that gets the latest version of a file in a CMS given it s filename (i.e. regardless of what ...

sql simple query

Yesterday my friend asked me a question about this query: select * from user where 1=1 I said that the query is incorrect, but he said it s correct. I don t understand how this query can be correct....

Codeigniter WHERE on "AS" field

I have a query where I need to modify the selected data and I want to limit my results of that data. For instance: SELECT table_id, radians( 25 ) AS rad FROM test_table WHERE rad < 5 ORDER BY rad ...

SEARCH several Tables IN SQL

I m trying to search several tables at once for a search term. My query is: SELECT item.ItemID FROM Inventory.Item item JOIN Inventory.Category catR // each item can be in several ...

热门标签