11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TROLLBACKSET x="default",^y="default"WRITE !,"level:",$TLEVELWRITE !,"local:",x," global:",^yTSTARTSET x="first",^y="first"WRITE !,"TSTART level:",$TLEVELWRITE !,"local:",x," global:",^yTSTARTSET x=x_" second",^y=^y_" second"WRITE !,"TSTART level:",$TLEVELWRITE !,"local:",x," global:",^yTSTARTSET x=x_" third",^y=^y_" third"WRITE !,"TSTART level:",$TLEVELWRITE !,"local:",x," global:",^yTROLLBACKWRITE !!,"After Rollback:"WRITE !,"TROLLBACK level:",$TLEVELWRITE !,"local:",x," global:",^yThe following example shows how $INCREMENT changes to a global are not rolled back.SET ^x=-1,^y=0WRITE !,"level:",$TLEVELWRITE !,"Increment:",$INCREMENT(^x)," Add:",^yTSTARTSET ^y=^y+1WRITE !,"level:",$TLEVELWRITE !,"Increment:",$INCREMENT(^x)," Add:",^yTSTARTSET ^y=^y+1,^z=^z_" second"WRITE !,"level:",$TLEVELWRITE !,"Increment:",$INCREMENT(^x)," Add:",^yTSTARTSET ^y=^y+1,^z=^z_" third"WRITE !,"level:",$TLEVELWRITE !,"Increment:",$INCREMENT(^x)," Add:",^yTROLLBACKWRITE !!,"After Rollback"WRITE !,"level:",$TLEVELWRITE !,"Increment:",^x," Add:",^yThe following example transfers money from one account to another as a transaction usingprimitive error checking:Transfer(from,to,amount)// Transfer funds from one account to anotherIF ('$Data(^ACCOUNT(from,"Balance"))) {QUIT "FROM account does not exist."}TSTARTSET ^ACCOUNT(from,"Balance")=^ACCOUNT(from,"Balance")-amountIF ('$Data(^ACCOUNT(from,"Balance"))) {TROLLBACKQUIT "TO account does not exist."}SET ^ACCOUNT(to,"Balance")=^ACCOUNT(to,"Balance")+amountTCOMMITQUIT 1<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 141

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!