sapdev logo background
sapdev logo sapdev logo
Comments

SAP REF TRANSF OUTPUT PARAM GUIDL documentation, setup help and example usage



Return to SAP documentation index


GUIDELINE 6.40

Pass By Reference for Output Parameters

ABAP_BACKGROUND
When parameters are passed to a procedure by reference, this procedure directly uses the data object that has been passed as a parameter. Its value is consequently determined by the calling program of the procedure. Particular notice must be made of this behavior for
EXPORTING parameters, whose value is (unlike the pass by value method) not initialized when the procedure is called. After the procedure has started, an output parameter that was passed by reference has the value of the supplied actual parameter.

ABAP_RULE
Use Output Parameters with the Pass by Reference Method Correctly
Do not evaluate EXPORTING parameters that are passed by reference in a procedure ( method ) until a value has been explicitly assigned.

ABAP_DETAILS
Because the value of an output parameter that has been passed by reference is undefined from the procedure�s perspective, it cannot be evaluated within the procedure in a useful manner. Therefore, no assumptions can be made regarding the content of the parameter until the first value has been assigned to it.
If a parameter like this is an internal table or a string, a simple write is not sufficient. First, an initialization must be implemented. For example, if new rows are to be inserted in an internal table that is supposed to be produced by reference, its current content needs to be deleted first. Pass by reference means that it cannot be guaranteed that the table is actually empty when the procedure is started. The same applies to strings that are filled using concatenation operations within the procedure.

Note
If the described properties are to be exploited for writable parameters that have been passed by reference in a procedure (
method ), that is, a read is to be performed prior to the write or an existing dynamic data object is to be extended, the appropriate formal parameter type must be specified, that is, input/output parameter ( CHANGING parameter).

Exception
Strictly speaking, optional output parameters that have been passed by reference must be initialized only if the parameter is bound to an actual parameter when called. This can be determined using the IS SUPPLIED query. The obsolete query, IS REQUESTED , in contrast, should no longer be used.

Example
The following source code shows how an internal table that, for performance reasons, is implemented by reference is returned. For this reason, it cannot be declared as a RETURNING parameter. The tabular output parameter is explicitly initialized at the beginning of the method before new lines are inserted.
CLASS class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS get_some_table
EXPORTING e_some_table TYPE table_type.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD get_some_table.
DATA new_line LIKE LINE OF e_some_table.
CLEAR e_some_table.
...
INSERT new_line INTO TABLE e_some_table.
...
ENDMETHOD.
ENDCLASS.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




REF_TRANSF_GLOBAL_DATA_GUIDL
REF_TYPES_OBJECTS_GUIDL




comments powered by Disqus