I am able to export the data to a text file but the formatting in the text file is not good. For example when a filed value has space in it - it contains a new line in the file.
Sample data: 846438828|10121803||HEIN|KATIE|270||PEBBLE
CREEK|DR|||usa|GA|30605||7DAY|1|2| 842486060|1012||GUNTER|LEWELL|230||MCDUFFIE|DR|||ATHENS|GA|30605|7065430640|FRI-SUN|1|2| 889388948|101205||WEEKS|JD|183||MELL|ST|||ATHENS|GA|30605|7065481437|SUNONLY|1|2|
The value of the field streetname "PEBBLE "CREEK but in the report it looks like:
PEBBLE
CREEK
Why does this happen?
def var v-copies as inte no-undo.
def var v-phone as char format "x(16)" no-undo.
def var v-loc as char no-undo.
def var v-file as char format "x(30)" no-undo.
def var v-demoid as char format "x(20)" no-undo.
def var v-email as char format "x(30)" no-undo.
def var v-hostname as char format "x(20)" no-undo.
def var v-RouteIDs as char no-undo.
def var v-Product as char no-undo.
def var v-ExDir as char format "x(80)" no-undo.
def var v-LookBack as int no-undo init 90.
{tools/altpubs/audit/var.i}
{tools/altpubs/audit/procedures.i}
def stream sout.
def temp-table tt-demo
field entityid as int format ">>>>>>>>>9"
field answer like DemographicAnswer.Answer.
v-ConfigFile = search(v-ConfigFile).
if v-ConfigFile = ? then do:
message "config file config.csv was not found" view-as alert-box.
RETURN "ERROR".
end.
input from value(v-ConfigFile).
run ReadConfig.
input close.
for each tt-Config where tt-Config.Section = 'local' and
tt-Config.SectionValue <> ?:
v-loc = tt-Config.SectionValue.
case tt-Config.SettingName:
when 'ExchDir' then v-ExDir = tt-Config.SettingValue.
when 'Product' then v-Product = tt-Config.SettingValue.
when 'Routes' then v-RouteIDs = tt-Config.SettingValue.
when 'LookBack' then
do:
v-LookBack = integer(tt-Config.SettingValue) no-error.
if error-status:error then v-LookBack = 90.
end.
end.
end.
v-ExDir = v-Exdir + lc(v-loc) + "/".
file-info:file-name = v-ExDir.
if not( file-info:file-type begins "D") or file-info:file-type = ? then
do:
unix silent makedir value(v-ExDir) && chmod 777 value(v-ExDir).
file-info:file-name = v-ExDir.
end.
assign
v-File = v-ExDir + lc(v-Product) + "Audit" +
string(month(today),"99") + "-" +
string(day(today),"99") + "-" +
substring(string(year(today),"9999"),3) + ".txt".
for each DemographicAnswer where DemographicAnswer.DemographicId = v-RouteIDs
no-lock:
create tt-demo.
assign tt-demo.entityid = int(DemographicAnswer.EntityId)
tt-demo.answer = DemographicAnswer.Answer.
end.
output stream sout to value(v-file).
put stream sout unformatted
"HEADER B2 " string(today) skip.
for each tt-demo,
each Subscription no-lock
where Product = v-product
and SubscriptionID = tt-demo.entityid
and Subscriber = yes
and Getspaper = yes:
find last RouteSubscription of Subscription no-lock no-error.
if available routeSubscription then do:
for each Occupant of Subscription no-lock,
each Address of Subscription no-lock:
find OccupantPhone of Occupant no-lock no-error.
if available OccupantPhone then
v-phone = OccupantPhone.AreaCode + OccupantPhone.Phone.
else
v-phone = "".
find last OccupantEmail of Occupant no-lock no-error.
if available OccupantEmail then
v-email = OccupantEmail.EmailAddress.
else
v-email = "".
case DeliveryScheduleId:
when "MON-FRI" then v-copies = RouteSubscription.Copies[2].
when "FRI-SUN" then v-copies = RouteSubscription.Copies[1].
when "SUNONLY" then v-copies = RouteSubscription.Copies[1].
when "7DAY" then v-copies = RouteSubscription.Copies[1].
when "MON-SAT" then v-copies = RouteSubscription.Copies[2].
when "THUONLY" then v-copies = RouteSubscription.Copies[5].
when "WEDONLY" then v-copies = RouteSubscription.Copies[4].
when "SATSUN" then v-copies = RouteSubscription.Copies[1].
end case.
put stream sout unformatted
tt-demo.Answer "|"
Subscription.SubscriptionId "|"
Subscription.Product "|"
Occupant.LastName "|"
Occupant.FirstName "|"
trim( Address.HouseNumber) "|"
trim(Address.Postdirectional) "|"
trim(Address.StreetName) "|"
trim(Address.StreetSuffixId) "|"
trim(Address.postdirectional) "|"
trim(Address.UnitDesignatorID + trim(Address.UnitNumber)) "|"
Address.CityId "|"
Address.StateId "|"
Address.ZipCode "|"
v-phone "|"
Subscription.DeliveryScheduleId "|"
v-copies "|"
"2" "|"
v-email skip.
end.
end.
end.
put stream sout unformatted
"TRAILER ".
output stream sout close.
This could really only depend on a few things but it's hard to answer without seeing your code.
1) There really isn't a new line there. It only looks like it since your texteditor breaks the line when you open the file. If this is the case maximizing/changing window size of your editor would change where the new line is displayed.
2) There really is a new line in the field. That would be exported. If you are exporting values with EXPORT you could try to do something like this to replace new line characters:
EXPORT REPLACE(streetname, "~n","").
If this has effect you have new lines in your database.
3) Something is wrong with the way you export data. Since your not posting example code (it's always a good idea to do that) we cannot know about this.
My bets are on number 1 or 2. If you use a straightforward exporting method like EXPORT you really shouldn't get into trouble...
Pretty much what Jens said (I'd have left this as a comment, but Stack Overflow won't let me..).
Try opening the file(s) in Notepad++ and disable View->Wrap, or do a similar thing with an editor of your choice. The linefeeds are in all likelyhood "not really there".
I had the same kind of problem some time ago. The problem was in the content of datafield, which had CHR(10) (line feed) and CHR(13) (carriage return) chars inputted by users with key. I found a simple solution to go around this by creating a function to convert those chars into '' and using it with PUT statements. I'll use two of your fields for instance ...
FUNCTION stringExport RETURNS CHAR
( INPUT p-input AS CHAR ):
RETURN TRIM(REPLACE(REPLACE(p-input,CHR(13),''),CHR(10),'')).
END FUNCTION. /* stringExport */
PUT STREAM sout UNFORMATTED
stringExport(Occupant.FirstName) "|"
stringExport(Address.HouseNumber) "|" SKIP.
Doing this maybe you solve your problem. Obviously you can substitute '' by ' '. It depends on your needs.
Hope it helps.
Looks like the field you are having trouble with is address.postdirectional
. As others have said, the first thing to check is that there isn't a hidden line break in the data.
In the procedure editor / tramlines, try something simple like:
for each address no-lock:
display procedure.postdirectional.
end.
You should see any line breaks in the data at that point, too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.