Page 1 of 1

variable in write work file statement?

PostPosted: Tue Dec 14, 2010 4:34 pm
by diptisaini
Write work file 1 variable

I just need to know what is the exact use of variable in above statement. Can anyone please explain me with a example ?

Re: variable in write work file statement?

PostPosted: Tue Dec 14, 2010 5:25 pm
by ats
Hi Dipti,

We can write records with different fields to the same work file and need to use different WRITE WORK FILE statements. However, in this case, the VARIABLE clause must be specified in all WRITE WORK FILE statements. The records on the external file (assigned within JCL) will be written in variable format. Natural will write all output files as variable-blocked (unless you specify a record format and block size in the execution JCL).

Assuming you know the simple WRITE WORK FILE structure, below is an example with VARIABLE clause:

WRITE WORK FILE 1 VARIABLE #FIRST-NAME #LAST-NAME
........ (statements to be followed)
........
WRITE WORK FILE 1 VARIBALE #FIRST-NAME #LAST-NAME #ADDRESS-LINE-1 #PHONE-NUMBER


Thanks,
Ats

Re: variable in write work file statement?

PostPosted: Tue Dec 14, 2010 10:05 pm
by RGZbrog
A minor adjustment to what Ats said:

It's not the different field lists that force the use of the VARIABLE clause, it's the difference in logical record lengths. You don't need to code VARIABLE if all the record lengths are the same.

Here's an example where both records are 15 bytes long.
DEFINE DATA LOCAL
1 #A (A5)
1 #B (P11.2)
1 #C (N3)
1 #1 (L)
1 #2 (C)
1 #3 (D)
1 #4 (A8)
END-DEFINE
WRITE WORK 1 #A #B #C
WRITE WORK 1 #1 #2 #3 #4
END

Re: variable in write work file statement?

PostPosted: Wed Dec 15, 2010 11:05 am
by diptisaini
Hi,

Thanks for the clarification.
1 #2 (C)

I need to know in above statement what (c) repesent . As (c) is used as control variable in online maps so why we are using this in case of batch ?

Re: variable in write work file statement?

PostPosted: Wed Dec 15, 2010 11:36 am
by RGZbrog
Just a quick way of defining fields of various lengths for my example. (A control variable is 2 bytes in length.) I can't think of a good reason to write a CV to a work file, but there is no reason that you can't do it.

Re: variable in write work file statement?

PostPosted: Wed Dec 15, 2010 1:33 pm
by ats
To add to Ralph's note on CV, a variable defined with format C may be used to assign attributes dynamically to a field used in a DISPLAY, INPUT, PRINT, PROCESS PAGE or WRITE statement and attributes assigned will take effect in online mode. If they used in BATCH, it will STOW successfully but simply won't be effective (with their assignment).

Thanks,
Ats

Re: variable in write work file statement?

PostPosted: Wed Dec 15, 2010 10:08 pm
by RGZbrog
Ats,

I hope that you're not saying that control variables are of no use in batch.

This thread is going a bit off-topic, so I'll submit my comments in a new one (Control Variables in batch):

posting.php?mode=post&f=11&sid=835d3fd32bc813723f1ba958285e139c#preview

Re: variable in write work file statement?

PostPosted: Thu Dec 16, 2010 11:41 am
by ats
Hi Ralph,

I saw your other example of CV in batch, in another post. As you hoped, I wasn't mean it's of no use in Batch. However, was limited to attributes such as AD, CD that won't be effective in batch mode (or they would be :?: , I really didn't come accross). Hope that clears the confusion :D

Regards,
Ats

Re: variable in write work file statement?

PostPosted: Fri Dec 17, 2010 5:14 pm
by fidelis
Hi diptisaini,

When do you use WRITE WORK FILE statements, It is possible to write records with different fields to the same work file with different WRITE WORK FILE statements. In this case, the records on the external file will be written in variable format.

When the operand list includes a dynamic variable (that could change in size for different executions of the WRITE WORK FILE statement), the VARIABLE entry must be specified in all WRITE WORK FILE statements.