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 

Nested loop in Easytrieve

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


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Thu Feb 05, 2004 8:04 am    Post subject: Nested loop in Easytrieve Reply with quote

Folks,
I have a question here on Easytrieve. Attach is a code snippet of the same. Basically, I want to run through IN2 file for every single record in IN1. If the keys are matching, I write an output. Else, I just write that record from IN1 as is. I was looking about the "POINT" feature of easytrieve but apparenly found that it can be used only for ISAM/VSAM files. So how do I achieve this?

Code:


 FILE IN1                                                       
   FILE1-KEY   1 3 A                                             
   FILE1-REST  4 3 A                                             
 FILE IN2                                                       
   FILE2-KEY   1 3 A                                             
   FILE2-REST  4 3 A                                             
 FILE OUT FB (0 0)                                               
    FIELD1     1 3 A                                             
    FIELD2     4 3 A                                             
                                                                 
 W-END-LOOP    W 1 A                                             
                                                                 
 JOB INPUT IN1
    GET IN1                                                     
    DO WHILE IN1
       JOB INPUT IN2
       GET IN2                                                   
       W-END-LOOP = 'F'                                         
       DO WHILE IN2 AND W-END-LOOP = 'T'                         
         IF FILE1-KEY = FILE2-KEY     
            FIELD1 = FILE2-REST       
            FIELD2 = FILE2-KEY       
            PUT OUT                   
         ELSE-IF FILE1-KEY < FILE2-KEY
             PUT OUT FROM IN1         
             W-END-LOOP = 'T'         
         END-IF                       
         GET IN2                     
       END-DO                         
    GET IN1                           
    END-DO                           



Cheers,
Coolman.
________
buy vapir oxygen


Last edited by coolman on Sat Feb 05, 2011 1:33 am; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Feb 05, 2004 8:56 am    Post subject: Reply with quote

Coolman,

You need to look at syncronised file processing. Read chapter9: File processing. you just need a if matched clause and it is very easy. Check this link for the manual.

http://www.mvsforums.com/manuals/EZT_PL_APP_63_MASTER.pdf


Code:


FILE IN1                                                       
   FILE1-KEY   1 3 A                                             
   FILE1-REST  4 3 A                                             

FILE IN2                                                       
   FILE2-KEY   1 3 A                                             
   FILE2-REST  4 3 A                                             
 
FILE OUT FB (0 0)                                               

JOB INPUT (IN1  KEY (FILE1-KEY)  +
           IN2  KEY (FILE2-KEY))
 
   IF MATCHED
      PUT OUT FROM IN2
   ELSE-IF IN1
      PUT OUT FROM IN1
   ELSE-IF
      DISPLAY 'THIS KEY IS NOT FOUND IN IN1 FILE: '  IN2-KEY
   END-IF     



Also check this topic which discusses about matching files

http://www.mvsforums.com/helpboards/viewtopic.php?t=11&highlight=match


Hope this helps...

Cheers

Kolusu

PS: Never code your own match logic in easytrieve unless it is a situation where the syncronised file processing cannot handle.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
coolman
Intermediate


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Thu Feb 05, 2004 10:17 am    Post subject: Reply with quote

kolusu,
I was aware of the synchronised file processing. I have quoted a situation which cannot be handled by if matched clause. matched clause would handle the case of 1-m or m-1 records, but it does not handle m-m records. Please excuse me for not having shown the data in the input files.

Now, if both the i/p files have duplicates, i guess the matching logic would not work and i would have to write my own matching logic. Correct me if iam wrong.

Now the code what i have shown is coming out with max-cc of 16. I feel you cannot be having another JOB within a JOB. But im thinking if there is a way out to this.

Thanks kolusu for your quick reply.

Cheers,
Coolman.
________
M47


Last edited by coolman on Sat Feb 05, 2011 1:33 am; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Feb 05, 2004 10:56 am    Post subject: Reply with quote

Coolman,

You are absolutely right about easytrieve syncronised file processing works for one to many match or many to one match.

A many to many file match cannot be handled with syncronised file processing. Yes in that case you need to write your own match logic.

yes you cannot have a job within a job.

Show me a sample of input data from both the files and desired output.

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


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Thu Feb 05, 2004 11:28 am    Post subject: Reply with quote

kolusu,
Assume these as the inputs.

Code:


i/p 1
===
111abc
222bcd
222cde
333def
444efg

i/p 2
===
222xyz
222cba
555zzz


o/p
===
111abc
xyzbcd
xyzcde
cbabcd
cbacde
333def
444efg

________
Honda CH150


Last edited by coolman on Sat Feb 05, 2011 1:33 am; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Feb 05, 2004 3:54 pm    Post subject: Reply with quote

Coolman,

The many to many match is always a pain. I am not really comfortable with coding my own logic for matching. However for your question I came up with a solution. I haven't tested it out for all cases but for simple cases it will work.

A Brief explanation of the code. There are 2 job statements in this job. I have taken the IN2 file and cummulated all the duplicate records to be a single record. i.e the output from the first job will be as follows. I assumed that you will have a maximum of 5 duplicate records.

Code:

222XYZCBA                                               
555ZZZ                                               


By doing so the actual match now becomes a ONE to MANY match.The second Job is matching the temp file created in the first job to the IN1 file and creating the output as desired.


[code:1:70b52da4ef]
//IN1 DD *
111ABC
222BCD
222CDE
333DEF
444EFG
//IN2 DD *
222XYZ
222CBA
555ZZZ
//OUTPUT DD SYSOUT=*,LRECL=6
//SYSIN DD *

FILE IN1
IN1-KEY 1 03 A
IN1-REST * 03 A

FILE IN2
IN2-KEY 1 03 A
IN2-REST * 03 A

W-PREV-KEY W 03 A
W-STR1 W 03 A
W-STR2 W 03 A
W-STR3 W 03 A
W-STR4 W 03 A
W-STR5 W 03 A
W-SUB W 01 N 0 VALUE 1

FILE TEMP FB(18 0) VIRTUAL
T-KEY 1 03 A
T-STR 4 03 A OCCURS 5 INDEX IDX1

FILE OUTPUT FB(0 0)
O-KEY 1 03 A
O-REST * 03 A

***********************************************************************
* MAINLINE *
***********************************************************************

JOB INPUT NULL START INIT

DO UNTIL EOF IN2
IF IN2-KEY EQ W-PREV-KEY
PERFORM POPULATE
ELSE
PERFORM WRITE-OUTPUT
W-PREV-KEY = IN2-KEY
W-SUB = 1
PERFORM POPULATE
END-IF
GET IN2
END-DO

PERFORM WRITE-OUTPUT
STOP

INIT. PROC
GET IN2
W-PREV-KEY = IN2-KEY
W-SUB = 1
END-PROC

POPULATE. PROC

CASE W-SUB
WHEN 1
W-STR1 = IN2-REST
WHEN 2
W-STR2 = IN2-REST
WHEN 3
W-STR3 = IN2-REST
WHEN 4
W-STR4 = IN2-REST
WHEN 5
W-STR5 = IN2-REST
END-CASE
W-SUB = W-SUB + 1

END-PROC

WRITE-OUTPUT. PROC

T-KEY = W-PREV-KEY
T-STR (1) = W-STR1
T-STR (2) = W-STR2
T-STR (3) = W-STR3
T-STR (4) = W-STR4
T-STR (5) = W-STR5
PUT TEMP

MOVE SPACES TO W-STR1 W-STR2 W-STR3 W-STR4 W-STR5
W-SUB = 1

END-PROC

JOB INPUT (TEMP KEY (T-KEY) +
IN1 KEY (IN1-KEY))

IF MATCHED
IDX1 = 1
DO WHILE IDX1 < 5
IF T-STR(IDX1)
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
coolman
Intermediate


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Thu Feb 05, 2004 10:43 pm    Post subject: Reply with quote

Well, there are "still" some things left that "only" a complete programming language can do.

Thanks kolusu.

Cheers,
Coolman
PS: Does easytrieve not provide a facility to close and open the files at will.
________
volcano vaporizer


Last edited by coolman on Sat Feb 05, 2011 1:33 am; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Feb 06, 2004 5:21 am    Post subject: Reply with quote

coolman,

Easytrieve is not real programming language. It was developed as a reporting language. so there are somethings that you cannot do. For example there is no INSPECT verb in easytrieve. Similary none of the INTRINSIC functions are available in easytrieve. However you can achieve some of the results coding your own logic with DO statement.

Easytrieve does not have the option of opening and closing the files at will

Kolusu
_________________
Kolusu
www.linkedin.com/in/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 -> 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