Difference between revisions of "Snippets"
(Long Procedure name) |
m (fix link) |
||
Line 66: | Line 66: | ||
===Long Procedure Name=== | ===Long Procedure Name=== | ||
− | original post [http://archive.midrange.com/wdsci-l/ | + | original post [http://archive.midrange.com/wdsci-l/200806/msg00002.html] |
How do I get the PR to stay at the same column position, irrespective of what name I use for the procedure ? | How do I get the PR to stay at the same column position, irrespective of what name I use for the procedure ? | ||
Line 79: | Line 79: | ||
Return to [[#TOP]] | Return to [[#TOP]] | ||
− | |||
===Examples=== | ===Examples=== |
Revision as of 23:41, 3 June 2008
Contents
SNIPPETS
A snippet is a sort of code template or skeleton that allows you to quickly set up a commonly used code fragment like a subprocedure definition (in ILE RPG). This differs from code templates because the code template is invoked by the code completion facility Ctrl+Space. Code completion with templates requires you to start keying the 'trigger' (in RPG, usually the operation code.) With snippets, you can have Lpex include anything at all, with no trigger needed aside from the double click on the selected snippet.
Snippets View
original post [1]
To open a snippets view:
- Window -> Show view -> Other -> Basic -> Snippets
Return to #TOP
Create a Snippets Category
original post [2]
- You only need to create a Category once, conceptually its like CRTSRCPF.
- Create as many Categories as you wish.
- -Right-click in the Snippets view and select Customize...
- -Click the New button and create a New Category
- -Click the New button and create a New Item
- -Click on the snippet and then click the New button that is adjacent to the Variables list
- -Enter your snippet and use the Insert Variable Placeholder button to add the variable
alternatively use the copy, right click process below, its easier.
Use snippets for RPGLE, CLLE, DSPF and PRTF source members.
Return to #TOP
Snippets RPG
original post [3]
You can use the snippets to insert stuff into your program.
To create your own RPG snippets,
- you can open the view in RSE or iSeries Editing perspective,
- select your source,
- and right click / Past in the snippets view, into your Previously created Category.
It will then create a new template.
To use the snippet;
- Open a source member for editing.
- Place the cursor where you want the code.
- Go to the Snippets view, to the Category where the snippet is.
- Double click on the snippet and it appears in the source
original post [4]
Another method is to create a Snippet.
- Open the Snippets view.
- Create a new 'Drawer' for your snippets.
- Copy some source.
- Right-click in your snippet drawer, paste.
- This will bring up the snippet creation wizard.
Long Procedure Name
original post [5]
How do I get the PR to stay at the same column position, irrespective of what name I use for the procedure ?
Use:
D ${Procedure}... PR
Otherwise the procedure name has to always be 12 characters in length. With the elipsis (...) it can be up to 60 odd characters in length.
Return to #TOP
Examples
Subprocedure skeleton:
Subprocedure skeleton
* ${proc_comment} p ${proc_name} b d ${proc_name} pi 10i 0 d ${parm_name} 1a d rc 10i 0 inz c/free return rc; /end-free p e
EXEC SQL
ref [6]
C/EXEC SQL C+ SELECT * FROM mylib/myfile C/END-EXEC free exec sql select * from mylib/myfile;
Open Cursor and Fetch Mainline
ref [7]
H ActGrp(*CALLER) H DftActGrp(*NO) D OpenCursor PR n D FetchCursor PR n D CloseCursor PR n D MyLib s 10a D MyFile s 10a /free *inlr=*on; if not OpenCursor(); // perform error routine to alert the troops // ... Else; Dow FetchCursor(); // putting the fetchcursor on the do loop allows the user of // iter, and thus iter will not perform an infinite loop // normal processing here... EndDo; CloseCursor(); EndIf; return; /end-free
Open Cursor Procedure
ref [8]
P OpenCursor B D OpenCursor PI like(ReturnVar) D ReturnVar s n // The immediately following /EXEC SQL is SQL's version of RPG's H Spec // It is never executed. Just used at compile time. C/EXEC SQL C+ Set Option C+ Naming = *Sys, C+ Commit = *None, C+ UsrPrf = *User, C+ DynUsrPrf = *User, C+ Datfmt = *iso, C+ CloSqlCsr = *EndMod C/END-EXEC C/EXEC SQL C+ Declare C1 cursor for C+ Select System_Table_Schema as library, C+ System_Table_Name as file C+ from qsys2/systables C/END-EXEC C/EXEC SQL C+ Open C1 C/END-EXEC /free Select; When SqlStt='00000'; return *on; Other; return *off; EndSl; /end-free P OpenCursor E
Fetch Cursor Procedure
ref [9]
P FetchCursor B D FetchCursor PI like(ReturnVar) D ReturnVar s n C/EXEC SQL C+ Fetch C1 into :MyLib, :MyFile C/END-EXEC /free Select; When sqlstt='00000'; // row was received, normal ReturnVar=*on; When sqlstt='02000'; // same as %eof, sooner or later this is normal ReturnVar=*off; Other; // alert the troops! ReturnVar=*off; EndSl; return ReturnVar; /end-free P FetchCursor E
Close Cursor Procedure
ref [10]
P CloseCursor B D CloseCursor PI like(ReturnVar) D ReturnVar s n C/EXEC SQL C+ Close C1 C/END-EXEC /free Select; When sqlstt='00000'; // cursor was closed, normal ReturnVar=*on; Other; // alert the troops! ReturnVar=*off; EndSl; return ReturnVar; /end-free P CloseCursor E
Return to #TOP
External links
The official WDSC web page [11]
The WDSC Developer blog [12]
WDSC tags on del.ici.ous [13]