IBM MAINFRAME HELP & SUPPORT FORUMS
Technical Forums for IBM Mainframe Applications like COBOL, JCL, CICS, DB2, FileAid, DFSORT, Endevor, Xpediter, CoolGen, CA-7&11, AbendAid, IMS, IDMS, PL/I, MqSeries, SyncSort, Assembler, ChangeMan, Easytrieve, InterTest, REXX, CLIST etc...
 

Mutiple condtions using REXX

THIS IS AN ARCHIVE FORUM: CLICK HERE TO GO TO THE ORIGINAL TOPIC
Goto page 1, 2, 3  Next
 
       IBMMAINFRAMES.com - IBM Mainframe Support Forums Index -> CLIST & REXX
View previous topic :: View next topic  
Author Message
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Mon Jul 07, 2008 2:44 pm    Post subject: Mutiple condtions using REXX  

Hi,

i need to check mutiple conditons using REXX based on the number of variables present
EX: A = 123,B=NH,C=' ',D='2008'
i need to retrieve the records where
A=123,B=NH & D='2008' Must leave out C as the value is blank
like IF (SUBSTR(RC.I,1,3)=A & SUBSTR(RC.I,4,2)=B & SUBSTR(RC.I,8,4)=D)
and this may go in loop so that the IF condition needs to differ based on the varibales having the values. we will not know which field is blank at what time it is also possible to have more than one filed blank.

please let me know your suggestions.
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 2:50 pm    Post subject: Reply to: Mutiple condtions using REXX  

Quote:
please let me know your suggestions.

very humble suggestion :(
try to express Your requirements in a more understandable way,
the issue may be clear to You, but the way You exposed does not make it clear for everybody...
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 3:05 pm    Post subject: Reply to: Mutiple condtions using REXX  

trying to infer something from the info provided

recd is the thing You are trying to analyze
var1, var2, var3 are the variables You need to chek

here is a code snippe


Code: recd = "var1var2var3var4"
pos1 = 1; len1 = 4; var1 = "var1"
pos2 = 5; len2 = 4; var2 = ""
pos3 = 9; len3 = 4; var3 = ""

NOT_MATCHED = 0
    MATCHED = 1

trace "I"
do 1
    flag = NOT_MATCHED
    if  var1 <> ""  & ,
        substr(recd,pos1,len1) <> var1 then leave
    if  var2 <> ""  & ,
        substr(recd,pos2,len2) <> var2 then leave
    if  var3 <> ""  & ,
        substr(recd,pos3,len3) <> var3 then leave
    flag = MATCHED
end

if flag = MATCHED then ,
   say "MATCHED"
else ,
   say "NOT MATCHED"

exit
Back to top  
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Mon Jul 07, 2008 3:06 pm    Post subject: Reply to: Mutiple condtions using REXX  

EX: say i have some variables
A=123
B=NE
C=' '
D=2008
my input file has
RECORD1:123,NE,D,2008
RECORD2:123,NE,T,2008
RECORD3:111,HN,U,2007

I Need to fetch all the records having the value A=123,B=NEand D=2008 we dont have condition for C as the value of C=" ' (blank)
the condition will be like
IF ((SUBSTR(RECORD.I,1,3)=A & SUBSTR(RECORD.I,5,2)=B&SUBSTR(RECORD.I,10,4)=D)) This will retrieve me
RECORD1:123,NE,D,2008
RECORD2:123,NE,T,2008

like wise my IF CONDITION needs to be altered as per the fields having values. if A is balnk in then i should leave that fileds and frame the condition with the fields B,C and D.

how can this be done is my question.
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 3:17 pm    Post subject: Reply to: Mutiple condtions using REXX  

then the code snippet given does just that, tested


this new snippet tests for not existing variables or empty variables
Code: recd = "var1var2var3var4"
pos1 = 1; len1 = 4; var1 = "var1"
pos2 = 5; len2 = 4; var2 = ""
drop var2
pos3 = 9; len3 = 4; var3 = ""

NOT_MATCHED = 0
    MATCHED = 1

trace "I"
do 1
    flag = NOT_MATCHED
    if  symbol('var1') =  "VAR" & ,
      strip(var1)    <> ""    & ,
        substr(recd,pos1,len1) <> var1 then leave
    if  symbol('var2') =  "VAR" & ,
      strip(var2)    <> ""    & ,
        substr(recd,pos2,len2) <> var2 then leave
    if  symbol('var3') =  "VAR" & ,
      strip(var3)    <> ""    & ,
        substr(recd,pos3,len3) <> var3 then leave
    flag = MATCHED
end

if flag = MATCHED then ,
   say "MATCHED"
else ,
   say "NOT MATCHED"

exit
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 3:34 pm    Post subject: Reply to: Mutiple condtions using REXX  

this snippet is a bit more sophisticated

it builds the variable names dynamically from a list

Code: recd = "var1var2var3var4"
pos1 = 1; len1 = 4; var1 = "var1"
pos2 = 5; len2 = 4; var2 = ""
drop var2
pos3 = 9; len3 = 4; var3 = "var3"

NOT_MATCHED = 0
    MATCHED = 1

vnam_l = "var1 var2 var3 var4"
vpos_l = "1    5    9    13" 
vlen_l = "4    4    4    4" 


trace "I"
flag = MATCHED
do  v = 1 to words(vnam_l)
   vnam = word(vnam_l,v)
    vpos = word(vpos_l,v)
   vlen = word(vlen_l,v)
   vval = value(vnam)
    if  symbol(vnam) <> "VAR" then ,
      iterate

    if  strip(vval) =  "" then ,
      iterate
   
    if  substr(recd,vpos,vlen) <> vval then do
      flag = NOT_MATCHED      
      leave
   end
end

if flag = MATCHED then ,
   say "MATCHED"
else ,
   say "NOT MATCHED"

exit
Back to top  
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Mon Jul 07, 2008 3:36 pm    Post subject: Reply to: Mutiple condtions using REXX  

Thank you for the suggestions ...

but this one displays me the records even if one varible is present but i dont want it that way
i need to check for the all the varibles having values if it is present in that record and then fetch only that record as i have specified in my example before.

your suggestion on this?
Back to top  
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Mon Jul 07, 2008 3:49 pm    Post subject: Reply to: Mutiple condtions using REXX  

Thank you so much enrico-sorichetti

This is what i was seraching for its does it and can please tell me why you have used DROP VAR2
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 3:54 pm    Post subject: Reply to: Mutiple condtions using REXX  

Quote: i need to check mutiple conditons using REXX based on the number of variables present
EX: A = 123,B=NH,C=' ',D='2008'
i need to retrieve the records where
A=123,B=NH & D='2008' Must leave out C as the value is blank


my samples just do that
if any of the source variables are not defined,or blanks or empty,
the comparison is skipped

written, made better, tested, found working as per quoted requirement, and posted



Quote: your suggestion on this?

just learn to express Your requirements in a non misleading way, please :evil:

added multiple records, tested as per original requirement

Code:
recd.0 = 5
recd.1 = "var1var2var3var4"
recd.2 = "var1varxvar3var4"
recd.3 = "var1var2varxvar4"
recd.4 = "var1var2var3varx"
recd.5 = "var1var2var3varx"

var1 = "var1"
var3 = "var3"

NOT_MATCHED = 0
    MATCHED = 1

vnam_l = "var1 var2 var3 var4"
vpos_l = "1    5    9    13" 
vlen_l = "4    4    4    4" 


do  r = 1 to recd.0
   recd = recd.r
   trace "O"
   flag = MATCHED
   do  v = 1 to words(vnam_l)
      vnam = word(vnam_l,v)
      vpos = word(vpos_l,v)
      vlen = word(vlen_l,v)
      vval = value(vnam)
      if  symbol(vnam) <> "VAR" then ,
         iterate
   
      if  strip(vval) =  "" then ,
         iterate
      
      if  substr(recd,vpos,vlen) <> vval then do
         flag = NOT_MATCHED      
         leave
      end
   end
   
   if flag = MATCHED then ,
      say "MATCHED    " r recd.r
   else ,
      say "NOT MATCHED" r recd.r

end

exit

Back to top  
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Mon Jul 07, 2008 4:09 pm    Post subject: Reply to: Mutiple condtions using REXX  

Thank you so much for the help provided on this enrico-sorichetti
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 4:21 pm    Post subject: Reply to: Mutiple condtions using REXX  

the drop statement was to test for no existance of a variable...

there is a glitch in the last snippet

Code:
... before
      vlen = word(vlen_l,v)
      vval = value(vnam)
      if  symbol(vnam) <> "VAR" then ,
         iterate


      if  strip(vval) =  "" then ,
         iterate


Code:
... after
      vlen = word(vlen_l,v)
      if  symbol(vnam) <> "VAR" then ,
         iterate

      vval = value(vnam)
      if  strip(vval) =  "" then ,
         iterate


it is wiser to retrieve a variable value after having checked its existence
Back to top  
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Mon Jul 07, 2008 4:54 pm    Post subject:  

Got it thank you
Back to top  
dick scherrer



Joined: 23 Nov 2006
Posts: 8732
Location: 221 B Baker St

Posted: Mon Jul 07, 2008 8:34 pm    Post subject:  

Hi Enrico,

Quote: there is a glitch in the last snippet
Long ago someone told me that bugs were "sons of glitches". . . .
Back to top  
enrico-sorichetti



Joined: 14 Mar 2007
Posts: 3168
Location: italy

Posted: Mon Jul 07, 2008 10:35 pm    Post subject: Reply to: Mutiple condtions using REXX  

Hi Dick,
I hope You will forgive my glitch :(
the snippet was written an tested while answering the TS
( ... can be seen by the messages timestamps )

I promise to be more careful in the future :D
Back to top  
vidyaa



Joined: 02 May 2008
Posts: 37
Location: chennai

Posted: Fri Aug 01, 2008 6:09 pm    Post subject:  

hi enrico,

this one executed fast for few records but my input has billons od records its very slow on doing this is there any way to make it better and faster.

Suggestions on this will be of great help
Back to top  
 
       IBMMAINFRAMES.com - IBM Mainframe Support Forums Index -> CLIST & REXX Goto page 1, 2, 3  Next
Page 1 of 3
THIS IS AN ARCIVE FORUM IN READ ONLY MODE. IF YOU WANT TO ASK YOUR DOUBTS USE THE ACTUAL FORUM