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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Lookups in one rule...

Status
Not open for further replies.

vrs1008

Programmer
Sep 16, 2003
62
US
Hi,

I have a situation where in on condinional basis I've to use multiple look up on the same datafile in the same rule.

Rule looks like :
If (partner_cd:.:message = "abc", Lookup for abc in data,
partner_cd:.:message = "pqr", Lookup for pqr in data))

Here Lookup is not working.

If I do somethng like :
If (partner_cd:.:message = "abc", f_lookupabc(),
partner_cd:.:message = "pqr", f_lookuppqr())

or

If (partner_cd:.:message = "abc", f_lookupabc(),
partner_cd:.:message = "pqr", Lookup for pqr in data))

then it is working perfectly fine.

Are there any limitations of using lookup function in a single rule???



Regards,
Vibhav1008
 
This is a binding problem in Datstage TX . You cannot use 2 lookups or extracts on the same series in one IF loop. What happens is Datstage consume the object in first lookup , thats why it goes to the else part always .

To overcome this , you got to use Functional maps.

This bug is documented in 6.7 version documentation.

Amit
 
This is not really a bug, but the way the engine works. It has been there since the earliest days of TSI and is still in the code in the soon to be released 8.0 version.

JuJutsu - Jeff S.
Support Analyst
 
Thanks Friend,

but if you observed the code above, It is clear that look up will get executed only once based on the condition.

Is this a problem mentioning multiple lookups in one rule even if lookup gets executed only once????

Can you pls let me know where exactly in the documentation it has been mentioned????



Regards,
Vibhav1008
 
When you say the lookup is not working, what is the result you are getting and what do you expect?
When you say the lookup will only get executed once, does this mean the rule is in a single occuring element and the data being passed does not have any loops and there will only be one ocurrance of partner_cd:.:message in the data?

If so, then there is a problem and a test case should be sent to support.

JuJutsu - Jeff S.
Support Analyst
 
The basic rule is just do one lookup per output rule. That way you'll never hit a problem.
I don't think you'll find anything in the documentation to explain this though.
 
Hi all,

I am having a similar problem.

The rule looks like this. I will name If as 1 and 2 just for the sake of illsutration

If1 (PRESENT(LOOKUP(SEGMENT,ELEMENT="Z7"),/*THEN*/
IF2(LEFT(LOOKUP(VALUE,SEGMENT="Z7"),2)="19",/*THEN*/
DO THIS1,
/*ELSE*/
DO THIS2)),
/*ELSE*/
DO THIS3)

Pretend I have two records. What I am getting is the result of f1 times two(four records) and the result of f2(One record).

Any help will be greatly appreciated.

Jose.
 
Don't do multiple lookups in one rule. See above.
 
janhes,

Thanks for the reply.

My problem is that I have to check three conditions within a file.

The three conditions require a lookup. Is there another way to do it?

The three lookup conditions are part of a functional map. For example, the functional map has data1 coming from card one, data2 is the result of the three lookups, data3 is coming from another card and so on.

Thanks.

Jose.


 
Jose,

I used the functional map to get rid of this problem. Just call a functional map and do the look up there.

Regards,
Vibhav1008
 
you could also do each lokup in aseparate output card and do your rule against the results.
If(present(card1 result) and present(card2 result)do this1
else do this2.
 
Hi,

Use different cards for dirrent lookups.

Copy the input card which you use in the lookup.
Now you have two input cards 1& 2, use them in different lookups.

lookup(card_1,condition) ,lookup(card_2,condition).

Both cards contain the same data.
 
Hi all,

Thanks for your suggestions!!! I got it to work!!!!

Boy that was a chalenge!!!!!!!!

In Visual Basic that would be translated to ....

IF Condition Then
Do This
ELSEIF Condition2 Then
Do This
ELSE
Do This

I could have acomplished it in a few minutes, but it took me some time in Mercator before I could see the results I was expecting.

Anyway!!!! This was my problem and what I did to solve it. I hope it's not a very long message.

Problem:

-A customer wants to transmit orders for three divisions, A,B, and C within the same file.

-Two of the divisions (A,B) are identified with the presence of the code Z7.

-Within divisions A and B, I must now identify which one is A and which one is B.

-My only identifier for B is that within the data segment(text line)Z7, the customer transmits a store number begining with "19".

Solution 1:(Not working)

If1 (PRESENT(LOOKUP(SEGMENT,ELEMENT="Z7"),/*THEN*/
IF2(LEFT(LOOKUP(VALUE,SEGMENT="Z7"),2)="19",/*THEN*/
DO THIS1,
/*ELSE*/
DO THIS2)),
/*ELSE*/
DO THIS3)

As I explained on my previous post, “Pretend I have two records. What I am getting is the result of f1 times two(four records) and the result of f2(One record).”

Solution 2:(Working)

My map consists of:
1). Incoming EDI data card (Input card1).
2). Divisions cross-reference file (Input Card2).
3). Division A (Output Card1)
4). Division B (Output Card2)
5). Division C (Output Card3)
6). Output Card4 parsing the incoming data into a database.



- On the first “IF” condition (building a functional map FFFF1), I only check for the availability of the Z7 code.
- By finding the Z7 code, I am dividing the divisions
(A & B) & C.
- Within FFFF1 I am building another functional map to parse the order header info which I call FFFF2 just for the sake of illustration.
- When building FFFF2 is when I am doing the other LOOKUP for presence of stores beginning with “19”.


So the final product looks like this.

a). FFFF1 Functional map.

FFFF1(Incoming Data,
If (PRESENT(LOOKUP(SEGMENT,ELEMENT="Z7")),/*THEN*/
Division A,
/*Else*/
Division B),
/*EndIf*/
Division C)

b). Within FFFF1 Functional map:

FFFF2(Incoming Header,
IF(LEFT(LOOKUP(Store number,Data segment=”Z7”),2)=”19”, /*Then*/
Division C,
/*Else*/
Input card from FFFF1 functional map)

Hope it's not too confusing!!!

Thanks for the help provided.

Jose.
 
You can also use the Either function to help you accomplish the same.

Just put the two lookups within an EITHER function and it should work.
 
mlapse,

I tried your suggestion before posting my question here and I was getting the same results.

The only thing that worked for me was what explained on my previous reply.

Thanks.

Jose.
 
I may be remembering this wrong but I believe the problem is that the way the rule was written its laready past the condition the second lookup is checking for. The working samples above work around the issue.

Another option might be searchup/down. Similar to a lookup but I think your rule might work here.

eyetry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top