Positioning the Cursor in a Window

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The following is a typical scenario in one of our maintenance programs. A user displays a maintenance screen. He then presses a command key to display additional information. Upon exiting, the user is returned to the maintenance screen and the cursor is positioned at the same screen location as it was prior to the press of the command key. This function is accomplished via the File Information Data Structure (INFDS in RPG) for the display file. The INFDS contains the current cursor location in positions 370-371. This information can then be used with the Cursor Location (CSRLOC) DDS keyword to position the cursor at its previous location.

A problem arises, however, when the first screen is a window. Positions 370-371 of the INFDS contain the cursor location relative to the full screen, but the CSRLOC keyword needs the cursor location relative to the starting position of the window.

The first time I tried the DDS window keywords, the cursor jumped around the screen every time I returned to it. My original solution to this problem was to calculate offset values based on the starting row and column of the window and adjust the values before redisplaying the screen. However, this can be a cumbersome solution if you design a window with variable starting locations. I have found a better, more generic solution.

In V2R2, IBM changed the File Information Data Structure for display files to include a field for the cursor position within the window (positions 382-383 of the INFDS). This binary field contains zeros if the screen being processed is not a window and contains the cursor position when processing a window format. The partial DDS and RPG code shown in Figures 5 and 6 illustrate the use of this technique.


Positioning the Cursor in a Window

Figure 5 Partial Display File for Cursor-positioning Exampl

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A CSRLOC(ROW COL) A ROW 3 0H A COL 3 0H *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
Positioning the Cursor in a Window

Figure 6 RPG Code Segment for Cursor-positioning Example

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FDSPF CF E WORKSTN F KINFDS CSRPOS * * File Information Data Structure to determine cursor position ICSRPOS DS I B 370 3710SCR I B 382 3830WDW * If not a window, position cursor based on screen location C WDW IFEQ *ZEROS C SCR DIV 256 ROW C MVR COL C ELSE * * Else (a window), position cursor based on window location C WDW DIV 256 ROW C MVR COL C ENDIF *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
BLOG COMMENTS POWERED BY DISQUS