如何在PowerBuilder中实现换行?

时间:2012-12-28 08:11:34

标签: powerbuilder

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

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

PBScript:

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

text buffer

文件写入功能脚本:

    //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()

1 个答案:

答案 0 :(得分:3)

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

祝你好运,

特里。