# Writing to flat file

**URL:** <https://techcommunity.softwareag.com/t/writing-to-flat-file/107756>\
**Category:** Forum\
**Tags:** EDI\
**Created:** [February 27, 2003, 9:32pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756 "2003-02-27T21:32:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmundy.10875](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tmundy.10875](https://techcommunity.softwareag.com/u/tmundy.10875)\
**Post date:** [February 27, 2003, 9:32pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/1 "2003-02-27T21:32:31Z")

</div>

I am having difficulty writing to a fixed length flat file.

I need to read records from an AS400 physical file then write them to a flat file on a 2000 server. I can read the file from the AS400 using execsql but am not sure how to write the records to the fixed length flat file, I have created a flat file schema to be used in the flow. I have tried using convertToString service but am getting no data in the string output of this service even though data is going in to the service.

Any help/quidence greatly appreciated

Regards

Tony Mundy

---

<div class="post-metadata">

**Author:** ![vinod.ravi.20798](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vinod.ravi.20798](https://techcommunity.softwareag.com/u/vinod.ravi.20798)\
**Post date:** [February 27, 2003, 9:42pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/2 "2003-02-27T21:42:31Z")

</div>

How many records do you fetch in one operation?  
If your results from execSQL has only a list of strings inside then it is easy.  
You can loop over the results structure and then do a simple map from each item to a string.  
Hope this works.  
Good luck!

---

<div class="post-metadata">

**Author:** ![tmundy.10875](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tmundy.10875](https://techcommunity.softwareag.com/u/tmundy.10875)\
**Post date:** [February 27, 2003, 11:46pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/3 "2003-02-27T23:46:14Z")

</div>

Hi VR,

Thanks for the prompt reply.

How would you write the data out to the file?

Ta

Tony

---

<div class="post-metadata">

**Author:** ![vinod.ravi.20798](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vinod.ravi.20798](https://techcommunity.softwareag.com/u/vinod.ravi.20798)\
**Post date:** [February 27, 2003, 11:51pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/4 "2003-02-27T23:51:46Z")

</div>

You can write the data to a file using the utilities which are uploaded here in wmusers.  
You can download that here.  
Hopefully you are able to get the data from the database query now.  
Thanks and Good Luck!

---

<div class="post-metadata">

**Author:** ![wMusers.Com1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wmusers.com1/32/170_2.png) [@wMusers.Com1](https://techcommunity.softwareag.com/u/wMusers.Com1)\
**Post date:** [February 28, 2003, 12:20am UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/5 "2003-02-28T00:20:00Z")

</div>

Specifically, take a look at the examples in Igor’s Toolbox package in the File Share area. Here’s a link: [url=“[wmusers.com](http://www.wmusers.com/shared/uploads/1631toolbox.zip)”][wmusers.com](http://www.wmusers.com/shared/uploads/1631toolbox.zip%5B/url%5D)

Mark

---

<div class="post-metadata">

**Author:** ![tmundy.10875](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tmundy.10875](https://techcommunity.softwareag.com/u/tmundy.10875)\
**Post date:** [February 28, 2003, 4:15am UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/6 "2003-02-28T04:15:31Z")

</div>

Once again, thanks for the quick response.

I can get the data from the AS400 without problem and populate a document list. I then need to convert this in to the flat file layout for which I have created a flatfile schema. My problem still lies in writing the records/fields that are in the flat file schema to the acctual flat file on the server. I have downloaded the zip file you mentioned Mark, problem is I think this has been written specifically for 4.6 rather than version 6 which we are on. One thing to note I have limited knowledge of Java.

The flow I have created goes something like this

connect (connect to As400)  
execSQL (get the data from the as400)  
LOOP (over all records in file retrieved)  
MAP (from document list to flat file schema)

Thanks again

Tony

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [February 28, 2003, 5:19am UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/7 "2003-02-28T05:19:07Z")

</div>

I got something similar to work, here was what I did. First I leveraged the WmSamples.samples:IO example. It gives you a basic java filewriter level of IO. So, adding to your example I’d do the following:

connect  
execSQL  
openFilewriter (specifying filename)  
LOOP  
MAP (using convertToString from the flatFileIO to convert the document to a string – STILL IN LOOP)  
writeFileWriter (passing the string just created – STILL IN LOOP)  
ENDLOOP  
flushFileWriter (you might need this inside the loop for large data)  
closeFileWriter

That’s basically what I did and it worked. I hope this helps!

Jamie Stanton  
Innotrac

---

<div class="post-metadata">

**Author:** ![kkl1.32315](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@kkl1.32315](https://techcommunity.softwareag.com/u/kkl1.32315)\
**Post date:** [February 28, 2003, 8:55am UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/8 "2003-02-28T08:55:41Z")

</div>

Another way is to use your execsql and add the following:

- stringtodocument service appling your flatfile template as input

- output of stringtodocument service to be input to documenttorecord service

- converttostring service using output of documenttorecord service as input for template and using your list string as data values input.

that’s it and it will produce a flat file format of string data for you to use on Sql Server. Keep in mind that the high-level structure names of both converttostring inputs must match and your xml flatfile template must conform to webMethods rules. These 2 pieces are critical!

---

<div class="post-metadata">

**Author:** ![tmundy.10875](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tmundy.10875](https://techcommunity.softwareag.com/u/tmundy.10875)\
**Post date:** [March 12, 2003, 10:29pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/9 "2003-03-12T22:29:20Z")

</div>

I am still no farther forward ( i’m beginning to think i’m  
thick). What I am trying to do sounds so simple and yet is  
proving quite the opposite. All I want to do is take an  
AS400 Physical File (any number of records and 36 fields in  
each) and from that create a flat file. My main problem is  
getting results fro m convertToString (I don’t get any).

I am noe trying something simple, one map service and  
convertToString, I am mapping two fields in a document into  
convertToString. I am supplying a Flat File schema in  
convertToString which is very basic two fields. When I run  
the service the output from convertToString in blank and the  
error field is null.

Thanks again for any help

Regards

Tony Mundy

---

<div class="post-metadata">

**Author:** ![chris18](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@chris18](https://techcommunity.softwareag.com/u/chris18)\
**Post date:** [March 12, 2003, 10:35pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/10 "2003-03-12T22:35:34Z")

</div>

Tony,

I’m moving to 6.0 this week but here’s my 2 cents.  
Your problem seems to be convertToString not getting any  
output. Check the following:

1. You are mapping your flat file record structure to the  
Values input.
2. You are mapping your flat file template to the  
EDITemplate input.
3. Step thru your flow and stop at convertToString. Then  
view your Results tab. Double chech that the structure of  
your template is the same as your flat file structure. The  
problem you’re describing I have seen before. If my memory  
is correct it had to do with different structures between  
the flat file template and the flat file record structure.

FlatFileRecList ------------- mapped to -------------  
Values  
–FlatFileRec  
-----Field1  
-----…  
-----…  
-----FieldN

boundnode  
—FlatFileTemplate --------------- mapped to -----------  
EDITemplate

Mapping the FlatFileRec level to Values or mapping the  
boundnode level to EDITemplate could result in the null  
error.

HTH

---

<div class="post-metadata">

**Author:** ![tmundy.10875](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tmundy.10875](https://techcommunity.softwareag.com/u/tmundy.10875)\
**Post date:** [March 12, 2003, 10:36pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/11 "2003-03-12T22:36:34Z")

</div>

Hi Chris, thanks for the reply.

convertToString is getting input, very simply I have  
specified a document with two fields and hard coded the  
values.

EDITemplate is not used in convertToString in version 6. I  
have stepped through and data is definatly getting into  
convertToString.

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [May 5, 2003, 6:57pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/12 "2003-05-05T18:57:35Z")

</div>

Tony,

Have you gotten anywhere with this ? I am having the same issue. I am now trying to duplicate the example from edi reference appendix A for FLR output. My result is a null error and an empty string. If you have had any success I would be interested to here what you did.  
Pat Sclafani

---

<div class="post-metadata">

**Author:** ![bash](https://avatars.discourse-cdn.com/v4/letter/b/439d5e/32.png) [@bash](https://techcommunity.softwareag.com/u/bash)\
**Post date:** [May 21, 2003, 2:01pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/13 "2003-05-21T14:01:16Z")

</div>

Hello Tony and Patrick,  
Try running the ConverttoString separately, by passing the values of the Record and the EDI Template through the input screen.

If this is working fine, then I guess, there is some problem with your mapping of the input variables to the ConverttoString service.

Good Luck

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [April 29, 2005, 11:02pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/14 "2005-04-29T23:02:43Z")

</div>

Hi,  
I’m facing a similar problem wherein I have a document type based on a 4010.X12.846. I’m reading values from a database and populating this document (it works till here), and then calling the wm.b2b.edi:convertToString service by mapping this document type ref to the Values input in convertToString. The resultant string I get is empty. Can someone tell me what I missed?  
Thanks

---

<div class="post-metadata">

**Author:** ![gupta\_r.17495](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@gupta\_r.17495](https://techcommunity.softwareag.com/u/gupta_r.17495)\
**Post date:** [May 1, 2005, 9:36am UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/15 "2005-05-01T09:36:54Z")

</div>

PB,

Please make sure the result 846 document structure that mapping to ffValues is exactly confirms with EDIFFSchema.

Are you seeing any error in logs?

HTH,  
RMG

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [May 7, 2005, 4:07pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/16 "2005-05-07T16:07:30Z")

</div>

Hi

Found the solution. Apparently the BIS guide is incorrect in this case - or at least inconsistent with the WmEDISamples service and also with what really worked for me.

Although the document says that the value of input variable “ffschema” needs to be set the the EDI 846 schema, I had to blank out the value for the ffschema, and set the value of the document type (EDIFFSchema.X12.V4010:T846) to the input variable “nsrecord”. (I followed the WmEDI samples here.)

And this worked for me.

PB

---

<div class="post-metadata">

**Author:** ![gupta\_r.17495](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@gupta\_r.17495](https://techcommunity.softwareag.com/u/gupta_r.17495)\
**Post date:** [May 7, 2005, 7:55pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/17 "2005-05-07T19:55:56Z")

</div>

If you set either ffschema or nsrecord convertToString work as expected.But always using schema it is good.

HTH,  
RMG

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [May 12, 2005, 6:11pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/18 "2005-05-12T18:11:10Z")

</div>

Hi professionals,

I am trying to use flat file schema for converting XML data to positional EDI file . While creating flat file schema for fixed length what do I need to give in the Record length column in( Flat File structure). I am not getting a correct output when I use convert to string service . I feel my flat file schema creating is wrong .Anybody please help.

Thanks in advance

Regards  
R

---

<div class="post-metadata">

**Author:** ![gupta\_r.17495](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@gupta\_r.17495](https://techcommunity.softwareag.com/u/gupta_r.17495)\
**Post date:** [May 12, 2005, 7:04pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/19 "2005-05-12T19:04:47Z")

</div>

Raghu,

In Recordlength column (specify each record length would be)say if the records end at 30 then enter this number.

HTH,  
RMG

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [May 13, 2005, 3:39pm UTC](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756/20 "2005-05-13T15:39:16Z")

</div>

Hi,  
Thanks RMG. My question is I am trying to define a record count for EDI (back end format) file . Each record if of different length. Then how do I give the lenght for the same.

Thanks & Regards  
R

[Next page](https://techcommunity.softwareag.com/t/writing-to-flat-file/107756.md?page=2)
