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.

<strong>Caché</strong> <strong>ObjectScript</strong> Functionsseparate accounts. Because ^client is a sparse array there may be undefined elements at anyof the three levels. The contents for a typical record might appear as follows:^client(5) John Jones^client(5,1) 23 Bay Rd./Boston/MA 02049^client(5,1,1) Checking/45673/1248.00^client(5,1,2) Savings/27564/3270.00^client(5,1,3) Reserve Credit/32456/125.00^client(5,1,4) Loan/81263/460.00The code below provides a separate subroutine to handle the output for each of the three arraylevels. It uses the $DATA function at the start of each subroutine to test the current arrayelement.The $DATA=0 test in Level1, Level2, and Level3 tests whether the current array element isundefined. If TRUE, it causes the code to QUIT and revert to the previous level.The $DATA=10 test in Level1 and Level2 tests whether the current array element containsa pointer to a subordinate element, but no data. If TRUE, it causes the code to write out a“No Data” message. The code then skips to the FOR loop processing for the next lower level.There is no $DATA=10 test in Level3 because there are no elements subordinate to this level.The WRITE commands in Level2 and Level3 use the $PIECE function to extract theappropriate information from the current array element.Start Read !,"Output how many records: ",nRead !,"Start with record number: ",sFor i=s:1:s+(n1) {If $Data(^client(i)) {If $Data(^client(i))=10 {Write !," Name: No Data"}Else {Write !," Name: " ,^client(i)}If $Data(^client(i,1)) {If $Data(^client(i,1))=10 {Write !,"Address: No Data"}Else {Write !,"Address: ",$Piece(^client(i,1),"/",1)Write " , ",$Piece(^client(i,1),"/",2)Write " , ",$Piece(^client(i,1),"/",3)}}For j=1:1:4 {If $Data(^client(i,1,j)) {Write !,"Account: ",$Piece(^client(i,1,j),"/",1)Write " #: ",$Piece(^client(i,1,j),"/",2)Write " Balance: ",$Piece(^client(i,1,j),"/",3)}}}}Write !,"Finished."Quit198 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

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

Saved successfully!

Ooh no, something went wrong!