값 설정 블록
값 설정 블록은 특성, 필드 또는 변수값을 설정할 수 있는 코드의 영역입니다. 특성에 대한 배경은 "EGL 특성의 개요"를 참조하십시오.
- 파트 정의
- 변수 선언
- new 연산자로 파트 작성
- call, transfer 또는 show 문의 특수 양식 코드화(특성 전용)
- 지정 명령문의 특수 양식 코드화(값 전용)
- "openUI"에 설명된 대로 openUI 문 코드화(값 전용)
마지막 두 경우에는 필드에 값만 지정할 수 있습니다.
program hello
myString STRING = "Hello, Cleveland";
{handleHardIOErrors = YES} // this works
...
end
program hello
myString STRING = "Hello, Cleveland"
{handleHardIOErrors = YES}; // this is part of myString declaration
...
end
문제는 handleHardIOErrors가 이제 문자열 "Hello, Cleveland"의 범위에 있다는 점입니다. 문자열에 설정할 필드가 없고 "handleHardIOErrors" 필드도 포함되지 않으므로 EGL이 표현식을 해석할 수 없습니다.
- 널 입력 가능 변수에 대한 널 플래그를 설정 해제합니다.
- 널 참조 변수의 새 파트를 초기화합니다.
myInt INT?{};
myList Dictionary; // myList = null
myList.x = 23; // illegal reference
그러나 다음
코드는 지정을 시도하기 전에 새 사전 변수를
초기화합니다. myList2 Dictionary; // myList2 = null
myList2{ x = 23 }; // myList2 now has one key, x, whose value is 23
package com.companyb.customer;
Record StructuredRecordA
10 fullCheckNum NUM(25);
15 bankNum NUM(9);
15 acctNum NUM(10);
15 checkNum NUM(6);
end
program calculate type BasicProgram
function main()
myRec1 StructuredRecordA
{fullCheckNum = 9531008501602141091001484};
writeStdOut(myRec1.bankNum); // 953100850
writeStdErr(myRec1.checkNum); // 1484
endend
myRec2 StructuredRecordA {checkNum = 1485};
writeStdOut(myRec2.fullCheckNum); // 1485
값 설정 블록에서 동일한 필드 또는 특성에 여러 값을 지정하는 경우 마지막 지정이 적용됩니다. 해당 규칙도 복합 특성의 필드에 적용되며 이 주제의 "복합 특성의 값 설정 블록"에서 이에 대해 설명합니다.
기본 상황의 값 설정 블록
- 각 값 설정 블록은 왼쪽 중괄호({)로 시작하고 쉼표로 구분된 0개 이상의 항목을 포함하며 오른쪽 중괄호(})로 끝납니다.
- 각 항목은 다음 두 형식 중 하나입니다.
- 이름/값 쌍(예: inputRequired = yes).
- 일련의 위치 값(배열의 연속되는 요소에 지정된 연속되는 값).
두 경우 모두 값 설정 블록은 수정되는 파트, 변수 또는 필드의 범위에 있습니다. 예제를 통해 구문의 변형을 잘 파악할 수 있습니다.
// the scope is myVariable
myVariable INT
{
inputRequired = yes,
align = left
};
// scope is optionEntry
DataItem optionEntry INT
{
inputRequired = yes,
align = left
};
end
// scope is menu1Option
menu1Option optionEntry
{
inputRequired = no
};
myRecord02.myContent01 = "abc";
myRecord02.myContent02 = "xyz";
myRecord02
{
myContent01="abc",
myContent02="xyz"
};
축약된 지정 명령문을 구조화 레코드의 필드에 사용할 수 없으며 해당 명령문을 사용하여 특성을 설정할 수 없습니다.
레코드의 필드에 사용되는 값 설정 블록
레코드 변수 내에서 필드에 값을 지정 중인 경우 다음과 같이 특정 필드로 범위를 좁히십시오.
record myBasicRecord03 type basicRecord
myInt04 INT;
end
record myBasicRecord02 type basicRecord
myInt03 INT;
myRec03 myBasicRecord03;
end
record myBasicRecord type basicRecord
myInt01 INT;
myInt02 INT;
myRec02 myBasicRecord02;
end
- 레코드의 값 설정 블록 작성
- 범위를 좁히기 위해 일련의 필드 이름 임베드
- 필드 특정 값 설정 블록 작성
특성 값을 지정하는 구문은 myInt04 필드에 적용되는 다음 예제에 표시된 모든 양식을 취할 수 있습니다.
// dotted syntax
myRecB myBasicRecord
{
myRec02.myRec03.myInt04{ align = left }
};
// bracket syntax
// You cannot use this syntax to affect
// fields in fixed structures
myRecC myBasicRecord
{
myRec02["myRec03"]["myInt04"]{ align = left }
};
// brace syntax
myRecA myBasicRecord
{
myRec02 {myRec03 { myInt04 { align = left }}}
};
// dotted syntax
myRecB myBasicRecord
{
myInt01 = 4,
myInt02 = 5,
myRec02.myRec03.myInt04{ align = left },
myRec02.myInt03 = 6
};
// bracket syntax
myRecC myBasicRecord
{
myInt01 = 4,
myInt02 = 5,
myRec02["myRec03"]["myInt04"]{ align = left },
myRec02["myInt03"] = 6
};
// brace syntax;
// but this usage is much harder to maintain
myRecA myBasicRecord
{
myInt01 = 4,
myInt02 = 5,
myRec02
{
myRec03
{ myInt04
{ action = label5 }},
myInt03 = 6
}
};
값 설정 블록에서 "this" 사용
변수 선언 또는 지정 명령문에 레코드 특성과 동일한 이름의 필드(예: keyItems)를 포함하는 컨테이너(예: SQL 레코드)가 있을 수 있습니다. 특성이 아닌 필드를 참조하려면 this 키워드를 사용하십시오. 이 키워드는 범위를 값 설정 블록이 상주하는 선언이 되도록 설정합니다.
Record ExampleRecord type SQLRecord
{ tableNames = [["myTable"]],
keyItems = [myKey] }
myKey CHAR(10);
myOtherKey CHAR(10);
keyItems CHAR(60);
end
myRecord ExampleRecord
{
keyItems = [myOtherKey],
this.keyItems = "abc"
};
배열 선언의 예제는 "추가 값 설정 블록 예제"를 참조하십시오.
복합 특성의 값 설정 블록
myService ExampleServicePart
{ @xml
{name="myService",
namespace="http://www.customerpackage.companyb.commy.useful.service"}
};
추가 값 설정 블록 예제
Record Point
x INT;
y INT;
end
Record Rectangle
topLeft Point;
bottomRight Point;
end
Function test()
screen Rectangle
{
topLeft{x=1, y=1},
bottomRight{x=80, y=24}
};
// change x, y in code, using a statement
// that is equivalent to the following code:
// screen.topLeft.x = 1;
// screen.topLeft.y = 2;
screen.topLeft{x=1, y=2};
end
pts Point[2]
{
this[1]{x=1, y=2},
this[2]{x=2, y=3}
};
pts{ x=1, y=1 };
pts[1]{x=10, y=20};
this 키워드는 값 설정 블록 외부에서는 다른 의미를 갖습니다("this" 키워드 참조). 여기서 pts[1]의 사용은 모호하지 않으므로 이와 같은 구분은 필요하지 않습니다.
points Point[];
points{x=1, y=1};
points[1]{x=10, y=20};
points{};
points.resize(2);
points{x=1, y=1};