凡尘clsoho™的博客

E-mail & MSN: clsoho@hotmail.com
QQ1超级群: <101817641已满> QQ2群:<110722895已满>
QQ3超级群:<23765855>QQ4超级群:<85338969>

DEFINE

Syntax

DEFINE macro.
  ... &1 ... &9 ...
END-OF-DEFINITION.

Effect

The statement DEFINE defines a macro. Naming conventions apply to the name macro and you cannot use ABAP language elements. Between the statements DEFINE and END-OF-DEFINITION, you can use any number of complete ABAP statements, with the exception of DEFINE, END-OF-DEFINITION, and program-initiating statements. These statements constitute a section of source code that can be inserted into a program under the name macro. The definition of a macro is not restricted to the limits of processing blocks.

语句DEFINE定义一个宏。命名规范适用于宏的名字并且你可以使用ABAP语言要素。在语句DEFINEEND-OF-DEFINITION之间,你可以使用任意数量的ABAP语句。这些语句不能包括DEFINEEND-OF-DEFINITION和程序初始化语句。这些语句可以作为源代码的一部以宏名字分插入到一个程序中。宏的定义不受处理块的限制。

The validity of a macro is defined by its position in the source code. It can be inserted at any position after END-OF-DEFINITION. If another macro is defined with the same name, it overwrites the previous macro from its new position.

一个宏的有效性是通过它在源代码中定义的位置确定的。它可以被插入到end-of-definition之后的任意位置。如果定义了另一个同名的宏,它在新的位置取代以前定义的宏。

Within a macro, you can use up to nine placeholders &1 ... &9 instead of language elements and operands. These placeholders must be replaced by fixed words when the macro is inserted.

在一个宏中,你可以最多使用9个点位符&1…&9来替代语言要素和操作符。这些点位符必须被固定的字符代替当宏被插入的时候。

As well as in the source code of a program, you can also store macros in the database table TRMAC, where they can be used by any program. The system first searches in the current program for a macro, and then in the table TRMAC. Do not define your own macros in TRMAC. One example of a macro in TRMAC is break, which sets a breakpoint in the system field sy-uname, depending on the current user name.

除了在程序代码中,你还可以在数据库表TRMAC中存储宏,在TRMAC中的宏可以被用在任何程序中。系统首先在当前程序中寻找宏,之后到表TRMAC中。不要在TRMAC中定义你自己使用的宏。宏在TRMAC中的一个例子就是break,它在系统字段sy-uname中设置一个断点,取决于当前的用户名。

  • In macros, you cannot set any breakpoints. In the ABAP Debugger, the statements of a macro cannot be performed in individual steps.

在宏中,你不能设置任何断点。在ABAP调试器中,宏的语句不能在独特的步骤中调用。

  • Macros must not include more than a few lines, and should be used sparingly, since it is very difficult to analyze macro errors. Instead of macros, use internal procedures or include programs.
    宏不能包括太多行,而应该被保守地使用。因为宏产生的错误很难分析。可以用过程和包含程序来替代宏。

Inserting Macros

macro [p1 p2 ... ].

If a previously defined macro is listed as the first word in an ABAP statement instead of a valid ABAP language element, then these statements are inserted in the source code at this position. Appropriate language elements or operands p1 p2 ... must be specified for all placeholders of the macro. p1 p2 ... replace the placeholders literally, one after the other.

如果一个预先定义好的宏取代一个有效的ABAP语言要素在ABAP语句的第一个语句中被列出,那么这些语句就在这个位置被插入到源代码中。必须指定适当的语言要素或者操作符p1 p1…来一个接一个地代替宏的占位符p1 p2 …

Note

A macro can insert other macros, but not itself.

一个宏可以插入到其它宏中。但不能插入到它自己中。

Example

In this example, a macro write_frame, which draws a frame around a placeholder &1 in a list, is defined and then implemented.

在这个例子中,宏write_frame被定义和应用,它在一个列表中围绕占位符&1绘出一个方框。

DATA: x TYPE i, y TYPE i, l TYPE i.
DEFINE write_frame.
  x = sy-colno. y = sy-linno.
  WRITE: '|' NO-GAP, &1 NO-GAP, '|' NO-GAP.
  l = sy-colno - x.
  y = y - 1. SKIP TO LINE y. POSITION x.
  ULINE AT x(l).
  y = y + 2. SKIP TO LINE y. POSITION x.
  ULINE AT x(l).
  y = y - 1. x = sy-colno. SKIP TO LINE y. POSITION x.
END-OF-DEFINITION.
SKIP.
write_frame 'In a frame!'.

posted on 2010-01-26 12:36  凡尘clsoho  阅读(648)  评论(0编辑  收藏  举报