Exporting a file to CSV on the IFS

Log in to save
CPYTOIMPF FROMFILE(PRODLIB/ITEMS)                +
          TOSTMF('/home/export/items.csv')       +
          MBROPT(*REPLACE)                       +
          STMFCCSID(1208)                        +
          RCDDLM(*CRLF)                          +
          DTAFMT(*DLM)                           +
          STRDLM(*NONE)                          +
          FLDDLM(';')

To include column names as the first row, add ADDCOLNAM(*SQL).

Note

STMFCCSID(1208) writes UTF-8 and is almost always the right choice. It is why accented letters come out correctly instead of as symbols: without it the file is written in the job's EBCDIC encoding, and whoever opens it on Windows sees the wrong characters.

Tip

in Italy the right delimiter is the semicolon, not the comma: Excel in an Italian configuration uses the comma as the decimal separator, and with FLDDLM(',') numbers end up split across two columns.


Releases. CPYTOIMPF has been there forever. The ADDCOLNAM parameter, which writes column names as the first row, is more recent: if the command rejects it as an invalid keyword, the system is on a release that does not have it, and the header must be added separately.

← Back to blog

Comments

No comments yet. Be the first to comment!

You need an account to comment. Log in · Sign up