SET /GET PARAMTER ID使用SPA/GPA 参数--SAP内存参数设置
这是在外部程序之间传送数据的最常用方法。使用EXPORT/IMPORT数据(ABAP/4内存)任何程序都可以使用EXPORT语句在ABAP/4内存中存储数据字段簇。因此,该数据就全局有效(使用IMPORT),在程序本身中以及任何被调事务、报表或其它模块中都有效。使用EXPORT:
EXPORT<OBJECT1><OBJECT2>...<OBJECTN>TOMEMORYID<ID-NAME>.
然后调用程序就会检索数据:IMPORT<OBJECT1><OBJECT2>...<OBJECTN>FROMMEMORYID<ID-NAM>.ID参数标识唯一的数据簇。如果将同一对象多次输出到同一ID,则会改写内存中该簇的第一个版本。如果第二次输出对象的子集,则仍会改写该组的第一个版本中的“所有”对象(不仅是子集)。只有调用程序和被调用程序经常一起使用时,才用EXPORT/IMPORT实现参数传送。对于外部应用程序可用的调用程序不推荐EXPORT/IMPORT,因为这些应用程序将根本无法找到调用所需的接口。
用SPA/GPA参数传送数据可使用SPA/GPA参数向被调用的程序传送数据。SPA/GPA参数是全局保存在内存中的字段值。每个参数都用三个字符代码标识:通过选择在第一个屏幕上的“其他对象”可以在对象浏览器中定义这些参数。SPA/GPA存储器是用户指定的并在用户整个会话期中都有效。有两种使用SPA/GPA参数的方法:通过在“屏幕制作器”中设置字段属性“SET参数”、“GET参数”和“参数ID”属性告知系统是向“参数ID”存储值还是从中检索值。系统使用这些值自动初始化屏幕字段值。对调用屏幕中给定字段的“SET参数”属性以及被调用屏幕中相应字段的“GET参数”属性进行标记。系统会自动将字段内容从调用事务传送给它所触发的事务中。通过使用
SET PARAMETER或GET PARAMETER语句用这些语句可以存储和检索来自ABAP/4程序的SPA/GPA值。如果两个事务的选择屏幕没有共享同一必需的字段,则请使用这些语句按名称显式存储屏幕字段。在从PAI模块调用新事务之前,用一个名称之下存储调用程序事务的字段:
SET PARAMETER ID 'RID' FIELD <FIELD NAME1>.系统将值存储在SPA参数‘RID’中的<字段1>中。三个字符的标识符‘RID’必须在SAP表TPARA中定义。如果SPA参数‘RID’已经包含值,则SET PARAMETER语句会将其改写掉(用<FIELD NAME1>的内容)。在被调事务的PBO模块中,在其他名称下检索字段:
GET PARAMTER ID 'RID' FIELD <FIELD NAME2>.
系统读取‘RID’的内容并将其传送给<FIELD NAME2>。例如,假定要将屏幕字段和其它数据从调用事务传送给被调用事务。调用事务可以将某些值存储在SPA参数中:
SET PARAMETER ID 'RID' FIELD REPORT ID.
CALL TRANSACTION 'SE38'.
然后,被调事务即可在PBO获取信息,以便将其显示到屏幕上。此处将出现事务SE38的初始屏幕,其报表ID已填好。这在使用CALL TRANSACTION AND SKIP FIRST SCREEN时非常有用。除非所需的字段值由内存提供,否则不能取消第一个屏幕。
以上内容转自:http://jiahongguang12.blog.163.com/blog/static/33466572007112792756238/
注:表TPARA存放字段参数和参数描述
以下为摘自SAP ABAP 经典中文帮助。
GET PARAMETER
Syntax
GET PARAMETER ID pid FIELD dobj.
Effect
This statement sets the content of the data object dobj to the content of the SPA/GPA parameter specified in pid. pid must be a flat character-type field that contains no more than 20 characters and does not consist solely of blanks; it is also case-sensitive. dobj must be a flat and (as of Release 6.10) character-type field into which the binary content of the SPA/GPA parameter is transferred unconverted.
If the SPA/GPA parameter specified in pid was not yet created in the SAP Memory for the current user, the data object dobj is initialized and sy-subrc is set to 4.
In a program, only those SPA/GPA parameters can be read for which there is a name in the table TPARA. The extended program check reports an error, if it can be statically determined that an ID specified in pid is not in the table TPARA.
System fields
sy-subrc | Meaning |
---|---|
0 | The SPA/GPA parameter specified in pid exists for the current user in the SAP Memory and its value was transferred to the target field. |
4 | The SPA/GPA parameter specified in pid does not exist for the current user in the SAP Memory. |
Notes
- An SPA/GPA parameter that is readable with GET PARAMETER can previously have been created in the SAP Memory using the SET PARAMETER statement or automatically during the event PAI of a screen or selection screen.
- For an SPA/GPA parameter specified in pid to match a name in the database table TPARA, it must be specified in uppercase.
Example
In this example, the current value of the SPA/GPA parameter RID is read from the SAP Memory to the data object prog. In the screens of the ABAP Workbench, this parameter is linked with the input fields for a program name. When an ABAP Workbench tool, in which an ABAP program is processed, is first called, the parameter is created at the event PAI and assigned the name of the program specified there. If in the same user session, no screen is processed that set the parameter RID and no corresponding SET PARAMETERstatement was executed beforehand, RID is not found in the SAP Memory.
DATA: para TYPE tpara-paramid VALUE 'RID', prog TYPE sy-repid. GET PARAMETER ID para FIELD prog. IF sy-subrc <> 0. MESSAGE 'Parameter not found' TYPE 'I'. ENDIF.