Problem solve Get help with specific problems with your technologies, process and projects.

Use SQL views to transfer packed data using FTP

Here's an easy way to transfer packed data from an iSeries to an ASCII system.

The question of how to transfer packed data from an iSeries to an ASCII system has been asked many times. It has been suggested that one can use a logical file that redefines the packed field as zoned. This works as long as the value is non-negative and the number of decimals is 0 - the decimal point does not get transferred. CPYTOIMPF and CPYFRMIMPF can also be used but require extra steps in the process.

A standard logical file cannot convert numeric data to character, either. But a view can use the CHAR function to convert any numeric data to left-justified values that have the sign and the decimal point.

To test this idea, take the following steps:

1. Create a PF with a single packed 5,0 field.


A          R PACKEDR              
A            PCKFLD         5P 2  

2. Create an LF that makes the packed field look like a zoned field.

A          R PACKEDR                   PFILE(PACKEDPF)
A            PCKFLD          S           

3. Create a view over the PF that converts the packed field to character.

create view somelib/charview (pckfld) as select char(pckfld) from packedpf

4. Add some data, both positive and negative - I used 5 and -4.

5. Start an FTP session from Windows, using ASCII mode.

6. Executing "get packedpf packedpf.txt" results in the usual garbage.

7. Executing "get zonedpf zonedpf.txt" gets closer but no decimal point, and the sign is obscured.


8. Executing "get charview charview.txt" gives almost a useful result.


There is still a problem with varying field lengths. However, you could use quotes and commas in the SELECT statement to generate a CSV-formatted output.


The Best Web Links: tips, tutorials and more.

Visit the ITKnowledge Exchange and get answers to your developing questions fast.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

Dig Deeper on FTP

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.