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 

Fetch value on different combination

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
vak255
Intermediate


Joined: 10 Sep 2004
Posts: 384
Topics: 79

PostPosted: Wed May 11, 2016 2:03 pm    Post subject: Fetch value on different combination Reply with quote

I need some help with the below.

Read a data from a file(this is extract from a Db2 table) and fetch rate from another lookup Db2 table based on various combinations.


Source File:
Code:

MAN_NUM      ACCT_NUM        LINE_CD        SKU
1001           901122             8           123
1002           805566             8           667
1003           122996             8           225


Lookup Table
Code:

Rule_Num     MAN_NUM         ACCOUNT_NUM    LINE_CD   SKU   COMM_PCT   Y_N_F   Effective Start Date   Effective End Date
1           1001                    901122      8    123    15           Y         1/15/2015               2/15/2015
2           1001                    901122      8           12           Y         6/16/2016               9/15/2016
3           1001                    901122      8           10           Y         6/16/2016               9/15/2016
4           1001                    901122      8     123   11           Y         4/15/2016               5/15/2016
5           1002                    805566      8           16           Y         4/15/2016               5/15/2016
6           1003                                8           17           Y         4/15/2016               5/15/2016
          


Read MAN_NUM, ACCT_NUM, LINE_CD, SKU from input and check the lookup table and fetch COMM_PCT for the current date.
Effective start and end date is used to validate the rule against current date.

Rules to fetch the COMM_PCT.
If there is a hit for the below iin lookup table
MAN_NUM + Account_NUM + PROD_LINE_CD + SKU combination --> fetch COMM_PCT
If not found check
MAN_NUM + Account_NUM + PROD_LINE_CD --> Fetch COMM_PCT
If not found check
MAN_NUM + PROD_LINE_CD --> Fetch COMM_PCT
If not found
<Write the input record to Error file>


Expected output.


Code:

MAN_NUM     ACCT_NUM             LINE_CD       SKU     COMM_PCT          RULE_Num       Y-N-F
1001           901122             8           123      11               4                Y
1002           805566             8           667      16               5                Y
1003           122996             8           225       17              6                Y



I know we can do this in cobol. since the lookup table will be hit multiple times to fetch the rate for one input read.
I am thinking if the lookup table could be extracted to a file and using a DFSORT utility, combine the source file and lookup file to get COMM_PCT in the output file will be a better way. please advise.[/code]
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed May 11, 2016 3:30 pm    Post subject: Reply with quote

vak255,


1. What are column definitions of the Lookup Table ? Post the DCLGEN layout of the lookout table.

2. What is the COBOL layout of the Source file?
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vak255
Intermediate


Joined: 10 Sep 2004
Posts: 384
Topics: 79

PostPosted: Thu May 12, 2016 8:30 am    Post subject: Reply with quote

pls find below the details.

Source file

MAN_NUM 9(4)
ACCT_NUM 9(5)
LINE_CD 9(1)
SKU x(11) -- above I gave only three digits for reference

Lookup table: this will be a new table, DCLGEN is not yet defined. below the field definitions.
Rule_Num - this will be sequence number - Smallint
MAN_NUM decimal(4,0)
ACCOUNT_NUM decimal(6,0)
LINE_CD SKU varchar(11)
COMM_PCT decimal(5,2)
Y_N_F varchar(1)
Effective Start Date
Effective End Date
Back to top
View user's profile Send private message
vak255
Intermediate


Joined: 10 Sep 2004
Posts: 384
Topics: 79

PostPosted: Thu May 12, 2016 8:42 am    Post subject: Reply with quote

rules with effective end date < current date are considered expired rules, so should not be considered in the processing.

Below rule should not be considered.


Code:


Rule_Num     MAN_NUM         ACCOUNT_NUM    LINE_CD   SKU   COMM_PCT   Y_N_F   Effective Start Date   Effective End Date
1           1001                    901122      8    123    15           Y         1/15/2015               2/15/2015

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


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

PostPosted: Thu May 12, 2016 12:33 pm    Post subject: Reply with quote

vak255 wrote:

LINE_CD SKU varchar(11)


Line_cd is varchar(11)? or is SKU 11?

vak255 wrote:

Y_N_F varchar(1)


Why would anyone define a column with VARCHAR(1)? what is that you are trying to save. with VARCHAR you do realize that there is a 2 byte length field.

If it is only 1 byte what is the point of having it as varchar?

either way I assumed the following for the table.
Code:

(                                                         
   RULE_NUM                        SMALLINT     NOT NULL   
  ,MAN_NUM                         DECIMAL(4,0) NOT NULL   
  ,ACCOUNT_NUM                     DECIMAL(6,0)           
  ,LINE_CD                         CHAR(1)      NOT NULL   
  ,SKU                             CHAR(11)               
  ,COMM_PCT                        DECIMAL(5,2) NOT NULL   
  ,Y_N_F                           CHAR(1)      NOT NULL   
  ,EFFECTIVE_START_DATE            DATE         NOT NULL   
  ,EFFECTIVE_END_DATE              DATE         NOT NULL   
 )                                                         


Use this JCL to unload the table to a sequential file.

Code:

//STEP0100 EXEC PGM=IKJEFT01                                       
//SYSTSPRT DD SYSOUT=*,DCB=BLKSIZE=121                             
//SYSPRINT DD SYSOUT=*                                             
//SYSTSIN  DD *                                                     
 DSN SYSTEM(DB2P)                                                   
 RUN  PROGRAM(DSNTIAUL) -                                           
      PLAN(DSNTIAUL)    -                                           
      PARMS('SQL')      -                                           
      LIB('DB2P.RUNLIB.LOAD')                                       
//SYSREC00 DD DSN=&&UNLD,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)       
//SYSPUNCH DD SYSOUT=*                                             
//SYSIN    DD *                                                     
 SELECT *                                                           
   FROM table                                               
  WHERE CURRENT DATE BETWEEN EFFECTIVE_START_DATE AND               
        EFFECTIVE_END_DATE                                         
   ;                                                               
//*


You should look at the syspunch dataset to see how the data is unloaded as it shows the positions of columns unloaded. watch out for the null indicators.
Code:

(                                                                       
RULE_NUM                               POSITION(       1         )       
SMALLINT                                     ,                           
MAN_NUM                                POSITION(       3:       5)       
DECIMAL                                      ,                           
ACCOUNT_NUM                            POSITION(       6:       9)       
DECIMAL                                                                 
     NULLIF(      10)='?',                                               
LINE_CD                                POSITION(      11         )       
CHAR(                      1)                ,                           
SKU                                    POSITION(      12         )       
CHAR(                     11)                                           
     NULLIF(      23)='?',                                               
COMM_PCT                               POSITION(      24:      26)       
DECIMAL                                      ,                           
Y_N_F                                  POSITION(      27         )       
CHAR(                      1)                ,                           
EFFECTIVE_START_DATE                   POSITION(      28         )       
DATE EXTERNAL(            10)                ,                           
EFFECTIVE_END_DATE                     POSITION(      38         )       
DATE EXTERNAL(            10)                                           
)                                                                       


Once you have the file , then all you need is to simply MATCH on the MAN_NUM using joinkeys like shown below

Code:

//STEP0200 EXEC PGM=SORT                                               
//SYSOUT   DD SYSOUT=*                                                 
//INA      DD DISP=SHR,DSN=&&UNLD                                     
//INB      DD *                                                       
10019011228123                                                         
10028055668667                                                         
10031229968225                                                         
10041111116227                                                         
//SORTOUT  DD SYSOUT=*                                                 
//ERROR    DD SYSOUT=*                                                 
//SYSIN    DD *                                                       
  OPTION COPY                                                         
  JOINKEYS F1=INA,FIELDS=(3,3,A)                   $ MAN_NUM           
  JOINKEYS F2=INB,FIELDS=(1,3,A)                   $ MAN_NUM           
  JOIN UNPAIRED,F2                                                       
  REFORMAT FIELDS=(F1:1,47,F2:1,20,?)                                 
                                                                       
  INREC IFTHEN=(WHEN=((03,03,PD,EQ,48,03,PD),AND,  $ MAN_NUM CHECK 
                      (06,04,PD,EQ,51,04,PD),AND,  $ ACCT_NUM CHECK
                      (11,01,CH,EQ,55,01,CH),AND,  $ LINE_CD CHECK 
                      (12,11,CH,EQ,56,11,CH)),     $ SKU CHECK     
        OVERLAY=(67:C'A'),HIT=NEXT),                               
        IFTHEN=(WHEN=((03,03,PD,EQ,48,03,PD),AND,  $ MAN_NUM CHECK 
                      (06,04,PD,EQ,51,04,PD),AND,  $ ACCT_NUM CHECK
                      (11,01,CH,EQ,55,01,CH),AND,  $ LINE_CD CHECK 
                      (67,01,SS,EQ,C' ,U')),       $ FILE IND CHECK
        OVERLAY=(67:C'B'),HIT=NEXT),                               
        IFTHEN=(WHEN=((03,03,PD,EQ,48,03,PD),AND,  $ MAN_NUM CHECK 
                      (11,01,CH,EQ,55,01,CH),AND,  $ LINE_CD CHECK 
                      (67,01,SS,EQ,C' ,U')),       $ FILE IND CHECK
        OVERLAY=(67:C'C'))                                         
                                                                   
  OUTFIL INCLUDE=(67,1,SS,EQ,C'A,B,C'),            $ COND 1,2,3 MATC
  BUILD=(05,03,                                    $ MAN_NUM       
         08,04,                                    $ ACCT_NUM       
         13,01,                                    $ LINE_CD       
         14,11,                                    $ SKU           
         26,03,                                    $ COMM_PCT       
         01,02,                                    $ RULE_NUM       
         28,10,                                    $ EFF_START_DATE
         38,10)                                    $ EFF_END_DATE   
                                                                   
  OUTFIL FNAMES=ERROR,INCLUDE=(67,1,CH,EQ,C'U'),                   
  BUILD=(48,03,PD,EDIT=(TTTT),                     $ MAN_NUM TO ZD 
         51,04,PD,EDIT=(TTTTTT),                   $ ACCT_NUM TO ZD
         55,01,                                    $ LINE_CD       
         56,11)                                    $ SKU           
                                                                   
//*                                                                 
//JNF2CNTL DD *                                                     
  INREC BUILD=(01,04,ZD,PD,LENGTH=3,               $ MAN_NUM TO PD 
               05,06,ZD,PD,LENGTH=4,               $ ACCT_NUM TO PD
               11,01,                              $ LINE_CD       
               12,11,                              $ SKU           
               C'U')                               $ FILE IND       
//*                                                                 

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vak255
Intermediate


Joined: 10 Sep 2004
Posts: 384
Topics: 79

PostPosted: Thu May 12, 2016 2:12 pm    Post subject: Reply with quote

Sorry, that was a typo.

Thanks for the solution.
U always rock Kolusu Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities 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