Export grouped data to CSV

harm.poelen
Member Posts: 36
Hi there,
I'm trying to find out how I could write information about shipments (one line per address) to a CSV file. This file then needs to be imported into the shipping program of the customer. What I can find out is that I can not use dataports because you are not able to setup a grouping level. What would be the most elegant solution? I am thinking along two possible ways to go:
1. just creating a custom tabel and retrieve all information from the Sales order / shipping lines that I need and generate the shipping lines I need to export (then I could use a dataport I think);
2. or using a temporary table to hold the data and export this table in some way....
What is the best course to follow? Any suggestions?
I'm trying to find out how I could write information about shipments (one line per address) to a CSV file. This file then needs to be imported into the shipping program of the customer. What I can find out is that I can not use dataports because you are not able to setup a grouping level. What would be the most elegant solution? I am thinking along two possible ways to go:
1. just creating a custom tabel and retrieve all information from the Sales order / shipping lines that I need and generate the shipping lines I need to export (then I could use a dataport I think);
2. or using a temporary table to hold the data and export this table in some way....
What is the best course to follow? Any suggestions?
CANE Microsoft Solutions BV
Prins Hendrikplein 14
2518 JC DEN HAAG
The Netherlands
http://www.cane.nl
Prins Hendrikplein 14
2518 JC DEN HAAG
The Netherlands
http://www.cane.nl
0
Comments
-
Hi Harm,
Why not just use a processing report and write the lines to a text file using the TEXTFILE.WRITE command ? At least then you can use multiple data items and group accordingley.
Dean.Remember: Keep it simple0 -
To define a data structure for a temporary table you need to specify a real table which should be base for temp table.
So you have to create real table anyway unless you can use some existing table as base for custom table.
Instead of Dataport, you could just create the file in C/AL code and fill the file manually with needed data...®obi
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯0 -
I ended up creating a fixed table which can also be maintained by the client through a form. Based on the shipping lines I write a line to this table per shipping address. After that the client can change some information and add some information that is not available from the sales orders. After that they can export the file. So then no more grouping is neccecary.
This is the code that manages the export:
Declarations: MyOutStream As OutStream
SHIPExportFile As FILE
ExportString As Text(250)
SHIPExportFile.CREATE('O:\SHIP\Zendingen.TXT');
SHIPExportFile.CREATEOUTSTREAM(MyOutStream);
IF SHIPLines.FIND('-') THEN REPEAT
ExportString := '';
ExportString := ExportString + PADSTR(SHIPLines.ShipToCustomer, 10, ' ');
ExportString := ExportString + PADSTR(SHIPLines.Name, 30, ' ');
ExportString := ExportString + PADSTR(SHIPLines.Address1, 30, ' ');
ExportString := ExportString + PADSTR(SHIPLines.ZipCode, 8, ' ');
ExportString := ExportString + PADSTR(SHIPLines.City, 30, ' ');
ExportString := ExportString + PADSTR(SHIPLines.Country, 2, ' ');
ExportString := ExportString + PADSTR(SHIPLines.Attn, 30, ' ');
ExportString := ExportString + PADSTR(SHIPLines.WhsShipCode, 10, ' ');
ExportString := ExportString + PADSTR(SHIPLines.SalesOrderNr, 10, ' ');
ExportString := ExportString + PADSTR(STRSUBSTNO('%1', SHIPLines.Collo), 10, ' ');
ExportString := ExportString + PADSTR(STRSUBSTNO('%1', SHIPLines.Weight), 10, ' ');
ExportString := ExportString + PADSTR(SHIPLines.Packing, 10, ' ');
MyOutStream.WRITETEXT(ExportString);
UNTIL SHIPLines.NEXT = 0;
SHIPExportFile.CLOSE;
Just one more problem to tackle... and that is that all lines are written in one long first export line. If anybody could give me a pointer on how to insert a CR/LF as the last character in the outputstring, I would be greatfull. I think I am going to experiment with the ArrayIndex and just put the 10 and 13 Char's in there... A bit ackward... but it seams to be the only way...? :-kCANE Microsoft Solutions BV
Prins Hendrikplein 14
2518 JC DEN HAAG
The Netherlands
http://www.cane.nl0 -
...and indeed... you can just assign the integer value of the character that you are looking for to the string (array):
ExportString[10+30+30+8+30+2+30+10+10+10+10+10+1] := 13;
ExportString[10+30+30+8+30+2+30+10+10+10+10+10+2] := 10;CANE Microsoft Solutions BV
Prins Hendrikplein 14
2518 JC DEN HAAG
The Netherlands
http://www.cane.nl0 -
Hi All,
I want to export data in a text file in a format where i would have on the first line 6 characters and on the second line of the text file some more descriptions and on the third line something and then repeating the whole thing in a similar way. I am trying to do it with a codeunit.
Can somebody pls tell me how should i break the line on text file that it should go on the next line. Please help
Regards,
Toshita0 -
If f is a FILE variable then after f.TEXTMODE(TRUE) all f.WRITE('some text') automatically starts in a new line.
Do It Yourself is they key. Standard code might work - your code surely works.0 -
Hi ,
Thanks for the reply. I got few more questions related to it. Now in the spreadhseet format i got a field lines which is of type integer and its length in the spreadsheet is 4. How shud i write it on the text file
format(lines,4) is that correct ? and secondly gota decimal field whose length is defined as 5(7).5(2). How should that be written on text file.?
please advise
regards
toshita0 -
Hi All,
Moving it up a bit
Cheers,
Toshita0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions