RDPScript EDI Language
The Premiere EDI Validation Language
RDPScript is a scripting language used to validate EDI data. Validation rules are used by the EDIValidator component to make sure EDI data is correct so that proper 997/999 acknowledgment files are created.
RDPScripting is used in the following scenarios
- Verifying data integrity
- Creating custom EDI errors
- Adding calculations at runtime
- Modifying segment rules at run-time
- Modifying element rules at run-time
- Modifying composite rules at run-time
- Changing element accepted values at run-time
- Checking for existence of segments and elements
- Verifying element content and lengths at run-time
RDPScript follows a well defined pattern and boils down to a if-then-end statement
Syntax
SegPos = if (Condition|CodeCondition|Calc) then Usage|LocalCode|Error end
SegPos = if (Condition|CodeCondition|Calc) then Usage|LocalCode|Error else Usage|LocalCode|Error end
if-then-elseif-then-end
SegPos = if (Condition|CodeCondition|Calc) then Usage|LocalCode|Error elseif (Condition) then Usage|LocalCode|Error end
Definitions
SegPos
The segment position we want to modify. Ordinal values are used. For example SegPos[1] is the ISA segment. SegPos[1:2] will be the second element of segment ISA. SegPos[1:2:1] would be ISA02 composite element 1
Condition
A condition that must evaluate to true before the statement in the then clause can execute.
+SegPos[27] = if (SegPos[26:2] == "18") then Usage[Optional] else Usage[NotUsed] end
In this scenario we want to change the usage of Segment Position 27 to Optional if Segment 26 Element 2 is equal to 18 otherwise mark it as Not Used
Calc
Calcs allow arithmetic calculations to be performed on element data to make sure they are correct
+SegPos[3:1] = if ( Calc{# (SegPos[3:1] - SegPos[2:2])* 10 #} == 2.23 ) then Error[ElementHasWrongValue,"Doesn't total up!"] end
Calcs currently supports the basic +,–,*, and / operators that can be combined in an infinite amount to ways to make sure EDI data is correct.
Calcs can be used on both the left hand and right side positions
Example
+SegPos[3:1] = if ( Calc{# (SegPos[3:1] - SegPos[2:2]) * 10 #} == Calc{# (SegPos[3:1] - SegPos[2:4])* 10 #} ) then Error[ElementHasWrongValue,"Doesn't total up!"] end
Example
+SegPos[3:1] = if ( Calc{# ((SegPos[3:1] - SegPos[2:2]) * (SegPos[3:1] - SegPos[2:2])) * ((SegPos[3:1] - SegPos[2:2]) - (SegPos[3:1] - SegPos[2:2])) #} == SegPos[2:7] ) then Error[ElementHasWrongValue,"Doesn't total up!"] end
The usual arithmetic operators can be used to compare the results of the Calcs. For example, ==, !=, <, >, <=, >=
Complex Conditions
+SegPos[146] = if ((SegPos[140:1] == "R") or (SegPos[140:1] == "S")) then Usage[Required] else Usage[Optional] end
Boolean Operations
or
|
Boolean OR
|
and
|
Boolean AND
|
Usage
Required
|
Required
|
Optional
|
Optional
|
NotUsed
|
Not Used
|
Examples
+SegPos[27] = if (SegPos[26:2] == "18") then Usage[Optional] else Usage[NotUsed] end
+SegPos[31] = if (SegPos[26:2] == "18") then Usage[Required] else Usage[Optional] end
+SegPos[40] = if (SegPos[26:2] == "18") then Usage[Required] else Usage[NotUsed] end
+SegPos[146] = if ((SegPos[140:1] == "R") or (SegPos[140:1] == "S")) then Usage[Required] else Usage[Optional] end
LocalCode
A keyword used to modify the accepted values of elements
+SegPos[3:1] = if ( SegPos[3:1] == "837" ) then LocalCode["we","w9"] end
+SegPos[3:1] = if ( SegPos[3:1] == "837" ) then LocalCode["we","w9"] else LocalCode["837"] end
In this scenario we are changing the accepted values of SegPos[3:1] to ‘we’ and ‘w9’ if it’s value is ‘837’
Error
A keyword used to create custom errors. EDIValidator will generate an error if the condition evaluates to true
+SegPos[135:5] = if (SegPos[135:5] == SegPos[40:5:1]) then Error[ElementHasWrongValue,"SV105 must be different from 2300 CLM05-01"] end
+SegPos[104:9] = if ((SegPos[26:9] != "") and (SegPos[104:9] != "")) then Error[ElementHasWrongValue,"SBR09 is used It should not be used after National PlanID is mandated"] end
+SegPos[275:2] = if ( SegPos[275:2] != SegPos[3:2] ) then Error[ElementHasWrongValue,"ST02 must be equal to SE02"] end elseif ( SegPos[275:2] != SegPos[3:3] ) then Error[ElementHasWrongValue,"ST02 must be equal to SE03"] end elseif ( SegPos[275:2] != SegPos[3:4] ) thenError[ElementHasWrongValue,"ST02 must be equal to SE04"] end else Error[ElementHasWrongValue,"ST02 must be equal to SE05"] end
Custom error messages that can be used are listed below
ElementHasWrongValue, ElementNotUsed, ElementRecommended, ElementNotRecommended, ElementMissing, CompositeElementHasWrongValue, CompositeElementNotUsed, CompositeElementRecommended, CompositeElementNotRecommended, CompositeElementMissing
, SegmentNotUsed, SegmentMissing, SegmentRecommended, SegmentNotRecommended
Checking for null
+SegPos[135:5] = if (SegPos[135:5] == null) then Error[ElementRecommended,"This element is recommended"] end
+SegPos[135:5] = if (SegPos[135:5] != null) then Error[ElementNotUsed,"This element is not used"] end
String Operations
Length
+SegPos[11:3] = if ( (SegPos[11:3] >l "13") and (SegPos[11:3] then Error[ElementHasWrongValue,"length"] end
Contains
+SegPos[11:3] = if (SegPos[11:3] =c "Provider") then Error[ElementHasWrongValue,"Cannot contain text Provider"] end
StartsWith
+SegPos[11:3] = if (SegPos[11:3] =s "P") then Error[ElementHasWrongValue,"Cannot start with P"] end
EndsWith
+SegPos[11:3] = if (SegPos[11:3] =e "xxx") then Error[ElementHasWrongValue,"Cannot end with xxx"] end
Operators
==
|
Equals
|
==i
|
Equals (Case Insensitive)
|
!=
|
Not Equals
|
!=i
|
Not Equals (Case Insensitive)
|
>
|
Greater Than
|
<
|
Less Than
|
>=
|
Greater Than Or Equal To
|
<=
|
Less Than Or Equal To
|
=c
|
Contains
|
=ci
|
Contains (Case Insensitive)
|
!c
|
Does Not Contain
|
!ci
|
Does Not Contain (Case Insensitive)
|
=s
|
Starts With
|
=si
|
Starts With (Case Insensitive)
|
!s
|
Does Not Start With
|
!si
|
Does Not Start With (Case Insensitive)
|
=e
|
Ends With
|
=ei
|
Ends With (Case Insensitive)
|
!e
|
Does Not End With
|
!ei
|
Does Not End With (Case Insensitive)
|
=l
|
Length Equals
|
!l
|
Length Does Not Equals
|
<l
|
Length Less Than
|
>l
|
Length Greater Than
|
Code Conditions – Custom Validating with .Net
+SegPos[277:2] = if ( CodeCondition["shouldStartWithZeros"] ) then Error[ElementHasWrongValue,"Value should start with zeros"] end
Register for the appropriate event on the EDIValidator
ediValidator.OnCodeCondition += new EDIValidator.CodeConditionEvent(ediValidator_CustomCondition);
Write a custom validation check using .Net
private void ediValidator_CustomCondition(object sender, CodeConditionEventArgs e)
{
if (e.CodeCondition.Id == "shouldStartWithZeros")
{
if (e.CurrentSegment.Elements[1].DataValue.StartsWith("0000")){
e.ConditionValid = true;
}
}
}
When Are Rules Are Executed
A Trigger SegPos is the segment that a rule belongs to. Rules are executed when the Trigger SegPos is encountered while validation occurs.
+SegPos[31] = if (SegPos[26:2] == "18") then Usage[Required] else Usage[Optional] end
The above rule is executed when segment 31 is encountered.
+SegPos[3:1] = if ( SegPos[3:1] == "837" ) then LocalCode["we","w9"] end
The above the rule is executed when segment 3 element 1 is encountered
RDPScript Short Hand
Syntax
[Segment/Element Position]=(Condition):ActionType:(true USAGE):(default USAGE)
[Segment/Element Position]=(Condition):ActionType: [Accepted Values]:[Default Values]
ActionType is either USAGE
or LOCALCODE
Examples
27=26:2'EQ'18!USAGE!0!1
31=26:2'EQ'18!USAGE!2!0
40=26:2'EQ'18!USAGE!2!1
146=140:1'EQ'R,S!USAGE!2!0
207=26:2'NE'18!USAGE!2!1
321=315:1'EQ'R,S!USAGE!2!0
The following USAGE
numbers can be used to change the usage of a segment or element
0
|
Optional
|
1
|
Not Used
|
2
|
Required
|
3
|
Recommended
|
4
|
Not Recommended
|
The following conditions can be used
EQ
|
Equal
|
NE
|
Not Equal
|
GT
|
Greater Than
|
GE
|
Greater Than Or Equal To
|
LT
|
Less Than
|
LE
|
Less Than Or Equal To
|
EXISTS
|
Exists
|
NEXIST
|
Not Exists
|
The different parts of the rule are separated by an exclamation character (!)
Rule
24=23:2'EQ'18!USAGE!0!1
Condition = 23:2'EQ'18
(If segment 23 element 2’s value is EQUAL to 18)
Action type=USAGE
(We are going to modify the usage of segment 24)
True Usage = 0 (segment 24 is optional)
Default Usage = 1 (segment 24 is not used)
Meaning:If segment 23 element 2’s value is EQUAL to 18 then segment 24 usage is OPTIONAL else segment 24 is NOT USED
Rule
28=23:2'EQ'18!USAGE!2!0
Condition = 28:2’EQ’18 (If segment 23 element 2’s value is EQUAL to 18)
Action type=USAGE
(We are going to modify the usage of segment 28)
True Usage = 2 (segment 28 is required)
Default Usage = 0 (segment 28 is optional)
Meaning: If segment 23 element 2’s value is EQUAL to 18 then segment 28 usage is REQUIRED else segment 28 is OPTIONAL
Rule
40=23:2'EQ'18!USAGE!2!1
Meaning: If segment 23 element 2’s value is EQUAL to 18 then segment 40 usage is REQUIRED else segment 40 is NOT USED
Rule
212=23:2'NE'18!USAGE!2!1
Meaning: If segment 23 element 2’s value is NOT EQUAL to 18 then segment 212 usage is REQUIRED else segment 212 is NOT USED
The condition can have more than one values
212=23:2'EQ'18,19!USAGE!2!1
Here we can see that the condition states that if segment 23 element 2
is equal to 18 OR 19 then segment 212 is REQUIRED else it is NOT USED.
Rule
149:2=23:2'NE'18!USAGE!2!1
Meaning: If segment 23 element 2’s value is NOT EQUAL to 18 then segment 149 element 2 usage is REQUIRED else NOT USED
Rule
97:2=23'EXISTS'!USAGE!2!1
Meaning: If segment 23 EXISTS then segment 97 element 2 usage is REQUIRED else NOT USED
LOCAL CODE
Rule
149:2=23:2'NE'18!LOCALCODE!2,3,4,5,6!7,8,9,10
Meaning: If segment 23 element 2’s value is NOT EQUAL
to 18 then segment 149 element 2 accepted value are 2,3,4,5,6 else the
default accepted values are 7,8,9,10
to 18 then segment 149 element 2 accepted value are 2,3,4,5,6 else the
default accepted values are 7,8,9,10