1. 程式人生 > >SAP ABAP 使用記憶體引數設定SET /GET PARAMTER ID

SAP ABAP 使用記憶體引數設定SET /GET PARAMTER ID

更多內容關注公眾號:SAP Technical

 

   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 pidpid 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.