【整理】ABAP 7.40新特性介绍(下)

ABAP 7.40 Quick Reference 

 

9.Strings  - 字符串

I.   String Templates 字符串模板

A string template is enclosed by two characters “|” and creates a character string.

字符串模板由两个“|”字符括起来,创建一个字符串。

Literal text consists of all characters that are not in braces {}. The braces can contain:

字面文本包含所有不在大括号{}内的字符。 大括号内可包括如下内容:

  • data objects, 数据对象
  • calculation expressions, 计算表达式
  • constructor expressions, 构造器表达式
  • table expressions, 内表表达式
  • predefined functions,  预定义功能
  • functional methods and method chainings,  功能方法和方法链

下面这个例子就是在大括号内包含了内表表达式,取的内表条件满足某个条件的某个值字段。

【整理】ABAP 7.40新特性介绍(下)

 

 II.  Concatenation 串联

【整理】ABAP 7.40新特性介绍(下)

 

III. Width/Alignment/Padding 宽度/对齐/填充

WRITE / |{ 'LEFT'       WIDTH = 20 ALIGN = LEFT      PAD = '0' }|.
WRITE / |{ 'CENTRE'   WIDTH = 20 ALIGN = CENTER  PAD = '0' }|.
WRITE / |{ 'RIGHT'     WIDTH = 20 ALIGN = RIGHT     PAD = '0' }|.

【整理】ABAP 7.40新特性介绍(下)

 

IV. Case

原态,大写,小写

WRITE / |{ 'Text' CASE = (CL_ABAP_FORMAT=>C_RAW)   }|.
WRITE / |{ 'Text' CASE = (CL_ABAP_FORMAT=>C_UPPER) }|.
WRITE / |{ 'Text' CASE = (CL_ABAP_FORMAT=>C_LOWER) }|.

【整理】ABAP 7.40新特性介绍(下)

 

V.  ALPHA conversion

DATA(LV_VBELN) = '0000012345'.
WRITE / |{ LV_VBELN  ALPHA = OUT }|. "or use ALPHA = IN to go in other direction

【整理】ABAP 7.40新特性介绍(下)

 

VI.  Date conversion

WRITE / |{ PA_DATE DATE = ISO }|.           "Date Format YYYY-MM-DD
WRITE / |{ PA_DATE DATE = USER }|.          "As per user settings
WRITE / |{ PA_DATE DATE = ENVIRONMENT }|.   "Formatting setting of language environment

 

10. Loop at Group By

I.   Definition 定义

LOOP AT itab result [cond] GROUP BY key ( key1 = dobj1 key2 = dobj2 … 
      [gs = GROUP SIZE] [gi = GROUP INDEX] ) 
      [ASCENDING|DESCENDING [AS TEXT]] 
      [WITHOUT MEMBERS] 
      [{INTO group}|{ASSIGNING <group>}]
      … 
      [LOOP AT GROUP group|<group> 
      … 
      ENDLOOP.] 
      …

ENDLOOP.

 

II.  Explanation 解释

The outer loop will do one iteration per key. So if 3 records match the key there will only be one iteration for these 3 records. The structure “group” (or “<group>” ) is unusual in that it can be looped over using the “LOOP AT GROUP” statement. This will loop over the 3 records (members) of the group. The structure “group” also contains the current key as well as the size of the group and index of the group ( if GROUP SIZE and GROUP INDEX have been assigned a field name). This is best understood by an example.

外部循环将对每个键执行一次迭代。因此,如果3条记录与关键值匹配,那么这3条记录将只有一次迭代。结构“group”(或“<group>”)不常见,因为它可以使用“LOOP AT group”语句循环。这将循环访问组的3个记录(成员)。结构“group”还包含当前键、组的大小和组的索引(如果组大小和组索引已分配了字段名)。这一点最好通过一个例子来理解。

 

III. Example 举例

TYPES: BEGIN OF TY_EMPLOYEE,
         NAME TYPE CHAR30,
         ROLE TYPE CHAR30,
         AGE  TYPE I,
       END OF TY_EMPLOYEE,
       TY_EMPLOYEE_T TYPE STANDARD TABLE OF TY_EMPLOYEE WITH KEY NAME.
DATA(GT_EMPLOYEE) = VALUE TY_EMPLOYEE_T(
( NAME = 'Mao'         ROLE = 'ABAP guru'       AGE = 29 )
( NAME = 'Zhangjie'    ROLE = 'FI Consultant'   AGE = 33 )
( NAME = 'Hujianchun'  ROLE = 'ABAP guru'       AGE = 37 )
( NAME = 'XiaoLiu'     ROLE = 'FI Consultant'   AGE = 31 )
( NAME = 'Xiuxianhai'  ROLE = 'ABAP guru'       AGE = 30 )
( NAME = 'Huangping'   ROLE = 'SD Consultant'   AGE = 42 ) ).
DATA: GV_TOT_AGE TYPE I,
      GV_AVG_AGE TYPE DECFLOAT34.
"Loop with grouping on Role
LOOP AT GT_EMPLOYEE INTO DATA(LS_EMPLOYEE)
  GROUP BY ( ROLE  = LS_EMPLOYEE-ROLE
             SIZE  = GROUP SIZE
             INDEX = GROUP INDEX )
  ASCENDING
  ASSIGNING FIELD-SYMBOL(<GROUP>).
  CLEAR: GV_TOT_AGE.
  "Output info at group level
  WRITE: / |Group:{ <GROUP>-INDEX }    Role: { <GROUP>-ROLE WIDTH = 15 }|
              & |     Number in this role: { <GROUP>-SIZE }|.
  "Loop at members of the group
  LOOP AT GROUP <GROUP> ASSIGNING FIELD-SYMBOL(<LS_MEMBER>).
    GV_TOT_AGE = GV_TOT_AGE + <LS_MEMBER>-AGE.
    WRITE: /13 <LS_MEMBER>-NAME.
  ENDLOOP.
  "Average age
  GV_AVG_AGE = GV_TOT_AGE / <GROUP>-SIZE.
  WRITE: / |Average age: { GV_AVG_AGE }|.
  SKIP.
ENDLOOP.

 

IV. Output 输出结果

【整理】ABAP 7.40新特性介绍(下)

 

11. Classes/Methods 类/方法

I.   Referencing fields within returned structures 引用返回结构中的字段

【整理】ABAP 7.40新特性介绍(下)

 

II.  Methods that return a type BOOLEAN 返回布尔类型的方法

【整理】ABAP 7.40新特性介绍(下)

NB : The type “BOOLEAN” is not a true Boolean but a char1 with allowed values X,- and <blank>.

       Using type “FLAG” or “WDY_BOOLEAN” works just as well.

注意 :类型“BOOLEAN”不是真正的布尔类型,而是一个char1,其允许值为X,-和空。使用类型“FLAG”或“WDY_BOOLEAN”也同样可以。

 

III. NEW operator - NEW运算符

This operator can be used to instantiate an object.此运算符可用于实例化对象。

【整理】ABAP 7.40新特性介绍(下)

 

12. Meshes 网格

Allows an association to be set up between related data groups.

允许在相关数据组之间设置关联。

 

I.Problem

Given the following 2 internal tables:

给出以下两个内表:

TYPES: BEGIN OF t_manager,
name   TYPE char10,
salary TYPE int4,
END OF t_manager,
tt_manager TYPE SORTED TABLE OF t_manager WITH UNIQUE KEY name.

TYPES: BEGIN OF t_developer,
name    TYPE char10,
salary  TYPE int4,
manager TYPE char10,   “Name of manager
END OF t_developer,
tt_developer TYPE SORTED TABLE OF t_developer WITH UNIQUE KEY name.

Populated as follows:填充如下值

【整理】ABAP 7.40新特性介绍(下)

【整理】ABAP 7.40新特性介绍(下)

Get the details of Jerry’s manager and all developers managed by Thomas.

 

II.  Solution

TYPES: BEGIN OF MESH M_TEAM,
         MANAGERS   TYPE TT_MANAGER  ASSOCIATION MY_EMPLOYEE TO DEVELOPERS
                                                            ON MANAGER = NAME,
         DEVELOPERS TYPE TT_DEVELOPER ASSOCIATION MY_MANAGER TO MANAGERS
                                                            ON NAME = MANAGER,
       END OF MESH M_TEAM.
DATA: LS_TEAM TYPE M_TEAM.
LS_TEAM-MANAGERS   = LT_MANAGER.
LS_TEAM-DEVELOPERS = LT_DEVELOPER.
*Get details of Jerry’s manager *
"get line of dev table
ASSIGN LT_DEVELOPER[ NAME = 'JERRY' ] TO FIELD-SYMBOL(<LS_JERRY>).
DATA(LS_JMANAGER) =  LS_TEAM–DEVELOPERS\MY_MANAGER[ <LS_JERRY> ].
WRITE: / |Jerry's manager:{ LS_JMANAGER-NAME }|,30
                  |Salary:{ LS_JMANAGER-SALARY }|.

"Get Thomas’ developers
SKIP.
WRITE: / |Thomas'developers:|.
"line of manager table
ASSIGN LT_MANAGER[ NAME = 'Thomas' ] TO FIELD-SYMBOL(<LS_THOMAS>).
LOOP AT LS_TEAM–MANAGERS\MY_EMPLOYEE[ <LS_THOMAS> ]
        ASSIGNING FIELD-SYMBOL(<LS_EMP>).
  WRITE: / |Employee name: { <LS_EMP>-NAME }|.
ENDLOOP.

 

III. Output

Jerry's manager: Jason     Salary: 3000
Thomas'developers:
Employee name: David
Employee name: Jack
Employee name: John

 

13. Filter 过滤器

Filter the records in a table based on records in another table.

根据另一个表中的记录筛选表中的记录。

 

I.Definition

… FILTER type( itab [EXCEPT] [IN ftab] [USING KEY keyname] 
           WHERE c1 op f1 [AND c2 op f2 […]] )

 

II.  Problem

Filter an internal table of Flight Schedules (SPFLI) to only those flights based on a filter table that contains the fields Cityfrom and CityTo.

将航班计划的内表(SPFLI)筛选出仅包含基于Cityfrom和CityTo字段的航班表。

 

III. Solution

TYPES: BEGIN OF TY_FILTER,
         CITYFROM TYPE SPFLI-CITYFROM,
         CITYTO   TYPE SPFLI-CITYTO,
         F3       TYPE I,
       END OF TY_FILTER,
       TY_FILTER_TAB TYPE HASHED TABLE OF TY_FILTER
           WITH UNIQUE KEY CITYFROM CITYTO.
DATA: LT_SPLFI TYPE STANDARD TABLE OF SPFLI.
SELECT * FROM SPFLI APPENDING TABLE LT_SPLFI.
DATA(LT_FILTER) = VALUE TY_FILTER_TAB( F3 = 2
                          ( CITYFROM = 'NEW YORK'  CITYTO  ='SAN FRANCISCO' )
                          ( CITYFROM = 'FRANKFURT' CITYTO = 'NEW YORK' )  ).
DATA(LT_MYRECS) = FILTER #( LT_SPLFI IN LT_FILTER
                                  WHERE CITYFROM = CITYFROM
                                    AND CITYTO = CITYTO ).
"Output filtered records
LOOP AT LT_MYRECS ASSIGNING FIELD-SYMBOL(<LS_REC>).
  WRITE: / <LS_REC>-CARRID,8 <LS_REC>-CITYFROM,30
           <LS_REC>-CITYTO,45 <LS_REC>-DEPTIME.
ENDLOOP.

【整理】ABAP 7.40新特性介绍(下)

Note: using the keyword “EXCEPT” (see definition above) would have returned the exact opposite records i.e all records EXCEPT for those those returned above.

注意:使用关键字“EXCEPT”(参见上面的定义)将返回完全相反的记录,即除上面返回的记录之外的所有记录。

 

【整理】ABAP 7.40新特性介绍(下)【整理】ABAP 7.40新特性介绍(下) SAP剑客 发布了2001 篇原创文章 · 获赞 3890 · 访问量 1021万+ 他的留言板 关注
上一篇:实现ABAP条件断点的三种方式


下一篇:SAP ABAP Netweaver里的SE80事务码是如何响应用户请求的