I've recently discovered a solution to the problem of not being able to display an empty subfile. For the most part, you usually would not want to display a subfile without records. However, there are occasions when this concept would be very useful. For example, suppose you are displaying a search screen that contains a subfile. Then a user enters a value that is past the end of the file you are reading. It would be nice to display an empty subfile and a message specifying that the parameters entered are out of the limits of the file. However, if you try this, you receive the IBM message "Session or Device Error Occurred" stating that it cannot process the subfile request.
All that is needed to correct this problem on the AS/400 is to successfully load the subfile one time in the program. After that, it can be displayed even when it is empty. I achieve this by adding a few lines of code in my "INIT" subroutine (see 1) which is only executed once during the program.
All that is needed to correct this problem on the AS/400 is to successfully load the subfile one time in the program. After that, it can be displayed even when it is empty. I achieve this by adding a few lines of code in my "INIT" subroutine (see Figure 1) which is only executed once during the program.
First, I clear the subfile to activate it; then, I write just one record to it. After that, I clear the subfile again and the system still thinks it is successfully loaded. When this routine is complete, the subfile can be displayed at any point in the program - even when it is empty.
Donald McGrath Cincinnati, Ohio
TechTalk: How to Display an Empty Subfile on the
Figure 1 RPG code for dummy write to a subfile
Figure 1: Partial RPG Code to Perform a Single Dummy Write to a Subfile ...1.... ....2.... ....3.... ....4.... ....5.... ....6.... ....7.... ....8 ***************************************************************** * INIT - Housekeeping subroutine only executed once ***************************************************************** INIT BEGSR * Clear and activate subfile MOVEA'01' *IN,95 WRITESFLCTL MOVEA'00' *IN,95 * Write one record to subfile ADD 1 SFLRRN WRITESFLREC * Clear subfile again MOVEA'01' *IN,95 WRITECTL MOVEA'00' *IN,95 * ENDSR *IN95 - SFLDSPCTL *IN95 - SFLDSP *IN96 - SFLCLR ...1.... ....2.... ....3.... ....4.... ....5.... ....6.... ....7.... ....8
LATEST COMMENTS
MC Press Online