This sample program demonstrates three techniques:
- Getting cursor location at the time the user hits enter.
- Getting the format and the field name that the user was at when enter was pressed.
- A method of overriding cursor positioning.
There are several uses for these techniques, but the main uses I?ve found is F4 prompting and developing a customized help system.
For example, if you had a screen that had multiple F4 prompts that would each call a separate prompting program to list possible field values, knowing the field name that the user was trying to prompt would be helpful in trying to determine which prompting program to call (technique #2). If the user cancels out of the prompt program without selecting a value, it may be useful to ensure that the cursor remains in the same position as it was before he tried to prompt (technique #3). In addition, you can optionally use the same technique to move the cursor to another location on the screen. Technique #2 also lends it itself very well to developing an online help system.
A little background about the techniques
Technique #1 is accomplished through the use of the information data structure (DPSFDS in the RPG program).
Technique #2 uses the RTNCSRLOC keyword in the DDS.
Technique #3 uses the CSRLOC keyword in the DDS.
*** DDS Source ASAMPL A DSPSIZ(24 80 *DS3) A R SAMPLE A RTNCSRLOC(&#FMT &#FLD) A CSRLOC(@CRW @CCL) A #FMT 10A H A #FLD 10A H A @CRW 3S 0H A @CCL 3S 0H A 1 33'Sample Screen' A DSPATR(HI) A 2 2'Field 1 . . .' A @FLD1 2A B 2 16 A 3 2'Field 2 . . .' A @FLD2 2A B 3 16 A 5 2'Field Name is . . .' A @FLD 10 O 5 22 A 6 2'Screen Format is. .' A @FMT 10 O 6 22 A 7 2'Cursor Row is . . .' A @ROW 2 0O 7 22 A 8 2'Cursor Column is. .' A @COL 2 0O 8 22 *** RPGLE Source ASAMPL FASAMPL CF E WORKSTN F INFDS(DSPFDS) D DSPFDS DS D #CSRLC 370 371B 0 C* C EXFMT SAMPLE C* C #CSRLC DIV 256 #ROW 2 0 C MVR #COL 2 0 C MOVEL #FMT @FMT C MOVEL #FLD @FLD C Z-ADD #ROW @ROW C Z-ADD #COL @COL C* IF I WANTED TO OVERRIDE WHERE THE CURSOR WAS GOING TO BE POSITIONED C* I WOULD CHANGE THESE VALUES BUT FOR THIS EXAMPLE I AM ENSURING THAT C* THE CURSOR RETURNS TO WHERE IT WAS WHEN THE USER HIT ENTER C Z-ADD #ROW @CRW C Z-ADD #COL @CCL C EXFMT SAMPLE C SETON LR
About the author: Tim is vice president of Technical Services at Interlink Technologies in Maumee, Ohio, where he serves as chief architect for their warehouse management system. He has worked in the banking, insurance, healthcare and distribution industries in various positions, including programmer/analyst, systems analyst and DP manager. Tim has worked on IBM midrange platforms since 1983.
- Search400's Best Developer Web Links: tips, tutorials and more.
- Ask your programmer questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our programmer gurus are waiting to answer your technical questions.
- What do you think of this tip? Send us your comments -- good or bad -- to firstname.lastname@example.org.