Sharing a Record Group Across Forms in Oracle D2k
Sharing a Record Group Across Forms
Before Forms 5.0, there was no way to share data by means of record groups across forms in a multiform application. Such a requirement arises when a result set is to be shared. The only way to do this is either by means of a PL/SQL table of records defined in a package or by means of too many global variables. The former requires additional code to be maintained out side Forms or to-and-fro round trips from Forms to server, and vice-versa, if maintained in the database.
The following tips are worth noting:
Sharing a record group by passing it as a parameter to the called form is not allowed.
Copying or subclassing a record group across other forms shares only the structure and not the data.
Referencing a record group does not share data in the record group. Only the structure is carried over.
Record groups created dynamically and placed in a library do not share data contained in them.
From Forms 5.0 onwards, there is a way to share the data in record groups across forms in the same run-form session—by creating the record group dynamically and specifying GLOBAL_SCOPE for the scope parameter.
Consider two forms, A and B. Create a record group RG_LIST in form A with the scope parameter specified as GLOBAL_SCOPE. Form A is the calling form that calls form B. The following code segment illustrates this concept:
rg_name := 'RG_LIST';
rg_id := FIND_GROUP(rg_name);
IF NOT ID_NULL(rg_id) THEN
The constant GLOBAL_SCOPE is specified to indicate global scope.
The default scope is FORM_SCOPE, which is for the current form only */
'SELECT state_code, state_name from state order by 1', GLOBAL_SCOPE);
ret_code := POPULATE_GROUP( rg_id );
IF (ret_code <> 0) THEN
MESSAGE('ERR: Populating Record Group '||rg_name);
In form B, the data in this record group can be assessed by a call to the GET_GROUP_..._CELL as follows:
FOR i IN 1..GET_GROUP_ROW_COUNT LOOP
/* The column state_name of the record group rg_list created in form A
is directly accessible in form B */
v_state_name := GET_GROUP_CHAR_CELL('RG_LIST.STATE_NAME', i);
Note how a call to GET_GROUP_CHAR_CELL makes the value of a cell of the record group created in form A, directly available.
Additional Tips for Sharing Record Groups
The following points provide a list of useful tips to be kept in mind while sharing record groups across forms:
A record group created with GLOBAL_SCOPE can be either query or nonquery. However, if a query record group contains local bind variable references, it is automatically converted into a nonquery record group, with the data retained after the current form is exited.
GLOBAL_SCOPE record groups, when placed in libraries and attached to two or more forms, enable the data to be shared even if the target forms are the result of calls to CALL_FORM or OPEN_FORM with the data_mode parameter set to NO_SHARE_LIBRARY_DATA.
The need to use PL/SQL 2.x and 8.x features such as packaged index-by tables, tables of records, cursor variables, object types, and so on, is eliminated by using GLOBAL_SCOPE record groups. This avoids unnecessary trips to the database. Also server memory is saved significantly.