I am rather new to the whole IBM i (as400), rpgle scene.

I was given the task to export some information into XML format.

I was able to make the output of the information correct, the problem arose when I used CPYTOPCD to copy the information to the XML file.

For some reason I have yet to understand or even find information about, CPYTOPCD only copies a fraction of the data when I use from within my program. When I go to the as400 command line though, it copies the entirety of the data without problem.

The only difference I can see when I do this is that in the command line the CPYTOPCD command all fits within the one row while in the program I must use the '+' and move on to the next row to finish the command.

I have looked on many different sites but I cannot find a similar problem. Perhaps I am not phrasing the problem correctly and that has been my biggest problem.

I apologize if I may not be explaining the situation well enough so please let me know what other information I could supply to make it easier.

Thank you very much for any help you can provide.

edit: I don't know if this is part of the problem or not but I figured I might as well add it in just in case. When I check on the outputted XML, where it ends, which is half way through some tag that it has written before without problem, it puts a small box. From what I have found online I think it is a whitespace character but I am not sure.

edit2: CLP is this multiple times for different files.

CLRPFM FILE(SDIXW4)

CALL PGM(SDI812)

CPYTOPCD FROMFILE(SDIXW4) TOFLR('AUDIT') +
TODOC(RELLOC.XML) REPLACE(*YES) + TRNFMT(*NOTEXT)

edit3: I am going to try the suggestion that Charles gave. Hopefully this bypasses the problem I am getting with CPYTOPCD. I will update this after testing the new form. Thanks again for all your help.

4

There are 4 best solutions below

4
On BEST ANSWER

I had the same problem some time ago ... CPYTOPCD didn't export all records from my file ... but I called the command through QCMDEXEC at the end of my RPG code but was enough a "close myfile" befor QCMDEXEC to solve it. Do you end your rpg code with a "return" or a "seton LR" ?

1
On

What version and release are you working with?

As Buck mentioned, CPYTOPCD has been depreciated for a long time. CPYTOSTMF and CPYTOIMPF are better choices.

Since you mention adding the XML tags yourself, a better choice than the CPYxxx commands would be to simply use the write() function available in the C Runtime library to write directly to the IFS stream file. You can use this function from a ILE C or ILE RPG program. (example code from Scott Klement's XML from RPG presentation

fd = open('/home/scottk/xml/test.xml'
: O_WRONLY+O_CREAT+O_TRUNC+O_CCSID
: M_RDWR
: 819);
xml =
'<?xml version="1.0">'
+ '<CustFile>'
+ ' <CustRec custno="' + %trim(CustNo) + '">'
+ ' <Name>' + %trim(Name) + '</Name>'
+ ' <Address>'
... And so forth ...
callp write(fd: %addr(xml)+2: %len(xml));
callp close(fd);
/end-free

If you happen to be on a recent release (7.1 or 7.2) of IBM i, then you could probably use the XML functions that have been added into DB2 for IBM i.

5
On

I assume you're in a source edit session of some sort. That being so, I suggest that rather than typing the plus sign, going to the next line and completing the command ... that you just type CPYTOPCD, then press F4 and then F10, and complete the command prompted. (Use Page keys to see the entire command parameters and options list.) Maybe you'll see the thing you missed before. Another advantage of this approach, is that you can use F1 to get help for any of the parameters in the command.

9
On

CPYTOPCD is very much deprecated. What's more, it doesn't convert / export DB2 to XML, so it seems that your DB2 table already contains XML. CPYTOSTMF is a far better choice to simply move an already-XML table to the Integrated File System (IFS).

EDIT: Check the job log. IBM i commands like CPYTOPCD almost always issue some sort of message if they encounter an error. It's very unusual that one fails without any messages at all. CALL QCMD to get to the naked command line and press F10 to see all messages.