指针
赋值:
FIELD-SYMBOLS: <fs1>. "定义一个指针
DATA: num0 TYPE i VALUE 10,
num1(10) TYPE c VALUE '巴拉巴拉'.
ASSIGN num0 TO <fs1>.
WRITE:/ '<FS1>:',<fs1>. "输出结果:10
WRITE:/ 'num0:',num0. "输出结果:10
IF <fs1> IS ASSIGNED. "一定要进行判断
<FS1> = 21.
ENDIF.
WRITE:/ 'num0:',num0. "输出结果:21 ;当指针的值变化时,赋值给指针的变量的值也将改变
字符串的处理
*&---------------------------------------------------------------------*
*& Program Name :YTST_PPJLI_WAIT
*& Title : 字符串处理
*& Module Nam :
*& Author :PPJLI
*& Create Date :24.07.2019 13:49:35
*& Program Type :Report Program
*& Requested by :开发项编号
*& Description :
*&---------------------------------------------------------------------*
REPORT ytst_ppjli_wait.
*--------------------------------字符串移动------------------------------------*
DATA: lv_string1 TYPE string,
lv_string2 TYPE string.
DATA: lv_subs(3) TYPE c VALUE 'ABC'.
DATA: lv_subs1(3) TYPE c VALUE 'FGH'.
lv_string1 = 'ABCDEFGH'.
lv_string2 = 'ABCDEFGH'.
WRITE:/ sy-uline.
WRITE:/ lv_string1.
SHIFT lv_string1 BY 3 PLACES LEFT.
SHIFT lv_string2 BY 3 PLACES RIGHT.
WRITE:/ '左移动:',lv_string1. "左移:结果DEFGH 默认向左移动,如果不指定移动方向
WRITE:/ '右移动:',lv_string2. "左移:结果 ABCDEFGH
*------------------------------删除string2左边的空格------------------------------------*
SHIFT lv_string2 LEFT DELETING LEADING space.
WRITE:/ '删除左边的空格:',lv_string2. "删除空格:结果ABCDEFGH
SHIFT lv_string2 LEFT DELETING LEADING lv_subs.
WRITE:/ '删除左边的指定字符:',lv_string2. "删除指定字符:结果DEFGH
*----------------------------字符串替换---------------------------------------------*
lv_string1 = 'ABCDEFG'.
lv_string2 = '1234'.
WRITE:/ '替换前:',lv_string1.
* 将lv_string1中的ABC替换成1234
REPLACE lv_subs WITH lv_string2 INTO lv_string1.
WRITE:/ '替换后的结果:',lv_string1. "输出结果1234DEFG
*------------------------字符串大小写转换--------------------------------------------*
TRANSLATE lv_string1 TO LOWER CASE.
WRITE:/ '转换小写:',lv_string1.
*---------------------------指定字符的查找-----------------------------------------*
SEARCH lv_string1 FOR lv_string2. "运行结果:0 0 ,找不到指定字符时,SY-SUBRC返回4,SY-FDPOS返回0
SEARCH lv_string1 FOR 'E'. "运行结果:0 5
WRITE:/ '查找结果:',sy-subrc,sy-fdpos. "SY-FDPOS:查找指定字符的首位置
*---------------------------字符串拼接-----------------------------------------*
CONCATENATE lv_string1 lv_string2 lv_subs lv_subs1 INTO lv_string1 SEPARATED BY '*'.
WRITE:/ '拼接后的字符串:',lv_string1. "运行后的结果:1234defg*1234*ABC*FGH
*---------------------------字符串拆分-----------------------------------------*
SPLIT lv_string1 AT '*' INTO lv_string1 lv_string2 lv_subs lv_subs1.
WRITE:/ lv_string1,/ lv_string2,/ lv_subs,/ lv_subs1.
DATA: lv_string3 TYPE c LENGTH 20 VALUE ' 12 34 56'.
CONDENSE lv_string3 . "CONDENSE: 去前导0
WRITE:/ '去前导0:',lv_string3. "输出结果12 34 56
CONDENSE lv_string3 NO-GAPS. "NO-GAPS:删除所有的0
WRITE:/ '删除所有的0:',lv_string3. "输出结果123456
内表数据处理
*&---------------------------------------------------------------------*
*& 内表处理
*&---------------------------------------------------------------------*
*--------------------------定义内表------------------------------------------*
*1. 自定义类型的内表
TYPES: BEGIN OF ty_itab1,
field1 TYPE char10,
field2 TYPE int2,
END OF ty_itab1.
DATA: lt_itab1 TYPE STANDARD TABLE OF ty_itab1,
lt_itab3 TYPE STANDARD TABLE OF ty_itab1,
lt_itab2 TYPE SORTED TABLE OF ty_itab1 WITH UNIQUE KEY field1,
lwa_itab1 TYPE ty_itab1,
lwa_itab3 TYPE ty_itab1.
* 添加条目到标准表
lwa_itab1-field1 = '111'.
lwa_itab1-field2 = 4.
INSERT lwa_itab1 INTO lt_itab1 INDEX 1.
APPEND lwa_itab1 TO lt_itab1.
COLLECT lwa_itab1 INTO lt_itab1. "即计算数字字段之和
* 添加条目到排序
INSERT lwa_itab1 INTO lt_itab2 INDEX 1.
*lwa_itab1-field1 = '222'.
*lwa_itab1-field2 = 5.
lwa_itab1-field1 = '222'.
lwa_itab1-field2 = 3.
APPEND lwa_itab1 TO lt_itab2. "主键值应该不一样,一样append不进去,因为有一条数据已经存在
COLLECT lwa_itab1 INTO lt_itab2. "collect键值相同的值 "????????????????????????????/
* 添加一个内表到另一个内表(标准表)
APPEND LINES OF lt_itab1 TO lt_itab3.
APPEND LINES OF lt_itab1 FROM 1 TO 2 TO lt_itab3. "???????????????????????????from to
INSERT LINES OF lt_itab1 INTO lt_itab3 INDEX 2. "从第二行开始插入数据
* 更新 + 定位行
lwa_itab3-field1 = 'CCCC'.
lwa_itab3-field2 = 888.
MODIFY lt_itab3 FROM lwa_itab3 INDEX 2.
MODIFY lt_itab3 FROM lwa_itab3 INDEX 3 TRANSPORTING field1. "TRANSPORTING:指定修改的字段,其他字段不受影响
BREAK-POINT. " 不区分内外断点
网友评论