# Multiple layouts written into same file

**URL:** <https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [March 26, 2007, 9:23pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079 "2007-03-26T21:23:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vallish](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vallish](https://techcommunity.softwareag.com/u/Vallish)\
**Post date:** [March 26, 2007, 9:23pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/1 "2007-03-26T21:23:10Z")

</div>

Hello,

I want to know if there is a way to do the below:

```auto

01 #LAYOUT-1 (A200)
01 #LAYOUT-2 (A300)
01 #FLAG (A1)

IF #FLAG = 'A'
   WRITE WORK 1 #LAYOUT-1
END-IF

IF #FLAG = 'B'
  WRITE WORK 1 #LAYOUT-2
END-IF

```

When I try this, I get an error: 'NAT0364 Inconsistency in multiple writing to the same work file".

To add, the same code will be executed in different steps of a JCL according to the step, the flag will be set.

---

<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:** [March 27, 2007, 12:13am UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/2 "2007-03-27T00:13:55Z")

</div>

Natural is telling you that the record layouts are of different lengths. Add the VARIABLE keyword to each WRITE WORK, as in

```auto
WRITE WORK 1 VARIABLE #LAYOUT-1
```

---

<div class="post-metadata">

**Author:** ![Vallish](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vallish](https://techcommunity.softwareag.com/u/Vallish)\
**Post date:** [March 27, 2007, 12:01pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/3 "2007-03-27T12:01:27Z")

</div>

Yes, I could do that. But I do not want to define the file as VB. Why does Natural have this restriction?

---

<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:** [March 27, 2007, 12:27pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/4 "2007-03-27T12:27:24Z")

</div>

Natural computes the LRECL and passes it it to the operating system. When he sees two LRECLs, what should he do but presume a variable length record? How is Natural to know that only one record format will be written in each of your job steps?

Keep the VARIABLE keyword, but put RECFM=FB and the LRECL of the longest layout on each file definition in your JCL. Or, pad the record layouts so that all the lengths are the same, and remove the VARIABLE keyword.

---

<div class="post-metadata">

**Author:** ![Vallish](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vallish](https://techcommunity.softwareag.com/u/Vallish)\
**Post date:** [April 16, 2007, 8:14pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/5 "2007-04-16T20:14:01Z")

</div>

Just to add, I worked around this problem differently. I did not define the file as VB.

I used multiple files - work 01, 02, 03 etc, but defined the files using the same DD card names. for ex:

```auto

DEFINE WORK 01 OUT1
...
...
DEFINE WORK 02 OUT1 
```

The define statements were under different conditions.

---

<div class="post-metadata">

**Author:** ![Fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@Fabian](https://techcommunity.softwareag.com/u/Fabian)\
**Post date:** [May 7, 2007, 8:34pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/6 "2007-05-07T20:34:20Z")

</div>

Hi, i hope it isn´t too late.  
I could work with different layouts doing the next:

DEFINE DATA  
LOCAL  
1 #WORK1 (A30)  
1 REDEFINE #WORK1  
2 #W1-AA (A15)  
2 #W1-BB (A10)  
1 REDEFINE #WORK1  
2 #W2-AA (A5)  
2 #W2-BB (A20)  
2 #W2-CC (A5)  
.  
.  
.  
END-DEFINE  
.  
WRITE WORK FILE 1 #WORK1  
.

and I don’nt need ask for differents condition, because the different variables are being charged.  
In JCL, you must define large of WKF as long as the biggest file, as you defined in the program.

Greetings, Fabi

---

<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, 2:41pm UTC](https://techcommunity.softwareag.com/t/multiple-layouts-written-into-same-file/62079/7 "2021-04-02T14:41:07Z")

</div>


