if you can use a CSV file there are a couple ways to do this. If you already have a program that is creating the information, say to a database file, you can do a CPYTOIMPF command from inside the RPG program to copy the ‘native’ file to the IFS. Change the program so the output file is user controlled, at the end of the logic, close the output file, and do a CPYTOIMPF from either a QCMDEXC command or the C system() function.
if you have more time or are creating the program from scratch, consider writing directly to the IFS using among others the open(), write(), and close() api’s. I typically build a string of comma delimited data then write the entire string (record, row) at once.
Since a .CSV isn’t an Excel file, though Excel can certainly read and write them (but so can RPG and COBOL and…), I assume that what you want is to write an actual Excel .XLS file.
The simplest way to do it from (ILE) RPG is to use the Java POI/HSSF API. And almost certainly the best introduction to that is through Scott Klement’s articles on POI/HSSF from RPG.
You could, of course, study Microsoft and other documentation on Excel file formats and write them directly with (ILE) RPG. But there’s not much point to it since most of it is already done with POI/HSSF.