简体   繁体   English

类中的逻辑SELECT-OPTIONS

[英]Logical SELECT-OPTIONS in classes

I faced a problem with building complex logical conditions in class method through SELECT-OPTIONS statement: 我通过SELECT-OPTIONS语句在类方法中构建复杂的逻辑条件时遇到了一个问题:

IF col IN seltab.
  ...logic....
ENDIF.

I receive error local SELECT-OPTIONS are not allowed... 我收到错误消息, 不允许进行本地SELECT-OPTIONS ...

I coded according to the example in ABAPDOCU. 我根据ABAPDOCU中的示例进行了编码。 The below piece of code also had no sense: 下面的代码也没有意义:

DATA: codes TYPE RANGE OF tcode.
codes-sign = 'I'.
codes-option = 'EQ'.
codes-low = 'VL32N'.
apppend codes.

I got the error Codes is a table without header line and therefore has no component called sign . 我得到的错误代码是没有标题行的表,因此没有名为sign的组件

Is it possible to use logical selection tables in classes? 是否可以在类中使用逻辑选择表? If no what is the alternative? 如果没有,那有什么选择?

Yes, it is possible, and the system states exactly what was wrong. 是的,这是可能的,并且系统会准确说明出了什么问题。 You need to declare this: 您需要声明以下内容:

DATA: lt_range_codes TYPE RANGE OF tcode,         " this is an internal table WITHOUT a header line
      ls_range_codes LIKE LINE OF lt_range_codes. " this is a corresponding structure

ls_range_codes-sign   = 'I'.
ls_range_codes-option = 'EQ'.
ls_range_codes-low    = 'VL32N'.
APPEND ls_range_codes TO lt_range_codes.

Remember that tables with header lines are not allowed within ABAP Objects classes, so you always need an additional structure. 请记住,ABAP Objects类中不允许使用带标题行的表,因此您始终需要其他结构。 Of course, a field symbol and APPEND INITIAL LINE TO ... ASSIGNING <...> will do as well. 当然,字段符号和APPEND INITIAL LINE TO ... ASSIGNING <...>也可以。

Keep in mind you can also create range tables in transaction SE11. 请记住,您也可以在事务SE11中创建范围表。 I would recommend this if you use the same range table in multiple classes. 如果您在多个类中使用相同的范围表,则建议这样做。 Create a table data type with SE11, then go up to EDIT->DEFINE AS RANGE TABLE TYPE and the rest is self explanatory. 使用SE11创建一个表数据类型,然后转到EDIT-> DEFINE AS RANGE TABLE TYPE,其余内容不言自明。 Enter the element type you want a range table for and then you can use this type in all your classes. 输入您想要范围表的元素类型,然后可以在所有类中使用此类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM