hey guys - me again.
I need to develop a dataport that can read a varying length file. It's an EDI document. As such, the length of the overall record, and the length of each field within the record, is dependent on the first character of the record.
I think I've determined that the stock usage of dataports (variable or fixed width) will not work for this. It appears that I'm going to need to parse the data myself. To do this, I would think that I would need to create a text field as long as my longest record (defined to be 64 characters), and read each row, parsing as I go.
Is this a correct assumption? If so, how do I read the data into a variable instead of a table record? Should I just create a table to hold the data and read it into that table, then parse from the table?
Any suggestions would be appreciated.
0
Answers
myitem,myitemdescription,mycost
"myitem","myitemdescription","mycost"
for example or something more complicated?
850 00000000000AB24836 PO HSS 000000126126 1260012 004010VICS 000004010004010X X4014010104010 P P
850 BEG0020000000SAAB24836 20060802
850 REF00400000IA 00848
850 DTM0120000001020060803
850 N1 02300000BY NEWARK 928048
850 PO103000000 0000000000000003EA200000000000000164 UP688047410022 VA19740
850 PO103000000 0000000000000003EA200000000000000438 UP741655100348 VA99059
850 PO103000000 0000000000000006EA200000000000000585 UP074469414586 VA12800
850 PO103000000 0000000000000006EA200000000000000363 UP011313020951 VA21600
850 PO103000000 0000000000000003EA200000000000000277 UP015228123462 VA38585
850 PO103000000 0000000000000003EA200000000000000234 UP018787767047 VA20190
850 PO103000000 0000000000000003EA200000000000000234 UP018787767061 VA20200
850 PO103000000 0000000000000003EA200000000000000473 UP018787765166 VA20240
850 PO103000000 0000000000000012EA200000000000000085 UP041670131229 VA19892
850 PO103000000 0000000000000003EA200000000000000185 UP041670132370 VA19902
850 PO103000000 0000000000000003EA100000000000000039 UP052336331655 VA24960
850 PO103000000 0000000000000003EA200000000000000759 UP074469414746 VA12855
850 PO103000000 0000000000000003EA100000000000000036 UP022796812032 VA40617
850 PO103000000 0000000000000003EA100000000000000036 UP022796174017 VA17001
850 PO103000000 0000000000000003EA100000000000000036 UP022796174024 VA17002
850 PO103000000 0000000000000003EA200000000000000473 UP018787761168 VA20150
850 PO103000000 0000000000000003EA200000000000000208 UP018787765043 VA20250
850 PO103000000 0000000000000003EA100000000000000036 UP022796800039 VA40685
850 PO103000000 0000000000000003EA100000000000000036 UP022796800022 VA40720
850 CTT063000000000019
http://www.BiloBeauty.com
http://www.autismspeaks.org
Perhaps you could consider that. EDI documents are not simple.
http://www.BiloBeauty.com
http://www.autismspeaks.org
I could write this in an hour in VB.Net, but I'm unsure in C/AL
I'm assuming that the file your'e reading is a text file.
It seems that the 1st character is the definition of the line.
You could create a new codeunit to read the file.
REPEAT
CASE COPYSTR(Line,1,1) OF
'H' : BEGIN
some code here;
END;
'D' : BEGIN
some code here;
END;
END:
UNTIL File.POS = File.LEN;
where File is DatType File
Line DataType Text Len 64 (or maxlen of the data)
Hope this helps
Finally getting back to this. I ended up creating a "buffer" table of 6 columns :
an integer row id,
the header type from the file (1st character of each line),
the data of the row (the remainder of the row),
the user id who is running the dataport,
the date of the run, and
the Location code, specified through a filter on the request form.
I've cheated for now and put the parsing code in the "OnPostDataItem". I loop through each record in my buffer, and insert the appropriate data in the Production Forecast Entry table after I've verified all the information in the file.
it's ugly, and i'll probably port it to a two-dataport solution in the future, but it works.
Thanks.