当前位置:网站首页>SAP abap内表分类与增删改查操作
SAP abap内表分类与增删改查操作
2022-06-11 08:38:00 【雨天行舟】
SAP abap内表分类与增删改查操作
1.内表的分类
1.1.标准表 (standard table )
系统为该表每一行生成一个院级索引.填表是可以将数据附加在现有行之后,也可以插入到指定的位置,程序对内表的寻址可以通过关键字或者索引进行.在对表进行行插入,删除等操作,各行数据在内表的位置不变,系统仅重新排列个数据行的索引值.
DATA:ITAB TYPE TABLE OF LINE_TYPE.
1.2排序表(sorterd table)
也具有一个逻辑索引,不同的是排序表总是按照其表关键字升序排序后再进行存储,其访问方式与标准表相同
DATA:ITAB TYPE SORTED TABLE OF LINE_type with unique non-unique key keyname.
1.3.哈希表(hashed table)
没有索引,只能通过关键字来访问,系统用哈希算法来管理表中的数据
data:itab type hashed table of linetype with unique key keyname.
例:
标准表:
data: gt_table_t type standard table of gty_table.
排序表:
data:gt_table_s type sorted table of gty_table with non-unique key name.
哈希表:
data: gt_table_h type hashed table of gty_table with non-unique key name.
1.4 index table / any tablev
可以定义数据类型,但不能生成数据对象,数据对象一般是在程序中动态指定的,一般在perform程序块或者是fieldsymbols里使用.
clear 清空
2.表头行
- 在创建内表的同时可以使用选线 with header line 隐式的定义一个工作表头行,也称作内表工作区
data: itab type table_type with header line- 用以上语句创建内表的同时就隐含的创建一个内表的工作区
2.1内表的引用方法
itab[]
2.2工作区的引用方法
itab
data: gt_table2 type table of gty_tble initial size 10 with header line ."定义表头行的内表
CLEAR : GT_TABLR2, GT_TABLE2[]
3.内表数据的增加
3.1追加 - append
append 相当于在内表的最后一行追加,他只能使用在索引表中而且最好是标准表,而标准表示abap编程中最常用的表.
哈希表不可使用append,排序表不建议使用append.
append [line | initialline] to itab.
append lines of itab1 [from n1 ] [to n2] to itab2.
向表中添加数据 append
append gs_score to gt_score. 从结构体
append gt_scprt 从表头行
append lines of gt_score form 1 to 3 to gt_score2.
*说明: line:结构 itab:内表 idx: 索引值
3.2插入 - insert
3.2.1将行插入到内表中指定的位置,需要使用insert语句.
3.2.2对于索引表,可以指定某行的索引,则新行将插入到该索引所代表的的行之前;
3.3.3对于哈希表,不能指定行的索引,系统会按照关键字将新行插入其特殊的位置.
3.2.4给内表插入行可以为单行,也可以为多行,甚至整张表.
3.2.5按照索引值插入(只适用于索引表)
insert line into itab index idx
3.2.6按照关键字插入(可用于所有表)
insert line into table table
3.2.7多行插入
insert lines of itab1 [from n1][to n2] into [table] itab2 [index idx].
3.2.8示例
INSERT gs_score INTO gt_score INDEX 1.
INSERT gs_score INTO TABLE gt_score .
INSERT LINES OF gt_scpre FROM 1 TO 3 INTO TABLE gt_score
3.3聚集附加 - collect
作用:将工作区里的关键字段值跟内表里的字段值比较,如果相同的话不在内表里追加行,而是将工作区里的数值字段值跟内表里的相关行的字段值累加,然后将工作区里的数字值更新到内表中的相关行里;如果比较后没有在内表中找到相关行就将工作区里的内容添加到内表中.
collect line into itab.
4.内表数据的修改
4.1修改 - modify
4.1根据索引更改内表的语法:
modify:itab [from wa] [index idx] transporting f1 f2....].
4.2使用关键字来更改表行可以应用所有类型的内表,语法:
modify table itab from wa[transporting f1 f2 ...].
4.3示例:
修改内表中的数据 modify
modify gt_score from gs_score index 3 transporting name.
modify table gt_score from gs_score.
*内表循环 loop
loop at gt_score into gs_score.
if gs_score-name = 'a'.
gs_score-sex = 'm'.
modify gt_score from gs_scpre.
endif.
write: / gt_scpre,gs_score-name.
endloop.
5.表内容数据的读取
5.1 读取 - read
对于索引表可以利用索引读取单行
read table [into wa | assigning <fs> ] index idx.
可以通过关键字读取任何类型的内表
read table itab with [table]key k1 = f1 ..[into wa] | assigning <fs>] index idx.
使用关键字table 要求指定的key字段必须都是关键字段,并且把所有的关键字段都列出来,是哈希表读取时比较适合的语句
不使用table关键字,指定的key不必都是关键字也无需把所有的关键字段都列出来,是索引表读取时比较适合的语句.
对于索引表的读取可以使用binary search语句加快读取速度.
binary search叫做二分法搜索,可以成几倍的加过搜索速度.
条件:1.内表必须是索引表.2.内表必须是已经按照搜索的关键字排序.
6.内表数据的删除
6.1 删除 - delete
根据索引删除内表的语法
delete itab [from wa ] [index idx].
使用表关键字来删除内表行可以应用所有类型的表
delete table itab from wa
删除邻近的重复行
sort itab by field1 field2
delete adjacent duplicates from itab [comparing field1 field2].
6.2清空表内容
clear :itab,itab[] .
refresh : itab.
6.3 示例
*删除内表的数据 delete
delete gt_score index 1.
delete table gt_score from gs_score.
sort gt_score by name.
delete adjacent duplicates from gt_socre comparing name.
7.内表的数据的增加
open SQL - select
从数据库表中向内表/结构中取数 : select
7.1取多条数据
select * from database table into[corresponding] table itab
7.2示例
*取出字段的值依次序放入内表中的字段
select * from zhq_score_01 into table gt_score.
*取出字段的值对应放入内表中的字段
select * from zhq_score_01
into corresponding fields of table gt_score.
*取出所有的字段对应放入内表中的字段
select * from zhq_score_01
into corresponding field of table gt_score.
边栏推荐
- GCC AVR(Atmel Studio+ AVR Studio)如何将结构体数组定义在程序存储器(flash)空间并进行读操作
- 一些学习记录i=
- Cron expressions in scheduled tasks
- Sword finger offer 40 Minimum number of K
- Introduction to the principles of linkedblockingqueue, arrayblockingqueue, synchronousqueue, concurrentlinkedqueue and transferqueue
- 不想项目失控?你需要用对项目管理工具
- Design of optimization table
- Heap can also be regarded as a tree structure. It is specified that the root node must be greater than or less than the left and right child nodes, but the size order of the left and right child nodes
- leetcode - 518. Change II
- Introduction to database system experiment report answer Experiment 6: advanced query of data table
猜你喜欢

MySQL advanced features, you can read more about it and meet the interview

Qiao NPMS: get the download volume of NPM packages

In place reversal of a LinkedList

Multiple limit of the same field of SQL

BFS on tree (tree breathing first search)

不想项目失控?你需要用对项目管理工具

centos随笔03:centos8.2安装mysql

你所不知道的console

使用express+mysql创建一个基于nodejs的后台服务

leetcode - 230. 二叉搜索树中第K小的元素
随机推荐
Web design and website planning assignment 11 game selection form
How to do a good job in project management? Learning these four steps is enough
Oracle learning (I)
EN 45545-2T10水平法烟密度检测的注意事项
2022 Niuke winter vacation 3
Sword finger offer 62 The last remaining number in the circle
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
B+ super tree helps you know the underlying structure of MySQL
ICML2022有意思的文章
vagrant 安装踩坑
Introduction to the principles of linkedblockingqueue, arrayblockingqueue, synchronousqueue, concurrentlinkedqueue and transferqueue
Codeworks round 723 (Div. 2)
Implementation of CRF for named entity recognition
Heap can also be regarded as a tree structure. It is specified that the root node must be greater than or less than the left and right child nodes, but the size order of the left and right child nodes
(2) Analysis of AAC source code from the perspective of architecture design - my livedata
光伏板怎么申请ASTM E108阻燃测试?
Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
Cyclic sort
利用docker-compose搭建redis5集群
[software tool] installation ffmpeg