Error
Error Code:
1313
SAP S/4HANA Error 1313: Invalid SQLScript Output Parameter
Description
This error, ERR_SQLSCRIPT_OUT_PARAM_TABLE, indicates that an output parameter within an SAP HANA SQLScript procedure or function is not correctly defined as a table or a table variable. It typically occurs when the SQLScript logic attempts to return a set of rows and columns through a parameter declared for a scalar value, preventing the procedure from executing successfully.
Error Message
ERR_SQLSCRIPT_OUT_PARAM_TABLE: Output parameter should be a table or a table variable
Known Causes
3 known causesIncorrect Output Parameter Type
The output parameter in the SQLScript procedure or function definition is declared with a scalar data type (e.g., INT, VARCHAR) instead of a TABLE type or a table variable type.
Return Type Mismatch
The logic within the SQLScript attempts to assign a table or a record set as the result to an output parameter that was not explicitly defined to receive a table or table variable.
Scalar Output for Table Data
A SQL query or operation that produces multiple rows or columns is erroneously assigned to an output parameter that is defined to hold only a single, scalar value.
Solutions
3 solutions available1. Correct Output Parameter Type in SQLScript easy
Ensure the output parameter of your SQLScript is declared as a table type.
1
Identify the SQLScript that is causing the error. This is typically found in stored procedures or functions used within SAP S/4HANA.
2
Examine the declaration of the output parameter. It should be declared using a table type. If it's declared as a scalar type (e.g., VARCHAR, INT), it needs to be changed.
-- Incorrect declaration:
OUT my_scalar_output VARCHAR(100);
-- Correct declaration:
OUT my_table_output MY_TABLE_TYPE; -- Assuming MY_TABLE_TYPE is a defined table type
3
If a suitable table type doesn't exist, create one using the `CREATE TYPE` statement. This type should match the structure of the data you intend to return.
-- Example of creating a table type:
CREATE TYPE MY_TABLE_TYPE AS TABLE (
column1 INT,
column2 VARCHAR(50)
);
4
Ensure that the SQLScript populates this table type output parameter with data before returning.
-- Example of populating the table output:
INSERT INTO :my_table_output (column1, column2)
SELECT col_a, col_b FROM some_source_table WHERE condition;
2. Review Table Variable Usage for Output medium
Verify that any table variables used as output parameters are correctly declared and populated.
1
Locate the SQLScript and identify any table variables that are intended to be returned as output.
2
Check the declaration of the table variable. It should be declared using `TABLE` or a defined table type. Ensure it's not a scalar variable.
-- Correct table variable declaration:
DECLARE my_table_var MY_TABLE_TYPE;
-- Or using a built-in table type (less common for output):
DECLARE my_table_var TABLE (...);
3
Confirm that the table variable is assigned to the output parameter of the SQLScript. The syntax might involve direct assignment or returning the table variable itself.
-- Example of assigning a table variable to an OUT parameter:
OUT my_output_table MY_TABLE_TYPE;
-- ... within the procedure body ...
my_output_table = my_table_var;
4
Ensure that data is actually inserted into the table variable before it's returned. An empty table variable might still cause issues depending on the calling context.
3. Validate Calling Application's Parameter Handling medium
Check if the application calling the SQLScript is expecting a table as output.
1
Identify the application or SAP S/4HANA component that is calling the problematic SQLScript. This could be a custom ABAP report, a CDS view, or another stored procedure.
2
Examine the code in the calling application that handles the output of the SQLScript. It should be prepared to receive a table structure.
-- Example in ABAP:
CALL METHOD lo_sql_script->execute
EXPORTING
...
IMPORTING
et_output_table = lt_output_data. " Expecting a table type
3
Ensure that the data type of the receiving variable in the calling application matches the table type defined in the SQLScript's output parameter.
4
If the calling application is expecting a scalar value but the SQLScript is designed to return a table, this mismatch will cause the error. Adjust either the SQLScript's output or the calling application's expectation.