Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers

Ray Moser -- webMethods Ezine Columnist

Create Positional Flat File Templates for the WmEDI Parser



By Ray Moser

 


The Positional Template for the Contact Record

With the contact record fresh in your mind, take a look at the template required by the WmEDI Package Flow convertToValues.

The first section of the template I refer to as the header. It contains little useful information for us except for the SEGMENT-DELIMITER field. In the example below, note that we are separating segments using an ASCII 10 character:

<?xml Version="1.0"?>
<rec_ContactRecord>
  <SEGMENT-DELIMITER>
    <KEYWORD></KEYWORD>
    <OFFSET></OFFSET>
    <FIXED>10</FIXED>
  </SEGMENT-DELIMITER>
    <FIELD-DELIMITER>
    <KEYWORD></KEYWORD>
    <OFFSET></OFFSET
    <FIXED></FIXED>
  </FIELD-DELIMITER>
  <SUB-FIELD-DELIMITER>
    <KEYWORD></KEYWORD>
    <OFFSET></OFFSET>
    <FIXED></FIXED>
  </SUB-FIELD-DELIMITER>

The template's next section contains all of the file's segments. You should see now why all of the information is required in our data dictionary -- failure to identify a segment will produce undefined segment data.

Move about halfway down to find segment ADD002:

  <SEGMENT ID="HDR001">
    <POSITION NAME="HDR001" START="0" LENGTH="6"/>
  </SEGMENT>
  <SEGMENT ID="REC001">
    <POSITION NAME="REC001" START="0" LENGTH="6"/>
    <POSITION NAME="ContactRecord" START="6" LENGTH="20"/>
  </SEGMENT>
  <SEGMENT ID="NAM001">
    <POSITION NAME="NAM001" START="0" LENGTH="6"/>
    <POSITION NAME="FirstName" START="6" LENGTH="20"/>
    <POSITION NAME="LastName" START="26" LENGTH="20"/>
  </SEGMENT>
  <SEGMENT ID="DAT001">
    <POSITION NAME="DAT001" START="0" LENGTH="6"/>
    <POSITION NAME="Company" START="6" LENGTH="30"/>
    <POSITION NAME="Title" START="36" LENGTH="30"/>
  </SEGMENT>
  <SEGMENT ID="ADD001">
    <POSITION NAME="ADD001" START="0" LENGTH="6"/>
    <POSITION NAME="Address1" START="6" LENGTH="30"/>
    <POSITION NAME="Address2" START="36" LENGTH="30"/>
  </SEGMENT>
  <SEGMENT ID="ADD002">
    <POSITION NAME="ADD002" START="0" LENGTH="6"/>
    <POSITION NAME="City" START="6" LENGTH="20"/>
    <POSITION NAME="State" START="26" LENGTH="10"/>
    <POSITION NAME="PostalCode" START="36" LENGTH="9"/>
    <POSITION NAME="CN" START="45" LENGTH="2"/>
  </SEGMENT>
  <SEGMENT ID="EMAIL1">
    <POSITION NAME="EMAIL1" START="0" LENGTH="6"/>
    <POSITION NAME="EmailAddress" START="6" LENGTH="60"/>
  </SEGMENT>
  <SEGMENT ID="NTE001">
    <POSITION NAME="NTE001" START="0" LENGTH="6"/>
    <POSITION NAME="Note" START="6" LENGTH="70"/>
  </SEGMENT>
  <SEGMENT ID="TRL001">
    <POSITION NAME="TRL001" START="0" LENGTH="6"/>
  </SEGMENT>

The last section of the template is the most important and most confusing.

The loop descriptions tell the parser which segments come in which order. The Contact Record file contains a header, a trailer and an array of record segments (REC001) which are denoted by the comma after REC001 below:

  <LOOP START="ContactRecord">
    <SEG-ID>HDR001</SEG-ID>
    <SEG-ID>REC001,</SEG-ID>
    <SEG-ID>TRL001</SEG-ID>
  </LOOP>

This second loop description contains the elements in the REC001 record array in the exact order:

  <LOOP START="REC001">
    <SEG-ID>REC001</SEG-ID>
    <SEG-ID>NAM001</SEG-ID>
    <SEG-ID>DAT001</SEG-ID>
    <SEG-ID>ADD001</SEG-ID>
    <SEG-ID>ADD002</SEG-ID>
    <SEG-ID>EMAIL1</SEG-ID>
    <SEG-ID>NTE001</SEG-ID>
  </LOOP>
</rec_ContactRecord>

You have now seen the Positional Flat File Contact Record and the template that can be used to parse it. Next, I will show you how to generate this template automatically.


Auto Generation of the Positional Template

No matter how you slice it, making templates is a tedious and sometimes difficult job.

Many of us must take off our developer caps and replace it with our "BA" business analyst caps. Without proper mapping guidance you will not successfully be able manipulate your data.

If you installed the package, take a quick look at the PositionalDataDictionaryChart.pdf file located in the package's /pub directory. The file contains, as a minimum, the data required to create a template. With this file handy, we can fill in the blanks.

contains a helper Record structure for creating templates using TemplateDesigner.Positional:getRecordProperties. This Record is described below:


RmUtils Record TemplateDesigner.Positional:TemplatePositional

About the Positional Template
RecordStructureNameName of the outerloop for your file
SegmentDelimiterRecord Separator
HDREmpty
IDIdentifies each segment
PositionNameName of field in segment
StartStart Point
LengthLength of field in segment
STARTName of the segment ID at which to start
ValueContains Segment ID to loop
IsMultiArrayIs there more than one of these segments?
TRLClosing tags for the template

 

Once this record is "filled out", TemplateDesigner.Positional:generateTemplate reads the properties and generates the proper template.


How to Use RmUtils to Create Templates

Earlier, we looked at the webMethods Record TemplateDesigner.Positional:TemplatePositional. Here is another look at the same Record


Input view of RmUtils Record TemplateDesigner.Positional:TemplatePositional

To fill in the Header segment HDR001, click the Segment section's Add Row symbol and in the pop-up window, supply HDR001 for the ID value.


Header segment input values

Still inside the pop-up, click the Position segment's Add Row button. In the pop-up window, provide the values as shown below:


Position segment input values

To build a template for your specific file, repeat this for each segment and for all fields in each segment.

Here are the steps that I took to set the input values for ADD002:

  1. Create a segment entry for ADD002
  2. Provide field position information for NAME, START and LENGTH as shown below.


Input values for ADD002

Next, we need to describe the looping for your file. If the file is flat and doesn’t have any repeatable sections, then only one loop is needed. Otherwise, for each repeatable section, a loop description is needed. Our contact record has two loops:

<LOOP START="ContactRecord">
    <SEG-ID>HDR001</SEG-ID>
    <SEG-ID>REC001,</SEG-ID>
    <SEG-ID>TRL001</SEG-ID>
  </LOOP>
  <LOOP START="REC001">
    <SEG-ID>REC001</SEG-ID>
    <SEG-ID>NAM001</SEG-ID>
    <SEG-ID>DAT001</SEG-ID>
    <SEG-ID>ADD001</SEG-ID>
    <SEG-ID>ADD002</SEG-ID>
    <SEG-ID>EMAIL1</SEG-ID>
    <SEG-ID>NTE001</SEG-ID>
  </LOOP>

The first loop describes the contact record. Notice in the first loop that REC001 has a comma. This denotes that there are multiple instances of REC001 possible in the file.

If you do not have the second loop, the parser will only parse for HDR001, REC001 and TRL001 segments.

The second loop describes the child elements of REC001. These elements will always be found between REC001 elements and makeup the contact record data.

The input screen for the first loop is below:


First input loop view of TemplatePositional Record

To make the comma for REC001, make sure isMultiArray is set to "Y".

The input screen for the second loop is below:


Second input loop view of TemplatePositional Record

Notice that the REC001 segment is defined as a sub-element of the looping structure.

Remember, the WmEDI parser requires that each segment be identified in the template. If data is included in a file that is not within the template specification, wm.b2b.edi:convertToValues will list it as unDefData and your segmentCount will be greater than zero.

To view the POS template, invoke the Flow TemplateDesigner.Positional:generateTemplate.

To parse the POS file, invoke the Flow TemplateDesigner.Positional:parsePositionalFile.


Conclusion

I hope this article helps to speed along your projects. I have used this code to cut down on the amount of time spent on what I consider a mundane task so I can concentrate my valuable time elsewhere. I hope that you can do the same.



<<Prev  1  [2]  

Go Deeper on the Subject: The wMUsers Discussion Forums


Ray Moser is a a Principal Consultant with Zettaworks LLC, Houston, Texas and is working in Sydney, Australia on various webMethods projects. He has over 10 years experience in application architecture and development. He has architected and built several successful integration projects using the webMethods Integration server, Trading Networks and Enterprise Broker.

Ray can be reached at


Advertise at wMUsers






  Home | Join wMUsers | Discussion Forums | Knowledge Center | Jobs | Shareware | User Groups | Links |
Contact Us | Terms of Service | Privacy Policy

wMUsers is an independent organization and is not sponsored in any manner by Software AG.


© All Rights Reserved, 2001-2008.