Monday, July 27, 2009

WITH Statements

Following is the Syntax For WITH statment.
WITH [Record] DO [Statement]
When you work with records, addressing is created as record name, dot (period),
and field name: [Record].[Field]
you work continuously with the same record, you can use WITH statements. When you use a WITH statement, you only have to specify the record name once.
Within the scope of [Statement], fields in [Record] can be addressed without having to specify the record name.
You can nest several WITH statements. In case of identical names, the inner WITH overrules the outer WITH-statements.
For Eg:
Consider a variable-'CustRec', Data Type -'Record', Subtype-'Customer'.
CustRec."No." := '10000';
CustRec.Name := 'Creative Solutions';
CustRec."Phone No." := '555-444-333';
CustRec.Address := '1352 Avenue';
CustRec.City := 'NewYork City';
MESSAGE('A variable has been created for this customer.');
The following example shows another way to create a record variable that you can commit later.
WITH CustomerRec DO
BEGIN
"No." := '10000';
Name := 'Creative Solutions';
"Phone No." := '555-444-333';
Address := '1352 Avenue';
City := 'NewYork City';
MESSAGE('A variable has been created for this customer.');
END;

No comments: