Cursor-sensitive Searches

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

Q: I have started programming my interactive programs with cursor-sensitive searches. If the user presses a function key to perform a search, I calculate the location of the cursor. If it falls within a hard-coded range, I present the user with the requested search. I want to soft-code that range from the display file. I should be able to match the cursor position to the field location and present the user with the desired search. Is there a way to retrieve the location of a field within a display file (other than reading the display file source)?

A: There's an easy way to accomplish this. Use the DDS Return Cursor Location (RTNCSRLOC) record-level keyword in your display file. It returns the name of the field that the cursor is on. This method has some advantages over using hard-coded screen coordinates. It means that if you move a field in a display file from one location on the screen to another, you don't have to worry about changing the program which uses that display file.

The return cursor location has two required parameters as well as an optional third parameter. For an example of how to use this keyword look at the four lines of code in 3. The two required parameters, (cursor-record and cursor-field), must be defined as 10-character hidden fields. The cursor-record variable returns the name of the record format and the cursor-field variable returns the name of the field where the cursor is located. The third parameter (cursor-position) is optional and, if used, must be defined as a four-position, signed-numeric, hidden field. This field returns the relative position within the field where the cursor is located.

The return cursor location has two required parameters as well as an optional third parameter. For an example of how to use this keyword look at the four lines of code in Figure 3. The two required parameters, (cursor-record and cursor-field), must be defined as 10-character hidden fields. The cursor-record variable returns the name of the record format and the cursor-field variable returns the name of the field where the cursor is located. The third parameter (cursor-position) is optional and, if used, must be defined as a four-position, signed-numeric, hidden field. This field returns the relative position within the field where the cursor is located.

In your program, just test the value of the cursor-field variable. If it matches a field for which the user can perform a search, then present the search results. If it doesn't, you might want to display a message which says something like, "Search not valid for cursor location." Using this technique, you can code cursor-sensitive searches within your programs without hardcoding screen coordinates.


Cursor-sensitive Searches

Figure 3 DDS for RTNCSRLOC Keyword

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A RTNCSRLOC(&RCD &FLD &POS) A RCD 10A H A FLD 10A H A POS 4S 0H 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: