# a problem with WRITE WORK FILE

**URL:** <https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [April 18, 2011, 7:06pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820 "2011-04-18T19:06:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 18, 2011, 7:06pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/1 "2011-04-18T19:06:31Z")

</div>

Hi,

i have a question about the statement DEFINE WORK FILE.  
I have a solution for my problem, but I like to know, what’s the reason.  
In my first Program I have a problem:

```auto

DEFINE WORK FILE 1 #DSNAME           
DEFINE WORK FILE 2 #DSNAME_NEU 
FIND CATALOG-VIEW WITH DSNAME = #DSNAME AND NODE = #NODE 
  IF NO RECORDS FOUND 
    WRITE 'Keine Emtex-Datei gefunden!' 
    ESCAPE BOTTOM 
  END-NOREC 
  READ WORK FILE 1 RECORD #EMTEXDATENSATZ 
    MOVE SUBSTR(#EMTEXDATENSATZ,1,50) TO #TEST
    WRITE WORK FILE 2 VARIABLE #TEST
  END-WORK
END-FIND 
CLOSE WORK FILE 1 
CLOSE WORK FILE 2
END
```

The problem is in the WRITE WORK FILE statment.  
The systeme write: 1500 WORK-Datei 2 kann nicht geoeffnet werden , DMS ERROR: DD31.  
My solution:

```auto

DEFINE WORK FILE 1 #DSNAME           
DEFINE WORK FILE 2 #DSNAME_NEU 
FIND CATALOG-VIEW WITH DSNAME = #DSNAME AND NODE = #NODE 
  IF NO RECORDS FOUND 
    WRITE 'Keine Emtex-Datei gefunden!' 
    ESCAPE BOTTOM 
  END-NOREC
  FETCH RETURN 'ACEMTX' 
END-FIND 
CLOSE WORK FILE 1 
CLOSE WORK FILE 2
END
```

and the program ‘ACEMTX’:

```auto

READ WORK FILE 1 RECORD #EMTEXDATENSATZ 
 MOVE SUBSTR(#EMTEXDATENSATZ,1,50) TO #TEST 
 WRITE WORK FILE 11 VARIABLE #EMTEXDATENSATZV 
END-WORK 
END 
```

Why?

---

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 18, 2011, 7:07pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/2 "2011-04-18T19:07:37Z")

</div>

write work file 2 #emtexdatensatz

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [April 19, 2011, 12:34am UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/3 "2011-04-19T00:34:27Z")

</div>

Is work file 2 (CMWKF02) defined as a variable length RECFM in the DCB? Is it a sequential (QSAM) file? Does it work if you don’t specify the VARIABLE clause?

---

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 19, 2011, 11:48am UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/4 "2011-04-19T11:48:26Z")

</div>

Is work file 2 (CMWKF02) defined as a variable length RECFM in the DCB?  
Yes  
Is it a sequential (QSAM) file?  
It is a SAM-file.  
Does it work if you don’t specify the VARIABLE clause?  
It is the same problem with or without the VARIABLE clause.

The problem is:  
Why I can’t write in the work file 2 in the same program, but I use a second program it is OK?  
It is a time-problem?  
I define a work file and can’t use it in the same program. Why?

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [April 19, 2011, 1:05pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/5 "2011-04-19T13:05:48Z")

</div>

> [@Jörg Eckersberg](#):
>
> Why I can’t write in the work file 2 in the same program, but I use a second program it is OK?

You use work file 11 (instead of 2) in the subprogram… maybe that’s the reason why.

---

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 19, 2011, 1:18pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/6 "2011-04-19T13:18:12Z")

</div>

No, i have no right write in the first post.

It is WORK FILE 2.  
(I have try witch WORK FILE 11, but the same)

---

<div class="post-metadata">

**Author:** ![Aldo\_Teusch](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/aldo_teusch/32/87_2.png) [@Aldo\_Teusch](https://techcommunity.softwareag.com/u/Aldo_Teusch)\
**Post date:** [April 19, 2011, 1:57pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/7 "2011-04-19T13:57:40Z")

</div>

Could you provide the entire error message ?

---

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 19, 2011, 3:15pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/8 "2011-04-19T15:15:34Z")

</div>

I start the program in Natural with run.

Then I can read the message in Natural:  
==err\> 0000 1500 WORK-Datei 2 kann nicht geoeffnet werden , DMS ERROR: DD31.

I start the program with a batch-job.  
Then I can read in the outputfile the following massage:

39:ANEXT ACEMTER  
40:AACEMTER NAT1500 WORK-Datei 2 kann nicht geoeffnet werden , DMS  
ERROR: DD31  
41:ANEXT FIN·

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [April 20, 2011, 11:27am UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/9 "2011-04-20T11:27:03Z")

</div>

what do you have in “#DSNAME\_NEU”?

Your error seems to indicate that the program is writing to //DD31. Is this defined? Is “DD31” the content of #DSNAME\_NEU? What happens if you omit the DEFINE WORK FILE 2 #DSNAME\_NEU in the first program (assuming you have the default file assignments, the output should go to //CMWKF02)?

---

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 20, 2011, 5:21pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/10 "2011-04-20T17:21:34Z")

</div>

Hi,

#dsname is the name of a file with a lot of data (BS2000-Accounting-data).  
e.g. #dsname = sys.account.2011-03-23.e2  
I need a part of this data e.g. the data with TASK. This part I will write in a new work file. (work file 2 #dsname\_neu) .  
#dsname\_neu = acc.account.2011-03-23.e2

I will write in this file - not read.  
I read from work file 1 - this is all right.  
If I use the FETCH RETURN statment, I can write in work file 2.

But I don’t now, why I can’t write in work file 2 in the same program

Jörg

---

<div class="post-metadata">

**Author:** ![Jorg\_Eckersberg](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jorg\_Eckersberg](https://techcommunity.softwareag.com/u/Jorg_Eckersberg)\
**Post date:** [April 20, 2011, 5:29pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/11 "2011-04-20T17:29:22Z")

</div>

dd31 is a error-massage from BS2000 ( I think so)

If I write in the BS2000-console

help dd31

I can read the massege from BS2000

% DMS0D31 DATEINAME UNGUELTIG ODER FEHLERHAFT  
% ? Der Benutzer-Dateiname folgt nicht den Konventionen.  
% Moegliche Ursachen:  
% 1) $USER-ID ungueltig bzw. der Benutzer hat kein Zugriffsrecht auf  
% den angesprochenen Pubset;  
% 2) Verlangte Funktion erlaubt keinen teilqualifizierten Dateinamen;  
% Unter Meldung DMS0331 sind weitere moegliche Fehlerursachen aufgefuehrt.  
% ! Das Programm verbessern und erneut versuchen.

But with the second program I can.

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [April 20, 2011, 7:54pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/12 "2011-04-20T19:54:52Z")

</div>

Just a wild guess…

- and I am no expert in this area - my BS2000 knowledge is 15 years old 😉

Could this be related to the AM=STD setting in the NTWORK macro in NATPARM ?  
More specifically if the OPEN=… is set to ACC or INIT or ???  
In other words if the file is open at session init or at first access ?  
There is tons of different options described in the doc.  
[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat427mf/sm/definewo.htm](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat427mf/sm/definewo.htm)

Finn

---

<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:00pm UTC](https://techcommunity.softwareag.com/t/a-problem-with-write-work-file/96820/13 "2021-04-02T15:00:06Z")

</div>


