INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

HIGH-VALUE (COBOL) and DB2

HIGH-VALUE (COBOL) and DB2

(OP)
Hi everyone,

I'm working on a windows XP platform with a DB/2 database and I've got a problem when trying to insert (thru COBOL) a field that contains HIGH-VALUE.

Here is my problem illustrated with this little example :

My DB/2 table is created with :

CODE

CREATE TABLE PERS (
  RID INTEGER NOT NULL,
  "LAST_NAME"  VARCHAR(30),
  "FIRST_NAME"  VARCHAR(20),
  "AGE"  NUMERIC(3,0),
CONSTRAINT PERS_PK PRIMARY KEY (RID));

and my cobol program (before precompilation with DB2 precompiler) is :

CODE

       IDENTIFICATION DIVISION.
       PROGRAM-ID. INSER.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
           EXEC SQL INCLUDE SQLCA END-EXEC.
           EXEC SQL BEGIN DECLARE SECTION END-EXEC.
       01 WORK-VARS.
         05 HOST-RID PIC S9(9) COMP-5.
         05 HOST-LAST-NAME PIC X(30).
         05 HOST-FIRST-NAME PIC X(20).
         05 HOST-AGE PIC S9(4) COMP-5.
         EXEC SQL END DECLARE SECTION END-EXEC.
         EXEC SQL WHENEVER NOT FOUND CONTINUE END-EXEC.
         EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.
         EXEC SQL WHENEVER SQLWARNING CONTINUE END-EXEC.

       PROCEDURE DIVISION.
           EXEC SQL
              CONNECT TO sample user db2admin using ******
           END-EXEC.
           MOVE 1 TO HOST-RID.
           MOVE HIGH-VALUES TO HOST-LAST-NAME.
           MOVE "Jean" TO HOST-FIRST-NAME.
           MOVE 33 TO HOST-AGE.
           EXEC SQL
      ****************************************
              INSERT INTO PERS
              (
                "RID", "LAST_NAME", "FIRST_NAME","AGE"
              )
              VALUES
              (
                :HOST-RID, :HOST-LAST-NAME, :HOST-FIRST-NAME, :HOST-AGE
              )
           
           END-EXEC.
           IF NOT SQLCODE = 0 THEN
             DISPLAY "ERROR : SQLCODE " SQLCODE UPON CONSOLE
           ELSE
             EXEC SQL COMMIT END-EXEC
           END-IF.
           STOP RUN.

The error returned is -302 :THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER position-number IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE : http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db29.doc.codes/n302.htm?resultof=%22%53%51%4c%43%4f%44%45%22%20%22%73%71%6c%63%6f%64%65%22%20%22%33%30%32%22%20  

If I replace MOVE HIGH-VALUES TO HOST-LAST-NAME. by MOVE "Dupond" TO HOST-LAST-NAME. or MOVE HIGH-VALUE TO HOST-LAST-NAME(1:15).
 the insertion goes well. So it seems that DB/2 interpret a COBOL PIC X(30) that contains HIGH-VALUES as a VARCHAR(60). Does someone knows why ? If it is possible to change that ? Does somebody got a explanation of that strage transformation at the DB/2 side ?

Thanks a lot in advance for your answers.

Best regards,

Yan302

RE: HIGH-VALUE (COBOL) and DB2

Quote:

So it seems that DB/2 interpret a COBOL PIC X(30) that contains HIGH-VALUES as a VARCHAR(60)
Doubtful. . . A cobol pic x(30) is a db2 var/char(30). Are you by chance using a database that is set up to use dbcs?

What value is in "position-number"?

RE: HIGH-VALUE (COBOL) and DB2

Hi Yan302,
You varchar host variable should be defined as:
01 HOST-LAST-NAME.
   03 HOST-LAST-NAME-LEN PIC S9(4) COMP.
   03 HOST-LAST-NAME-TEXT PIC X(30).

You should move the data to the TEXT part and the length of the data to the LEN bit.

What is happening at the moment is you have effectively told DB2 that the length of the field is x'FFFF' which if dosen't like, and so therefore gives you the error.

Regards,
Marc Lodge
 

RE: HIGH-VALUE (COBOL) and DB2

Marc,

Ok, so if I correctly follow your reasoning why does the insert work when using

Quote:


MOVE "Dupond" TO HOST-LAST-NAME. or MOVE HIGH-VALUE TO HOST-LAST-NAME(1:15)
?
 

Philippe

RE: HIGH-VALUE (COBOL) and DB2

Good question Philippe, and one that off the top of my head I have no answer. The only thing I can say is that the statement as coded by yan302 is definitely wrong.

I also made a mistake in mine in that the 03 levels should in fact be 49 levels, according to the manual.

I'd be interested to hear back from yan302.

RE: HIGH-VALUE (COBOL) and DB2

(OP)
Hi everyone,

Thanks a lot for all your answers !

Marc, you're right, I should declare a VARCHAR with two fields, one containg the value and one the length. But DB2 seems to be permissif and accept my syntax also while it works with other values that HIGH-VALUE.

I think that the problem comes from my DB that is an UTF-8 database and so a conversion of caracter 0xFF is done by DB/2. 0xFF is transformed in 0xC3BF which is coded on 2 bytes. With a database in IBM-1252 (ascii) my problem disapeared.

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close