Question in reporting mode

I need some clarification in reporting mode. I have written a program like below.

READ EMPLOYEE-FILE BY EMP-ID EQ '12345'
  IF EMP-ID GT '50000'
   ESCAPE 
  PERFORM S001-WRITE-REPORT
  ...
  ...
LOOP
...
...
DEFINE SUBROUTINE S001-WRITE-REPORT
WRITE WORK FILE 01
 EMP-ID
 EMP-NAME
 EMP-DESIGNATION
 EMP-EXPERIENCE
 EMP-DOJ
RETURN

I have expected this program to write the details of the records read by READ statement. But, natural editor had not allowed me to stow this program and it shows error in the EMP-ID field in WRITE statement of subroutine (something like FIELD has to be defined). Someone please clarify, whether in reporting mode, we cannot use the database fields in subroutines as I have used above?

I have corrected the above program by removing the subroutine and keeping the write statement inside READ statement. Then, it had worked as expected.

P.S: I don’t have mainframe connection to post the exact code and error message.

Regards,
Bala

The scope of the variables in the READ encompass the READ/LOOP only. You can move the subroutine inside the LOOP and it should work.

Another option would be to move the database fields to variables before the perform and reference only variables in the subroutine.

Moving to temporary variables incurs unnecessary overhead. I suggest mixed-mode - Reporting mode with a DEFINE DATA. Create a view within that DEFINE DATA and all the field names will be available throughout the program.

Hi All,

Thanks for clarirfications & suggestions.