How do I write data to a PC file ?

We are moving from Mainframe to Natural for Windows. How do I define and write data to a file in my PC ? I have already tried many options but nothing works. The file can be a flat file. I’m just testing for now.

There are several ways to do this. Take a look at the documentation for the DEFINE WORK FILE and READ/WRITE/CLOSE WORK FILE statements.
http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat638unx/ops/ops-batchmode.htm#ops-batch-simulation

An overview of the configuration: http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat638win/unicode/uni-data.htm#uni-data-workprintfiles

and the relevant NATPARM configurations: http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat638win/config/cfg-profileparm.htm#cfg-prf-exe-workfiles

This sample program writes to “test.txt” in my Windows temp directory, using the environment variable %temp%:

DEFINE DATA LOCAL
01 #STUFF (A100) INIT<'hello, workfiles'>
END-DEFINE
DEFINE WORK FILE 1 '%temp%\test.txt'
WRITE WORK FILE 1 #STUFF
END

Jaime,

How do you know that it doesn’t work? Was there an error message?

Start with a very simple program. I like to avoid environment variables until I know everything else is working. You should find your file in your root directory:

DEFINE WORK FILE 1 'c:\myNatData.txt'
WRITE WORK 1 'ABC'
END

Doug gave you the places to look for the default values for the file’s name, location, and disposition.

Ralph, I just ran your code:

DEFINE WORK FILE 1 ‘c:\myNatData.txt’
WRITE WORK 1 ‘ABC’
END

It stow, and it looks like ran, but when I go to see the myNatData.txt, is empty.

  1. Do the file have to previously exist ? I created it before running the program.
  2. Do I need to have installed something called: Natural Connection ?

I guess that I have also to take a look at the links sent by Douglas, probably I’m missing a setting.

Thank you guys for Helping me.
Jaime

Jaime,

How do you know that it doesn’t work? Was there an error message?

Start with a very simple program. I like to avoid environment variables until I know everything else is working. You should find your file in your root directory:

DEFINE WORK FILE 1 'c:\myNatData.txt'
WRITE WORK 1 'ABC'
END

Doug gave you the places to look for the default values for the file’s name, location, and disposition.

Hi Jaime,

  1. Do the file have to previously exist ? I created it before running the program.

They don’t need to exist and will be created on the fly but, if they do exist, the default behavior is to overwrite. See Douglas’ NATPARM link for workfile parameters.

  1. Do I need to have installed something called: Natural Connection ?

Not for what you are trying to achieve. It can be used to write local PC files from a mainframe Natural session.

Cheers,

Graeme Lane

I would do a CLOSE WORK FILE 1.

Are you on a Mainframe using a SPoD-Session? AFAIK, you can’t write to files located on your PC using a Mainframe-SPoD-Session…

I’m running Natural for Windows 6.3.8, but MAPPED to a Linux box. My little write program in saved in the Linux box after been stowed, but I run it from Windows. Also, I’m going to all the links suggested by DOUGLAS, also checked on the NATPARM.

I was just told by an Analyst in our department to UNMAP from the Linux box and run Natural without MAPPING (Local). I guess I will try that.

Thank you

Natural will create the file if it doesn’t exist, but it won’t create directories.

The environment you run in is the one that determines the target for the WRITE WORK FILE. So, for Linux, you need to use Linux naming and path conventions. On Windows, you may or may not be able to write to your root directory, depending on your Windows version and group policies: if you can create a file in your target directory from Explorer, then you should be able to from Natural.

Douglas, Yes I’m able to create a file on my target directory from Explorer, I don’t have restrictions. I have also ran Natural in Local mode, without being mapped to Linux or the Mainframe.

Still the program runs, but the file is not created, or if I manually create the file, the program doens’t write anything into the file.

Thank you

Have you tried writing to the Windows box just to verify that the program is working. If it writes OK then you must have a problem with your Windows/Linux mapping.

How to add several records on “WORK FILE 1 '%temp%\test.txt '” or accumulate the data, then perform sequential read in NATURAL as a sequential file…

DEFINE DATA LOCAL
01 #STUFF (A100) INIT<'hello, workfiles'>
END-DEFINE
DEFINE WORK FILE 1 '%temp%\test.txt'
WRITE WORK FILE 1 #STUFF
END

[/quote]

You can use any number of WRITE WORK statements, optionally within a loop.

DEFINE DATA LOCAL
1 #I (I4)
1 #D (A10)      INIT <*DAT4U>
1 #T (A10)      INIT <*TIME>
1 #A (A5)
1 #WORK (A25)
END-DEFINE
WRITE WORK 1 VARIABLE #D
WRITE WORK 1 VARIABLE #T
FOR #I = 5000 6000 100
  MOVE EDITED #I (EM=Z,ZZ9) TO #A
  WRITE WORK 1 VARIABLE #A
END-FOR
RESET #I
READ WORK 1 #WORK
  ADD 1 TO #I
  DISPLAY #I
          #WORK
END-WORK
END
Page     1                                                   08/23/14  17:19:11
 
    #I        #WORK
----------- ----------
 
          1 08/23/2014
          2 17:19:11.6
          3 5,000
          4 5,100
          5 5,200
          6 5,300
          7 5,400
          8 5,500
          9 5,600
         10 5,700
         11 5,800
         12 5,900
         13 6,000

How to add DISP = OLD…(Accumulate records)

If you mean DISP=MOD then use

DEFINE WORK FILE 1 TYPE 'TXT' ATTRIBUTES 'APPEND'

Ralph It worked. Thank you. Could you give me a step by step how create a new file in the database “Adabas DBA Workbench”?? a file dude with my data for testing on my program ??

Grateful