I would like to compare 2 DS field by field and capture the changed fields into an audit file. Below is the scenario -
User is provided with a display screen where he can change any of the 20 fields pertaining to a file. Say if the user changed 10 fields, I want to write 10 records into the audit log file with below details -
Field changed
Before value
After value
Date/Time, etc
At the moment, I have written logic as below -
<code>
D File E DS EXTNAME(File1) // Contains latest image of the 20 fields
*
D P_File E DS EXTNAME(File1) Prefix(P_) // Contains previous image of the 20 fields
C If Field1 <> P_Field1
C Eval BeforeImage = P_Field1
C Eval AfterImage = Field1
C Eval Comment = 'Field1 changed'
C Write Auditfile
C EndIf
C If Field2 <> P_Field2
C Eval BeforeImage = P_Field2
C Eval AfterImage = Field2
C Eval Comment = 'Field2 changed'
C Write Auditfile
C EndIf
</code>
As you can see, I am writing 20 IF statements for manually checking changes one by one. But, is there a better approach to do this? (Something like looping through data structure to check all fields)
User is provided with a display screen where he can change any of the 20 fields pertaining to a file. Say if the user changed 10 fields, I want to write 10 records into the audit log file with below details -
Field changed
Before value
After value
Date/Time, etc
At the moment, I have written logic as below -
<code>
D File E DS EXTNAME(File1) // Contains latest image of the 20 fields
*
D P_File E DS EXTNAME(File1) Prefix(P_) // Contains previous image of the 20 fields
C If Field1 <> P_Field1
C Eval BeforeImage = P_Field1
C Eval AfterImage = Field1
C Eval Comment = 'Field1 changed'
C Write Auditfile
C EndIf
C If Field2 <> P_Field2
C Eval BeforeImage = P_Field2
C Eval AfterImage = Field2
C Eval Comment = 'Field2 changed'
C Write Auditfile
C EndIf
</code>
As you can see, I am writing 20 IF statements for manually checking changes one by one. But, is there a better approach to do this? (Something like looping through data structure to check all fields)
Comment