ITPub博客

首页 > 应用开发 > IT综合 > abap 中at new的用法

abap 中at new的用法

原创 IT综合 作者:clsoho 时间:2009-11-23 15:25:31 0 删除 编辑

(摘录)

1、AT New事件触发说明
如 AT New f.
f 是内表的一个字段,当f字段或者f字段左边的字段内容发生变化是该事件后面的语句都会执行。
TYPES: BEGIN OF COMPANIES_TYPE,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES_TYPE.

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,
WA_COMPANIES TYPE COMPANIES_TYPE.

...

LOOP AT COMPANIES INTO WA_COMPANIES.
AT NEW PRODUCT.
NEW-PAGE.
WRITE / WA_COMPANIES-NAME WA_COMPANIES-PRODUCT.
ENDAT.
WRITE: / WA_COMPANIES-PRODUCT, WA_COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-SALES.
ENDAT.
ENDLOOP.

这个样例当name变化时,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 发生时工作区的字段的值

  • All character type fields (on the right) are filled with "*" after the current control level key.
  • All other fields (on the right) are set to their initial values after the current control level key.
  • AT NEW │ AT END OF .
    ...
    ENDAT.
    如果字段 或当前摘录 记录中的排 序关键字的 较高层字段 中包含其它 值,并且该 值与摘
    录数 据集前面的 记录(对于 AT NEW)或 后续记录( 对于 AT END)中 的值不同, 将产生控
    制 中断,并且 系统将处理 AT-ENDAT 中的语句块 。字段 必须是 HEADER 字段组的一 部
    分。

    如果摘录数 据集没有排 序,则系统 将忽略 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.
    ...

    ENDAT.

    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.
    AT FIRST.... ENDAT.
    AT NEW f
    1....... ENDAT.
    AT NEW f
    2.......
    ENDAT.
    ...
    AT fg
    i.....
    ENDAT. Single record processing without control statement
    ...

    AT END OF f
    2.... ENDAT.
    AT END OF f
    1....
    ENDAT.
    AT LAST..... ENDAT.
    ENDLOOP.

    You do not have to use all of the statement blocks listed here, but only the ones you require.

    Example

    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.
    t1 ='BBCC'. t2 = 2. EXTRACT header.
    t1 ='AAAA'. t2 = 2. EXTRACT header.
    t1 ='AABB'. t2 = 1. EXTRACT header.
    t1 ='BBBB'. t2 = 2. EXTRACT header.
    t1 ='BBCC'. t2 = 2. EXTRACT header.
    t1 ='AAAA'. t2 = 1. EXTRACT header.
    t1 ='BBBB'. t2 = 1. EXTRACT header.
    t1 ='AAAA'. t2 = 3. EXTRACT header.
    t1 ='AABB'. t2 = 1. EXTRACT header.

    SORT BY t1 t2.

    LOOP.

    AT FIRST.
    WRITE 'Start of LOOP'.
    ULINE.
    ENDAT.

    AT NEW t1.
    WRITE / ' New T1:'.
    ENDAT.

    AT NEW t2.
    WRITE / ' New T2:'.
    ENDAT.

    WRITE: /14 t1, t2.

    AT END OF t2.
    WRITE / 'End of T2'.
    ENDAT.

    AT END OF t1.
    WRITE / 'End of T1'.
    ENDAT.

    AT LAST.
    ULINE.
    ENDAT.

    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:

    This graphic is explained in the accompanying text

    In the LOOP loop, the system displays the contents of the dataset and the control breaks it recognized as follows:

    This graphic is explained in the accompanying text

  • [@more@]

    来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22532731/viewspace-1028970/ ,如需转载,请注明出处,否则将追究法律责任。

    上一篇: 没有了~
    下一篇: 没有了~
    请登录后发表评论 登录
    全部评论

    注册时间:2009-09-14

    • 博文量
      1
    • 访问量
      15897