MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cursor to compare variable length field in Join - DB2 and co

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
JOSHI.SHOBHA
Beginner


Joined: 28 Jul 2007
Posts: 20
Topics: 7

PostPosted: Thu Mar 25, 2010 12:15 am    Post subject: Cursor to compare variable length field in Join - DB2 and co Reply with quote

We have a Query mentioned below
Code:

EXEC SQL
     DECLARE FOGCSE10-CURSOR CURSOR FOR
      SELECT A.CUSTOMER_KEY,
             A.CCY,
             A.SFX,
             B.MESSAGE_TYPE,
             B.AUTOGEN_TIME,
             B.FREQUENCY,
             B.UPDATE_TIMESTAMP,
             B.LAST_RUN_DATE,
             C.MT101_SENDER_BIC
        FROM TFOCPAC_CORP_ACCTS      A,
             TQE0520_AUTO_FREQ       B,
             TQE0700_MANDATE         C
       WHERE B.VISIBILITY       = 'V'
         AND A.CUSTOMER_KEY     = SUBSTR(B.STATEMENT_ACC_ID,7,8 )
         AND A.CCY              = SUBSTR (B.STATEMENT_ACC_ID,16,3)
         AND A.SFX              = SUBSTR (B.STATEMENT_ACC_ID,19,3)
         AND B.STATEMENT_ACC_ID = C.STATEMENT_ACC_ID
        WITH UR
         FOR FETCH ONLY
END-EXEC.

We were comparing Customer Key with Statement_Acc_Id assuming that it will always be a length of 8, BUT in production we saw some cases where Cutomer Key was always 8 ( 6 character + 2 spaces (padding done)) but in Statmenet_Acc_id we can have the length 0f 6 and no padding then a '-' character and then CCY and SFX starts.

Please advise if we can do some kind of length comparison in this cursor where the length in the substring can vary or any other way we can handle it.
_________________
Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Thu Mar 25, 2010 10:27 am    Post subject: Reply with quote

JOSHI.SHOBHA,

post some sample input data for B.STATEMENT_ACC_ID and A.CUSTOMER_KEY

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
JOSHI.SHOBHA
Beginner


Joined: 28 Jul 2007
Posts: 20
Topics: 7

PostPosted: Thu Mar 25, 2010 9:56 pm    Post subject: Reply with quote

B.STATEMENT_ACCT_ID is in the form
Code:

837584PSCOT-EURC     
831806DIPOSP-USDA   
17400ALEHO-CAD106   
560400ALEHO-EURA     
460008RITT-EURA

and A.STATEMENT is in the form
Code:

CUSTOMER_KEY  CCY      SFX   
CHAR(8)       CHAR(3)  CHAR(3)
------------  -------  -------
****************************
/FERBTYO      AED      000   
/ACBCILO      ATS             
/ACBCILO      AUD             
/ACBCILO      BEC

_________________
Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Fri Mar 26, 2010 11:06 am    Post subject: Reply with quote

JOSHI.SHOBHA,

I don't see a single matching record. Anyway here is an untested sql which I think will give you the desired results

Code:

   DECLARE FOGCSE10-CURSOR CURSOR FOR
      SELECT A.CUSTOMER_KEY,
             A.CCY,
             A.SFX,
             B.MESSAGE_TYPE,
             B.AUTOGEN_TIME,
             B.FREQUENCY,
             B.UPDATE_TIMESTAMP,
             B.LAST_RUN_DATE,
             C.MT101_SENDER_BIC
        FROM TFOCPAC_CORP_ACCTS      A,
             TQE0520_AUTO_FREQ       B,
             TQE0700_MANDATE         C
       WHERE B.VISIBILITY       = 'V'
         AND A.CUSTOMER_KEY     = SUBSTR(B.STATEMENT_ACCT_ID,7, 
                                  (POSSTR(B.STATEMENT_ACCT_ID,'-')-7))   
         AND A.CCY              = SUBSTR(B.STATEMENT_ACCT_ID, 
                                  POSSTR(B.STATEMENT_ACCT_ID,'-')+1,3)   
         AND A.SFX              = SUBSTR(B.STATEMENT_ACCT_ID, 
                                  POSSTR(B.STATEMENT_ACCT_ID,'-')+4,3)   
         AND B.STATEMENT_ACC_ID = C.STATEMENT_ACC_ID
        WITH UR
         FOR FETCH ONLY
Back to top
View user's profile Send private message Send e-mail Visit poster's website
JOSHI.SHOBHA
Beginner


Joined: 28 Jul 2007
Posts: 20
Topics: 7

PostPosted: Sun Mar 28, 2010 10:18 pm    Post subject: Reply with quote

Thanks Kolusu .. it worked Smile
_________________
Thanks
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Sun Mar 28, 2010 10:20 pm    Post subject: Reply with quote

Please post in the more appropriate forum (Database) next time.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
JOSHI.SHOBHA
Beginner


Joined: 28 Jul 2007
Posts: 20
Topics: 7

PostPosted: Mon Mar 29, 2010 9:59 pm    Post subject: Reply with quote

Sorry ... Will take care Terry
_________________
Thanks
Back to top
View user's profile Send private message
JOSHI.SHOBHA
Beginner


Joined: 28 Jul 2007
Posts: 20
Topics: 7

PostPosted: Mon Apr 05, 2010 4:16 am    Post subject: Reply with quote

Kolusu

Actually when we ran it thru our DBA he said that this might have prformance issues.... and asked us to provide alternative ... please advise can we remove the substring from this query and do it as a part of program or DFSORT utility using parse or some other option. Not sure if we are going on the correct path. Please advise.
_________________
Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Apr 05, 2010 7:00 am    Post subject: Reply with quote

Joshi.Shobha,

a lot has to do with the number of rows in the 3 tables.

if you want to take the time to explain the size and relationship of the 3 tables,
members could provided better suggestions.

as an aside,
anytime you off-load the work from DB2,
you will not have your DBA's complaining.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Mon Apr 05, 2010 9:58 am    Post subject: Reply with quote

Joshi.Shobha,

The other alternative would be just selecting the STATEMENT_ACCT_ID alone and parse it using unstring and then use it as a host variable for the main table. Btw you did have a SUBSTR function in the original SQL.

How do you plan to use DFSORT here? Unload all the 3 tables? and then perform the matching?

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
JOSHI.SHOBHA
Beginner


Joined: 28 Jul 2007
Posts: 20
Topics: 7

PostPosted: Mon Apr 05, 2010 10:48 pm    Post subject: Reply with quote

Kolusu

Actually we were planning to keep the comparisons for TQE0520_AUTO_FREQ and TQE0700_MANDATE table as it is just remove the TFOCPAC_CORP_ACCTS thing. And after the work is completed for the 2 tables then dump the O/p of cursor and TFOCPAC_CORP_ACCTS table in a file and use DFSORT to compare the STATEMENT_ACCT_ID.

Thanks
Shobha
_________________
Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Tue Apr 06, 2010 7:40 am    Post subject: Reply with quote

JOSHI.SHOBHA,

If you need help with DFSORT , open another topic with all the details. Post the LRECL and RECFM of both files and how you want the final output.

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group