2014-07-11 36 views
0

我能夠將數據導出到文本文件,但文本文件中的格式不好。例如,當一個字段值有空格時 - 它在文件中包含一個新行。爲什麼在導出到Progress 4GL中的文本文件時,帶空格的字段值包含新行?

樣本數據: 846438828 | 10121803 || HEIN | KATIE | 270 ||卵石
CREEK | DR |||美國| GA | 30605 || 7天| 1 | 2 | 842486060 | 1012 || GUNTER | LEWELL | 230 || MCDUFFIE | DR ||| ATHENS | GA | 30605 | 7065430640 | FRI-SUN | 1 | 2 | 889388948 | 101205 || WEEKS | J D | 183 || MELL | ST ||| ATHENS | GA | 30605 | 7065481437 | SUNONLY | 1 | 2 |

領域streetname 「石子」 CREEK它看起來像報告,但在價值:

卵石

CREEK

爲什麼會出現這種情況?

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. 
+0

你怎麼出口?你可以發佈代碼嗎? – Jensd

回答

2

這實際上只能依賴於一些東西,但如果沒有看到代碼就很難回答。

1)那裏確實沒有新線。它只是看起來像是因爲你的文本編輯器打開文件時出現問題。如果出現這種情況,編輯器的最大化/更改窗口大小將改變顯示新行的位置。

2)這個領域確實有一條新線。那會被輸出。如果要導出與出口值,你可以嘗試做這樣的事情,以取代新行字符:

EXPORT REPLACE(streetname, "~n",""). 

如果有你在你的數據庫中的新線效應。

3)您導出數據的方式有些問題。由於您沒有發佈示例代碼(這樣做總是一個好主意),所以我們無法瞭解這一點。

我的投注上的數字1或2,如果你使用一個簡單的方法導出像EXPORT你真的不應該陷入困境......

+0

我可以使用放置流。 – user3715001

+0

然後我仍然確信你只在你的編輯器中看到新的一行或者它真的在那裏......仍然最好張貼準確的代碼... – Jensd

0

差不多延斯說什麼(我已經離開這個作爲一個評論,但堆棧溢出不會讓我..)。

嘗試在Notepad ++中打開文件並禁用View-> Wrap,或者使用您選擇的編輯器做類似的事情。 換行符都是「不是真的存在」。

0

前段時間我有同樣的問題。問題出在數據字段的內容上,這些數據字段有用戶使用密鑰輸入的CHR(10)(換行)和CHR(13)(回車)字符。我找到了一個簡單的解決方案,通過創建一個函數將這些字符轉換爲''並使用PUT語句來解決這個問題。我會用你的兩個字段...

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. 

這樣做也許你可以解決你的問題。顯然你可以用''替代''。這取決於你的需求。

希望它有幫助。

+0

這是我在第二點的答案:CHR(10)(換行)+ CHR(13)(回車)替換爲「〜n」替換爲「」。 – Jensd

+0

謝謝@Jensd!我不知道「〜n」與「CHR(10)+ CHR(13)」是一樣的。 – Bruno

+0

〜n是通用的「換行符」。在UNIX上,chr(10)在Windows上是chr(10)+ chr(13)。 –

0

看起來像你有麻煩的領域是address.postdirectional。正如其他人所說,首先要檢查的是數據中沒有隱藏的換行符。

在程序編輯/有軌電車線路,嘗試像一些簡單:

for each address no-lock: 
    display procedure.postdirectional. 
end. 

您應該看到任何換行符在該點的數據了。

相關問題