ABAP语法示例

原创 2016年05月30日 11:16:27

1、FIELD-SYMBOLS

FIELD-SYMBOLS是字段符号,类似于FOXPRO的宏,FOXPRO能把一段程序存入一个字符串中,再通过某种方式使该字符串运行。SAP的FIELD-SYMBOLS,把一个结构定义分配给字段符号,通过字段符号来引用结构中的成员。

REPORT  YTEST20160527.
DATA:BEGIN OF MAN,
        NAME(30) TYPE C,
        HIGH TYPE P DECIMALS 2,
        WEIGHT TYPE P DECIMALS 2,
     END OF MAN.

FIELD-SYMBOLS <FSA> LIKE MAN.
DATA MAN1 LIKE MAN.
MAN1-NAME = 'JAY'.
MAN1-HIGH = '1.78'.
MAN1-WEIGHT = 140.

ASSIGN MAN1 TO <FSA>.
WRITE:/ <FSA>-NAME,
       <FSA>-HIGH,
       <FSA>-WEIGHT.

输出结果

2、合并字符串

REPORT  YTEST20160527.
DATA:C1(2) TYPE C,
     C2(2) TYPE C,
     C3(2) TYPE C,
     C4(2) TYPE C,
     C5(20) TYPE C,
     C9(2) TYPE C.

C1 = 'AB'.
C2 = 'CD'.
C3 = 'EF'.
C4 = 'GH'.
C9 = '+'.
CONCATENATE C1 C2 C3 C4 INTO C5.
WRITE C5.
CONCATENATE C1 C2 C3 C4 INTO C5 SEPARATED BY C9.
WRITE / C5.

输出结果

3、拆分字符串

REPORT  YTEST20160527.
DATA:C1(2) TYPE C,
     C2(2) TYPE C,
     C3(2) TYPE C,
     C4(2) TYPE C,
     C5(20) TYPE C VALUE '11*22*33*44'.

WRITE C5.
SPLIT C5 AT '*' INTO C1 C2 C3 C4.
WRITE :/ C1,C2,C3,C4.

输出结果

4、内表带有标题行

REPORT  YTEST20160527.
DATA:BEGIN OF MAN,
  NAME(20) TYPE C,
  HIGH TYPE P DECIMALS 2,
  WEIGHT TYPE P DECIMALS 2,
  END OF MAN.

DATA: MAN1 LIKE TABLE OF MAN WITH HEADER LINE,
      MAN2 LIKE TABLE OF MAN.

MAN-NAME = 'JAY'.
MAN-HIGH = '1.68'.
MAN-WEIGHT = 120.
APPEND MAN TO MAN1.

MAN-NAME = 'ADOLF'.
MAN-HIGH = '1.69'.
MAN-WEIGHT = 160.
APPEND MAN TO MAN1.

MOVE MAN1[] TO MAN2.

LOOP AT MAN2 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

LOOP AT MAN1.
  WRITE:/ MAN1-NAME,MAN1-HIGH,MAN1-WEIGHT.
ENDLOOP.

输出结果

本例中内表MAN1有表头,内表MAN2无表头,输出结果一样


5、内表排序

REPORT  YTEST20160527.
DATA:BEGIN OF MAN,
  NAME(20) TYPE C,
  HIGH TYPE P DECIMALS 2,
  WEIGHT TYPE P DECIMALS 2,
END OF MAN.

DATA: MAN1 LIKE HASHED TABLE OF MAN WITH UNIQUE KEY NAME.

MAN-NAME = 'JAY'.
MAN-HIGH = '1.68'.
MAN-WEIGHT = 120.
INSERT MAN INTO TABLE MAN1.


MAN-NAME = 'ADOLF'.
MAN-HIGH = '1.69'.
MAN-WEIGHT = 100.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = 'BABO'.
MAN-HIGH = '1.70'.
MAN-WEIGHT = 130.
INSERT MAN INTO TABLE MAN1.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

SORT MAN1 BY HIGH WEIGHT DESCENDING.
SKIP.
ULINE.
LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

SORT MAN1 DESCENDING BY HIGH WEIGHT.
SKIP.
ULINE.
LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

输出结果

SORT MAN1 BY HIGH WEIGHT DESCENDING.--------------------只有WEIGHT 字段是降序,其他字段还是默认的升序

SORT MAN1 DESCENDING BY HIGH WEIGHT.--------------------BY后面所有的字段都是降序

多个字段排序,字段在前面的优先排序

6、修改内表数据

REPORT  YTEST20160527.
DATA:BEGIN OF MAN,
  NAME(20) TYPE C,
  HIGH TYPE P DECIMALS 2,
  WEIGHT TYPE P DECIMALS 2,
END OF MAN.

DATA: MAN1 LIKE HASHED TABLE OF MAN WITH UNIQUE KEY NAME.

MAN-NAME = 'JAY'.
MAN-HIGH = '1.68'.
MAN-WEIGHT = 120.
INSERT MAN INTO TABLE MAN1.


MAN-NAME = 'ADOLF'.
MAN-HIGH = '1.69'.
MAN-WEIGHT = 100.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = 'BABO'.
MAN-HIGH = '1.70'.
MAN-WEIGHT = 130.
INSERT MAN INTO TABLE MAN1.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

MAN-NAME = 'JAY'.
MAN-HIGH = '2.22'.
MAN-WEIGHT = 180.
MODIFY TABLE MAN1 FROM MAN.

SKIP.
ULINE.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

输出结果


7、删除内表记录

REPORT  YTEST20160527.
DATA:BEGIN OF MAN,
  NAME(20) TYPE C,
  HIGH TYPE P DECIMALS 2,
  WEIGHT TYPE P DECIMALS 2,
END OF MAN.

DATA: MAN1 LIKE HASHED TABLE OF MAN WITH UNIQUE KEY NAME.

MAN-NAME = 'JAY'.
MAN-HIGH = '1.68'.
MAN-WEIGHT = 120.
INSERT MAN INTO TABLE MAN1.


MAN-NAME = 'ADOLF'.
MAN-HIGH = '1.69'.
MAN-WEIGHT = 100.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = 'BABO'.
MAN-HIGH = '1.70'.
MAN-WEIGHT = 130.
INSERT MAN INTO TABLE MAN1.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

DELETE MAN1 WHERE NAME = 'BABO'.
SKIP.
ULINE.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

输出结果

8、使用索引插入内表行

REPORT  YTEST20160527.
DATA:BEGIN OF MAN,
  NAME(20) TYPE C,
  HIGH TYPE P DECIMALS 2,
  WEIGHT TYPE P DECIMALS 2,
END OF MAN.

DATA: MAN1 LIKE TABLE OF MAN.

MAN-NAME = 'JAY'.
MAN-HIGH = '1.68'.
MAN-WEIGHT = 120.
INSERT MAN INTO TABLE MAN1.


MAN-NAME = 'ADOLF'.
MAN-HIGH = '1.69'.
MAN-WEIGHT = 100.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = 'BABO'.
MAN-HIGH = '1.70'.
MAN-WEIGHT = 130.
INSERT MAN INTO TABLE MAN1.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

MAN-NAME = 'JIN'.
MAN-HIGH = '1.58'.
MAN-WEIGHT = 110.
INSERT MAN INTO MAN1 INDEX 2.
SKIP.
ULINE.

LOOP AT MAN1 INTO MAN.
  WRITE:/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.

输出结果




版权声明:本文为博主原创文章,未经博主允许不得转载。

SAP ABAP入门学习-基本语法

SAP ABAP入门学习-基本语法
  • happy987852720
  • happy987852720
  • 2016年12月16日 14:41
  • 1359

简单的屏幕开发实例-ABAP

注:屏幕又叫动态程序,所有有时候会命名为DYNPRO,ABAP屏幕的主要组成部分有GUI  STATUS(屏幕的状态,和title一样,用来分配给某个屏幕) 、 GUI  TITLE(屏幕的title...
  • fillever
  • fillever
  • 2013年12月08日 10:17
  • 1798

ABAP开发实例

  • 2011年12月25日 10:52
  • 1.48MB
  • 下载

SAP ABAP入门学习-基本语法

SAP ABAP入门学习-基本语法
  • happy987852720
  • happy987852720
  • 2016年12月16日 14:41
  • 1359

ABAP 7.4 新语法-内嵌生命和内表操作

1.内嵌声明     2.内表操作     3.opensql *&---------------------------------------------------------...
  • zhongguomao
  • zhongguomao
  • 2017年06月19日 08:16
  • 531

我们一起学ABAP (02)~基础语法与数据类型,输出到屏幕

1、ABAP(ABAP/4)的基本语法 基本数据类型及属性:  DECIMALS  可以再数据类型后制定小数位的个数。      首先:我们常见的低级错误~  语法切换时(中英),忽略了符号在...
  • qq_37625033
  • qq_37625033
  • 2017年03月24日 16:31
  • 372

SAP ABAP7.40新语法简介第一篇

SAP ABAP7.40新语法简介第一篇
  • SAPmatinal
  • SAPmatinal
  • 2017年02月08日 10:20
  • 838

ABAP 7.4新特性(二):NEW 操作符

NEW实例操作符 了解JAVA的知道,我们可以new一个对象实例出来,现在ABAP也可以这样了。NEW可以创建匿名的数据对象或者类的实例。匿名就是new出来的对象没有名字。。。因为后面不需要这个对象了...
  • yang362046076
  • yang362046076
  • 2016年06月03日 17:12
  • 1158

用新语法写更简洁的ABAP代码

相比其他语言,ABAP可能有很多特有的长处,但简洁从来就不是它的优点之一。 不像其他语言通过Library提供常用功能,ABAP大量使用内置声明(Built-In Statement) 来完善自身,...
  • zhongguomao
  • zhongguomao
  • 2017年04月13日 16:49
  • 1032

ABAP 7.4新特性(三): VALUE 操作符

关于VALUE前面也提到过了,其主要是用来给一个结构、内表等对象初始化值。主要有下面三个方式: ...value dtype\#()  构造一个任意类型的初始值 ...value dtype\#( c...
  • yang362046076
  • yang362046076
  • 2016年06月06日 17:32
  • 1794
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ABAP语法示例
举报原因:
原因补充:

(最多只允许输入30个字)