10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ArraysHow You Can Add Rows to an ArrayBecause creating an array does not populate it, adding rows to the array maybe the first task to perform after declaring the array. There are several waysthat you can populate an empty array or add additional rows to a populatedarray:• Add rows by first assignment• Use the InsertRow method• Assign the contents of one array to another• Create a populated array by duplicating an existing array• Allow the user to append to a table fieldThe following sections describe each of these methods in more detail.Add Rows by First AssignmentWhen you make an assignment to a nonexistent row in your 4GL code,OpenROAD creates that row if it is the next row in the array sequence; if it isnot, an error occurs. This is an easy way to fill an array.For example, the following select loop fills the custacct array:i = 1;select :custacct[i].acctno = cacctno,:custacct[i].custname = cname,:custacct[i].acctbalance = acctbalfrom customerbegini = i + 1;end;These statements perform the following operations:1. Place the first row that the select returns into the first row of the array.2. For each row retrieved, increment i (the index into the array) by one.3. Place the second returned row into the second row in the array (in thesecond iteration of the loop) and again increment i.4. Continue this process for each row returned by the select statement.If any of the array's rows were nonexistent prior to executing the selectstatement, they are automatically created when the statement is executed.216 <strong>Programming</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!