Multiple layouts written into same file

Hello,

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



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.

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

WRITE WORK 1 VARIABLE #LAYOUT-1

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

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.

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:


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

The define statements were under different conditions.

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