Basics
3 snippetsX++ fundamentals
Variables & Types
str name = "Hello";
int count = 42;
real price = 19.99;
boolean active = true;
date today = systemDateGet();
utcDateTime now = DateTimeUtil::utcNow(); Class & Method
class MyService
{
public str greet(str _name)
{
return strFmt("Hello, %1!", _name);
}
public static void main(Args _args)
{
MyService svc = new MyService();
info(svc.greet("World"));
}
} Info & Error
info("Informational message");
warning("Warning message");
error("Error message");
Global::info(strFmt("Count: %1", count)); Table Operations
4 snippetsSelect, insert, update, delete
Select
CustTable custTable;
select firstOnly custTable
where custTable.AccountNum == "US-001";
if (custTable.RecId)
info(custTable.Name); While Select
SalesTable salesTable;
while select salesTable
where salesTable.SalesStatus == SalesStatus::Open
{
info(salesTable.SalesId);
} Join
SalesTable st;
CustTable ct;
while select st
join ct
where ct.AccountNum == st.CustAccount
&& st.SalesStatus == SalesStatus::Open
{
info(strFmt("%1 - %2", st.SalesId, ct.Name));
} Insert & Update
ttsBegin;
CustTable cust;
cust.AccountNum = "US-999";
cust.Name = "New Customer";
cust.insert();
ttsCommit;
ttsBegin;
select forUpdate cust where cust.AccountNum == "US-999";
cust.Name = "Updated Name";
cust.update();
ttsCommit; Set-Based Operations
3 snippetsBulk data manipulation
insert_recordset
insert_recordset tmpTable (AccountNum, Name)
select AccountNum, Name from custTable
where custTable.Blocked == CustVendorBlocked::No; update_recordset
update_recordset custTable
setting Blocked = CustVendorBlocked::All
where custTable.LastTransDate < prevYr(today()); delete_from
delete_from tmpTable
where tmpTable.Processed == NoYes::Yes; Tired of looking up syntax?
DocuWriter.ai generates documentation and explains code using AI.
Exception Handling
2 snippetsTry/catch and transactions
Try / Catch
try
{
ttsBegin;
// database operations
ttsCommit;
}
catch (Exception::Error)
{
error("Operation failed");
}
catch (Exception::Deadlock)
{
retry;
} Throw
if (!custTable.RecId)
{
throw error("Customer not found");
}
if (!this.validate())
{
throw error("@SYS12345"); // Label reference
} Collections
3 snippetsLists, maps, and sets
List
List myList = new List(Types::String);
myList.addEnd("first");
myList.addEnd("second");
ListEnumerator le = myList.getEnumerator();
while (le.moveNext())
{
info(le.current());
} Map
Map myMap = new Map(Types::String, Types::Integer);
myMap.insert("a", 1);
myMap.insert("b", 2);
if (myMap.exists("a"))
info(int2Str(myMap.lookup("a"))); Container
container c = ["a", 1, "b", 2];
str val = conPeek(c, 1); // "a"
int len = conLen(c); // 4
c = conIns(c, 3, "new"); // Insert at position 3
c = conDel(c, 1, 1); // Delete 1 element at pos 1