二 ABAP语法Demo

1.Field-Symbols

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

2.字符串处理

合并字符串:

先将字符串C1、C2、C3、C4合并到字符串C5,再将字符串C1、C2、C3、C4用间隔符字符串C9合并到字符串C5。
*&---------------------------------------------------------------------*
*& Report  ZABAP_SCOTT_04
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_SCOTT_04.
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.


拆分字符串:
*&---------------------------------------------------------------------*
*& Report  ZABAP_SCOTT_05
*&
*&---------------------------------------------------------------------*
*&拆分字符串
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_SCOTT_05.
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',
      C9(2) TYPE C.

C9 = '*'.
WRITE C5.

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


3.内表带有标题行

内表MAN1有表头,内表MAN2无表头,输出结果一样
*&---------------------------------------------------------------------*
*& Report  ZABAP_SCOTT_06
*&
*&---------------------------------------------------------------------*
*&内表建立标题行
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_SCOTT_06.
DATA: BEGIN OF MAN,
  NAME(20) TYPE C,
  HEIGHT 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 = 'SCOTT'.
MAN-HEIGHT = '1.75'.
MAN-WEIGHT = '130'.
APPEND MAN TO MAN1.

MAN-NAME = '小白'.
MAN-HEIGHT = '1.80'.
MAN-WEIGHT = '140'.

APPEND MAN TO MAN1.

MOVE MAN1[] TO MAN2.
LOOP AT MAN2 INTO MAN.
  WRITE: / MAN-NAME,MAN-HEIGHT,MAN-WEIGHT.
ENDLOOP.
LOOP AT MAN1.
  WRITE: / MAN1-NAME,MAN1-HEIGHT,MAN1-WEIGHT.
ENDLOOP.
二 ABAP语法Demo_第2张图片

4.内表排序

*&---------------------------------------------------------------------*
*& Report  ZABAP_SCOTT_07
*&
*&---------------------------------------------------------------------*
*&内表排序
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_SCOTT_07.
DATA: BEGIN OF MAN,
  NAME(20) TYPE C,
  HEIGHT 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 = 'SCOTT'.
MAN-HEIGHT = '1.75'.
MAN-WEIGHT = '130'.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = '小白'.
MAN-HEIGHT = '1.80'.
MAN-WEIGHT = '140'.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = '小花'.
MAN-HEIGHT = '1.60'.
MAN-WEIGHT = '90'.
INSERT MAN INTO TABLE MAN1.

LOOP AT MAN1 INTO MAN.
  WRITE: / MAN-NAME,MAN-HEIGHT,MAN-WEIGHT.
ENDLOOP.
SORT MAN1 DESCENDING BY WEIGHT ASCENDING.
SKIP.
ULINE.
LOOP AT MAN1 INTO MAN.
  WRITE: / MAN-NAME,MAN-HEIGHT,MAN-WEIGHT.
ENDLOOP.
二 ABAP语法Demo_第3张图片

5.修改内表记录

*&---------------------------------------------------------------------*
*& Report  ZABAP_SCOTT_08
*&
*&---------------------------------------------------------------------*
*&修改内表数据
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_SCOTT_08.
DATA: BEGIN OF MAN,
  NAME(20) TYPE C,
  HEIGHT 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 = 'SCOTT'.
MAN-HEIGHT = '1.78'.
MAN-WEIGHT = '130'.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = '小白'.
MAN-HEIGHT = '1.60'.
MAN-WEIGHT = '90'.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = '小花'.
MAN-HEIGHT = '1.70'.
MAN-WEIGHT = '90'.
INSERT MAN INTO TABLE MAN1.

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

MAN-NAME = 'SCOTT'.
MAN-HEIGHT = '2.42'.
MAN-WEIGHT = '260'.
MODIFY TABLE MAN1 FROM MAN.

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

二 ABAP语法Demo_第4张图片

6.删除内表记录

*&---------------------------------------------------------------------*
*& Report  ZABAP_SCOTT_09
*&
*&---------------------------------------------------------------------*
*&删除内表记录
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_SCOTT_09.
DATA: BEGIN OF MAN,
  NAME(20) TYPE C,
  HEIGHT 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 = 'SCOTT'.
MAN-HEIGHT = '1.78'.
MAN-WEIGHT = '130'.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = '小白'.
MAN-HEIGHT = '1.60'.
MAN-WEIGHT = '90'.
INSERT MAN INTO TABLE MAN1.

MAN-NAME = '小花'.
MAN-HEIGHT = '1.70'.
MAN-WEIGHT = '90'.
INSERT MAN INTO TABLE MAN1.

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

DELETE MAN1 WHERE NAME = 'SCOTT'.
SKIP.
ULINE.
LOOP AT MAN1 INTO MAN.
  WRITE: / MAN-NAME,MAN-HEIGHT,MAN-WEIGHT.
ENDLOOP.



7.使用索引插入内表行


8.格式化输出


9.内部数据存为文件


10.直接存入文件


11.不使用提示框提示直接读入文件


12.列表输出





你可能感兴趣的:(SAP,合并,格式化,abap,tcode)