PA教材提纲 TAW102

Unit1 Introduction to the ABAP Dictionary(ABAP字典介绍)

1.1 Describing the ABAP Dictionary(描述ABAP字典)

ABAP Dictionary基本功能:

  • Create user-defined types ( data elements, structures, table types )
  • Create the database objects ( tables, indexes, views )
  • Find a number of service that support program development ( locks, F4 input help, F1 field help )

ABAP Dictionary基本数据类型(types):

  • Data elements: describe an elementary type by defining the data type, length, and decimal places
  • Structures: consist of components that can have any type
  • Table types: describe the structure of an internal table

( Any complex user-defined type can be built from these basic types )

ABAP Dictionary services support program development程序开发服务:

  • Input helps for screen fields: F4 search help
  • Field help for screen fields: F1 documentation
  • Input check: using foreign keys
  • Set and release locks
  • Data buffering
  • Logging: 日志

ABAP Dictionary与runtime程序的关系:

  • Each change in the ABAP Dictionary takes immediate effect in the relevant ABAP programs and screens
  • When a program or screen is executed, the ABAP Interpreter and the Screen Interpreter access the type definitions stored in the ABAP Dictionary
  • The ABAP tools and the Screen Painter use the information stored in the ABAP Dictionary(比如Screen Painter上的Get from Dictionary按钮,可以直接通过数据表字段生成输入框)
  • The database interface uses the information about tables or database views stored in the ABAP Dictionary to access the data of these objects

Unit2 Data Types in the ABAP Dictionary(ABAP字典的数据类型)

2.1 Creating Domains and Data Elements(创建域和数据元素)

基本类型(重点是Domain部分):

  • Data Elements: uses domains or integrated types to define technical properties

    (1) Domains: manage the technical properties(比如Format、Output Characteristics), cannot be used directly in programs, tables and so on(域不能直接用于类型定义)

    (1.1) Format:

    (1.1.1) data type: must be from built-in list of data types(内置数据类型build-in dictionary types):

    1)CHAR: 该类型在表中最长为255字符,更长的字符需要LCHR类型,但在结构中无长度限制

    2)DATS: 长度8字符,允许在user profile中定义输出格式

    3)DEC: 最长31字符,含小数点、正负号、千分号等

    4)NUMC: 最大255字符,只能含有数字型字符

    (1.1.2) number of characters

    (1.1.3) number of decimal places

    (1.2) Output Characteristics:

    (1.2.1) maximum field length ( including commas, decimal points ): 这里的长度用于控制输入输出,但是基于format中的长度定义,且可以修改

    (1.2.2) conversion routine: 允许在display format和SAP-internal format中转换

    (1.2.3) +/-sign: 选中后数字型数值 ( DEC, FLTP, QUAN, CURR ) 前面会被占用一位,用于+/-符号,此时输出长度为数值长度加1

    (1.2.4)lower case: 不选择时小写会自动变成大写,选择后会区分大小写

    (1.2.5) value ranges: fixed values/value table for input checks

  • Structures: consists of components

    (1) elementary fields

    (2) tables

    (3) structures

  • Table types: has line type

    (1) structured type

    (2) elementary type

Data elements知识点:

  • define data types which can be used on screens, search helps, ABAP programs, and complex data types
  • contain both semantic and technical information about data type(但分工上讲更偏重语义,因为domain负责技术属性)
  • 我们可以直接用内置类定义data elements的技术属性,但SAP推荐我们使用domains来定义data elements的技术属性
  • 可作为reference type: tr_dt TYPE REF TO DATA.(这里的DATA与ANY、OBJECT类似,属于generic type)
  • 支持翻译,事务代码SE63(或ABAP Dictionary->Initial Screen->Goto->Translation)
  • 可添加additional options

    (1) Documentation: 说明文档

    (2) Search help

    (3) Set/Get Parameter

    (4) Default component name: 当data element作为BAPI structure的component时可以快速找到对应参数

    (5) Change document: 字段级的日志在CDHDR、CDPOS表中查看,表级的日志在事务代码SCU3中查看

    (6) Input history: 下拉菜单输入历史

    (7) Bi-directional options: 从左往右或从右往左

2.2 Creating Flat Structures(创建扁平式结构)

Structure components types结构元素可以有的类型:

  • Data elements
  • Integrated types内置类型
  • Table types
  • Definition of database tables and database views
  • Other structure types

Flat structure: a list of fields typed with data elements, one-dimensional

Nested structure: include another structured object

Deep structure: 元素中有表结构

注意: 有一类特殊结构叫做RANGES,标准RANGES命名规则为<fieldname>_ran,故可用*_ran在SE11中搜索。

2.3 Creating Table Types and Deep Structures(创建表类型和深度结构)

定义表结构需要以下参数(事务代码SE11):

  • A line type
  • Access mode ( standard table, sorted table, hashed table, index table, table )
  • Primary key definition and key category (Unique/Non-unique/Not specified)
  • Secondary key ( optional ) can be hashed or sorted, and sorted secondary key can be unique or non-unique

几种常见的表类型:

  • standard table: 允许index访问或key访问,只能用non-unique key
  • sorted table: 允许index访问或key访问,可以用unique key或non-unique key
  • hashed table: 只能key访问,只能用unique key
  • 通用表类型(不声明key和key category,允许使用secondary keys)

    (1) index table: standard table或sorted table

    (2) table: 所有基础表类型

  • ranges table: 含有SIGN, OPTION, LOW, HIGH等字段,配合IN计算等使用(定义ranges table可用事务代码SE11,输入表名后选择Edit->Define as ranges table type)

2.4 Creating Type Groups(创建类型组)

Type group的可用于定义:

  • Global-complex data types
  • Global constants
  • Macros宏

(新版本系统推荐使用OO技术,即constant class-attribute定义global constants)

Type group命名规则:

  • Group Name: up to 5 characters
  • Each type name and each constant name: begin with type group name

常用事务代码:

  • 事务代码SE11,ABAP Dictionary
  • 事务代码SE38,ABAP Editor(type group对应的源代码关键字为TYPE-POOL,type group文件第一句申明即是TYPE-POOL申明)

Unit3 Database Tables(数据库表)

3.1 Creating Transparent Tables(创建透明表)

表的组成:

  • fields: 字段为列

    (1) unique name

    (2) attributes: 比如是否为键值

    (3) primary key: 是一组key field,它们能唯一确定一行数据

    (4) 如果存在CURR或QUAN字段,则必需要reference table提供CUKY或UNIT

  • entries: 数据为行
  • delivery class: 表用途
  • maintenance authorization: 维护权限

Basic objects for defining data in ABAP Dictionary:

  • Tables
  • Domains
  • Data elements

两种不改原表增加字段的方法:

  • INCLUDE: Edit->Include->Insert Include

    (1) can re-use可复用

    (2) a table cannot include in another table

    (3) includes may contain other includes

    (4) foreign keys defined in INCLUDE structure are passing on to the including table附加表的外键会插入主表

  • APPEND: 新建structure

合理选择indexes、tables ( data class, size category )可以有效减少内存碎片( defragmentation )

主要的Data Class包括:

  • Master data主数据,很少被修改
  • Transaction data业务数据,经常被修改
  • Organization data组织数据,定制化或安装系统时设置,很少被修改
  • System data系统数据,配置系统用

Size Category:有0~9等选项,每个选项有固定的extend size

Log Data Changes:

  • 需要在technical settings激活
  • 需要在系统参数rec/client中启用

    (1) rec/client = ALL 所有clients启用

    (2) rec/client = 000[...] 指定client启用

    (3) rec/client = OFF全部不启用

  • 查询日志的事务代码SCU3,对应数据表DBTABLOG

Write Access Only with Java:只能用Java修改表数据,用ABAP可能出错

Technical Settings: DB-Specific Properties:配置数据库属性,如行存储、列存储等

3.2 Defining Cluster Tables and Pools Tables(定义簇表和池表)

查看簇表和池表对应的数据库表的方法:Utilities->Runtime Object

名词概念:

  • Cluster Table: 组成簇的各表
  • Table Cluster: 各表组成的簇
  • Pool Table: 组成池的各表
  • Table Pool: 各表组成的池

(注意: 簇表数据有关联functionally dependent,池表数据无关联not dependent)

簇表的字段组成:

  • Cluster Key: 即合成簇表的各表的公共键值(非公共键值将放在VARDATA中)
  • PAGNO: 各表的编号
  • TIMESTAMP:
  • PAGELG:
  • VARDATA: 非公共键值的其它字段将被压缩后存放在这里
  • Cluster Table: 组成簇的各表
  • Table Cluster: 各表组成的簇

池表的组成:

  • TABNAME: 即合成池表的各表的名称
  • VARKEY: 各表的键值,与簇表不同,各表不用使用相同的公共键值,而且分别使用各自不同的键值
  • DATALN: 各行VARDATA的长度
  • VARDATA: 除键值外的其它字段
  • Pool Table: 组成池的各表
  • Table Pool: 各表组成的池

注意:

  • 簇表数据存在关联性: In cluster tables, you store functionally dependent data among different tables into the table cluster.
  • 池表数据不存在关联性: A table pool, as opposed to table clusters, stores data records from tables that are not dependent on one another.

簇表和池表的优缺点:

  • 优点:

    (1) Fewer tables and data fields更少的表和字段

    (2) Data compression数据压缩( reduce memory and network load )

    (3) Encrypted data storage加密存储

  • 缺点:

    (1) Limitations on database functions

    (1.1) no native SQL

    (1.2) no views or ABAP joins

    (1.3) no secondary indexes

    (1.4) no GROUP BY, ORDER BY

    (2) No table appends

    (3) For cluster tables, selection is limited to cluster key fields(非键值速度慢)

    (4) For pooled tables, longer keys are needed than necessary

Unit4 Performance During Table Access(读表性能)

4.1 Creating Database Table Indexes(创建数据表索引)

Index: can be considered to be a copy of a database table reduced to certain fields(Index就是一个索引表).

创建index的注意事项:

  • 尽量小: An index should be as small as possible
  • 常用字段往前放: The most frequently selected fields should be at the first positions in the index
  • 只包含有用字段: An index must contain significant fields only(significant fields指对检索行有帮助的字段)
  • 经常变动的表尽量少定义索引: When you insert, update, or delete database content, the system must adjust all of the assigned indexes ( time-consuming ). Tables whose contents are frequently changed must not have too many indexes.
  • 尽量分离: Indexes on a table are as disjunct(分离) as possible

The database optimizer decides which index on the table should be use by the database to access data records.

Each database table has one primary index and an arbitrary(任意) number of secondary indexes and extension indexes:

  • Primary index: unique key,激活表时自动创建
  • Secondary index: 可以是unique key或non-unique key,本质是索引表,升级时可能丢失
  • Extension index: 属于Enhancement Framework,升级后不会丢失

Index命名规则:

  • three-character ID
  • ID 0 is reserved for the primary index
  • customer indexes must begin with Y or Z

创建Index的知识点:

  • 创建路径: ABAP Dictionary (SE11)->Indexes button->Create button
  • 创建时可以选择unique或non-unique,其中unique index在以下情况使用

    (1) 我们需要这个index每次只找到一个record

    (2) insert或update操作不会造成重复数据

4.2 Setting Up Table Buffering(设置表缓存)

The table access performance is improved by a factor of 10 to 100.

When you enter /$TAB in the command field, the system resets the table buffers on the corresponding application server.(注意:只有存在inconsistencies问题时执行该操作,因为该操作可能消耗数个小时。)

Buffering Types缓存类型:

  • Full buffering: all the records of the table are loaded into the buffer

    (1) Full buffering适用情形1: 表很小,经常读数很少写数

    (2) Full buffering适用情形2: 要访问的数据经常不存在,需要快速做存在检查

    (3) 只有从左往右以数据表键值进行SELECT时,才能访问这种buffer(否则应用secondary index)

  • Generic buffering: all the records whose left-justified part of the key are the same are loaded into the buffer

    (1) Generic key is a left-justified part of the primary table key

    (2) Generic key不能把表切割得太小,否则应使用full buffering

    (3) Generic buffering使用情形1: 特定区域的数据经常被访问

    (4) Generic buffering使用情形2: 数据表属性为client-dependent, fully buffered,此时实际变为Generic buffered,因为client field被视为generic key

    (5) Generic buffering使用情形3: Language-dependent tables

  • Single-record buffering: Only the record that was accessed is loaded into the buffer

    (1) 只会由SELECT SINGLE语句触发,写入buffer或读出buffer

    (2) Single-record buffering适用情形1: 只有少量用SELECT SINGLE访问的数据(非SELECT SINGLE读数操作此时会忽略buffer直接访问database)

    (3) 如果某个数据不存在,则buffer会标注该键值为non-existent,避免以后再读取这个键值

    (4) Single-record buffering与其它缓存类型的区别:

    (4.1) Single-record buffer节省存储空间

    (4.2) 管理开销( administration overhead )大于其它缓存形式

    (4.3) 如果要存入多条数据需要load很多次(而full buffering只载入一次,非常适合经常访问的小表)

配置缓存的途径:

  • ABAP Dictionary (SE11)->Technical Settings->Buffering / Buffering Type
  • 事务代码SE13

Buffer Synchronization缓存同步:

  • 周期性同步: 每隔多少秒同步一次

    (1) 配置的事务代码RZ10,系统参数rdisp/buffertime,值必须为60~3600(推荐为60~240)

    (2) 可通过事务代码RSPFPAR或程序RSPFPAR查看

  • 用指令或程序强制刷新缓存

    (1) /$SYNC - buffers of the application server

    (2) /$CUA - CUA buffer of the application server

    (3) /$TAB - the TABLE buffers of the application server

    (4) /$NAM - the nametab buffer of the application server

    (5) /$DYNP - the screen buffer of the application server 

    (6) SE63修改翻译的文本后,若屏幕未更新,可运行RSLANG20程序清空缓存

    (7) GGB1替代文本后,若屏幕未更新,可运行RGUGBR00程序重新生成主程序

Advantages and Disadvantages of Table Buffering表缓存的优缺点:

  • Advantage: the load on the network is kept to a minimum
  • Disadvantage: the local buffers of the application servers can contain obsolete data between the moments of synchronization

Summary结论:

  • Only those tables that are written very infrequently ( read mostly ), or those for which temporary inconsistencies are of no importance, may be buffered. 只有常取值少写值、数据不一致不影响业务的表才适合缓存。
  • Tables whose entries change frequently should not be buffered. Otherwise, there is constant invalidation and reloads form the database.经常被修改的表不应缓存,否则会引起频繁的数据失效与同步。

Decision Tree for Buffering设置缓存的决策策略:

是否接受临时数据不一致、是否以读数为主?

(1) 是: 可以缓存——是否预期表尺寸小于32KB?

(1.1) 是: Full buffering

(1.2) 否: 是否以SELECT SINGLE访问为主?

(1.2.1) 是: Single record buffering

(1.2.2) 否: 是否预期表尺寸大于1MB(1000条数据)?

(1.2.2.1) 是: 需要根据经验选择secondary index或buffering,以及full buffering还是generic buffering

(1.2.2.2) 否: 是否访问时常用从左到右的键值?

(1.2.2.2.1) 是: Generic buffering

(1.2.2.2.2) 否: Full buffering

(2) 否: 不可缓存

Unit5 Input Checks(输入检查)

5.1 Creating Fixed Values(创建固定值范围)

固定值的概念:

  • 固定值描述了域的值范围,可以是单值列表,也可以直接用值表
  • 只有CHAR、NUMC、DEC、INT1、INT2、INT4几种域可以用固定值
  • 固定值属于modification-free enhancements,升级后不会受到影响

用域的fixed values和字段的foreign keys,我们可以在不额外编码的情况下实现屏幕字段检查。( Validation of screen fields does not occur until a foreign key is defined or fixed values are provided in the domain definition. )

域用data type和field length描述字段取值范围。( A domain describes the value range of a field by specifying its data type and field length. )若取值范围为一组值,则可使用fixed values。

5.2 Defining Foreign Keys to Perform Input Checks(定义外键以实现输入检查)

外键的概念:

  • 如果表T的字段T-field3是表M的键值,则T-field3可以作为外键,此时T-field3的值必须是M-field3中已经有的值,否则报错。此时M被称为主表,T被称为从表(SAP系统中的主数据表和文本表就是这样的关系);
  • 默认情况下,主表和从表会互相约束:

    (1) 新增: 从表增加的数据,其外键必须存在于主表中

    (2) 更新: 主表更新的操作不能影响到从表数据

    (3) 删除: 主表只能删除从表不存在的数据

  • 用户也可以自定义主表和从表的关系,主要有三种:

    (1) NULL: 即默认情况

    (2) CASCADE: 即删除主表数据时自动删除从表数据,更新主表数据时自动更新从表数据

    (3) SET NULL: 即删除主表数据时从表对应字段值为NULL,更新主表数据时从表对应字段值为NULL

一些重要的名词和概念:

  • Foreign key: 一组字段,这组字段是check table的primary key,它关联了foreign key table和check table
  • Foreign key fields: 组成Foreign key的一组字段,这组字段同时也是主表的键值,包括但不限于check field
  • Check field: Foreign key中被检查的字段,即被主表约束的字段
  • Foreign key table: 外键表,即从表,被约束的表
  • Check table: 检查表,即主表,约束从表的表,主表也被称为referenced table

ABAP Dictionary中设置外键时需要注意的细节:

  • The same domain is required for the check field and referenced key field of the check table ( different data elements can be used, but they must refer to the same domain ).
  • The requirement for domain equality is only valid for the check field.
  • For all other foreign key fields, it is sufficient if the data type and the field length are equal(但是还是推荐domain一致,这样check table修改字段长度时,从表的字段长度会自动调整,否则会出现字段长度不一致的问题)
  • If the domain of the check field has a value table, you can have the system make a proposal with the value table as a check table.(即在创建foreign key时,系统允许用户通过check field的value table自动创建外键和检查表)
  • 上述方法在遇到同一个domain定义的不同字段时会出错,此时需要用户手工设置check table,ABAP Dictionary会列出使用该domain的所有表协助用户进行设置

Cardinality基数:设置外键时需要设置基数,ABAP Dictionary中的基数不是强限制,但会影响view的生成

  • 1:1 即主表每条数据对应从表1行数据
  • 1:N 即主表每条数据对应从表N行数据
  • 1:C 即主表每条数据对应从表0至1行数据
  • 1:CN 即主表每条数据对应从表0至N行数据

Types of Foreign Key Fields外键类型:

  • Not specified: 没有类型信息可提供
  • No key fields/candidates: 外键不是从表的主键或后备主键
  • Key fields/candidates: 外键是从表主键或后备主键
  • Key fields of a text table: 外键是主表的文本表的键值,加上语言代码字段后构成了文本表主键

补充:

  • Candidates: 指那种不是主键但是可以像主键那样确定唯一一行数据的字段组
  • Text table: 文本表,SAP系统中用于描述主表数据的一类表,他们会有一个SPRAS字段表示语言代码,以提供不同语言的文本(在主表中,选择Goto->Text table就可以查看其文本表)
  • 以T005U表为例,LAND1字段是主键的一部分但是不能确定T005U唯一一行,故其类型为Key fields/candidates;BLAND字段配合前面的字段能确定唯一一行,故其类型为Key fields of a text table,在search help中使用BLAND字段会把LAND1字段直接带出来。

5.3 Creating Text Tables(创建文本表)

知识点:

  • 主数据表为check table,即主表
  • 文本表为foreign key table,即从表
  • 每个主表最多只有一个文本表

创建文本表的步骤:

  • 创建主表和文本表
  • 进入文本表,选中要描述的字段,按下Foreign keys按钮,关联文本表和主表
  • 手工调整字段对应关系,并选择基数(通常为1:CN
  • 选中文本表中语言代码字段(通常为SPRAS),给语言代码设置外键(标准的语言代码数据存放在T002表中)
  • 保存并激活

Unit6 Dictionary Object Dependencies(字典对象依赖关系)

6.1 Differentiating Between Active and Inactive Dictionary Objects(区分激活的与非激活的字典对象)

Basic Difference激活与非激活的基本区别:

  • Active version:

    (1) the components of the runtime environment access (实际运行时的版本).

    (2) It's not initially changed (不做修改操作时就存在了).

  • Inactive version:

    (1) It has no effect on the runtime system (跟运行无关).

    (2) when you change an active object ,the system creates an inactive version that can be saved without checking (修改时创建,且保存时不做有效性检查).

用户可执行activation操作,此时将做一致性检查,如果没有问题,Inactive version将取代原来的Active version变成新的激活版本。一致性检查的意思是,待激活对象依赖的其它对象均可以被激活(即不存在错误)。对于耗时长的激活,可以选择Activating Objects in the background选项。

Mass Activation批量激活:允许同步( simultaneously )激活大量字典对象,且自动调整其激活顺序

激活操作如果成功将自动创建runtime object,如果失败将生成activation log(提供错误信息)。如果我们想显示或检查字典对象的runtime object,可以选择Utilities->Runtime Object。Runtime objects会被缓存,以便于快速访问。

Runtime Objects information:

  • Information about the overall structure(比如对象类型、字段总数等)
  • Information about individual structure fields(比如字段名称、位置、数据类型、长度、小数点位置、参考字段、参考表、转换例程等等)
  • Information required by the database interface to access the table data(比如client、缓存、键值等)

(注意:runtime objects本质上是data elements, table types, views, structures, tables等,所以可以直接用来作为types使用。)

6.2 Identifying Dependencies with ABAP Dictionary Objects(确认ABAP字典对象的依赖关系)

Dependent objects: objects that use another object either directly or indirectly.

当我们激活一个对象时,这个对象的dependent objects会被找到并也被激活。

Where-used list: 我们可以通过该表找到所有跟当前对象有关的其它对象(访问路径为Utilities->Where-used list)。

Repository Information System: The Repository Information System ABAP Dictionary is part of the general Repository Information System. The where-used list for Repository objects can be called from the information system.(Information System可用于查看仓库对象,并可以调用where-used list。)

Unit7 Table Changes(表的修改)

7.1 Performing a Table Conversion(执行表的转化)

Runtime objects、透明表和底层数据库表的关系:

  • Runtime objects的结构必须和透明表一致,否则程序运行时会报错
  • 透明表改动时底层数据库表也会改动,但有些特定改动例外(比如修改透明表的字段顺序,此时底层数据库表的字段顺序并不会改变)

查找runtime objects和database objects的方法:

  • Utilities->Runtime Object: 查看runtime对象
  • Utilities->Database Object: 查看底层数据库对象

当我们修改透明表时,可能通过以下途径改变数据库表:

  • Deleting the database table and creating it again.(这种情况会删除旧表再创建同名新表,旧表数据丢失)
  • Changing the database catalog ALTER TABLE.(即添加、修改、删除列,此时数据会保留,但是需要重新生成index)
  • Converting the table.(表转化,非常耗时)

系统如何判定选择哪种途径改变数据库表:

  • 如果表为空,则删除再创建
  • 如果表不为空,系统优先用ALTER TABLE调整列
  • 如果调整列不能解决问题,系统会采用table conversion(转化消耗资源,且期间不能访问原表,故不能在业务繁忙时采用这种方式)

(归根结底考虑三个问题:有没有数据存在、哪些数据库系统在用、有没有结构性变化。)

下面以TAB表为例讲解表转化的过程:

(1) 首先锁表,且与该表有关的视图变成非激活状态(如果转化过程中报错,则该锁不能自动解除)

(2) TAB表重命名为QCMTAB表(即TAB表名前加QCM),并删除TAB表的secondary index(如果以前已经存在QCMTAB表,旧QCMTAB表会被删除)

(3) 创建QCM8TAB表,系统中将存在两个表QCMTAB表和QCM8TAB表

(3.1) QCMTAB表沿用原TAB的结构,且存放有原表数据

(3.2) QCM8TAB表与新TAB结构相同,且不含数据

(3.3) 如果转化过程中原表数据丢失,可以进入QCM开头的表中找回原数据

(4) 通过MOVE-CORRESPONDING语句将QCMTAB的数据复制到QCM8TAB

(4.1) 如果字段长度有缩小,此时会出现信息丢失

(4.2) 必须保证足够的复制空间,另外rollback segment需要至少16MB空间

(4.3) 如果键值被减弱了,则只会有一条符合条件的数据被复制过来(这种状况建议清空表数据)

(5) 复制完成后,如果有键值减弱的操作,则QCMTAB会被保留,否则QCMTAB会被删除

(6) QCM8TAB表重命名为TAB表,重新建立TAB表的secondary index,并激活有关的视图

(7) 解锁并删除restart log(如果转化过程中报错,则锁会保留,且生成reset log,里面记录着每步操作的状态)

(8) 如果有报错,必须清除引起错误的原因并执行完转化过程

常见转化错误与解决方法:

  • Tablespace overflow: 扩展tablespace并重启转化
  • Data loss if key is reduced in size: 如果键值减弱,则只会有一条符合键值的数据被保留,建议提前清空表数据
  • Invalid change of type: 当MOVE-CORRESPONDING不能支持新的数据类型时,用户需要恢复原状

    (1) 删除新表

    (2) 将QCM表改回原表名称

    (3) 重新生成runtime object

    (4) 恢复table structure并激活

  • 对于簇表和池表,理论上也可以通过QCM开头的透明表进行转化,但是转化对于表的字段数量有限制,只要簇表或池表的字段超过数量限制就无法进行转化了

解决转化错误常用工具:

  • 事务代码SE14,Object Log允许用户查看特定表的状态或出错原因
  • 事务代码SM21,System Log允许用户查看系统日志(在Object Log找不到错误原因时使用)
  • 事务代码ST22,ABAP Dump Analysis允许用户查看报错分析
  • 另外转化出错时Database Utility会出现以下按钮:

    (1) Continue adjustment: 即用户修复错误以后,可以继续转化过程

    (2) Unlock table: 解锁(注意:如果正处于临时表互相赋值的阶段,禁止解锁)

7.2 Enhancing Tables Using Append Structures(通过Append结构增强表)

Append Structures概念:

  • 允许用户在不修改表的情况下追加字段
  • 每个append structure只能用于一个表,但一个表可以有多个append structures
  • 表激活时,所有激活的append structure的字段都会显示,而append structure修改激活后,表也会被激活
  • 与其它structure一样,append structure也可以在程序中使用
  • 如果我们复制一个表,原表append structure的字段将转换为普通字段
  • 升级不会影响append structure(事务代码SPDD允许用户手工调整升级后的表)
  • 如果在append structure增加字段后,由于升级或用户增加字段出现了新字段,底层数据库直接会把新字段放在更后面,但透明表里append的字段总是在最后(底层数据表字段和透明表字段的顺序可以不一致)

Append Structure的使用限制:

  • No append structures may be created for pooled and cluster tables
  • Tables containing a long field ( data type LCHR or LRAW ) cannot be extended with appends structures(长字符型字段必须在数据表最后)
  • The fields in the append structure must be in the customer namespace beginning with YY or ZZ.
  • It is recommended that you choose the names for your append structures from your namespace.

ABAP Dictionary can be enhanced by the customer in the following ways:

  • Customizing includes
  • Using appends

增强可能导致的错误:

  • Displacement: 即增强结构的字段置换了原表的字段
  • Syntax and runtime error: 如果取消Unicode checks,可能导致类型检查出错或深度结构出错
  • Value assignments, operand checks, access with offset and length: 如果启用Unicode checks,可能导致赋值错误等

在ABAP Dictionary菜单Extras->Enhancement category。我们可以查看对应表格的可增强属性,通常有以下几种:

Level

Category

Meaning

1

Not classified

The structure does not have an enhancement category

2

Not enhanceable

The structure cannot be enhanced

3

Enhanceable and character-like

All structure components and their enhancements must be character-like

4

Enhanceable and character-like or numerical

The structure and its enhancement cannot contain any deep data types

5

Freely extendable

The structure and its enhancements may contain components whose data type is optional

(主表内部includes和substructures的可增强属性Level不能超过主表。)

注意:

Character-like types: C, D, N, T

Numerical types: F, I, P

Hexadecimal types: X

Deep types: STRING, XSTRING

Unit8 Views and Maintenance Views(视图和维护视图)

8.1 Creating Database Views(创建数据库视图)

Views的定义: application-specific views of data in multiple tables.

  1. Several tables can be combined in a meaningful way using a view ( join )
  2. Hide information that is not important ( projection )
  3. Display only those data records that satisfy certain conditions ( selection )

构造视图的过程

  1. Cross: 首先把要JOIN的表做叉乘运算
  2. Join Condition: 然后通过ON运算筛选JOIN的数据
  3. Field Selection: 然后做PROJECTION运算,去掉不要的列
  4. Selection Condition: 然后通过WHERE运算,筛取符合条件的数据

(注意:我们可用ABAP Dictionary做JOIN运算,也可在代码中用OPEN SQL做JOIN运算,但是后者速度比较慢。)

三种视图使用的JOIN:

  • database view: inner join
  • maintenance view: outer join
  • help view: outer join

Database view知识点:

  • It is defined in the ABAP Dictionary and automatically created in the database during activation(即字典中激活则自动在底层创建对应的视图)
  • If an append structure is added to a table included in a view, the fields added with the append structure are automatically included in the view(即全表映射式的视图,如果原表有append structure,新增字段将自动进入视图)
  • To include a table in a view, you must enter the character "*" in theView Field in the view maintenance(即实现全表映射的方法是,字段栏用*号)
  • If you do not want to insert a field of the included table in the view, you must enter a "-" in the View Field, the name of the included table in the Table field, and the name of the field to be excluded in the Field name field(即全表映射若要排除不需要的字段,则需要用-号将排除的表或字段标注出来)

8.2 Creating Maintenance Views(创建维护视图)

基础概念:

  • Application Object功能对象的概念: Data that is distributed across more than one table forms a logical unit, called an application object.
  • Maintenance Views维护视图: You can easily maintain application objects by using a maintenance view. The data is automatically distributed across the underlying database table.(例如,有几个表有共同的字段,我们可以把它们用OUTER JOIN做到维护视图里,这样我们维护视图字段的时候,所有表的对应字段都将被维护。)

    (1) 维护视图的OUTER JOIN关系不是用户指定的,而是通过foreign key自动生成的,这与database view并不相同(在SE11创建视图界面的Table/Join Conditions页签有一个Relationships按钮,可列出所有外键关联的表,用户可从中选择需要联接的表,但是不能直接输入这个表)

    (2) one-step maintenance dialog相当于table control,键值不能修改,其它字段可修改

    (3) two-step maintenance dialog允许用户双击某行进入明细维护界面

  • Maintenance User Interface用户维护接口: 通过维护视图创建、修改、展示数据的接口。

创建维护视图的途径:

  • 事务代码SE54,Generate Table Maintenance Dialog
  • ABAP Dictionary->Utilities->Table Maintenance Generator
  • ABAP Dictionary->View->Maintenance View

使用SE11创建维护视图时的注意事项:

  • Select Maintenance View as the View Type
  • Place all the key fields of primary table in the View Definition
  • Include the client field for client-dependent tables or views(虽然不显示,但是MANDT会被视为primary key)
  • Do not copy the language fields for text tables as secondary tables(登录时会指定SPRAS值,所以此处不能有SPRAS字段)
  • First define the key fields, then define the function fields(即键值字段必须在普通字段之前)

在字段维护界面,有一列为maintenance attributes(字段名为P):

  • R ( Read only ): 即用户不能通过屏幕输入该字段,只能通过底层代码自动输入该字段
  • H ( Hidden ): 不在屏幕上显示
  • S ( Subset ): 显示前该字段会出现筛选条件,用户可以筛选需要的子集
  • 空值: 即正常可维护

创建维护视图( Maintenance View )的步骤:

  1. Copy Tables复制主表
    1. 指定主表
    2. 指定主表的主键
    3. 指定需要的外键,并通过relationships按钮(见基础概念部分)加入OUTER JOIN的其它表
    4. 指定其它表的外键,并通过relationships按钮加入更外围的表
  2. Copy the View Fields维护视图字段
  3. Selection Conditions筛选条件
    1.  
      1. 直接使用筛选条件
      2. 通过SE54创建表维护视图并创建变式( maintenance view variants )
  4. Maintenance Status维护状态
    1.  
      1. 设置该页签的属性,可以控制如何通过事务代码SM30访问维护视图界面
  5. Activate激活

创建表维护生成器( Maintenance Dialog )的步骤:

(维护生成器除了维护视图,还会有maintenance modules和maintenance interfaces)

  1. 创建维护视图
    1. 在ABAP Dictionary (SE11)->Utilities->Table Maintenance Generator
    2. 或在SAP Easy Access menu,选择Tools->ABAP Workbench->Development->Other Tools->Generate Table Maintenance Dialog
    3. 或直接使用事务代码SE54
  2. 通过Maintain Table Views(事务代码SM30)访问
    1.  
      1. 输入table或view名称
      2. 选择Generated Objects
      3. 选择Create/Change按钮

定义表维护生成器( Maintenance Dialog )的关键参数:

  • Function Group: maintenance components将在该函数组中
  • Authorization Group: 可以指定访问用户
  • Maintenance Type: 即one-step和two-step,后者的主界面仅列出键值和超过20字符的文本字段,其它字段将放在明细界面
  • Maintenance Screens: 屏幕编号,可通过Find Screen Number自动分配号码
  • Recording Routine: 可决定是否以及如何传输维护的数据

8.3 Creating View Cluster(创建视图簇)

为何要用视图簇(视图簇由多个维护视图组成):

  • 维护视图的表数据为1:1关系(除了文本表),而视图簇允许N:M关系
  • 在有逻辑关联的表或维护视图之间建立约束关系,保证数据一致性(原来的表和维护视图可以继续使用)

视图簇的优点:

  • Navigation导向性: 即用树状层级关系关联有关表和视图
  • Consistency一致性: 即通过约束关系保证数据一致性

视图簇由多个维护视图组成。( A view cluster consists of one or more maintenance views. )

Unit9 Search Help(搜索帮助)

9.1 Creating Search Helps(创建搜索帮助)

创建Search Help需要哪些要素:

  • Context(即上一步输入的条件 to limit the set of possible values)
  • Selection values

    (1) interface of the search help: 即IMPORT和EXPORT参数(参数可不在hit list或restriction中显示)

    (2) search string: 即通配符*和+

    (3) 辅助说明字段不应被设为IMPORT型参数

  • Dialog

    (1) hit list: 即可选值列表

    (2) hit list dialog box: 即提供可选值列表的dialog

    (3) dialog box for value restriction: 当hit list过大时,可有额外的输入界面用于筛选数据

  • Return value

(注意: Search Help可以没有IMPORT参数,但是必须有EXPORT参数。)

Elementary Search Helps基本搜索帮助需要定义如下参数:

  • Where the data com from ( selection method )
  • What information must be displayed ( search help parameters )
  • Which field contents can be selection values or return values ( search help parameters )
  • Which dialog steps must be executed( dialog behavior )

搜索帮助与视图的关系:

  • Maintenance View不可用于搜索帮助
  • Database View可用于大部分搜索帮助
  • 如果我们希望把OUTER JOIN的数据用于搜索帮助,我们需要Help View

搜索帮助增强选项:

  • 事务代码SDSH_CONFIG,Use proposal search选项为启用搜索帮助增强(需要权限对象S_DEVELOP中的02 Change权限)
  • Type-ahead search输入字段的建议搜索: 会直接显示参考表(而不用点按钮),且顺序按LPos值排序
  • Full text search全文模糊搜索: 当不确认要输入的字段值时,允许通过选择屏上其它字段找到目标数据

三种典型的search help:

  • 直接连接字段:attached directly to a field in a structure or table
  • 通过检查表/外键:if a field has a check table, its contents are automatically offered as possible values in the input help
  • 通过数据元素:the semantics of a field and its possible values are defined by its data element

(注意:Search Help维护界面右键选择技术信息,可以查看其类型。)

访问不同类型search help的优先级:

  1. Input help from screen(屏幕上的search help)
    1. PROCESS ON VALUE-REQUEST(F4函数)
    2. Search help for screen field(屏幕定义,MATCH CODE)
    3. Check of the flow logic(代码逻辑,FIELDCAT-REF_TABLE、FIELDCAT-REF_FIELD)
  2. Search help for field(本表字段的search help)
  3. Check table help(外部检查表的search help)
    1.  
      1. Search help for check tables(检查表有search help)
      2. Check table with text tables(检查表有文本表)
      3. Key values of check table(检查表有主键)
  4. Search help for data element(数据元素定义)
    1.  
      1. Search help in data element(数据元素有search help)
      2. Fixed values(数据元素的domain有固定值)
      3. Clock or calendar help(时间或日历帮助)

常用的F4函数:

  • F4IF_FIELD_VALUE_REQUEST: 将表中字段对应的search help引入
  • F4IF_INT_TABLE_VALUE_REQUEST: 自定义内表作为search help

帮助视图(Help Views)的知识点:

  • The same outer join logic is used for help views as for maintenance views
  • Selection using a table and text table corresponds to a virtual help view, don't need to create extra virtual help view. Unless there is field with the same name as a non-key field in the text table.(通常主表和文本表之间自动有帮助视图,不用专门创建。唯一的例外是主表某个字段跟文本表某个非键值字段同名,此时需要手动创建帮助视图。)
  • Start the name of help views with the prefix H_. Views beginning with the prefixes H_Y or H_Z are customer namespace.

输入帮助( input help )类型:

  • List box: 即下拉菜单
  • Control ( amodal ): 即选择屏与hit list在同一个屏幕
  • Dialog ( modal ): 即hit list

(注意:在Help->Settings里,用户可以选择显示的模式。)

9.2 Applying Advanced Search Help Techniques(提供升级版的搜索帮助技术)

Collective and Elementary Search Helps(集中搜索帮助或基本搜索帮助)

  • Collective Search Help: 包含多个基本搜索帮助或集中搜索帮助,用不同页签显示

    (1) Collective Search Help的parallel tab pages,会自动把用户最近用过的页签放在前面

    (2)Collective Search Help包含的elementary search help至少有一个激活了Proposal Search for Input Fields选项,我们才能在Collective Search Help中使用type-ahead增强选项

    (3)Collective Search Help不直接指定目标表,而是Include其它Search Help,再选择展示哪些字段给用户

    (4)Collective Search Help通过Param Assignment(参数分配)建立和子元素的映射关系

    (5) Collective Search Help前缀为C_

  • Elementary Search Help: 基本搜索帮助,一个基本搜索帮助可以被包含在多个集中搜索帮助里

用附加搜索帮助(append search help)增强集中搜索帮助(collective search help)的方法:

(1) 打开一个collective search help,选择Goto->Append search helps

(2) 输入append search help的名称和描述

(3) 选择页签Included Search Helps

(4) 选择Parameter Assignment,选择需要的字段

(5) 如果希望隐藏某些字段,请选中该字段的Hidden checkbox

(6) 激活append search help

(注意:append search help本身也是特殊的collective search help。利用append search help可以在不修改标准search help的情况下,隐藏不需要的elementary search help)

搜索帮助出口函数:

在定义搜索帮助的界面,有一个选项叫"搜索帮助出口",可参考函数F4IF_SHLP_EXIT_EXAMPLE,该函数允许用户在Search Help的输入、输出等阶段进行逻辑判断,如权限判断等。(F4UT开头的函数模块可用于实现搜索帮助出口)

利用Append Search Help可以在不修改标准Collective Search Help的情况下,隐藏不需要的Elementary Search Help。

Unit10 Selection Screens(选择屏幕)

10.1 Implementing a Selection Screen(实现一个选择屏)

Selection Screen定义: serve as an interface between the program and the user.

常用关键字:

  • PARAMETERS<name>: 单值参数(PARAMETER变量名不能超过8字符),可配合TYPE、LIKE使用

    (1) DEFAULT <value>: 默认值

    (2) OBLIGATORY: 必须输入设置

    (3) MEMORY ID <pid>: 内存传参ID(名称不超过20字符),可配合SET/GET使用

    (4) AS CHECKBOX: 作为复选框

    (5) VALUE CHECK: 输入有效性检查

    (6) RADIOBUTTON GROUP <grp> MODIF ID <id> USER-COMMAND <com>: 作为单选框,且分配该单选框的分组

    (6.1) MODIF ID <id>: 屏幕ID,配合LOOP AT SCREEN和SCREEN-GROUP1字段使用(该字段可以找到对应的MODIF ID)

    (6.2) USER-COMMAND <com>: 选择后激活一个命令,会跳入到AT SELECTION-SCREEN OUTPUT事件中(注意:INITIALIZATION事件只运行一次,后续如果返回输入界面,只会在PBO AT SELECTION-SCREEN OUTPUT和PAI AT SELECTION SCREEN中往返。INITIALIZATION事件可用于填写default value,包括1000选择屏之外的additional selection screen)

  • SELECT-OPTIONS <name>: 范围参数配合FOR使用,本质是一个RANGES型内表

    (1) DEFAULT: 同PARAMETERS

    (2) MEMORY ID <pid>: 同PARAMETERS

    (3) LOWER CASE: 将输入变成小写

    (4) OBLIGAGORY: 同PARAMETERS

    (5) NO-EXTENSION: 去掉右侧按钮,不允许多重选择

    (6) NO INTERVALS: 去掉HIGH字段的输入

  • NODES<name>: 逻辑数据库( Logical Database )选择屏
  • SELECTION-SCREEN BEGIN OF SCREEN<xxx>和CALL SELECTION-SCREEN<xxx>: 手工分配选择屏幕编号(因为默认值是1000),以及根据编号调用选择屏幕

    (1) BEGIN OF LINE: 设为一行

    (2) SELECTION-SCREEN COMMENT pos(length): 设置注释文本

    (2.1) FOR FIELD <f>: 说明文字跟在哪个字段后面

    (2.2) POSITION: 如果不直接给出位置值,就用该关键字给出位置

    (3) SKIP: 空值,如果需要设置一个空行就可以用这个

(更多细节请参考第三方资料。)

选择屏幕文本编辑路径:Goto->Text Elements->Selection Texts

SELECT-OPTIONS部分参数的含义:

Field

Value

Meaning

SIGN

I

Include

E

Exclude

OPTION

EQ

Equal

NE

Not Equal

LE

Less or Equal

LT

Less Than

GE

Greater or Equal

GT

Greater Than

BT

Between

NB

Not Between

CP

Contains Pattern

NP

Does Not Contain Pattern

10.2 Implementing Multiple Selection Screens(实施多个选择屏幕)

实施多个Selection Screen的知识点:

  • 因为默认选择屏幕编号为1000,如果有多个选择屏幕需要用户手动设置屏幕编号,设置方法为SELECTION-SCREEN BEGIN OF SCREEN <nnn>. ... SELECTION-SCREEN END OF SCREEN <nnn>.
  • 调用某个SELECTION SCREEN的方法为CALL SELECTION-SCREEN <nnn> STARTING AT <left_col><upper_row> ENDING AT <right_col><lower_row>.
  • 进入AT SELECTION-SCREEN事件,sy-dynnr可以查看当前选择屏幕编号
  • sy-subrc可以查看刚刚用户执行的操作,0代表刚刚执行了Execute操作或F8操作,4代表刚刚执行了Cancel或Exit操作

实施多个Subscreen的知识点:

  • 将选择屏幕申明为Subscreen的关键字为SELECTION-SCREEN BEGIN OF SCREEN <nnn> AS SUBSCREEN. ... SELECTION-SCREEN END OF SCREEN <nnn>.
  • 选择屏作为子屏幕,不能用于普通的Selection Screen,只能用于Dialog程序的subscreen area控件或tab控件(tab中含有subscreen area)
  • 在Dialog程序中,我们需要在主屏幕的MODULE STATUS_<nnn>.之后使用CALL SUBSCREEN <subscreen_area> INCLUDING sy-repid <nnn>.这种方式定义子屏幕
  • 在Dialog程序中,我们需要在MODULE USER_COMMAND_<nnn>.之前使用CALL SUBSCREEN <subscreen_area>这种方式获取子屏幕中输入的值
  • 在Dialog屏幕中嵌入选择屏幕作为subscreen,可以实现在屏幕中定义SELECTION-OPTION的功能
  • 定义SUBSCREEN时可以跟NESTING LEVEL <m>控制嵌入层级(通常是页签使用),跟NO INTERVALS把子屏幕的SELECT-OPTIONS变成单值输入

(可参考本人整理的在普通屏幕嵌入select-options的资料。)

实施多个Tabstrips的知识点:

  • 申明Tabstrips的方法为SELECTION-SCREEN BEGIN OF TABBED BLOCK tab_block FOR 5 LINES. ... SELECTION-SCREEN END OF BLOCK tab_block.

    (1) tab_block是用于页签控制的内表,我们需要在INITIALIZATION事件中给其赋值以选择初始显示的页签。其中有三个字段:

    (1.1) prog: 当前激活的程序,通常用默认值

    (1.2) dynnr: 初始的子屏幕编号,比如102(如果不给值,将默认为第一个子屏幕编号)

    (1.3) activetab: 初始的指令,比如'COMM2'

  • 申明页签的方法为SELECTION-SCREEN TAB (10) tab1 USER-COMMAND comm1 DEFAULT SCREEN 101.

    (1) (10)是tab1的最大长度,tab1也就是tab的名称,我们可以在INITIALIZATION事件中使用 tab1 = 'Connection'(001).这种方式给页签起名

    (2) USER-COMMAND即选中该页签时发出的指令

(请参考教材TAW10-2 310页代码。)

10.3 Implementing Input Checks and Creating Variants(实现输入检查与创建变式)

输入检查事件:

  • AT SELECTION-SCREEN ON <f/seltab>: 即输入参数改动时触发该事件
  • AT SELECTION-SCREEN ON BLOCK <block>: 即区域内输入参数改动时触发该事件
  • AT SELECTION-SCREEN ON END OF <f/seltab>: 即输入参数完成输入动作时触发该事件
  • AT SELECTION-SCREEN ON HELP-REQUEST FOR <f/seltab>: 即F1文档触发该事件
  • AT SELECTION-SCREEN ON VALUE-REQUEST FOR <f/seltab>: 即F4帮助触发该事件

变式(可配合SE93事务代码配置控制界面显示与输入):

  • 配置变式的路径为: Goto->Variants
  • 传输变式的路径为: Utilities->Transport
  • 变式可在有界面或后台进程使用,如果选择Only for Background Processing则只能后台进程使用
  • 如果选择Only Display in Catalog,则该变式虽然存在,但是却无法通过F4菜单看到,可避免别人修改该变式
  • 如果要寻找在Catalog中的变式,可以通过以下途径ABAP Editor->Goto->Variants->Variants->Catalog,该表以ALV方式展示变式以及变式的输入参数

    (1) 参数类型S: SELECT-OPTIONS

    (2) 参数类型P: PARAMETERS

  • Variant Attributes变式属性

    (1) Selection protected: 用户不能直接输入

    (2) Hide: 隐藏该输入参数

    (3) Selection variables: runtime values即动态加载输入参数

    (3.1) TVARVC table ( type T ): 用TVARVC表赋值

    (3.2) Dynamic date calculation ( type D or type X ): type D会用本地时间赋值,type X会用系统时间赋值

    (3.3) User-specific variables ( type B ): 通过MEMORY ID <pid>赋值

(变式配合事务代码运行的方法请参考第三方资料。)

Unit11 Introduction to Screen Programming(屏幕编程介绍)

11.1 Explaining the User Dialog Programming Model(解释用户对话框程序模块)

Single-Screen Transaction(单屏幕程序):

  • Input screen and data screen combined in one window
  • Switch between Create, Change, and Display
  • Direct access to each object
  • System retains context after saving

(注意: 该类型程序通常有多个INCLUDE文件)

单屏幕程序界面分为四个区:

  • Object selection: 一个树状结构,用于选择目标
  • Object ID: 显示目标主要属性
  • Details of object: 主要属性下方区域的表格,可以看到明细数据
  • Application functions: 最上层的功能按钮

ABAP Program Types(两大类六小类ABAP程序类型):

  • Complete Types: 即可执行程序类型

    (1) Executable program: Type 1

    可以用System->Services->Reporting或直接执行方式执行

    (2) Module pool: Type M

    要执行M型程序,需要至少一个事务代码,并指定初始屏幕

  • Incomplete Types: 即不可执行程序类型

    (1) Function group: Type F

    提供函数模块、类型说明、全局变量、屏幕等

    (2) Interface pool: Type J

    提供全局接口

    (3) Class pool: Type K

    提供全局类

    (4) Include program: Type I

    提供任意申明

头文件(Include programs)命名规则:

  • <name>TOP: 全局申明(如MZDEMOTOP)
  • <name>_E<nn>: Events(如MZDEMO_E01)
  • <name>_F<nn>: Form Routines(如MZDEMO_F01)
  • <name>_<module>I<nn>: PAI(如MZDEMO_<Module>I01)
  • <name>_<module>O<nn>: PBO(如MZDEMO_<Module>O01)

(当程序结构比较复杂时,最好将不同部分分别装入不同的头文件,以便于进行管理。)

11.2 Introducing Screen Programming(屏幕编程入门)

屏幕元素分类:

  • 按用途分类:

    (1) general attributes

    (2) dictionary attributes

    (3) program attributes

    (4) display attributes

  • 按可修改性分类:

    (1) Attributes that are defined statically and cannot be changed dynamically

    (2) Attributes that are defined statically and can be changed dynamically

    (3) Attributes that are only set dynamically

(在线查看屏幕元素属性的方法http://help.sap.com/nw75,Function-Oriented View ( choose language )->Application->Application Server ABAP->Application Development on AS ABAP->ABAP Workbench - Classic->ABAP Workbench Tools->Screen Painter->Maintaining Attributes for Screen Elements)

屏幕属性:

  • Administration Attributes:

    (1) Screen number:

    (2) Program: to which it belongs

  • Type: the purpose of a screen
  • Size:
  • Sequence:

    (1) Next screen: the screen must be processed after the current screen in a fixed sequence

  • Settings:

(在线查看屏幕属性的方法http://help.sap.com/nw75,Function-Oriented View ( Choose language )->Application->Application Server ABAP->Application Development on AS ABAP->ABAP Workbench - Classic->ABAP Workbench Tools->Screen Painter->Creating a Screen->Maintaining Screen Attributes)

关于OK_CODE属性:

在所有屏幕创建时(不含子屏幕),都有一个叫OK(或确定)的元素。我们可以给元素起名(如OK_CODE),。然后在程序中用同名变量获取屏幕上输入的指令。而sy-ucomm获取的不仅仅是屏幕上输入的指令。

11.3 Creating Screens and Screen Elements(创建屏幕与屏幕元素)

创建屏幕的步骤:

  • Set the general screen attributes on the attribute screen(我们有四类屏幕可选:Normal普通屏幕, Subscreen子屏幕, Modal dialog box对话框, Selection screen选择屏幕)
  • Design the screen layout in the Layout Editor(此处有按钮提供从表中选取字段作为屏幕元素的功能)
  • Set the field attributes in the field list
  • Write the flow logic in the flow logic editor

两种processors( in one program ):

  • ABAP processor: controls the program flow in a module
  • DYNP processor: controls the flow logic and prepares data to be displayed on the screen

11.4 Modifying Screens at Runtime(运行时修改屏幕)

在PBO模块中,程序会将屏幕属性读到一个行类型为SCREEN的内表中,该内表常见属性有:

  • SCREEN-NAME: unique identifier
  • SCREEN-GROUP1: 常用于RADIO分组,组名不能超过3字符
  • SCREEN-GROUP2
  • SCREEN-GROUP3
  • SCREEN-GROUP4
  • SCREEN-VALUES_IN_COMBO
  • SCREEN-LENGTH
  • SCREEN-INPUT
  • SCREEN-OUTPUT
  • SCREEN-REQUIRED

    (1) 0: user input is not required

    (2) 1: user input is required

    (3) 2: user input is recommended

  • SCREEN-INTENSIFIED: 增强
  • SCREEN-INVISIBLE
  • SCREEN-ACTIVE

运行时修改屏幕的代码(在PBO中):

LOOP AT SCREEN.

IF screen-group1 = 'SEL'.

screen-input = 1.

ENDIF.

IF screen-name = 'FIELD1'.

screen-active = 0.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

(注意: LOOP AT SCREEN命令不能跟随WHERE条件)

11.5 Designing Screen Sequence(设计屏幕顺序)

几种控制屏幕顺序的方法:

  • Static Screen Sequences: 直接通过Next Screen属性赋值,如果赋值为0或为空,则会执行完毕后回到本屏幕初始界面
  • Dynamic Screen Sequence: 动态控制

    (1) SET SCREEN nnn. LEAVE SCREEN.:离开当前屏幕进入nnn屏幕

    (2) LEAVE TO SCREEN nnn.:离开当前屏幕进入nnn屏幕

    (3) SET SCREEN 0. LEAVE SCREEN.:离开当前屏幕,进入调用该屏幕的主屏幕逻辑代码

    (4) LEAVE TO SCREEN 0.: 离开当前屏幕,进入调用该屏幕的主屏幕逻辑代码

    (5) CALL SCREEN nnn.:主屏幕调用别的屏幕时使用(注意: 该方法会insert a screen sequence)

    (6) LEAVE PROGRAM.:退出当前程序

  • Cursor Position on Screen: 光标控制,任意运行的程序会有光标指向第一个输入字段,用户可以在PBO模块用代码制定光标指向的位置

    (1) SET CURSOR FIELD <object_name> OFFSET <position>.:设定光标位置

    (2) 也可在Screen Painter中屏幕元素属性Cursor Position指定参数值

11.6 Calling a Dialog Box Dynamically(动态调用对话框屏幕)

调用屏幕代码示例:

CALL SCREEN <nnnn> STARTING AT left_col upper_row ENDING AT right_col lower_row.

注意:

  • STARTING AT会控制被调用屏幕的左上角位置
  • ENDING AT若被忽略( omit ),则屏幕尺寸由屏幕属性决定(Lines/Columns)
  • ENDING AT若给值,则屏幕将显示在指定的区域,若区域不够,则屏幕用滚动条方式显示

Unit12 The Program Interface(程序接口)

12.1 Explaining User Interfaces(解释用户接口)

User Interface用户接口:

  • GUI Title: 标题栏,通过SET TITLEBAR <n>.设置
  • GUI Status: 状态栏,通过SET PF-STATUS <n>.设置,有四个要素
  1. Menu bar: 菜单栏(含子菜单),其中System和Help菜单所有屏幕都有且不能修改或隐藏
    1. 包含Menu list,其中System和Help菜单自动出现在所有程序中
    2. 最多只有15个栏目(entries),3个层级
    3. 如果要静态菜单文本,则直接赋值(如Menu1),如果要动态菜单文本,则应给右键出字段名(此时生成的字段名称格式有尖括号围住,如<GV_MENUNAME>),然后在代码中定义同名字段(类型为SMP_DYNTXT或DYNTEXT_DEF)进行PBO赋值(详情可参考第三方资料)
    4. 通过Edit->Insert->Include menu可以将当前菜单包含进其它程序的status中
  2. Standard toolbar: 标准工具栏,所有屏幕都相同,不可用的按钮会灰掉
  3. Application toolbar: 应用工具栏,含常用按钮
  1.  
    1. 最多只有35个按钮
    2. 如果想控制未激活的按钮是否显示,需进入Goto->Attributes->Pushbutton assignment
    1. Function key settings: 快捷键
  2.  
    1. 包含Key assignments和Application toolbars
    2. 设置Application toolbars的方式为Menu Painter->Goto->Interface objects; Function key settings-><name>->Pushbutton settings; User interface->Subobject->Create
    3. function list会列出所有的menus和key assignments

PF-STATUS的按钮均含有Function Type属性,该属性决定了按钮用途:

  • 用户可用的类型

    (1) 空值: Normal

    (2) E: Exit

    (3) P: Tabstrip ctrl

  • 系统预定的类型

    (1) S: System

    (2) H: Help request

  • 事务代码

    (1) T: Transaction

(在线查看function信息的方法http://help.sap.com/nw75,Function-Oriented View ( Choose your language )->Application Server ( on left panel )->Application Server ABAP->Application Development on AS ABAP->ABAP Workbench-Classic->ABAP Workbench Tools->Menu Painter->Basic Concepts->Functions)

(查看开关switches信息的方法ABAP Keyword documentation->ABAP-Release-Specific Changes->Changes for Release 7.0->Switch Framework for Release 7.0)

注意: 我们能看到的function key有三种:

1. Reserved Function Keys

2. Recommended Function Keys

3. Freely Assigned Function Keys

12.2 Setting a GUI Title and a GUI Status(设置GUI标题和状态)

动态创建GUI标题方法示例:

  • 在PBO模块中写下如下代码: SET TITLEBAR '0100' WITH STR1 STR2.
  • 双击0100创建标题对象,在标题一栏,输入格式如下<text>&&,这里的&代表了后面动态输入的参数(最多只能有9个动态参数)
  • 最终标题会显示为<text> STR1 STR2,这里STR1、STR2作为参数代替了&符号(标题总长度不能超过20字符)

快捷键设置key settings

  • 需要符合人体工程学(ergonomic),在Menu Painter->Environment里可以看到屏幕示例。
  • 标准的function keys都在standard toolbar中被占用了(系统自动分配),自定义的function keys请把按钮放在application toolbar中(最多35个)
  • 如果想在application toolbar增加分隔符,请使用右键插入(或Edit->Insert menu)
  • 如果想在menu中增加分隔符,请使用右键插入(或Edit->Insert menu)

OK_CODE属性(前面章节有介绍):为了屏幕跳转时不要报错,我们应在跳转前使用CLEAR OK_CODE.清空指令。

注意: 我们可以用reference technique复制GUI Status,以复用menu bars、application toolbars、function key assignments。

Unit13 Simple Screen Elements(简单屏幕元素)

13.1 Creating Screen Elements for Output(创建输出用的屏幕元素)

  • Text Fields:

    (1) 不能用_开头,_符号被视为空格

    (2) 在Screen Painter->Goto->Translation可以翻译Text Fields的文本

    (3) 我们可以直接创建Text Fields,也可以通过ABAP Dictionary创建Text Fields

  • Status Icons:

    (1) Status Icons在运行时才赋值,值都预定义在系统中(可参考Report SHOWICON)

    (2) 系统会默认设置Status Icons为Output field和2D Display,用户不可更改,默认数据格式为CHAR

    (3) 用户可以更改的参数包括Vis. length、Bright、Invisible

    (4) 如果我们定义了名为iconfield的Status Icon,那么可以在代码中申明DATA: iconfield TYPE icons-text.(ICONS是ABAP Dictionary中的标准结构),然后在PBO模块中通过ICON_CREATE函数动态赋值。

  • Group Boxes:

    (1) 我们可以通过系统表SCREEN修改其Vis. length、Invisible等属性

    (2) 如果框中的元素都不可见,则框也不显示

    (3) Box可以有名称和标题,我们可以给Box起名并勾选Output attribute,然后在代码中定义同名的STRING型变量,就可以动态控制Box的标题

13.2 Creating Input/output Fields(创建输入/输出字段)

基本概念:

  • Input field: a rectangular screen element where users enter data
  • Output field: a rectangular screen element where the system displays text or other data
  • templates: Input/output fields

Input fields输入检查:

  • Automatic field input checks: 数据类型检查( related to their data type )
  • Data consistency checks: 一致性检查( create with reference to ABAP Dictionary fields )
  • Input helps: 输入帮助( possible value help )

我们可以通过系统表SCREEN修改input/output field的灰掉的属性。

不同类型的input/output field使用的属性不同,比如数据类型为CHAR时,Leading zeros属性就失效了。

创建input/output fields的方式:

  • 直接在Layout Editor中拖入

    (1) _代表字符

    (2) ,代表千分号(仅用于numeric values)

    (3) .代表小数点(仅用于numeric values)

    (4)v代表正负号(仅用于numeric values,且只能在最后)

  • 使用ABAP Dictionary模板(即使用Dictionary/Program按钮)

(自定义输入/输出字段,用DATA关键字定义同名变量进行赋值。从DDIC导入的输入/输出字段,则需要用TABLES关键字声明同名表再进行赋值。)

Dropdown boxes下拉菜单:禁止用户输入值,只能在列表中选值。创建方式如下:

  • 将Dropdown属性设为List box或Listbox with key

    (1) List box可以不输出键值

    (2) Listbox with key必须输入键值

  • 将Vis. length属性设为descriptive text (描述文本) 的长度(该长度包括了下拉按钮)
  • 将Value list属性设为空:如果字段是从ABAP Dictionary导入的且该字段有搜索帮助search help、超过两列的检查表check table或固定值fixed values,那么将自动带入列表值

13.3 Defining Checkboxes and Radio Button Groups(定义复选框和单选框)

单选框和复选框的共同属性:

  • Name:控件名称,必填
  • Text: 选项后面的文本
  • Icon: 图标
  • Input: 输入字段,即是否能输入,可用SCREEN动态修改
  • Invisible: 是否不可见,可用SCREEN动态修改

创建复选框:

  • 拖入check box控件
  • 在ABAP程序定义如下对象:DATA: <check_box_name>(1) TYPE c.
  • 我们可以分配一个function code和function type给复选框,这样就能在PAI事件中从OK_CODE获取被点击的框

创建单选框(和组):

  • 创建独立的单选按钮
  • 创建单选按钮组(选中一组按钮,选择Edit->Group->Radio button group->Define)
  • 我们可以分配一个function code和function type给单选框,这样就能在PAI事件中从OK_CODE获取被点击的框

(也可右键创建分组,而设置group1的值并不能给控件分组)

13.4 Creating Pushbuttons(创建按钮)

Pushbuttons: are input fields for the command field OC_CODE.(当我们按下按钮,PAI事件就通过OK_CODE调用对应的函数)

Pushbuttons常用属性:

  • Text: 文本描述
  • Icon: 图标,可以是静态图标,也可以配合ICON_CREATE函数实现动态图标(详细方法参见Status Icons的章节)
  • Vis. length: 可见长度,可用SCREEN动态修改
  • Output field: 输出字段,即是否作为输入值,可用SCREEN动态修改
  • Invisible: 不可见,可用SCREEN动态修改

创建Pushbuttons的方法:

  • 创建按钮,定义文本、function code和function type

    (1) function type为空: 则按下后PAI模块按顺序执行

    (2) function type为E: 则系统会在传参和输入检查之前调用后缀为AT EXIT-COMMAND的模块(该模块不受顺序影响),该模块执行完后再按顺序执行屏幕处理和输入检查等PAI操作(如果希望Exit后不再执行后续模块,就需要在该模块中增加LEAVE PROGRAM.这样的语句)

  • 激活OK_CODE

Unit14 Screen Error Handling(屏幕错误处理)

14.1 Handling Errors Using Dialog Messages and Field Input Checks(通过对话框消息和字段输入检查处理错误)

通过SET和GET读写input/output fields(请参考TAW10-1 15.2章内存部分):

  • you can save the values of the input/output fields in the SAP memory(ABAP memory用于在同一个窗口的程序间分享,而SAP memory则可在同一个用户的不同窗口下共享) using a parameter ID
  • these values are user-session specific, but available to all internal(每个代表一个程序) and external(每个代表一个窗口) sessions
  • the SET parameter copies the input/output field contents into the SAP memory in the PAI processing block
  • the GET parameter copies the corresponding field contents from the SAP memory at the end of the PBO processing block

定义SET和GET参数的方法:

  • 在ABAP Dictionary的data element中可以定义Parameter ID值,如果我们在Screen Painter中导入这个数据元素对应的字段,就可以自动带入Parameter ID的值
  • 在我们导入输入字段时可以看到一些设置属性的地方,SPA代表是否为Set Parameter ID、GPA代表是否为Get Parameter ID,PID则为ID值,我们可以通过这个结构让ID只用于SET或者GET
  • 我们可以直接在ABAP Workbench中定义Parameter ID

对话框消息共有6种:

Category

Text

Description

A

Termination

The processing terminates, and the user must restart the transaction.

X

Exit

The processing terminates with short dump MESSAGE_TYPE_X, and the user must restart the transaction.

E

Error

The processing interrupts, and the user must correct the entry.

W

Warning

The processing interrupts, and the user may correct the entries.

I

Information

The processing interrupts, but the user can continue by confirming the message choosing Enter

S

Success

Information displays on the status bar of the output screen.

Input Checks输入检查:在PAI运行前,系统会自动进行输入检查:

  1. Mandatory fields check必输字段检查:首先执行,检查必输项是否都填写
  2. Field format check格式检查:检查值类型是否与输入字段类型匹配
  3. Foreign key check外键检查:若输入字段对应的ABAP Dictionary字段有检查表,则进行外键检查
  4. Fixed values固定值检查:如果轮到固定值检查,则help function激活并列出下拉菜单

Field Input Checks with Error Dialog单一字段输入检查:

(1) Flow logic:

PROCESS AFTER INPUT.

FIELD <field_name> MODULE check_input.

(2) ABAP program:

MODULE check_input INPUT.

... MESSAGE E ... .

ENDMODULE.

注意:

  • 当系统标准的输入检查不够用时,用户需要自己编写输入检查模块,上面的例子就是针对单个字段进行输入检查的代码写法
  • 这种模块如果报出E类型或者W类型消息,系统会退回到输入界面,但是不运行PBO模块
  • E类型或者W类型消息显示时,只有被检查有错的字段是可输入的(其它字段不可编辑)

Check on Groups of Fields组合字段输入检查代码:

(1) Flow logic:

PROCESS AFTER INPUT.

CHAIN.

FIELD: <f1>, <f2>, ...<fn>.

MODULE check_input.

ENDCHAIN.

(2) ABAP program:

MODULE check_input INPUT.

.... MESSAGE E ... .

ENDMODULE.

注意:

  • 某个字段可以被包括在多个CHAIN中
  • 跟输入字段有联动输入的字段也要被包括在CHAIN中

一个输入检查控制的例子:

(1) Flow logic:

PROCESS AFTER INPUT.

FIELD A MODULE check_A.

FIELD B MODULE check_B.

CHAIN.

FIELD: C, D.

MODULE check_CD.

ENDCHAIN.

CHAIN.

FIELD: C, B.

MODULE check_CB.

ENDCHAIN.

(2) ABAP program:

MODULE check_CB.

... MESSAGE E ... .

ENDMODULE.

上面的代码,如果在输入B、C字段时出错,则会进行如下操作:

  1. 跳过PBO,回到输入界面,此时其它字段不可编辑,B、C字段可重新输入
  2. 如果B字段被更改,则从FIELD B MODULE check_B.开始执行;如果C字段被更改,则从FIELD: C, D.开始执行。总之就是从第一个申明的行开始执行。

这是因为输入检查控制遵循以下规则:

  1. If the application sends an error or warning message, the current screen is displayed back to the user, but the PBO module is not processed again.
  2. Only the fields to which the module is assigned are ready for input again.
  3. After the user enters new values, the PAI module is not completely reprocessed. It is restarted somewhere within the processing block.
  4. The system identifies the field that the user has changed and resumes processing at the first corresponding FIELD statement.
  5. If the user confirms a warning message without changing the content of the field, the system restarts the PAI processing after the MESSAGE statement where the error was triggered.

其它跟FIELD关键字有关的知识点:

  • 如果屏幕字段有的用FIELD申明过,有的没有,那么在PAI中会首先将没有申明的字段传入到程序中的同名变量,然后按顺序传入FIELD申明的字段值;
  • 如果有E或W类型消息,我们会回到输入界面,出错字段的值和跟它在同一个CHAIN中的字段的值都会被自动带入输入界面。

只在非初始值时进行输入检查的方法:

(1) 单字段写法:

PROCESS AFTER INPUT.

FIELD <field_name> MODULE <module> ON INPUT.

(2) 组合字段写法:

PROCESS AFTER INPUT.

CHAIN.

FIELD: <f1>, <f2>, ...<fn>.

MODULE <module> ON CHAIN-INPUT.

只在修改操作时进行输入检查的方法:

(1) 单字段写法:

PROCESS AFTER INPUT.

FIELD <field_name> MODULE <module> ON REQUEST

(2) 组合字段写法:

PROCESS AFTER INPUT.

CHAIN.

FIELD: <f1>, <f2>, ...<fn>.

MODULE <module> ON CHAIN-REQUEST.

避免输入检查的方法:

(1) Flow logic:

PROCESS AFTER INPUT.

MODULE exit AT EXIT-COMMAND.

因为退出型模块比所有模块都先执行,也先于自动输入检查执行,所以我们可以把返回和退出功能放在这种模块里。这样我们如果直接退出,就不会进行输入检查了。

如果我们未退出,那么还是会按顺序执行后面的模块,包括先进行的自动输入检查。

(2) ABAP program:

MODULE exit INPUT.

CASE ok_code.

WHEN 'CANCEL'.

CLEAR ok_code.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE.

开关控制( Switch-Depending )的模块调用方法:

(1) Flow logic:

PROCESS AFTER INPUT.

MODULE add_check SWITCH sw_nnn.

只有开关存在且处于ON状态时才执行该模块。开关不存在或者OFF都不执行该模块。

开关对应的屏幕字段不能用FIELD关键字申明。

(2) ABAP program:

MODULE add_check INPUT.

CASE ok_code.

WHEN 'ADD_FUNCTION'.

...

ENDCASE.

ENDMODULE.

14.2 Handling Errors Using Navigation and Input Help(用导航和输入帮助处理错误)

Navigation Functions导航函数:

  • Back: 返回同级的前一个输入界面,如果是被调用程序则返回主程序输入界面
  • Cancel: 返回当前程序输入界面初始状态
  • Exit: 返回主程序界面
 

BACK/Change Session

Exit

Cancel

Saves dialog

Yes

Yes

No

Check entries

Yes

Yes

No

Sequence

Check, then save dialog

Save dialog, then check

-

Function type

''

'E'

'E'

Example

Save data?

Save data?

Unsaved data will be lost, Cancel?

Function module for dialog

popup_to_comfirm

popup_to_comfirm

popup_to_comfirm

用户输入标识: SY-DATAR,当用户有输入时为X,否则为空,可用于在退出前进行检测,以避免丢失数据。

Change Session: 上表中的Change Session即Change/Display切换,需要注意的是,如果没有保存修改后的数据就切换成Display,则系统会显示保存前的数据。

Input Help: 即系统标准功能F4帮助,可以通过Field旁边的按钮或F4打开并列出所有参考输入值。通常input help跟语义层有关,所以在ABAP Dictionary中定义。

注意: 在Single-Screen Transaction中,BACK和EXIT会退出当前程序并进入主调程序calling program,但CANCEL会再次显示界面并清空输入字段with initialized data fields。

Unit15 Subscreens(子屏幕)

15.1 Creating Subscreens(创建子屏幕)

子屏幕概念:A subscreen area is reserved rectangular area on a screen in which you place another screen at runtime.

根据概念可知,子屏幕具有以下特点:

  • 模块化 Modularization of screens
  • 动态化 Dynamic screen modifications
  • 可复用 Reusable subscreens

子屏幕主要用途:

  • 用分组展示输出元素 (display a group of objects from the main screen)
  • 控制某些元素的展示或隐藏 (display or hide extra fields on the main screen)
  • 复用 (一个子屏幕可用于多个主屏幕,一个主屏幕可包含多个子屏幕,用户可在runtime决定用哪个子屏幕)

以下场景可能用到子屏幕:

  • 屏幕增强: Screen Enhancement ( for example, screen exits )
  • 屏幕切换: Within other screen objects ( for example, tabstrip controls )
  • 修改帮助: Modification Assistant
  • 网页程序: Web transactions

子屏幕常用属性:

  • Resizable: 允许从纵向(Vertical )或横向(Horizontal )缩放子屏幕的大小
  • Minimum size: 允许设定纵向或横向的最小尺寸
  • Scrollable: 允许在subscreen area面积不足时出现滚动条(默认情况下,若子屏幕面积大于subscreen area则从左上角起只显示subscreen area大小的部分)
  • Context: 允许在子屏幕输出时设定上下文相关的菜单

使用子屏幕的限制:

  • CALL SUBSCREEN不能在LOOP和ENDLOOP之间、CHAIN和ENDCHAIN之间使用
  • 子屏幕没有OK_CODE字段
  • 一个主屏幕中的子屏幕不能重名
  • 子屏幕没有AT EXIT-COMMAND型的module
  • 子屏幕不能使用SET TITLEBAR,SET PF-STATUS,SET SCREEN,LEAVE SCREEN等关键字

在Screen Painter拖入Subscreen Area即可创建屏幕区域,且必须在Flow logic的PBO和PAI模块写代码进行调用:

PROCESS BEFORE OUTPUT.

CALL SUBSCREEN <subarea> INCLUDING <program_name><dynpro_number>.

PROCESS AFTER INPUT.

CALL SUBSCREEN <subarea>.

  • <subarea>即屏幕区域名称
  • <program_name>即哪个程序中的子屏幕(可使用任何程序名,如函数组主程序名、sy-repid、sy-cprog等)
  • <dynpro_number>即子屏幕编号

有时为了动态选择屏幕号,PBO代码会写成:

CALL SUBSCREEN sub INCLUDING sy-cprog dynnr.

为了在ABAP Program中动态控制dynnr,我们需要在TOP头文件中定义同名变量:

DATA: dynnr TYPE sy-dynnr,

ok_code TYPE sy-ucomm.

如何通过函数组实现可重复调用的子屏幕:

  1. 在SE80创建Function Group并在其中创建屏幕
  2. 同一个函数组的对象可以共享全局变量,故子屏幕的全局变量需要被定义在函数组头文件中,以供其它Functions使用,这些Functions将用来对子屏幕进行读值和写值
  3. 主程序跟要调用的子屏幕不在同一个函数组,故不能直接通过全局变量读写子屏幕中的值,这时就需要第2步写的读值和写值functions来帮助主程序进行读值和写值

主程序利用函数组调用子屏幕的示例代码如下:

  1. Flow logic:

PROCESS BEFORE OUTPUT.

MODULE status_<nnnn>.

MODULE export_data.

CALL SUBSCREEN sub1 INCLUDING 'SAPL…''0100'.

PROCESS AFTER INPUT.

CALL SUBSCREEN sub1.

MODULE import_data.

MODULE user_command.

注意: 若想显示时子屏幕有值,则子屏幕读值函数得在PBO中调用子屏幕之前;若想把主屏幕的值写入子屏幕,则子屏幕的写值函数应在PAI中调用子屏幕之后。为了让主程序能响应子屏幕的输入,则user_command应该在最后。

  1. ABAP Program:

MODULE export_data OUTPUT.

CALL FUNCTION 'F1'

EXPORTING

p1_f1 = … .

ENDMODULE.

MODULE import_data INPUT.

CALL FUNCTION 'F2'

IMPORTING

p1_f1 = … .

ENDMODULE.

Unit16 Tabstrip Controls(页签控制)

16.1 Creating Tabstrip Controls(创建页签控制)

页签适用场景:

  • To simplify complex applications
  • Whenever you have various components of an application that form a logical unit

页签不可使用的场景:

  • You need to change the screen environment while processing the application components (页签的屏幕环境必须恒定)
  • The components need to be processed in a certain order ( 页签根据用户最近访问排序,没有固定顺序 )
  • The components are processed dynamically ( 页签不支持动态,否则用户在一个页上输入可能跳出别的页 )

页签的组成:

  • Current tab title
  • Scrollbar for more tab pages
  • List of all tab pages ( current page is indicated )
  • Tab border

创建页签的方法:

  1. Define the tab area定义页签控制区域( tabstrip control area ):
    1. Choose tabstrip control from the object list in the Screen Painter, and place it on the screen.
    2. Assign a name to the tabstrip control in the Object name attribute.
    3. In the TOP include of your ABAP program, declare like this – CONTROLS: my_tab_strip TYPE TABSTRIP.(注意: TABSTRIP是定义在CXTAB类型池中的结构,其字段可控制页签,比如ACTIVETAB字段可以指定展示的页)
  2. Define the tab titles and, if necessary, add further tab titles定义页标题
    1.  
    2.  
      1. 页标题相当于一个pushbutton
      2. 设定的属性包括Name、Text、Function code、Function type(空值类型,则按下页时触发PAI;P类型,用户可在页间滑动而不触发PAI)
      3. 如果想增加页的数量,可以拖动Pushbutton按钮到你的页标题区域(tab title area )
  3. Assign a subscreen area to each page element分配子屏幕
    1.  
    2.  
    3.  
      1. 页签中间的位置,可以放置子屏幕区域
      2. 在页标题中,有一个属性叫做reference field,其值为子屏幕区域ID,通过这个参数,我们可以让不同的页共享子屏幕,也可以让它们分别使用自己的子屏幕
      3. 如果我们在点中某个页之后再将子屏幕区域拖入,系统将自动为其命名并与页标题进行关联

16.2 Programming Tabstrip Controls(编程控制页签)

各页拥有自己子屏幕区域的情况:

  1. Flow logic:

PROCESS BEFORE OUTPUT.

CALL SUBSCREEN subarea1 INCLUDING sy-cprog '0101'.

CALL SUBSCREEN subarea1 INCLUDING sy-cprog '0102'.

CALL SUBSCREEN subarea1 INCLUDING sy-cprog '0103'.

PROCESS AFTER INPUT.

CALL SUBSCREEN subarea1.

CALL SUBSCREEN subarea2.

CALL SUBSCREEN subarea3.

  1. ABAP:

CONTROLS: my_tab_strip TYPE TABSTRIP.

  • 每页都有自己的子屏幕区域,分配不同的子屏幕
  • 我们在主屏幕的flow logic调用这些子屏幕
  • 如果我们希望自由滑动( locally scrolling ),则各页的Function Type均应为P(注意: local scrolling适合显示型业务display transaction)
  • 如果有某页的Function Type为空值,则所有页都将触发PAI
  • 如果某子屏幕不含任何控件,则将被隐藏

各页共享子屏幕区域的情况:

  1. Flow logic:

PROCESS BEFORE OUTPUT.

MODULE fill_dynnr.

CALL SUBSCREEN subarea INCLUDING sy-cprog dynnr.

PROCESS AFTER INPUT.

CALL SUBSCREEN subarea.

MODULE user_command.

  1. ABAP:

CONTROLS: my_tab_strip TYPE TABSTRIP.

DATA: ok_code LIKE sy-ucomm,

dynnr LIKE sy-dynnr.

MODULE fill_dynnr OUTPUT.

CASE my_tab_strip-activetab.

WHEN 'FC1'.

dynnr = '0101'.

WHEN 'FC2'.

dynnr = '0102'.

WHEN 'FC3'.

dynnr = '0103'.

WHEN OTHERS.

dynnr = '0101'.

my_tab_strip-activetab = 'FC1'.

ENDCASE.

ENDMODULE.

MODULE user_command INPUT.

CASE ok_code.

WHEN 'FC1' OR 'FC2' OR 'FC3'.

my_tab_strip-activetab = ok_code.

ENDCASE.

ENDMODULE.

  • PBO模块,我们需要在调用子屏幕前确定要显示的子屏幕是哪个
  • PAI模块,我们需要对选中的子屏幕做出反映
  • 所有页共享子屏幕区域,且Function type为空值
  • 我们可用SCREEN-ACTIVE控制各页显示或隐藏

用户若不愿手工创建页签,可以借助Tabstrip Control Wizard自动创建页签。

原文地址:https://www.cnblogs.com/Intercalaryland/p/10522537.html