首页 > 应用开发 > IT综合 > abap 中at new的用法
(摘录) 1、AT New事件触发说明 举例:字段a b c d 1 1 1 1 1 1 1 2 1 2 1 1 at new c ,当循环第一,二行时,字段a b 都未发生变化,那就循环继续,当循环第三行时,字段b变化了,也就是说c左边的字段发生变化了,那本次循环结束,开始新的循环。把第三行换成1 1 2 1,字段a b 未发生变化,只有c发生变化,也就是说c发生变化,则循环停止,开始新的循环。在at new f 时,不考虑字段f之后的字段内容变化,也就是后面说的(All character type fields (on the right) are filled with "*" after the current control level key. ),在字段f之后系统将默认为"*",也就是说f之后的内容不管相同与否,都视为“*”,不将其考虑,不在at new 事件的考虑范围之内。 2、AT New 发生时工作区的字段的值 ... ENDAT. 如果字段 录数 据集前面的 记录(对于 AT NEW)或 后续记录( 对于 AT END)中 的值不同, 将产生控 制 中断,并且 系统将处理 AT-ENDAT 中的语句块 。字段 分。 如果摘录数 据集没有排 序,则系统 将忽略 AT-ENDAT 中的语句块 。 在决定控制 中断时,系 统将忽略未 在摘录过程 中定义的 系统将一个 接一个地处 理循环中的 所有 AT...ENDAT 处理块。所 以要当心它 们的顺序。 在 控制级逻 辑内,请保 持排序顺序 。该顺序不 一定是 HEADER 字段组中的 字段的顺序 ,但可 以是 在 SORT 语句中确定 的顺序。 When you perform a sort using the SORTstatement, control levels are defined in the extract dataset. For general information about control levels, refer to Processing Internal Tables in Loops The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the header field group. After sorting, you can use the ATstatement within a LOOP loop to program statement blocks that the system processes only when the control level changes. AT NEW f | AT END OF f. A control break occurs when the value of the field f or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field f must be part of the header field group. If the extract dataset is not sorted, the AT - ENDAT block is never executed. Furthermore, all extract records with the value HEX null in the field f are ignored when the control breaks are determined. The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the header field group, but can also be the one determined in the SORT statement. If you have sorted an extract dataset by the fields f1, f2, …, the processing of the control levels should be written between the other control statements in the LOOP loop as follows: LOOP. You do not have to use all of the statement blocks listed here, but only the ones you require.
REPORT demo_extract_at_new. DATA: t1(4) TYPE c, t2 TYPE i. FIELD-GROUPS: header. INSERT t2 t1 INTO header. t1 ='AABB'. t2 = 1. EXTRACT header. SORT BY t1 t2. LOOP. AT FIRST. AT NEW t1. AT NEW t2. WRITE: /14 t1, t2. AT END OF t2. AT END OF t1. AT LAST. ENDLOOP. This program creates a sample extract, containing the fields of the header field group only. After the sorting process, the extract dataset has several control breaks for the control levels T1 and T2, which are indicated in the following figure:
In the LOOP loop, the system displays the contents of the dataset and the control breaks it recognized as follows:
|
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22532731/viewspace-1028970/ ,如需转载,请注明出处,否则将追究法律责任。