TDINFBCD

Description

Retrieves the length and number of decimal places for a specified decimal column or parameter.

Syntax

COPY SYGWCOB.
01 TDPROC                    PIC S9(9)USAGE COMP SYNC.
01 RETCODE                   PIC S9(9)USAGE COMP SYNC. 
01 OBJECT-TYPE               PIC S9(9)USAGE COMP SYNC. 
01 OBJECT-NUMBER             PIC S9(9)USAGE COMP SYNC. 
01 BCD-LENGTH                PIC S9(9)USAGE COMP SYNC.
01 BCD-NUMBER-DECIMAL-PLACES PIC S9(9)USAGE COMP SYNC.
CALL 'TDINFBCD' USING TDPROC,RETCODE,OBJECT-TYPE, OBJECT-NUMBER,BCD-LENGTH, BCD-NUMBER-DECIMAL-PLACES. 

Parameters

TDPROC

(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.

RETCODE

(O) Variable where the result of function execution is returned. Its value is one of the codes listed in Table 3-13.

OBJECT-TYPE

(I) Object type indicator. Indicates whether the object being queried is a parameter or a column. Assign this argument one of the following values:

TDS-OBJECT-COL (1)

Object is a column in a return row.

TDS-OBJECT-PARM (2)

Object is a parameter.

OBJECT-NUMBER

(I) Number of the column or parameter.

If the object is a column, this is the position of the column in the row, counting from left to right. Columns are numbered sequentially; the leftmost column in a row is number 1.

If the object is a return parameter, this is the number of the parameter with the value that is being checked. All parameters are counted, whether or not they are return parameters. Parameters are numbered sequentially; the first parameter is number 1.

BCD-LENGTH

(O) Variable where the length of the packed decimal field is returned. When used for Sybase numeric/decimal, this is a precision of the numeric or decimal field.

BCD-NUMBER-DECIMAL-PLACES

(O) Variable where the number of decimal places in the packed decimal field is returned.

Returns

The RETCODE argument can contain any of the return values listed in Table 3-13.

Table 3-13: TDINFBCD return values

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-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.

Examples

Example 1

The following code fragment shows two methods of converting datatypes. One uses TDESCRIB to convert data from the DB2 datatype DECIMAL (TDSDECIMAL) to TDSFLT8. The other uses TDCONVRT to convert data from the DB2 datatype DECIMAL (TDSDECIMAL) to the DB-Library datatype DBMONEY (TDSMONEY). This program uses TDSETBCD to set the number of decimal places in the column to 2; it uses TDINFBCD to check how many decimal places are in the column. This example is taken from the sample program, SYCCSAR2, in Appendix B, “Sample RPC Application for CICS.”

*    Here we let TDESCRIB convert from TDSDECIMAL to TDSFLT8.
 
      CALL 'SYGETAD' USING DB-DESCRIBE-HV-PTR, EMPLOYEE-JC.
      CALL 'SYGETAD' USING DB-COLUMN-NAME-HV-PTR, CN-JC.
      MOVE LENGTH OF EMPLOYEE-JC TO WRKLEN1.
      MOVE LENGTH OF CN-JC       TO WRKLEN2.
      MOVE TDSDECIMAL            TO DB-HOST-TYPE.
      MOVE TDSFLT8               TO DB-CLIENT-TYPE.
      PERFORM DESCRIBE-COLUMN.
 
 *    We must inform the Server Library how many decimal places
 *    are in the EMPLOYEE-JC column.
 
      CALL 'TDSETBCD' USING GWL-PROC, GWL-RC, TDS-OBJECT-COL,
                            CTR-COLUMN, TDS-DEFAULT-LENGTH,
                            GWL-SETBCD-SCALE.
 
 *    Demonstrate getting decimal column information.
 
      CALL 'TDINFBCD' USING GWL-PROC, GWL-RC, TDS-OBJECT-COL,
                            CTR-COLUMN, GWL-INFBCD-LENGTH,
                            GWL-INFBCD-SCALE.
 
 *    Here we intend to use TDCONVRT to convert from TDSDECIMAL to
 *    TDSMONEY, so we point TDESCRIB to the output of TDCONVRT,
 *    rather than the original input.
 
      CALL 'SYGETAD' USING DB-DESCRIBE-HV-PTR, WRK-EMPLOYEE-SAL.
      CALL 'SYGETAD' USING DB-COLUMN-NAME-HV-PTR, CN-SAL.
      MOVE LENGTH OF WRK-EMPLOYEE-SAL TO WRKLEN1.
      MOVE LENGTH OF CN-SAL           TO WRKLEN2.
      MOVE TDSMONEY                   TO DB-HOST-TYPE.
      MOVE TDSMONEY                   TO DB-CLIENT-TYPE.
      PERFORM DESCRIBE-COLUMN.
 
      PERFORM FETCH-AND-SEND-ROWS
          UNTIL ALL-DONE.
 *-----------------------------------------------------------------
  FETCH-AND-SEND-ROWS.
 *-----------------------------------------------------------------
      EXEC SQL FETCH ECURSOR INTO :EMPLOYEE-FIELDS END-EXEC.
 
      IF SQLCODE = 0 THEN
 
 *        Convert from DB2 decimal (TDSDECIMAL) to dblib 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, TDSDECIMAL,
                                WRKLEN1, EMPLOYEE-SAL, TDSMONEY,
                                WRKLEN2, WRK-EMPLOYEE-SAL
 
 *        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
          MOVE 'Y' TO ALL-DONE-SW
          PERFORM FETCH-ERROR
      END-IF.
 
 *-----------------------------------------------------------------
  GET-PARM-INFO.
 *-----------------------------------------------------------------
      CALL 'TDINFPRM' USING GWL-PROC, GWL-RC, GWL-INFPRM-ID,
                            GWL-INFPRM-TYPE, GWL-INFPRM-DATA-L,
                            GWL-INFPRM-MAX-DATA-L
                            GWL-INFPRM-STATUS, GWL-INFPRM-NAME,
                            GWL-INFPRM-NAME-L,
                            GWL-INFPRM-USER-DATA.

 *-----------------------------------------------------------------
  DESCRIBE-COLUMN.
 *-----------------------------------------------------------------
      SET ADDRESS OF LK-DESCRIBE-HV    TO DB-DESCRIBE-HV-PTR.
      SET ADDRESS OF LK-COLUMN-NAME-HV TO DB-COLUMN-NAME-HV-PTR.
      ADD 1                            TO CTR-COLUMN.
 
      CALL 'TDESCRIB' USING GWL-PROC, GWL-RC, CTR-COLUMN,
                            DB-HOST-TYPE, WRKLEN1, LK-DESCRIBE-HV,
                            DB-NULL-INDICATOR, TDS-FALSE,
                            DB-CLIENT-TYPE, WRKLEN1,
                            LK-COLUMN-NAME-HV, WRKLEN2.

Usage

See also

Related functions