Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable length input

Status
Not open for further replies.

Pedrique

Programmer
May 24, 2001
4
US
Have Unix script where user enters data (check number range), where the check numbers can be from 1 to 9 characters, validated within the script. However, in Cobol, this is passed to fixed length variables - pic x9

My cursor uses these check numbers for a reprint process, but the database does not recognize check number "987654 ", or "000987654." How do I make sure that the user input is EXACTLY what is used within the cursor?

Thanks.
 
Hi Pedrique,

You're probably long gone by now, but anyway, what do you want to do? Correct the COBOL pgm to pass you only the required # of digits? How would you know what the len of the field is to be? Or is the Unix script going to clean up the field?

Jack
 
Currently, the unix script pads spaces to the user entry, so that user enters '987654', and '987654 ' is passed to the cobol pgrm - pic x(9). Check numbers can be a maximum of 9 digits. Within the sql cursor, I have where database check number BETWEEN :first input check number AND :last input check number.

It doesn't seem to like the input values. (I've tested without the between statement and it returns all checks ready to print)

What is the best way to make sure that the literal user input is passed to the cursor?

Thanks.
 
Hi Pedrique,

It sounds like you're saying that the Unix script is passing the chk# to the cobol pgm where it's expanded to nine digits. If the DB is DB2 I might be able to help.

DB2, as I recall, has various numeric formats: int, small int, decimal. There may be others but yours is probably one of these. Check the cobol pgm and make sure the field that contains the passed chk# is defined the same as the DB2 field. Check the DCLGEN O/P to determine this.

If you're not using DB2, I have to get off at this stop, but the concept should be the same.

Regards, Jack.
 
It's an Oracle database, and it's an alphanumeric field, not numeric, which is part of the problem. I'm simply trying to do a mod to an existing (albeit complex) Cobol program rather than try to reinvent the wheel with another procedural language.

Any more help would be appreciated.
 
Hi,

I was afraid you would say that. Can you look at the DB and see how the field is represented in the table? Does it have leading/trailing/no blanks if the chk# is less than 9 bytes? Does it use a special padding Char?

All of that aside, if you're using COBOLII you can represent the field like this:

WHERE DB_CHK_NBR = WS-CHK-NBR(1:n)

where, n = number of sig digits in the field WS-CHK-NBR

To find n, code:

This goes in Working Storage
05 WS-SUB PIC S9(002) COMP.

This goes in the Procedure Division, right before your DB query.
PERFORM VARYING WS-SUB FROM +1 BY +1
UNTIL WS-SUB > +09 OR WS-CHK-NBR(WS-SUB:1) = SPACE
END-PERFORM
SUBTRACT +1 FROM WS-SUB
IF WS-SUB = ZERO
chk# is all spaces, what to do is up to you
END-IF

Then you can code the WHERE clause above with WS-CHK-NBR(1:WS-SUB)

Hope you don't mind my getting down to the basics, but I got the impression you were a Unix guy and unfamiliar with COBOL.

Regards, Jack.
 
I appreciate the detail. I've worked with COBOL before but not extensively. Will test and let you know (perhaps not until Monday though).

thanks.
 
What is the exact oracle definition of the column?

Your problem may be more complex that you realize. If the data is defined as CHAR for example, and the range of numbers you need to print is:

980 to 1100 a BETWEEN will not work.

However, what you CAN do, is this:

Select something from whatever where to_number(column_name) between to_number(from_variable) and to_number(to_variable)

Between is inclusive.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top