Kbase P151058: How to share a reference-only ProDataSet between external procedures
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  8/14/2009 |
|
Status: Unverified
GOAL:
How to share a reference-only ProDataSet between external procedures
GOAL:
Example using REFERENCE-ONLY and BIND to share a ProDataSet between procedures
GOAL:
Example of passing a dataset parameter by reference
FIX:
The following example code illustrates how a single ProDataSet can be shared between persistent procedures that are external to each other. The main procedure defines a ProDataSet with one temp-table for use by two external procedures which are run persistently. The two procedures each define both the dataset and the underlying temp-table REFERENCE-ONLY. This means that they will each use the dataset that was created in the main procedure, not two private copies of it. The dataset is in scope for all three procedures as long as the main procedure is running.
The persistent procedures can run each other's internal procedures. Each of them always has the results of any changes the other procedure has made to the dataset, because they are both updating the same object. Whether a procedure is running its own internal procedure or running a procedure in the external persistent procedure's handle, it always passes the dataset as a parameter BY-REFERENCE. Each internal procedure defines its input parameter with the BIND keyword, so it can perform its operations on the shared ProDataSet rather than creating a copy.
/* Procedure: calling.p */
/*
Create a ProDataSet to be shared by two external persistent procedures.
Demonstrate how they are shared by passing the dataset BY-REFERENCE.
*/
DEFINE TEMP-TABLE ttCallingTable
FIELD iField AS INTEGER
FIELD cField AS CHARACTER
INDEX ifield IS UNIQUE
ifield .
DEFINE DATASET dset FOR ttCallingtable .
DEFINE VARIABLE hProcA AS HANDLE NO-UNDO.
DEFINE VARIABLE hProcB AS HANDLE NO-UNDO.
RUN jl/called2a.p PERSISTENT SET hProcA.
RUN jl/called2b.p PERSISTENT SET hProcB.
CREATE ttCallingTable.
ASSIGN
iField = 100
cField = 'Assigned in calling2.p'.
RUN DisplayRoutineTable IN hprocA (INPUT DATASET dset BY-REFERENCE,
INPUT hprocB).
RUN DisplayttCallingRoutineTable ('Calling Procedure after A').
RUN DisplayRoutineTable IN hprocB (INPUT DATASET dset BY-REFERENCE,
INPUT hprocA).
RUN DisplayttCallingRoutineTable ('Calling Procedure after B').
DELETE PROCEDURE hProcA.
DELETE PROCEDURE hProcB.
PROCEDURE DisplayttCallingRoutineTable:
DEFINE INPUT PARAMETER pcMessage AS CHARACTER NO-UNDO.
FIND FIRST ttCallingTable.
MESSAGE pcMessage SKIP
iField cField
VIEW-AS ALERT-BOX.
END PROCEDURE.
/* Procedure: called_a.p */
/*
First of two procedures to demonstrate the binding and sharing of a
ProDataSet passed BY-REFERENCE. This procedure is assumed to be run
persistently by a main procedure which creates the dataset.
*/
DEFINE TEMP-TABLE ttCalledTable
REFERENCE-ONLY
FIELD iField AS INTEGER
FIELD cField AS CHARACTER
INDEX ifield IS UNIQUE ifield..
DEFINE DATASET dset REFERENCE-ONLY FOR ttCalledTable.
PROCEDURE DisplayRoutineTable:
DEFINE INPUT PARAMETER DATASET FOR dset BIND.
DEFINE INPUT PARAMETER hOtherPersistentProcedure AS HANDLE NO-UNDO.
FIND FIRST ttCalledTable.
MESSAGE 'Called A - Before Update' SKIP iField cField
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ASSIGN ifield = 25
cField = "Got it A".
MESSAGE 'Called A - After Update' SKIP iField cField
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RUN AnotherInternalProcedureA (INPUT DATASET dset BY-REFERENCE).
RUN AnotherInternalProcedureB
IN hOtherPersistentProcedure (INPUT DATASET dset BY-REFERENCE).
END PROCEDURE.
PROCEDURE AnotherInternalProcedureA:
DEFINE INPUT PARAMETER DATASET FOR dset BIND.
FIND FIRST ttCalledTable.
MESSAGE 'AnotherInternalProcedureA - my DATASET IS IN scope'
SKIP iField cField
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END PROCEDURE.
/* Procedure: called_b.p */
/*
Second of two procedures to demonstrate the binding and sharing of a
ProDataSet passed BY-REFERENCE. This procedure is assumed to be run
persistently by a main procedure which creates the dataset.
*/
DEFINE TEMP-TABLE ttCalledTable
REFERENCE-ONLY
FIELD iField AS INTEGER
FIELD cField AS CHARACTER
INDEX ifield IS UNIQUE ifield.
DEFINE DATASET dset REFERENCE-ONLY FOR ttCalledTable.
PROCEDURE DisplayRoutineTable:
DEFINE INPUT PARAMETER DATASET FOR dset BIND.
DEFINE INPUT PARAMETER hOtherPersistentProcedure AS HANDLE NO-UNDO.
FIND FIRST ttCalledTable.
MESSAGE 'Called B - Before Update' SKIP iField cField
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ASSIGN ifield = 50
cField = "Got it B".
MESSAGE 'Called B - After Update' SKIP iField cField
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RUN AnotherInternalProcedureB (INPUT DATASET dset BY-REFERENCE).
RUN AnotherInternalProcedureA
IN hOtherPersistentProcedure (INPUT DATASET dset BY-REFERENCE).
END PROCEDURE.
PROCEDURE AnotherInternalProcedureB:
DEFINE INPUT PARAMETER DATASET FOR dset BIND.
FIND FIRST ttCalledTable.
MESSAG.E 'AnotherInternalProcedureB - my DATASET IS IN scope'
SKIP iField cField
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END PROCEDURE.
.