Sets the column length for a variable-length field before sending it to a client.
COPY SYGWCOB.
01 TDPROC PIC S9(9) USAGE COMP SYNC. 01 RETCODE PIC S9(9) USAGE COMP SYNC. 01 COLUMN-NUMBER PIC S9(9) USAGE COMP SYNC. 01 NEW-COLUMN-LENGTH PIC S9(9) USAGE COMP SYNC.
CALL 'TDSETLEN' USING TDPROC, RETCODE, COLUMN-NUMBER, NEW-COLUMN-LENGTH.
(I) Handle for this client/server connection. This must be the same value specified in the associated TDACCEPT call. The TDPROC handle corresponds to the connection and command handles in Open Client Client-Library.
(O) Variable where the result of function execution is returned. Its value is one of the codes listed in Table 3-30.
(I) The number of the column that is being described. Columns are numbered sequentially; the first column in a row is number 1.
(I) New length of the column data.
This argument specifies the length of the data that is sent in subsequent TDSNDROW calls. This value must be greater than zero but cannot be greater than the maximum length of the column, as determined by TDESCRIB.
The RETCODE argument can contain any of the return values listed in Table 3-30.
Return value |
Meaning |
---|---|
TDS-OK (0) |
Function completed successfully. |
TDS-CONNECTION-TERMINATED (-4997) |
Connection closed. The remote partner closed (deallocated) the client/server connection. |
TDS-ENTRY-NOT-FOUND (-8) |
The specified column number, transaction number, or parameter does not exist. |
TDS-INVALID-DATA-TYPE (-171) |
Illegal datatype. A Sybase datatype supplied in the call is not supported and the conversion cannot be done. The operation failed. |
TDS-INVALID-LENGTH (-173) |
Wrong length. The length specified in the NEW-COLUMN-LENGTH argument is too long. |
TDS-INVALID-PARAMETER (-4) |
Invalid parameter value. The value assigned to one or more of the arguments supplied in the call is not valid. The operation failed. |
TDS-INVALID-TDPROC (-18) |
Error in specifying a value for the TDPROC argument. |
The following code fragment illustrates a typical use of TDSETLEN.
*---------------------------------------------------------------- FETCH-AND-SEND-ROWS. *---------------------------------------------------------------- EXEC SQL FETCH ECURSOR INTO :EMPLOYEE-FIELDS END-EXEC.
IF SQLCODE = 0 THEN
* -------------------------------------------------------- * Convert from DB2 decimal type (TDS-PACKED-DECIMAL) to * DB-Library MONEY. * -------------------------------------------------------- MOVE LENGTH OF EMPLOYEE-SAL TO WRKLEN1 MOVE LENGTH OF WRK-EMPLOYEE-SAL TO WRKLEN2 CALL 'TDCONVRT' USING GWL-PROC, GWL-RC, GWL-CONVRT-SCALE, TDS-PACKED-DECIMAL, WRKLEN1, EMPLOYEE-SAL, TDSMONEY, WRKLEN2, WRK-EMPLOYEE-SAL
* -------------------------------------------------------- * Do not send trailing blanks of EMPLOYEE-LNM. * -------------------------------------------------------- MOVE LENGTH OF EMPLOYEE-LNM TO WRKLEN1 MOVE 2 TO CTR-COLUMN
PERFORM VARYING WRK-BLANKS-SS FROM 1 BY 1 UNTIL WRK-BLANKS-SS > WRKLEN1 OR EMPLOYEE-LNM-CHARS(WRK-BLANKS-SS) <= SPACE END-PERFORM
IF WRK-BLANKS-SS < WRKLEN1 THEN SUBTRACT 1 FROM WRK-BLANKS-SS CALL 'TDSETLEN' USING GWL-PROC, GWL-RC, CTR-COLUMN, WRK-BLANKS-SS END-IF
* ------------------------------------------------------ * Send a row to the client. * ------------------------------------------------------ CALL 'TDSNDROW' USING GWL-PROC, GWL-RC ADD 1 TO PARM-RETURN-ROWS
IF GWL-RC = TDS-CANCEL-RECEIVED THEN MOVE 'Y' TO ALL-DONE-SW END-IF
ELSE IF SQLCODE = +100 THEN MOVE 'Y' TO ALL-DONE-SW
ELSE IF SQLCODE < 0 THEN MOVE 'Y' TO ALL-DONE-SW PERFORM FETCH-ERROR END-IF.
A server application uses this function to specify the length of data for a single column, before it is sent to the client.
Column data lengths are initially set with TDESCRIB. For fixed-length fields, there is no need to set the column lengths again. For variable-length fields, if the actual data length changes from one row to another, your application needs to reset the column length before you send the row of data to the client.
Your application must issue a separate TDSETLEN for each column for which the data length changes.
Each column of the row must first be defined in a TDESCRIB statement. The TDSETLEN statement must be coded after the TDESCRIB statement for that column.
Your application must be in SEND state for this function to execute successfully. If it is not in SEND state, TDSETLEN returns TDS-WRONG-STATE. To switch to SEND state, call TDRESULT.
The column length set by TDSETLEN must not be greater than the maximum column length specified in TDESCRIB. If it is longer, the function returns TDS-INVALID-LENGTH.
Related functions
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |