MIW:Advanced Functions

From Remain Software

The Script Editor

The Script Editor lets you write and execute scripts in Javascript.

With the Script Editor, you have access to the following resources of MiWorkplace.

  • document — editor content
  • selection — editor selection (selected text range of the editor instance)
  • ast — AST - abstract syntax tree of the editor content
var procedures = ast.listProcedures();
for each (var procedure in procedures) {
  print(procedure.name);
}

Editor Content

The editor content is available via the document variable. It is an instance of the Java class org.eclipse.jface.text.Document.

It provides many methods (RPG term: procedures).

  • get() — Get the whole editor content
  • get(start, length) — Get a part of the editor code
  • getLineLength(line) — Get the length of the line
  • getLineOffset(line) — Returns the offset of the line
  • getLineOfOffset(offset) — Returns the line number which the passed offset is part of
  • getNumberOfLines() — Returns the number of lines of the document
  • replace(position, length, text) — Replaces the position with passed text
  • set(text) — Replaces the content of the whole document

If you want to insert code, use the replace method and use 0 for the length.

Selection

The selection variable represents the text the user selected in the editor. The selection is a simple Point class which has two fields: x and y.

  • x — Start position of the selection
  • y — Length of the current editor selection

AST

Depending on what type of source code the editor instance has loaded astrepresents different Java classes.

CL

  • listFiles() — returns a list of File objects
  • listLabels() — returns a list of labels (Token)
  • listSubroutines() — returns a list of Subroutine objects
  • listVariables() — returns a list of global variables declared in this CL program
  • listParameters() — returns a list of parameters
File

Represents a file declared in a CL with the keyword DCLF.

  • getFile() — file name
  • getLibrary() — library name (default: *LIBL)
  • getRecordFormat() — the used record format (default: *ALL)
  • getAllowNull() — value of parameter ALWNULL
  • getAllowGraphic() — value of parameter ALWGRAPHIC
  • getAllowVariableLength() — value of parameter ALWVARLEN
  • getDeclareBinaryFieldsToken() — value of parameter DCLBINFLD
  • getStatement() — returns Statement
Subroutine
  • getName() — returns the name of the subroutine
  • getStart() — returns the first token of the subroutine
  • getEnd() — returns the last token of the subroutine
  • list() — returns all Statement objects which make up this subroutine
Variable
  • getName() — returns the name of the variable
  • getType() — returns the type (Character, Integer, UnsignedInteger, Boolean, Decimal, Pointer)
  • getLength() — returns the declared length of the variable
  • getDecimalPositions() — returns the declared decimal positions of the variable
  • getStatement() — returns Statement
Parameter
  • getName() — returns the name of the parameter (withouth the leading & sign)
Statement

A statement consists of one or more tokens. A statement can be layed out on multiple lines.

  • list() — list of tokens
  • size() — number tokens in this statement
Token
  • offset — start position of this token in this line (zero-based)
  • line — line number (zero-based)
  • value — token value

Fixed Form RPG

  • getProcedures() — returns a list of Procedure objects
  • getSubroutines() — returns a list of Subroutine objects
Procedure
  • getName() — returns the name of the procedure
  • getStartLine() — returns the starting line of the procedure
  • isExported() mdash; returns true if the procedure is exported (keyword export)
Subroutine
  • getName() — returns the name of the subroutine
  • getStartLine() — returns the starting line of the subroutine

Free Form RPG

  • listConstants() — returns a list of Constant objects
  • listFiles() — returns a list of File objects
  • listIncludes() — returns a list of Include objects
  • listPrototypes() — returns a list of Prototype objects
  • listProcedures() — returns a list of Procedure objects
  • listSubroutines() — returns a list of Subroutine objects
  • listVariables() — returns a list of global variables as Variable objects
Constant
  • name — the name of the constant
  • value — the value of the constant (Strings are returned enclosed in ')
  • statement — Statement of this constant
File
  • isExternallyDescribed() — true if externally described else false
  • isQualified() — true if the file is to be used with qualified naming and data structures for IO (keyword qualified)
  • isStaticFile() — true if the file is static (keyword static)
  • isTemplate() — true if the file is only a template (keyword template)
  • getFilename() — returns the filename
  • getStatement() — returns the Statement object
  • getType() — returns the type of the file (Disk, Printer, Workstation)
Include
  • getFile() — returns the copy book (may include quotes)
  • getFileUnquoted() — returns the copy book (without quotes)
  • getStatement() — returns the Statement object
Prototype
  • getExternalProcedure() — returns the declared external procedure name
  • getExternalProgram() — returns the declared external program name
  • getName() — returns the name of the prototype
  • getParameters() — returns a list of Parameter objects
  • getReturnValue() — returns a Variable or DataStructure
  • getStatements() — returns a list of Statement objects
  • isReturnParameter() — true if the prototype is declared with the keyword rtnparm
Parameter

A Parameter can either be a Variable or a DataStructure.

  • isPassedByRef() — true if parameter is defined with const
  • isPassedByValue() — true if parameter is defined with value
  • getOptions() — returns a list of options
Procedure
  • getName() — returns the name of the procedure
  • getProcedureInterface() — returns the ProcedureInterface
  • isExported() — returns true if the procedure is exported (keyword export)
  • listConstants() — returns a list of Constant objects
  • listFiles() — returns a list of File objects
  • listIncludes() — returns a list of Include objects
  • listPrototypes() — returns a list of Prototype objects
  • listSubroutines() — returns a list of Subroutine objects
  • listVariables() — returns a list of global variables as Variable objects
ProcedureInterface
  • isReturnParameter() — true if the prototype is declared with the keyword rtnparm
  • getParameters() — returns a list of Parameter object
  • getStatements() — returns a list of Statement objects
  • getReturnValue() — returns a Variable or DataStructure
Subroutine
  • name() — returns the name of the subroutine
  • list() — returns a list of Statement objects
Variable
  • getArraySize() — returns the array size (defined with the keyword dim)
  • getBased() — returns the name of the based pointer
  • getCcsid() — returns the declared ccsid
  • getCompileTimeArray — returns true if the variable is declared as a compile time array
  • getDecimalPositions() — returns the decimal positions
  • getExported() — returns true if the variable is declared as exported
  • getExternalName() — returns the external name if the variable is exported or imported
  • getImported() — returns true if the variable is declared as imported
  • getLength() — returns the length of the variable
  • getLengthAdjustment() — returns the length adjustment
  • getLike() — returns the field name which is used as a template for this variable
  • getName() — returns the variable name
  • getStatement() — returns the Statement object
  • getType() — returns the type of the variable (Character, Integer, UnsignedInteger, Boolean, Zoned, Packed, Pointer, Time, Timestamp, Date, Graph, UCS2, Varchar, BinaryDecimal, Float, Object)
  • isInitialized() — returns true if the variable is declared with an initial value (keyword inz)
DataStructure
  • getArraySize() — returns the array size (defined with the keyword dim)
  • getBased() — returns the name of the based pointer
  • getExported() — returns true if the data structure is declared as exported
  • getExternalName() — returns the external name if the data structure is exported or imported
  • getImported() — returns true if the variable is declared as imported
  • getLength() — returns the length of the data structure
  • getLikeRecord() — returns the record name which is used as a template for this data structure
  • getName() — returns the data structure name
  • getStatements()) — returns a list of Statements objects
  • getSubfields() — returns a list of objects, either Variable or DataStructure
  • isInitialized() — returns true if the data structure is declared with an initial value (keyword inz)
  • isQualified() — true if the data structure is to be used with qualified naming for accessing subfields (keyword qualified)
  • isTemplate() — true if the data structure is only a template (keyword template)
Statement
  • getFirstLine() — returns the staring line number of this statement
  • getFirstToken() — returns the first token of this line
  • list() — returns a list of Token objects
  • size() — returns the number of tokens in this statement
  • startsWith(string) — checks if the statements starts with the given string (case insensitive)
Token
  • line — line number
  • lineOffset — offset of the token in this line
  • offset — offset of the token in the whole program code
  • value — token value

DDS

  • listRecordFormats() — returns a list of record formats
RecordFormat
  • line — returns the line number of the record format (zero-based)
  • name — returns the name of the record format

Console

Besides the Script Editor view there is also the Console view which displays the output of the script done with the print function.

print(document.get());

Debugger

MiWorkplace itself doesn't come with a debugger, but you don't have to miss that feature at all.

JTOpen

The JTOpen project comes with a debugger for the IBM i server. It supports debugging all of the ILE languages. But as the debugger isn't licensed under the IBM Public License it can't be bundled with MiWorkplace and you have to download it yourself from JTOpen download section.

Unzip the archive with your favorite archive tool. You will find a lib folder in it. You will need the jt400.jar and tes.jar files.

jtopen_9_1
├── changes.html
├── lib
│   ├── composer.jar
│   ├── java6
│   │   ├── jt400.jar
│   │   └── jt400.jar.MD5
│   ├── java8
│   │   ├── jt400.jar
│   │   └── jt400.jar.MD5
│   ├── jt400android.jar
│   ├── jt400android.jar.MD5
│   ├── jt400.jar
│   ├── jt400.jar.MD5
│   ├── jt400Proxy.jar
│   ├── jt400Proxy.jar.MD5
│   ├── jt400Servlet.jar
│   ├── jt400Servlet.jar.MD5
│   ├── jtopenlite.jar
│   ├── jtopenlite.jar.MD5
│   ├── jui400.jar
│   ├── outputwriters.jar
│   ├── reportwriter.jar
│   ├── tes.jar
│   ├── uitools.jar
│   └── util400.jar
├── license.html
└── readme.html

Move the whole folder to a directory for easier navigation later on.

Debug Location

Now we have to tell MiWorkplace where to find the debugger. This can be configured in the preferences (Main Menu -> Window -> Preferences -> Debug).

Once you have entered the path of the lib folder the Start debug button in the context menu of the connection in the Remote Explorer view will be enabled.

Debug Start

Resources on the web

There are some good resources on the web about the IBM i System Debugger. Most notably from IBM itself at their developerworks section.

Other resources are

TODO