Padding FF Fields Using FormatService

Greetings,

I’m using IS 6.0.1 and am a little new to the wmFlatFile package…

Basically, I’ve created a schema referencing records from a dictionary. It’s a delimited record parser. I also used fixed position extractors on the dictionary fields for each record.

The problem I am having is that I now have a requirement to pad all numeric values with zeros, and I’m not sure how to do that. I’ve heard about using FormatServices, but I’m not sure how I could get one to help me in this instance.

Any thoughts?

Thanks in advance!

This is a pad utility in the WmEDI package if you happen to have this package:

wm.b2b.edi.util:pad

I usually create two wrapper services that call this particular utility. One that pads numbers (left with zeros); one that pads strings (right with spaces).

The wrapper utilities expect inputs of string, totalLength and type.

Then, it figures out based on number or string which way to pad, what to pad with and how many padded locations are needed.

For example, a string, whose length is 6, but requires a total amount of 12 spaces for the document would have 6 char(32) spaces concatenated to the end of the string. So, the string ‘wmuser’ would appear as 'wmuser '. For the number 123, whose whole length is 10, it would appear as ‘0000000123’.

This is assuming that you are padding left with zeros for numbers and padding right for strings with spaces.

HTH

Ray

Peterson,

Format Services are like any other services except the inputs and outputs of the format service should be specified by invoking the specification which is in WmFlatFile Package from the input/output tab of the format service(i.e Specification which is in WmFlatFile Package must be invoked from format service to specify inputs and outputs of format service).And map the input to the value(one of inputs in specification) and after logic is performed map the resultant output to the formattedOutput(one of outputs in specification).And inovoke the format service in Dictionary for corresponding field.

Thanks for the quick responses!

Usha, the problem I am having with this is, since I am using a fixed length extractor on a delimiter record parsed schema the maxLength pipeline input will only return the length extracted as opposed to the total length that the field should be. Any thoughts on how I could get the total length of the field?

Ray, I do have that package, but was not aware of that util. How does the service know what to use as the padding?

Thanks again!

Grant,

I stand corrected. It will ONLY PAD STRINGS.

However, I gleamed through the packages because I KNOW there must be something that does this and there is:

pub.string:padLeft
pub.string:padRight

Write a wrapper as I specified earlier and call either padLeft for the number or padRight for the string.

Should be easier now that I am steering you to the right place. Sorry.

Ray

I didn’t get the formatservice working. Did anybody try to get it working ?

Mike,

That’s because I was reading cross-eyed. My last post rectifies this. Sorry again.

Ray

In fact, to rectify my ills, I have included a package here that will do the padding for you, just copy the flow to your utils package and rename. Cheers.

Ray

String Pad Utility
RayMoserUtils.zip (4.7 k)

Ray,

Thanks for the code example. I think that will work well, but I’m having a hard time using it in conjunction with my flat file schema. As I said above, I’m using a delimiter record parser, and on the dictionary, I’m using a fixed position extractor to pull the appropriate fields. But doing this limits my ability to use your code in a FormatService, since the pipeline value MaxLength will only be equal to the length of the field extracted, and not the total length possible.

Since I can’t seem to form my schema any differently, is there any way for me to pad the numeric values using your code in a format service?

At some given point, your data should be in an IData object in the pipeline. Before you run the pub.flatFile:convertToString service, add a loop above it and loop through the data. In the loop, create a map step and call the service that you have now to pad as a transformer and set the appropriate padding and length. Should work.

This is the older methodology that was used prior to the FF adapter.

HTH

Ray