# Read of 2 Work Files

**URL:** <https://techcommunity.softwareag.com/t/read-of-2-work-files/176633>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [May 27, 2014, 10:35am UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633 "2014-05-27T10:35:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Meier](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Matthias\_Meier](https://techcommunity.softwareag.com/u/Matthias_Meier)\
**Post date:** [May 27, 2014, 10:35am UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/1 "2014-05-27T10:35:19Z")

</div>

Hi,  
I want to read parallel 2 work files, but I don’t know, how does it works. If I use two interlaced READ Statements, I had to end the inner READ-Loop with END-WORK to make the next READ of the first Work File.

READ WORK FILE 01 #W01-SATZ  
\*  
READ WORK FILE 02 #W02-SATZ  
\*  
IF #W01-SATZ NE #W02-SATZ  
WRITE ‘\<\>’  
ELSE  
write ‘=’  
END-IF  
\*  
END-WORK  
\*  
END-WORK

In this kind, it does’nt work parallel! What can I do to read both Work-Files parallel? Perhaps it is easy, but I don’ have a good idea.  
Thanks for your help!

best regards  
Matthias

---

<div class="post-metadata">

**Author:** ![Giles](https://avatars.discourse-cdn.com/v4/letter/g/c68b51/32.png) [@Giles](https://techcommunity.softwareag.com/u/Giles)\
**Post date:** [May 27, 2014, 12:29pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/2 "2014-05-27T12:29:05Z")

</div>

REPEAT UNTIL EOF1 AND EOF2  
READ WORK 1 ONCE  
AT END MOVE TRUE TO EOF1  
READ WORK 2 ONCE  
AT END MOVE TRUE TO EOF2  
…  
END-REPEAT

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [May 27, 2014, 12:37pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/3 "2014-05-27T12:37:45Z")

</div>

As an alternative to Giles post, you could simply change your READ WORK FILE 02 to READ WORK FILE 02 ONCE and get rid of one END-WORK. This assumes that WF1 has at least as many records as WF2.

Both will work fine (given the length observation above).

steve

---

<div class="post-metadata">

**Author:** ![Matthias\_Meier](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Matthias\_Meier](https://techcommunity.softwareag.com/u/Matthias_Meier)\
**Post date:** [May 27, 2014, 4:29pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/4 "2014-05-27T16:29:58Z")

</div>

Thank you very much! It worked very well!  
Thanks a lot for you both!  
Best Regards  
Matthias

---

<div class="post-metadata">

**Author:** ![Sebastiao\_Teixeira\_Vasconcelos\_Junior](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Sebastiao\_Teixeira\_Vasconcelos\_Junior](https://techcommunity.softwareag.com/u/Sebastiao_Teixeira_Vasconcelos_Junior)\
**Post date:** [August 11, 2015, 2:00pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/5 "2015-08-11T14:00:09Z")

</div>

> [@Steve Robinson](#):
>
> As an alternative to Giles post, you could simply change your READ WORK FILE 02 to READ WORK FILE 02 ONCE and get rid of one END-WORK. This assumes that WF1 has at least as many records as WF2.
> 
> Both will work fine (given the length observation above).
> 
> steve

Hi,

As the first question, I do need to READ 2 Work File, but I need too compare both…  
For example: Compare If the ID that is in WKF1 is in WKF2 … And if its not, I need to do a WRITE WORK FILE

Please help me !

Tks !!!

---

<div class="post-metadata">

**Author:** ![Sebastiao\_Teixeira\_Vasconcelos\_Junior](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Sebastiao\_Teixeira\_Vasconcelos\_Junior](https://techcommunity.softwareag.com/u/Sebastiao_Teixeira_Vasconcelos_Junior)\
**Post date:** [August 11, 2015, 2:02pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/6 "2015-08-11T14:02:23Z")

</div>

> [@Steve Robinson](#):
>
> As an alternative to Giles post, you could simply change your READ WORK FILE 02 to READ WORK FILE 02 ONCE and get rid of one END-WORK. This assumes that WF1 has at least as many records as WF2.
> 
> Both will work fine (given the length observation above).
> 
> steve

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 11, 2015, 9:27pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/7 "2015-08-11T21:27:31Z")

</div>

A working program is available for download in the Code Samples section: [url][http://techcommunity.softwareag.com/ecosystem/communities/public/adanat/products/natural/codesamples/9aee98dd-de2d-11e4-89cb-cd8d7ef22065/?title=Sequential+Match[/url]](http://techcommunity.softwareag.com/ecosystem/communities/public/adanat/products/natural/codesamples/9aee98dd-de2d-11e4-89cb-cd8d7ef22065/?title=Sequential+Match%5B/url%5D) Adjust the record definitions and off you go.

---

<div class="post-metadata">

**Author:** ![mytwo22](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mytwo22](https://techcommunity.softwareag.com/u/mytwo22)\
**Post date:** [July 5, 2017, 6:22pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/8 "2017-07-05T18:22:17Z")

</div>

Hi, I hope I can still add to this post.  
When doing a Read Work File 02 Once, how do I continue looping?  
I only want to select records that are on both files.  
I tried to do escape top but that didn’t work.  
thank you!!!

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [July 5, 2017, 6:48pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/9 "2017-07-05T18:48:57Z")

</div>

READ WORK FILE 02 ONCE does not initiate a loop, so as you note, escape top does not work. If you need to skip a record in WF 2, you will need a repeat loop around the READ WORK FILE 02 ONCE statement and read one record at a time until you reach the end of file 2 or find a record to process.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [July 5, 2017, 8:02pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/10 "2017-07-05T20:02:24Z")

</div>

The sequential match program that I referenced earlier in this thread is working code that demonstrates how to do what you want. It is a parent-to-child match, where WORK1 is the parent and WORK2 is the child. You can allow a 1:many match or restrict it to 1:1. Add your own logic for matches, widows (parent; no child), and orphans (child; no parent).

---

<div class="post-metadata">

**Author:** ![mytwo22](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mytwo22](https://techcommunity.softwareag.com/u/mytwo22)\
**Post date:** [July 5, 2017, 9:45pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/11 "2017-07-05T21:45:00Z")

</div>

Thank you for taking the time, I am understanding it now!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:31pm UTC](https://techcommunity.softwareag.com/t/read-of-2-work-files/176633/12 "2021-04-02T15:31:12Z")

</div>


