AS400: How to know which program create a file?
ibm-midrange, rpg, sql-server
Solution
You can use journal management or program references to determine what is writing to the file.
Journal management
Starting the journal
To create a basic journal you need to create a journal receiver, a journal, and activate journalling for the file. Replace RECEIVER-LIB, RECEIVER-FILE, JOURNAL-LIB, JOURNAL-FILE, FILE-LIB and FILE with values appropriate for your system.
CRTJRNRCV JRNRCV(RECEIVER-LIB/RECEIVER-FILE)
CRTJRN JRN(JOURNAL-LIB/JOURNAL-FILE) JRNRCV(RECEIVER-LIB/RECEIVER-FILE)
STRJRNPF FILE(FILE-LIB/FILE) JRN(JOURNAL-LIB/JOURNAL-FILE) OMTJRNE(*OPNCLO)
Dumping the journal
DSPJRN JRN(JOURNAL-LIB/JOURNAL-FILE) FILE(FILE-LIB/FILE) RCVRNG(*CURCHAIN) JRNCDE(R) ENTTYP(PT PX DL UP) OUTPUT(*OUTFILE) OUTFILFMT(*TYPE1) OUTFILE(QTEMP/QADSPJRN)
Querying the journal
The field `JOPGM` will contain the program name that inserted, updated, or deleted records from the file.
Removing the journal
ENDJRNPF FILE(FILE-LIB/FILE)
DLTJRN JRN(JOURNAL-LIB/JOURNAL-FILE)
Program references
Dumping the references
DSPPGMREF PGM(*ALLUSR/*ALL) OUTPUT(*OUTFILE) OUTFILE(QTEMP/QADSPPGM)
Querying the references
Search the file for all references where the field `WHFNAM` equals FILE. The field `WHPNAM` will contain the program name. Due to file overrides, etc this method is not as accurate as using a journal.
Problem
I am not expert about AS400, just know some commands and i exporti some files from AS400 (iSeries) into SQL Server 2005. Actually i need to know which RPG Program created a file in a library. This because that file contains statistic data from other files stored in other AS400 libraries. This screenshot show the file `STTMVF` in the library `DAT_4DWH` (by `DSPLIB DAT_4DWH`) So there are a command that let me know which RPG program created the file STTMVF ? If yes i need to open the source RPG or CL and try to understand which phisical files are used to compose this statistic file. Thanks in advance!