简体   繁体   English

如何比较内部表中同一列中的两个字段? ABAP

[英]How to compare two fields in same column in internal table? ABAP

How to compare fields in same column in internal table?如何比较内部表中同一列中的字段? ABAP ABAP

Example to compare in column A:在 A 列中进行比较的示例:

col A | col B
 A    |   B
 A    |   A
 A    |   A
 B    |   B
 B    |   B

I would first loop through the contents of your internal table and do my comparison between field 1 and field 2 within the loop.我将首先遍历内部表的内容,并在循环中的字段 1 和字段 2 之间进行比较。 The comparison is done on a row by row level.比较是逐行进行的。 If the condition is true, I would add my business logic within the IF statement.如果条件为真,我会在 IF 语句中添加我的业务逻辑。

LOOP at itab.
   IF itab-col1 EQ itab-col2
   "Business logic.
   ENDIF. 
 ENDLOOP.

Would this suffice?这样就够了吗?

field-symbols: <ls_line> type (line structure of itab)

loop at itab assigning <ls_line>.
  if <ls_line>-column_a NE <ls_line>-column_b.
    write: / sy-tabix, <ls_line>-column_a, <ls_line>-column_b. 
  endif.
endloop.

sy-tabix will give the line number where there is a difference between the 2 columns. sy-tabix 将给出两列之间存在差异的行号。

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

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