규칙 변수의 유형

규칙 변수에 여러 유형의 값을 지정할 수 있습니다.

규칙 변수는 상수, 표현식, 비즈니스 용어 또는 비즈니스 용어의 콜렉션을 나타낼 수 있습니다. 이름 및 값을 지정하여 규칙 변수를 정의합니다. 사용자는 이름을 선택하고, 값은 텍스트, 숫자 또는 산술 연산식일 수 있습니다. 이 값은 규칙에 이미 있는 사전 정의된 비즈니스 용어(예: customer)일 수 있습니다. 변수를 설정하면 변수를 선언하는 규칙의 파트에서 이를 사용할 수 있습니다.

상수를 정의하는 규칙 변수

규칙 변수는 상수 값을 선언하여 가장 간단히 사용할 수 있습니다.

예를 들어, 변수 maxAmount가 다음 규칙을 더 쉽게 이해하도록 하고 규칙의 if 및 then 파트가 동일한 값을 사용하는지 확인합니다.

definitions
	set maxAmount to 1000000;
 if
		the amount of 'the loan'  is at least maxAmount 
then
		in 'the loan report', reject the data with the message "The loan cannot exceed " + maxAmount;

규칙 변수의 제한사항

where 연산자를 사용하여 규칙의 definitions 파트에서 변수를 추가로 제한할 수 있습니다.

예제

다음 규칙에서, where는 loyal customer 변수를 골드 카테고리의 고객으로 제한합니다.

definitions
		set 'loyal customer' to a customer 
				where the category of this customer is Gold; 
if
		the value of the shopping cart of 'loyal customer' is more than $200 
then
		apply the super discount;

예제

다음 규칙은 골드 카테고리에 있으며 65세 이상의 고객인 senior Gold customer 변수를 선언합니다.

definitions
		set 'senior Gold customer' to a customer 
				where all the following conditions are true: 
						- the category of this customer is Gold 
						- the age of this customer is at least 65;

2회 이상의 비즈니스 용어 발생을 참조하는 규칙 변수

비즈니스 용어가 규칙에서 둘 이상의 정의를 갖고 있는 경우 다른 정의를 정의해야 합니다.

개발자가 비즈니스 용어에 대해 자동 변수를 사용하도록 설정할 경우 단어 the가 이 유형의 항목을 사용하는 로케일에서 자동 변수를 식별합니다. 예를 들어, 규칙에서 비즈니스 용어로 단어 "customer"를 사용하는 경우 개발자는 the customer라는 자동 변수를 정의하며, 이는 사용자가 규칙에서 참조할 수 있습니다.

예를 들어, 규칙에서 2회 이상 발생하는 고객을 참조해야 하는 경우 규칙의 definitions 파트에서 기타 발생을 정의해야 합니다.

definitions
		set applicant to a customer; 
		set 'loyal customer' to a customer; 
if
	all of the following conditions are true:
				- applicant is married to 'loyal customer' 
				- 'loyal customer' is insured 
then
		upgrade applicant's rating; 

둘 이상 같은 유형 사이의 관계를 참조하는 규칙에서 변수가 유용합니다.

예를 들어, 다음 조건에 서로 다른 두 명의 고객이 포함되어 있습니다.

if
		’customer 1’ is married to ’customer 2’ 

이 조건은 2명의 서로 다른 고객을 식별하여 해당 이름을 지정합니다. customer 1 및 customer 2 비즈니스 용어 "customer"가 다양하고, 2개의 고객 변수를 정의하여 다음과 같은 규칙을 쓸 수 있습니다.

definitions
		set ’customer 1’ to a customer; 
		set ’customer 2’ to a customer; 
if
		’customer 1’ is married to ’customer 2’ 		and ’customer 2’ is insured 
then
		upgrade ’customer 1’’s rating;
참고: 규칙에 비즈니스 용어가 여러 번 발생할 경우 이 규칙은 모든 순열을 처리하기 위해 배수로 실행됩니다. 예를 들어, 2명의 고객이 있어서 규칙이 2회 실행됩니다. 규칙에 3명의 고객이 있으면 규칙이 6회 실행됩니다.

비즈니스 용어의 모든 발생을 검색하는 규칙 변수

BAL 연산자 all <...>을 사용하여 비즈니스 용어의 모든 발생 목록을 검색하는 변수를 작성할 수 있습니다. 예를 들어, 다음과 같습니다.

definitions 
		set 'gold customers' to all customers 
				where the category of this customer is gold; 
		set 'junior gold customer' to a customer in 'gold customers' 
				where the age of this customer is at most 15; 
		set 'senior gold customer' to a customer in 'gold customers' 
				where the age of this customer is at least 65;

이 예제에서는 세 개의 변수를 작성합니다.

  • gold customers: 골드 카테고리의 고객 목록입니다.
  • junior gold customer: 골드 고객 목록 중 15세 이하의 고객입니다.
  • senior gold customer: 골드 고객 목록 중 65세 이상인 고객입니다.