Integration Mapping – Parse Structured rule in Pega
In this blog article, we will see more in detail about the parse structured rule and the four specific methods.
This is the continuation of the previous blog article on Map structured rule. It is recommended to visit the Map structured article before proceeding here.
What is Parse structured rule?
Used to parse the structured data into clipboard properties.
They are mostly in conjunction with service file rules.
It looks the same as map structured rule right?!
Important Note: If the source is of simple fixed structure, always use map structured rule instead of parse structured rule.
This rule seems a bit complex rule to me!! Throughout my career with over 6 projects, I never saw using parse structured rule!! No worries, let’s explore it.
Where can you reference a parse structured rule?
1. You can use as parsing rule in Service file rule in Map to field to parse the input data
2. Activity can directly refer the parse structured rule using Apply-Parse-Structured method.
What are the configuration points in a Parse structured rule?
First, let’s start by creating a new parse structured rule.
Create and Open.
OOPS…. This look familiar. Yeah Pega uses the same template as activity rule.
Note: Technically the class Rule-Parse-Structured direct inherits from Rule-Obj-Activity. You can open and check the class rule form
Now you know, how a parse structured rule can handle complex structured parsing :). Parse structured rule can you most of the methods used by activity rule, also the pre-conditions and transitions. Again I will say, use it only when it is complex parsing!
We need to concentrate on four specialized methods, that can be used only in parse-structured rule
- Parse-Byte-Pos
- Parse-Char-Pos
- Parse-Fixed-Binary
- Parse-Packed-Decimal
Parse-Byte-Pos and Parse-Char-Pos
Both looks the same with the same method parameters. You can see they use Offset and length to parse and map to a target property.
Important Note: Parse structured work with the cursor moving. We will see about it soon
The main difference is
Parse-Byte-Pos – Used to extract fixed number of bytes (using length and Offset) from java input byte stream. This can be used when you want to read some binary rule
Parse-Char-Pos – Used to extract fixed number of characters from input character stream. This can be used when you want to read text files.
It’s good to visit my previous article on Service-File rule. We will use the already created service-file rule and going to replace the parse delimited with parse structured.
This was the input file I used in the post, where the values are comma separated. Let’s make it structured one and remove the commas.
I know this is not a good example of structured input, because you know Name cannot be in a structured way!!
Now this is the structured agreement
0-1 represents Record type identifier
2-6 represents Name
7-8 represents Age
9-12 represents Sex
Note: The position starts with 0 instead of 1
Let’s use this parsing structure in our parse structured rule
We need to define it in 3 steps as shown below
Offset & length logic is a bit different from map structured rule. You can see the second and third step starts with offset 0, because, the cursor has moved after step 1 and so we need to always use Offset 0.
Let’s test this.
How to test a Parse Structured rule?
Step 1: Configure the 3 steps and save the parse structured rule
Step 2: Update the service file rule with the parse structured
Step 3: Trace open the service file and run the service-file by providing the file with structured data.
Good, but there is one issue!!
The run window says, Failure. From tracer, I found only the first record is parsed and failed for the next record!
On analyzing, Pega says to include some offset for line break or record breaks of 2 characters (This 2 characters length may vary based on OS and type of file). Also remember, we used 2 characters as line breaker in service file rule.
Step 4: Add a new step, to skip the end of line characters.
Note: TargetProperty is not mandatory
Again with the cursor moving, specify the offset as 0 and Length as 2
Step 5: Run the service file again and check.
You see service parsed all 3 records and ended successfully.
There are 2 more methods you can use in Parse structured rule
Parse-Fixed-Binary and Parse-Packed-Decimal
Both are applicable only when the input is of byte stream
Parse-Fixed-Binary
Instead of specifying position, using this method we can always set a fixed bytes value to a property.
For example – First 8 bytes to customer name, next 2 bytes to Age and so on
LittleEndian – Specifies the order in which bytes are stored. Visit the below link for more detail
https://searchnetworking.techtarget.com/definition/big-endian-and-little-endian
Parse-Packed-Decimal
Again this is specific when the input is in packed decimal format.
For more info on the packed decimal format, please visit the below link
https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/rzasd/padecfo.htm
You can specify the digits and decimal places in the method.
The digits and decimals are used to extract the input and convert the value to save it into characters.
We couldn’t see a working tutorial here. You can also check with Pega community posts to know more about it!!
Note: Always try to use map structured instead of parse structured. It’s easy guys!
Hope you understood something new in this article.