473,799 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use of 'LIKE' in SQL 'WHERE' statement in Batch COBOL program

I cannot get the WHERE statement to work correctly unless I use a
literal with the LIKE. I want to use a working storage data name so
that I can vary the WHERE statement.

Example that works:

WHERE DSNAME LIKE 'ABC%'

Example that does not work:

WHERE DSNAME LIKE :WS-HOLD-LIKE-STRING

Is there an alternative method or work around?
Nov 12 '05 #1
4 25709

"Tom Walker" <jt******@us.ib m.com> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
I cannot get the WHERE statement to work correctly unless I use a
literal with the LIKE. I want to use a working storage data name so
that I can vary the WHERE statement.

Example that works:

WHERE DSNAME LIKE 'ABC%'

Example that does not work:

WHERE DSNAME LIKE :WS-HOLD-LIKE-STRING

Is there an alternative method or work around?


First of all, I'm going to assume that you are only showing a fragment of
the statement, specifically the WHERE clause, not the complete statement. I
assume you know that a WHERE clause by itself is never going to work; you
need at least a SELECT and FROM clause to make a legal SQL SELECT statement.

I don't have a COBOL compiler handy and haven't written a DB2 COBOL program
in a few years. However, I used to write quite a few of them so I'm pretty
sure that what you are doing *is* possible. (I say "pretty sure" because I
don't recall ever trying to use a host variable in a LIKE predicate.)

What datatype is the column you are searching with the LIKE predicate? As I
vaguely recall, CHARs and VARCHARs behave slightly differently with respect
to the LIKE predicate. With one of them - I don't recall which - you have to
put an extra blank at the end of the search string to make it work for some
cases. Unfortunately, I can't find the spot in the manual that says that.
Perhaps I saw it in a newsgroup post somewhere; you might try doing a Google
search in this newsgroup on 'LIKE'.

You didn't mention which version of DB2 you are using or what platform you
are using. However, the DB2 manuals are generally pretty good so I'd suggest
looking through your manuals for articles about LIKE and see what you can
find about the exact rules of the LIKE predicate. The closest thing I can
find in my manuals is the 'LIKE Predicate' article in the 'Language
Elements' section of the SQL Reference for my platform, DB2 V7.2 on
Windows/Linux/Unix. Unfortunately, I can't find the item about different
behaviours of LIKE for different datatypes. (Maybe they've changed the LIKE
to behave uniformly for all datatypes since I first saw that item??)

If the manual doesn't answer your question, perhaps you could post again
with more details, showing your full statement, information about the
definition of the DSNAME column in your table, a small sampling of data
showing us the cases that concern you, and some remarks about the results
you are getting versus the results you expected to get. That would give us a
better chance to help you. Also, it's *always* a good idea to state your
platform and DB2 version because there are still some differences in
behaviour between platforms and versions.

Rhino


Nov 12 '05 #2
In article <8c************ **************@ posting.google. com>, Tom
Walker (jt******@us.ib m.com) says...
I cannot get the WHERE statement to work correctly unless I use a
literal with the LIKE. I want to use a working storage data name so
that I can vary the WHERE statement.

Example that works:

WHERE DSNAME LIKE 'ABC%'

Example that does not work:

WHERE DSNAME LIKE :WS-HOLD-LIKE-STRING

Is there an alternative method or work around?


If I do remember right you need to fill the remaining part of the
string with %. If your WS-HOLD_LIKE-STRING has a length of 8 you need
to put the string 'ABC%%%%%' in this field.
Nov 12 '05 #3
jt******@us.ibm .com (Tom Walker) wrote in message news:<8c******* *************** ****@posting.go ogle.com>...
I cannot get the WHERE statement to work correctly unless I use a
literal with the LIKE. I want to use a working storage data name so
that I can vary the WHERE statement.

Example that works:

WHERE DSNAME LIKE 'ABC%'

Example that does not work:

WHERE DSNAME LIKE :WS-HOLD-LIKE-STRING

Is there an alternative method or work around?


I don't use cobal but I have run into similar problems

Make sure you are not passing spaces where you don't expect them. IE

WS-HOLD-LIKE-STRING = 'ABC %' or
WS-HOLD-LIKE-STRING = 'ABC% '
Nov 12 '05 #4
It will work, but WS-HOLD-LIKE-STRING must be "varchar", e.g (max length 18
here).
01 WS-HOLD-LIKE-STRING.
49 L PIC S9(4) COMP-5.
49 D PIC X(18).
The length of your string (4 for 'ABC%') goes into L.

I assume from your "it doesn't work" that you're using a fixed length string
variable. In that case, you have something like 'ABC% '
meaning to match ABC, anything, followed by 14 blanks (using my length 18
example).

Review the section on COBOL Host Variables in the Embedded SQL section of
the API Reference.

"Tom Walker" <jt******@us.ib m.com> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
I cannot get the WHERE statement to work correctly unless I use a
literal with the LIKE. I want to use a working storage data name so
that I can vary the WHERE statement.

Example that works:

WHERE DSNAME LIKE 'ABC%'

Example that does not work:

WHERE DSNAME LIKE :WS-HOLD-LIKE-STRING

Is there an alternative method or work around?

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22470
by: Zalek Bloom | last post by:
Actually I would like to know what additional JCL I will need if a COBOL non-DB2 program is calling to a COBOL/DB2 program. The original non-DB2 program is executed using: //STEP1 EXEC PGM=PROG1 I know I have to supply database name/plan to my program, but how? Another question: what happens is the PROG1 program is a DB2 program and is calling to another DB2 program with a different database and a different plan?
3
2737
by: Joachim Klassen | last post by:
I'm currently working on a migration of a DB2 VM V7.2 database to DB2 UDB Linux V8.2. In the first stage the applications will stay on VM only the database will be migrated. Applications will be migrated in a second stage in the future. The connectivity between DB2 VM as a DRDA requester and DB2 UDB as DRDA server has been established. At a first look at the applications one thing came up: they use SQL INSERT via a CURSOR. This works...
1
1834
by: Fred | last post by:
I am trying to convert an existing COBOL app from using exclusively tradional I-O (READ verb) to using a mix of traditional and and SQL. Please don't ask why, my question is conceptual. After populating a cursor from table A and displaying on the screen, a user makes a change to record #2. The program tries to read record #2 using traditional COBOL READ COMMAND in order to update it, yet gets an INVALID KEY condition because the record...
7
13714
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to reinitialize the addresses and even more when it decides not to do it. Recently I've ben strucked with a problem of host variables defined in LINKAGE SECTION, and it took me some time to find the cause and solution for the problem.
1
3055
by: GnanaKumar | last post by:
hi, Can any one explain me how to execute COBOL program using Python scripts... do i need any third party tool to do this.. can you pls help me out regards, Gnana Kumar
2
6416
by: pompeyoc | last post by:
Hi, I am a newbie when it comes to stored procs and i would like to learn how to call a COBOL program from a stored procedure. The SP can either be an DB2 SQL SP or an external COBOL/DB2 SP. I can use either depending on which is more efficient. One of the older posts ("Calling a COBOL Subroutine from COBOL/DB2 Stored Procedure" Dec 2005) suggested this is possible but I couldn't follow the explanation and there wasn't any examples....
0
1326
by: SUBHASH SHRIRANG JADHAV | last post by:
Hi, I have one doubt in cobol db2 program, plz help me. Q. Write a cobol program to read a file and in which suppose two fields are there one is account no and another is acct name so take a particular acct no match it with one DB2 table (contains same field suppose). If it matches the same acct no in file with DB2 table then display that acct no and his acct name on to the screen or another file.
2
1198
by: Subhrangsu Chandra | last post by:
I have created a MF-COBOL Program which generates an another COBOL Program.Now I am in search of the system command which can compile the newly(I am calling it as "child") created program when I compile the parent program.I mean to say that when I compile the parent program then the child program shold also be compiled with its errors ,if any and should show the output of both the programs.
0
1253
by: saroravi | last post by:
How can we write a cobol program without using session table. how Front end (PB) retrieve the data
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.