PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Join the forum, it's quick and easy

PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).
PMS Information Systems
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Copying data between heterogenous databases using CPYTOIMPF

Go down

data - Copying data between heterogenous databases using CPYTOIMPF Empty Copying data between heterogenous databases using CPYTOIMPF

Post  maran Mon Mar 25, 2013 7:07 pm

As per IBM description, The Copy To Import File (CPYTOIMPF) command copies an externally-described file to an import file. The term import file is used to describe a file created for purposes of copying data between heterogenous databases. The import file (TOSTMF or TOFILE parameter) will be called the to-file for this command.

Some of the specific functions that can be performed by the CPYTOIMPF command include the following:
• Copying from an externally described physical file to the to-file (TOFILE or TOSTMF parameter).
• Adding records to an existing to-file member or replace the contents of the to-file member (MBROPT parameter).

Now let us see go thru the different examples to explain the use:

CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
TOSTMF(custinfo.csv)
STMFCODPAG(*PCASCII)
RCDDLM(*CRLF)


In this example, the custinfo.csv file is created or overwritten in the job's current directory. A job's current directory is the directory that is assumed when no directory is specified. The current directory can be any of the following:
• an IFS directory
• a folder
• a database file
• a library

Normally you'll want to use an IFS directory for stream files. I've experimented with database files and haven't found them too friendly for stream data.

If you're ever in doubt as to which directory is your current directory, use the Display Current Directory (DSPCURDIR) command. You can use the Change Current Directory (CHGCURDIR, CD, or CHDIR) command to use another directory instead.
Assuming that the current directory in this example is /home/bobby, the command is interpreted as if the following had been keyed:

CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
TOSTMF('/home/ram/custinfo.csv')
STMFCODPAG(*PCASCII)
RCDDLM(*CRLF)


Here's a second example. Notice that the stream file is placed in the "dot" directory.

CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
TOSTMF('./custinfo.csv')
STMFCODPAG(*PCASCII)
RCDDLM(*CRLF)

The "dot" notation is a short way of referring to the current directory. This example does the same as the first one.

Let's move to the third example.

The stream file is placed into the "dot-dot" directory, which is the parent directory of the current directory.

CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
TOSTMF('../custinfo.csv')
STMFCODPAG(*PCASCII)
RCDDLM(*CRLF)

If the current directory is /home/PMS, custinfo.csv is created or overwritten in /home.
Let's look at one more shortcut. In this example, the stream file is in the tilde directory.
CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
TOSTMF('~/custinfo.csv')
STMFCODPAG(*PCASCII)
RCDDLM(*CRLF)

The tilde character is shorthand for the user's home directory, the directory that is assigned in a user's user profile. Take a look at the HOMEDIR parameter of the Create User Profile (CRTUSRPRF) command.

To this point, I have been illustrating relative addressing. Where a stream file is located is relative to the current directory or to the home directory. But you may also use absolute addressing, which means that you tell the system exactly which directory to use, no matter what the current and home directories may be. To indicate that you want absolute addressing, begin the stream file name with a slash character.

In this last example, the custinfo.csv file is created in directory /home/PMS/data, which would be found in the root file system.

CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
TOSTMF('/home/PMS/data/custinfo.csv')
STMFCODPAG(*PCASCII)
RCDDLM(*CRLF)




maran
maran
Admin

Posts : 442
Join date : 2009-07-24

https://pmsinformationsystem.forumotion.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum