Q: Open a browser when the user double-clicks an entry in my subfile! In the subfile record, there's an invoice number. When the user clicks that number, I want the browser to open and point to a document that contains the number.
For example, if a subfile contains order number 1111111, I want it to open a browser to http://ourserver/invoiceviewer/viewer.php?inv=1111111. How can I do that?
A: The previous article already explains how to open the browser, but there's still one part missing: How do you get your code to run when the user double-clicks your screen?
In some 5250 clients (e.g., the PC5250 product that comes with iSeries Access), you can enable http links. Click Edit|Preferences|Hotspots and select Execute URL. Then, when the user double-clicks a string that starts with "http://", the page automatically opens in a browser. Unfortunately, that means that you have to include the entire URL on the screen, not just the invoice number.
Perhaps a better solution is to use the Mouse Button (MOUBTN) DDS keyword to let your RPG program receive mouse events. With this option, you can use the technique that I presented in the previous tip to open a browser.
In a recent post to the System iNetwork forums, Barbara Morris of IBM Toronto posted some sample code that presents a simple subfile in which the user can key text. When the text is double-clicked, a browser opens and searches Google for that text. It's just a simple proof-of-concept program, but I thought it was an interesting use of these techniques.
For your invoice example, you'd have to adapt the program to display the invoice number and create a different URL (instead of Google). Otherwise, the same principle applies: Trap the mouse event with MOUBTN, use the screen coordinates to figure out the subfile record number, read the subfile to get the invoice number, and launch the browser with STRPCCMD.
Here's the DDS for Barbara's subfile. As you can see, it's very bare-bones, just enough to demonstrate the technique: A R SFL SFL
A FIELD1 10A B 10 10
A FIELD2 10A B 10 25
A R SFLCTL SFLCTL(SFL)
A MOUBTN(*ULD CF23)
A SFLCSRRRN(&RELRCD)
A RTNCSRLOC(&CSRRCD &CSRFLD)
* Use CF23, not CA23, so any data changed by the user is
* sent back to the program. When the subfile is
* displayed again, it will have their updated values.
A CF23(23)
A SFLSIZ(100)
A SFLPAG(10)
A 70 SFLDSP
A 70 SFLDSPCTL
A N70 SFLCLR
A RELRCD 5S 0H
A CSRFLD 10A H
A CSRRCD 10A H
A 5 10'Subfile example'
Here's the RPG code. For the sake of demonstration, it simply loads some letters and numbers you can change the values of the fields when you run the program. Then, double-click the field that you want to search on, and the program opens a Google search on that field.
If your 5250 emulator doesn't support mouse events, you can emulate the double-click by positioning your cursor in one of the fields and pressing F23. Fsubf cf e workstn sfile(sfl:rrn)
D rrn s 10i 0
D google pr
D fld 10a const
/free
exsr loadSubfile;
exsr showSubfile;
*inlr = '1';
begsr loadSubfile;
*in70 = '0';
write sflctl;
for rrn = 1 to 100;
field1 = %char(rrn);
field2 = %xlate('0123456789' : 'abcdefghij' : field1);
write sfl;
endfor;
endsr;
begsr showSubfile;
*in70 = '1';
exfmt sflctl;
dow *in23;
exsr handleDoubleclick;
exfmt sflctl;
enddo;
endsr;
begsr handleDoubleclick;
chain relrcd sfl;
if %found;
select;
when CSRFLD = 'FIELD1';
google(field1);
when CSRFLD = 'FIELD2';
google(field2);
endsl;
endif;
endsr;
/end-free
P google b
D google pi
D fld 10a const
D url s 500a varying
D cmd s 1000a varying
D qcmdexc pr extpgm('QCMDEXC')
D cmd 1000a const
D cmdlen 15p 5 const
D first s 1n static inz(*on)
/free
if (first);
cmd = 'STRPCO';
callp(e) qcmdexc(cmd: %len(cmd));
first = *off;
endif;
// this probably isn't the correct way to build a google url ...
url = 'http://www.google.com/search?q=' + fld;
cmd = 'STRPCCMD PCCMD('rundll32 url,FileProtocolHandler '
+ %trim(url) + ') PAUSE(*NO)';
qcmdexc (cmd : %len(cmd));
/end-free
P google e
23-02-2007 om 08:59
geschreven door Qmma 
|