1

我在下面编写了一个执行换行行为的脚本(参见附图作为参考输出)。但是当我通过 FTP 传输文本文件时,却导致反馈错误“文件的分隔符不正确。仍然是回车和换行。应该只是换行。”

希望得到任何人的回应......

脚本:

Long ll_row
ll_row = dw_Outbound.InsertRow(0)
dw_Outbound.SetITem(ll_row,'message',as_message)
as_message = ""

文本缓冲区

文件写入函数脚本:

    //Retrieve Transaction Set Header
    ids_TSH = CREATE DataStore
    ids_TSH.DataObject = 'd_inventory_advice_transetheader'
    ids_TSH.SetTransObject( SQLCA )
    ids_TSH.Retrieve()
    IF ids_TSH.ROwCount() = 1 THEN 
        ls_Msg += Trim(ids_TSH.Object.headerid[1])
        ls_Msg += "*" + Trim(ids_TSH.Object.setidcode[1])
        ls_Msg += "*" + Trim(ids_TSH.Object.setctrlnum[1])
        ls_Msg += "|" 
        //Set LineFeed
        //ls_Msg += "~n"
        of_ReturnOutboundMessage(ls_Msg)
        of_getInventoryAdviceTranRowCount(ls_Msg)
    END IF

    //Retrieve Beginning Segment
    ids_BIA = CREATE DataStore
    ids_BIA.DataObject = 'd_inventory_advice_begsegment'
    ids_BIA.SetTransObject(SQLCA)
    ids_BIA.Retrieve()
    IF ids_BIA.RowCount() = 1 THEN
        ls_Msg += Trim(ids_BIA.Object.biaid[1])
        ls_Msg += "*" + Trim(ids_BIA.Object.trnsetpcode[1])
        ls_Msg += "*" + Trim(ids_BIA.Object.reptypecode[1])
        ls_Msg += "*" + Trim(ids_BIA.Object.refid[1])
        ls_Msg += "*" + is_BIADATE
        ls_Msg += "|"   
        of_ReturnOutboundMessage(ls_Msg)
        of_getInventoryAdviceTranRowCount(ls_Msg)
    END IF

    //Assigned DateTime Reference
    ls_Msg += "DTM"
    ls_Msg += "*" + "007"        
    ls_Msg += "*" + is_BIADATE
    ls_Msg += "*" + is_Time
    ls_Msg += "*" + "UT"
    ls_Msg += "|" 
    of_ReturnOutboundMessage(ls_Msg)
    of_getInventoryAdviceTranRowCount(ls_Msg)

    //Assigned Reference Identification
    ls_Msg += "REF"
    ls_Msg += "*" + "EO"         
    ls_Msg += "*" + "SAPMBT01" //ISA06 SENDERID : SPI818TEST
    ls_Msg += "|"
    of_ReturnOutboundMessage(ls_Msg)
    of_getInventoryAdviceTranRowCount(ls_Msg)

    lds_Data = CREATE DataStore
    lds_Data.DataObject = 'd_inventory_advice_subinv_phldef'
    lds_Data.SetTransObject(SQLCA)
    lds_Data.Retrieve()

    lds_Name = CREATE DAtaStore
    lds_Name.DataObject = 'd_inventory_advice_nameheader'
    lds_Name.SetTransObject(SQLCA)
    lds_Name.Retrieve()

    IF lds_Name.RowCount() = 1 THEN 
        ls_Msg += Trim(lds_Name.Object.nameid[1])
        ls_Msg += "*" + Trim(lds_Name.Object.entityidcode[1])
        ls_Msg += "*" + Trim(lds_Name.Object.entityname[1])
        ls_Msg += "*" + Trim(lds_Name.Object.idcodequal[1])
        ls_Msg += "*" + Trim(lds_Data.Object.subinv[1])
        ls_Msg += "|"
        of_ReturnOutboundMessage(ls_Msg)
        of_getInventoryAdviceTranRowCount(ls_Msg)

        ls_Msg += Trim(lds_Name.Object.addressid[1])
        ls_Msg += "*" + Trim(lds_Name.Object.addressinfo[1])
        ls_Msg += "|"
        of_ReturnOutboundMessage(ls_Msg)
        of_getInventoryAdviceTranRowCount(ls_Msg)

        ls_Msg += Trim(lds_Name.Object.glid[1])
        ls_Msg += "*" + Trim(lds_Name.Object.cityname[1])
        ls_Msg += "*" + 'ML' //STATE OR PROVINCE CODE
        ls_Msg += "*" + Trim(lds_Name.Object.postalcode[1])
        ls_Msg += "*" + Trim(lds_Name.Object.countrycode[1])
        ls_Msg += "|"
        of_ReturnOutboundMessage(ls_Msg)
        of_getInventoryAdviceTranRowCount(ls_Msg)
    END IF

    //Administration Communication Contact
    /*lds_Contact = CREATE DataStore
    lds_Contact.DataObject = 'd_inventory_advice_contact'
    lds_Contact.SetTransObject(SQLCA)
    lds_Contact.Retrieve()
    IF lds_Contact.RowCOunt() = 1 THEN 
        ls_Msg += Trim(lds_Contact.Object.accid[1])
        ls_Msg += "*" + Trim(lds_Contact.Object.fnccode[1])
        ls_Msg += "*" + Trim(lds_Contact.Object.name[1])
        ls_Msg += "*" + Trim(lds_Contact.Object.numqual[1])
        ls_Msg += "*" + Trim(lds_Contact.Object.telnum[1])
        ls_Msg += "|"
        of_ReturnOutboundMessage(ls_Msg)
        of_getInventoryAdviceTranRowCount(ls_Msg)
    END IF*/

    //Initialize DataStore To Handle Line Item RowCount 
    ids_ITem = CREATE DAtaStore 
    ids_ITem.DataObject = 'd_edi_outbound_message_external'
    ids_ITem.SetTransObject( SQLCA )

    IF lds_Data.RowCOunt() > 0 THEN 
        FOR ll_Data = 1 To lds_Data.RowCOunt()      
            ls_item = lds_Data.getitemString(ll_Data, 'itemcode')
            ls_qtyonhand = String(lds_Data.getItemNumber(ll_Data,'sohqty'))
            ls_qtyavailable = String(lds_Data.getItemNumber(ll_Data,'availableqty'))
            ls_subinv = lds_Data.getItemString(ll_Data,'subinv')        

            ls_Msg = "LIN**MG*" + ls_item + "|"
            of_ReturnOutboundMessage(ls_Msg)
            of_getItemCodeRowCount(ls_Msg)
            of_getInventoryAdviceTranRowCount(ls_Msg)

            ls_Msg = "QTY*17*" + ls_qtyonhand + "|"
            of_ReturnOutboundMessage(ls_Msg)
            of_getInventoryAdviceTranRowCount(ls_Msg)

            ls_Msg = "QTY*33*" + ls_qtyavailable + "|"
            of_ReturnOutboundMessage(ls_Msg)
            of_getInventoryAdviceTranRowCount(ls_Msg)

            ls_Msg = "UIT*EA|"
            of_ReturnOutboundMessage(ls_Msg)
            of_getInventoryAdviceTranRowCount(ls_Msg)
        NEXT
    END IF

    ll_Filter = ids_ITem.RowCount()
    //Transaction Total
    ls_Msg += "CTT*" + String(ll_Filter) + "|"
    of_ReturnOutboundMessage(ls_Msg)
    of_getInventoryAdviceTranRowCount(ls_Msg)

    //Retrieve Set Trailer
    ids_TST = CREATE DataStore
    ids_TST.DataObject = 'd_inventory_advice_transettrailer'
    ids_TST.SetTRansObject(SQLCA)
    ids_TST.Retrieve()

    IF ids_TST.RowCount() = 1 THEN  
        of_getInventoryAdviceTranRowCount(ls_Msg)
        //Get the  DataStore RowCount For Trasaction Set Trailer
        is_SetTrailer = String(ids_InvTranTrailer.RowCount())

        ls_Msg += Trim(ids_TST.Object.trailerid[1])+ "*" + is_SetTrailer + "*"
        ls_Msg += Trim(ids_TSH.Object.setctrlnum[1]) + "|"
    END IF
    of_ReturnOutboundMessage(ls_Msg)

    //Note: Function below should not be remove.
    //of_getInventoryAdviceGroupTrailer()
    //of_getInventoryAdviceControlTrailer()

    GETDATETIME:
    ls_ServerDate = gnv_app.of_getServerDateTime()

    IF is_ServerDateNull = ls_ServerDate THEN GOTO GETDATETIME
    is_ServerDateNull = ls_ServerDate   

    FilePath = String(dw_path.Object.outboundfilepath[1])
    FileName = 'EDI_846_' + ls_ServerDate + '.TXT'
    FileDir = FilePath + '/' + FileName

    dw_Outbound.SaveAs(FileDir, TEXT!, FALSE)

    dw_Outbound.Reset()
4

2 回答 2

3

您遇到的问题是不同操作系统之间换行符概念之间的差异。PowerBuilder 是(在撰写本文时,您还没有描述哪个函数将数据从 DataWindow 传输到文本文件)使用 Windows 样式的换行符(CR+LF,或在 PowerScript 中)创建一个文件"~r~n",而您的 FTP 或FTP 收件人(不清楚此消息来自何处)需要 Unix 样式的换行符(LF,或 PowerScript 中的"~n")。如果您想控制换行符的生成方式,您将不得不自己编写文件(在脚本中,使用FileOpen(),FileWrite()等......而不是依赖 PB 来生成换行符,所以不FileOpen (..., LineMode!, ...)

祝你好运,

特里。

于 2012-12-28T14:56:47.580 回答
0

我感谢所有的投入,并感谢您的帮助。顺便说一句,我只想分享我是如何解决这个问题的。

在 IF lds_Data.RowCOunt() > 0 ELSE THEN 构造中,我进行了错误的连接,即“ls_Msg =”,它应该是“ls_Msg +=”。脚本已修改,文件已成功处理。

于 2013-01-07T08:22:41.383 回答