project QadFinancials > class BPaymentSelection > method ExportBEAbroad

Description

Export payment file in the format of Belgian foreign payments.


Parameters


iiCCollection_IDinputintegerCollection to be processed.
ilGroupingAllowedinputlogicalCan PaySelLines be grouped by creditor? General flag.
icOutputFilenameinputcharacterOutput file name.
itPayDateinputdateCollection payment date.
iiGL_IDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPaymentSelection.GenerateASCII


program code (program7/bpaymentselection.p)

/* check with query calls because it's run from execute, and everything is done on register */
/* go to document for this paysel_id, then go to collection and then do everything */
empty temp-table tExpFields.
empty temp-table tBLWI.

/*=========================================================================*/
/* Lookup a belgium vat number (zonder editering)                          */
/*=========================================================================*/
/* Get the Country Code of Belgium */
<Q-1 run CountryByCountry (all) (Read) (NoCache)
          (input ?, (CountryId)
           input {&BANKNUMBERVALIDATION-BE}, (CountryCode)
           output dataset tqCountryByCountry) in BCountry >
                            
find first tqCountryByCountry no-error.
if not available tqCountryByCountry
then do:
    <M-2 run SetMessage
       (input  #T-34'The country Belgium is not defined in the system.':80(2983)T-34# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  {&BANKNUMBERVALIDATION-BE} (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  ? (icRowid), 
        input  'QADFIN-1063':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
    assign oiReturnStatus = -1.        
    return.
end.
 
/* Get the Business Relation Code for the Company */
<Q-33 run CompanyPropertyByBusinessRel (first) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
           output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
find first tqCompanyPropertyByBusinessRel no-error.
if not available tqCompanyPropertyByBusinessRel
then do:
    <M-4 run SetMessage
       (input  #T-35'The system cannot find the entity property information.':80(999890826)T-35# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  ? (icRowid), 
        input  'QADFIN-1064':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
    assign oiReturnStatus = -1.        
    return.
end.

/* Get the VAT number for the Business Relation Code of the company */
<Q-5 run VatNumberPrim (all) (Read) (NoCache)
          (input ?, (VatNumberId)
           input ?, (BusinessRelationId)
           input ?, (IdentityCountryID)
           input '':U, (VatNumberIdentity)
           input tqCompanyPropertyByBusinessRel.tcBusinessRelationCode, (BusinessRelationCode)
           input if tqCountryByCountry.tlCountryIsEUCountry then {&BANKNUMBERVALIDATION-BE} else '':U, (IdentityCountryCode)
           output dataset tqVatNumberPrim) in BBusinessRelation >
find first tqVatNumberPrim no-error.

/* Get the Business Relation of the Company in Order to retrieve the Company Address */
/* ================================================ */
/* Select proper lines and fill in temporary table  */
/* ================================================ */
for each tCCollectionPaySel where
         tCCollectionPaySel.CCollection_ID = iiCCollection_ID,
    each tCDocumentInfoForCollection where
         tCDocumentInfoForCollection.tcPayFormatTypeCode = tCCollectionPaySel.tcPayFormatType,
    each tCDocumentInvoiceXrefPaySel where
         tCDocumentInvoiceXrefPaySel.CDocument_ID = tCDocumentInfoForCollection.tiCDocument_ID,
    each tPaySelLine where
         tPaySelLine.PaySelLine_ID      = tCDocumentInvoiceXRefPaySel.PaySelLine_ID and
         tPaySelLine.PayFormatTypeCode  = {&PAYMENTFORMAT-BE2},
    first tPaySel where
          tPaySel.tc_Rowid = tPaySelLine.tc_ParentRowid
    break by tPaySelLine.tcCreditorCode
          by tPaySelLine.tcInvoiceCurrencyCode
          by tPaySelLine.BankNumber_ID:

    /* Get the Creditor in order to decide if the grouping is possible */
    if first-of(tPaySelLine.tcCreditorCode)
    then do:
        <M-27 run ExportBEAbroadPreselect
          (output vcCredBusRelationCode (ocCredBusRelationCode), 
           output vcCredAddressStreet1 (ocCredAddressStreet1), 
           output vcCredAddressZip (ocCredAddressZip), 
           output vcCredAddressCity (ocCredAddressCity), 
           output vcCredAddressCountry (ocCredAddressCountry), 
           output vlCredIsIndividualPayment (olCredIsIndividualPayment), 
           output vcCredCountryDescription (ocCredCountryDescription), 
           output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.
    end.    
    
    /* Possible grouping based on creditor */
    if (ilGroupingAllowed and
        first-of(tPaySelLine.BankNumber_ID) and
        not vlCredIsIndividualPayment) or
    /* Grouping not allowed with the Payment Selection Transfer */    
       not ilGroupingAllowed                                    or
    /* Grouping allowed with the Payment Selection Transfer, but the creditor doesn't allow the grouping */   
       vlCredIsIndividualPayment
    then do:
        empty temp-table tqBankNumberPrim.
        
        if tPaySelLine.BankNumber_ID <> ? and
           tPaySelLine.BankNumber_ID <> 0
        then do:
            /* Get the Creditor's Bank Account on which the Payment has been Realised */
            <Q-10 run BankNumberPrim (all) (Read) (NoCache)
          (input tPaySelLine.BankNumber_ID, (BankNumberId)
           input ?, (ParentObjectId)
           input '':U, (BankNumber)
           input '':U, (BankNumberExtension)
           input ?, (BankPayFormatID)
           output dataset tqBankNumberPrim) in BBankNumber >
                               
            find first tqBankNumberPrim no-error.
            if not available tqBankNumberPrim
            then do:
                <M-11 run SetMessage
                   (input  #T-36'The supplier bank account ($1) is not defined in the system.':80(2985)T-36# (icMessage), 
                    input  tPaySelLine.tcCreditorCode (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'D':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-1065':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  'tPaySelLine.tcCreditorCode=':U + tPaySelLine.tcCreditorCode + chr(2) + 'tPaySelLine.BankNumber_ID=':U + trim(string(tPaySelLine.BankNumber_ID)) (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>             
                assign oiReturnStatus = -1.
                return.
            end.
        end.
        
        /* Get the Currency Code of the Creditor's Bank Account */
        <Q-25 run CurrencyPrim (all) (Read) (NoCache)
          (input '':U, (CurrencyCode)
           input tqBankNumberPrim.tiCurrency_ID, (Currency_ID)
           output dataset tqCurrencyPrim) in BCurrency >
        find first tqCurrencyPrim no-error.
        if not available tqCurrencyPrim
        then do:
            <M-26 run SetMessage
               (input  #T-37'The supplier bank account currency is not defined in the system.':80(3004)T-37# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'D':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-1072':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>             
            assign oiReturnStatus = -1.
            return.
        end.

        create tExpFields.
        assign tExpFields.tcCredCreditorCode         = tPaySelLine.tcCreditorCode 
               tExpFields.tcCredBankNumber           = tqBankNumberPrim.tcBankNumber
               tExpFields.tcCredBankNumberValidation = tqBankNumberPrim.tcBankNumberValidation
               tExpFields.tcCredBankNumberExtension  = tqBankNumberPrim.tcBankNumberExtension
               tExpFields.tcCredBusRelationCode      = vcCredBusRelationCode
               tExpFields.tcBankCurrencyCode         = tqCurrencyPrim.tcCurrencyCode
               tExpFields.tcCredBankSwift            = tqBankNumberPrim.tcBankNumberSwiftCode
               vcCredBankNumber                      = tqBankNumberPrim.tcBankNumber
               vcCredBankNumberValidation            = tqBankNumberPrim.tcBankNumberValidation
               vcCredBankNumberExtension             = tqBankNumberPrim.tcBankNumberExtension
               tExpFields.tlCredIsIndividualPayment  = vlCredIsIndividualPayment or not ilGroupingAllowed.

        if tqBankNumberPrim.tcBusinessRelationCode <> '':U and    
           tqBankNumberPrim.tcBusinessRelationCode <> ?
        then do:
            /* Get Creditor's Bank Address */
            <Q-22 run AddressPrim (all) (Read) (NoCache)
               (input '':U, (AddressCity)
                input '':U, (AddressStreet1)
                input '':U, (AddressStreet2)
                input '':U, (AddressZip)
                input {&ADDRESSTYPECODESYSTEM-PAYM}, (AddressTypeCode)
                input 0, (AddressID)
                input tqBankNumberPrim.tiBankBusinessRelation_ID, (BusinessRelationID)
                input tqBankNumberPrim.tcBusinessRelationCode, (BusinessRelationCode)
                input 0, (AddressTypeID)
                input '':U, (AddressStreet3)
                output dataset tqAddressPrim) in BBusinessRelation >
            find first tqAddressPrim no-error.
            if not available tqAddressPrim
            then do:
                <Q-44 run AddressPrim (all) (Read) (NoCache)
                   (input '':U, (AddressCity)
                    input '':U, (AddressStreet1)
                    input '':U, (AddressStreet2)
                    input '':U, (AddressZip)
                    input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
                    input 0, (AddressID)
                    input tqBankNumberPrim.tiBankBusinessRelation_ID, (BusinessRelationID)
                    input tqBankNumberPrim.tcBusinessRelationCode, (BusinessRelationCode)
                    input 0, (AddressTypeID)
                    input '':U, (AddressStreet3)
                    output dataset tqAddressPrim) in BBusinessRelation >
                find first tqAddressPrim no-error.
            end.
            if not available tqAddressPrim
            then do:
                <M-23 run SetMessage
                   (input  #T-38'The supplier bank account address ($1) is not defined in the system.':80(3005)T-38# (icMessage), 
                    input  tqBankNumberPrim.tcBusinessRelationCode (icArguments), 
                    input  '':U (icFieldName), 
                    input  tqBankNumberPrim.tcBusinessRelationCode (icFieldValue), 
                    input  'D':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-1071':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>             
                assign oiReturnStatus = -1.
                return.
            end.

            assign tExpFields.tcCredBankBusRelationCode = tqAddressPrim.tcBusinessRelationCode
                   tExpFields.tcCredBankAddressStreet1  = tqAddressPrim.tcAddressStreet1
                   tExpFields.tcCredBankAddressCountry  = tqAddressPrim.tcCountryCode
                   tExpFields.tcCredBankAddressZip      = tqAddressPrim.tcAddressZip
                   tExpFields.tcCredBankAddressCity     = tqAddressPrim.tcAddressCity.
        end.
        
        /* Get Creditor's Address */
        assign tExpFields.tcCredAddressStreet1     = vcCredAddressStreet1
               tExpFields.tcCredAddressZip         = vcCredAddressZip
               tExpFields.tcCredAddressCity        = vcCredAddressCity
               tExpFields.tcCredAddressCountry     = vcCredAddressCountry
               tExpFields.tcCredCountryDescription = vcCredCountryDescription.

        /* Get Export Group Codes */
        <M-31 run GetExportGroupCodes (input  {&PAYMENTFORMAT-BE2} (icPayFormatTypeCode), 
                               input  tPaySelLine.BankNumber_ID (iiBankNumber_ID), 
                               input-output tExpFields.tcBankGroup1 (bcBankGroup1), 
                               input-output tExpFields.tcBankGroup2 (bcBankGroup2), 
                               input-output tExpFields.tcBankGroup3 (bcBankGroup3), 
                               input-output tExpFields.tcBankGroup4 (bcBankGroup4), 
                               input-output tExpFields.tcBankGroup5 (bcBankGroup5), 
                               input-output tExpFields.tcBankGroup6 (bcBankGroup6), 
                               output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then return.
    end.
    else find tExpFields where
              tExpFields.tcCredCreditorCode         = tPaySelLine.tcCreditorCode and
              tExpFields.tcCredBankNumber           = vcCredBankNumber           and
              tExpFields.tcCredBankNumberValidation = vcCredBankNumberValidation and
              tExpFields.tcCredBankNumberExtension  = vcCredBankNumberExtension
              no-error.

    create tExportReferences.
    assign tExportReferences.tiPaySelLineId          = tPaySelLine.PaySelLine_ID
           tExportReferences.tlPaySelLineIsRefInFile = true.

    /* Get the Invoice for the PaySelectionLine in order to retrieve the Ext.reference */
    if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE}    OR
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR} OR
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE} OR
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} OR
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV} or
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}
    then do:   
        <Q-12 run CInvoiceByPaymentInfo (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input tExpFields.tcCredBusRelationCode, (BusinessRelationCode)
            input tPaySelLine.PaySelLineParentObject_ID, (CInvoice_ID)
            input '':U, (PaymentGroupCode)
            input '':U, (CurrencyCode)
            input '':U, (DivisionCode)
            input ?, (BusinessRelationIsInterco)
            input '':U, (CInvoiceType)
            input ?, (IsInvoiceApproved)
            input ?, (IsLockPayment)
            input ?, (CInvoiceIsSelected)
            input ?, (CInvoiceIsOpen)
            input ?, (BusinessRelationCountryCode)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
            output dataset tqCInvoiceByPaymentInfo) in BCInvoice >
        find first tqCInvoiceByPaymentInfo no-error.
        if not available tqCInvoiceByPaymentInfo
        then do:
            <M-13 run SetMessage
               (input  #T-39'The specified supplier invoice is not defined in the system or is invalid.':80(999890827)T-39# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'D':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-1066':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>             
            assign oiReturnStatus = -1.
            return.
        end.
        assign viLength = length(tExpFields.tcReference1 + ' ':U + tqCInvoiceByPaymentInfo.tcCInvoiceReference,"CHARACTER":U).
        if  viLength <= 41
        then assign tExpFields.tcReference1 = tExpFields.tcReference1 + ' ':U + caps(tqCInvoiceByPaymentInfo.tcCInvoiceReference).
        else if viLength <= 121
        then assign tExpFields.tcReference2 = tExpFields.tcReference2 + ' ':U + caps(tqCInvoiceByPaymentInfo.tcCInvoiceReference).
        else assign tExpFields.tcReference1 = '':U
                    tExpFields.tcReference2 = '':U
                    tExportReferences.tlPaySelLineIsRefInFile = false.
    end.
    else do:    
        <Q-28 run GetDInvoiceForPaymentSelection (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input ?, (IsPaymentAllowed)
            input tExpFields.tcCredBusRelationCode, (BusinessRelationCode)
            input tPaySelLine.PaySelLineParentObject_ID, (DInvoice_ID)
            input ?, (CurrencyCode)
            input ?, (DivisionCode)
            input ?, (BusinessRelationIsInterco)
            input ?, (DInvoiceType)
            input ?, (DInvoiceIsOpen)
            input ?, (DInvoiceIsSelected)
            input ?, (BusinessRelationCountryCode)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
            output dataset tqGetDInvoiceForPaymentSelection) in BDInvoice >
        find first tqGetDInvoiceForPaymentSelection no-error.
        if not available tqGetDInvoiceForPaymentSelection
        then do:
            <M-29 run SetMessage
               (input  #T-40'The specified customer credit note is not defined in the system or is invalid.':80(2987)T-40# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'D':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-1227':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>             
            assign oiReturnStatus = -1.        
            return.
        end.

        if vilength <= 41
        then assign tExpFields.tcReference1 = tExpFields.tcReference1 + ' ':U + caps(tqGetDInvoiceForPaymentSelection.tcDInvoiceTSMNumber).
        else if vilength <= 121
        then assign tExpFields.tcReference2 = tExpFields.tcReference2 + ' ':U + caps(tqGetDInvoiceForPaymentSelection.tcDInvoiceTSMNumber).
        else assign tExpFields.tcReference1 = '':U
                    tExpFields.tcReference2 = '':U
                    tExportReferences.tlPaySelLineIsRefInFile = false.
    end.
    
    /* Payment Amount */
    if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE} or
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTECORR} or
       tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-DEBTORCREDITNOTE}
    then assign tExpFields.tdAmountLC01 = tExpFields.tdAmountLC01 + abs(tPaySelLine.PaySelLineAmountTC).
    else if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE} OR
            tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR} or
            tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-DEBTORCNCORR} or
            tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}
    then assign tExpFields.tdAmountLC01 = tExpFields.tdAmountLC01 - abs(tPaySelLine.PaySelLineAmountTC).
    if tPaySelLine.PaySelLineObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}
    then assign tExpFields.tdAmountLC01 = tExpFields.tdAmountLC01 + tPaySelLine.PaySelLineAmountTC.
    assign tExpFields.tcCurrencyCodePay = tPaySelLine.tcInvoiceCurrencyCode.
    
/* XS BTS 1823 */
    if itPayDate = ? and
       tPaySel.PaySelDate <> ?
    then assign itPayDate = tPaySel.PaySelDate.
/* XE BTS 1823 */
end.
/* XS BTS 1823 */
if itPayDate = ?
then assign itPayDate = today - 1. /* wrong - fictive - date -> validation error */
/* XE BTS 1823 */

/* ==================== */    
/* Create payment file  */
/* ==================== */
do on error undo, retry:
    if retry 
    then do:
        <M-14 run SetMessage
           (input  #T-41'The system cannot create the file ($1).':80(2988)T-41# (icMessage), 
            input  icOutputFileName (icArguments), 
            input  '':U (icFieldName), 
            input  icOutputFileName (icFieldValue), 
            input  'D':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1067':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>             
        assign oiReturnStatus = -1.        
        return.
    end.

    /* Try to create the file */
    output stream sExpStream to value(icOutputFileName).
end.

/* get bank number */
<Q-15 run BankNumberByParentID (all) (Read) (NoCache)
   (input iiGL_ID, (ParentObjectId)
    input {&BANKNUMBERPARENTTYPE-GL}, (BankNumberParentType)
    input ?, (BankNumberIsDefault)
    input viCompanyId, (CompanyId)
    output dataset tqBankNumberByParentID) in BBankNumber >
find first tqBankNumberByParentID no-error.
if not available tqBankNumberByParentID
then do:
    <M-16 run SetMessage
       (input  #T-42'The bank account number specified is not defined in the system.':80(999890828)T-42# (icMessage), 
        input  '':U (icArguments), 
        input  'GL_ID':U (icFieldName), 
        input  string(iiGL_ID) (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-1068':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
    output stream sExpStream close.
    assign oiReturnStatus = -1.
    return.
end.

/* ============== */
/* Export header  */
/* ============== */
assign vcExpLine = '0':U +
                   string(day  (today),'99':U) +
                   string(month(today),'99':U) +
                   substring(string(year(today),'9999':U), 3, 2,"CHARACTER":U) +
                   fill (' ':U, 12).

assign vcExpLine = vcExpLine + substring(tqBankNumberByParentID.tcBankNumber, 1, 3,"CHARACTER":U).

assign vcExpLine = vcExpLine + 
                   '51':U.
                   
/* Diskette number equals to collection code */
find first tCCollectionPaySel where
           tCCollectionPaySel.CCollection_ID = iiCCollection_ID no-error.
if not available tCCollectionPaySel
then do:
    <M-18 run SetMessage
       (input  #T-43'The system cannot load the collection information.':80(2992)T-43# (icMessage), 
        input  '':U (icArguments), 
        input  'CCollection_ID':U (icFieldName), 
        input  iiCCollection_ID (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-1069':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
    output stream sExpStream close.
    assign oiReturnStatus = -1.
    return.
end.

assign vcExpLine = vcExpLine + 
                   string(tCCollectionPaySel.CCollectionNumber,'9999999999':U) +
                  (if available tqVatNumberPrim
                   then if tqCountryByCountry.tlCountryIsEUCountry
                        then '00':U + string(replace(tqVatNumberPrim.tcVatNumberIdentity, '.':U, '':U), 'x(9)':U)
                        else if vilength  = 11            and 
                                substring(tqVatNumberPrim.tcVatNumberIdentity, 4, 1,"CHARACTER":U) = '.':U and 
                                substring(tqVatNumberPrim.tcVatNumberIdentity, 8, 1,"CHARACTER":U) = '.':U
                             then '00':U
                                 + substr (tqVatNumberPrim.tcVatNumberIdentity, 1, 3,"CHARACTER":U)
                                 + substr (tqVatNumberPrim.tcVatNumberIdentity, 5, 3,"CHARACTER":U)
                                 + substr (tqVatNumberPrim.tcVatNumberIdentity, 9, 3,"CHARACTER":U)
                        else string(tqVatNumberPrim.tcVatNumberIdentity, 'x(11)':U)
                   else '00000000000':U) +
                  (if available tqVatNumberPrim
                   then if tqCountryByCountry.tlCountryIsEUCountry
                        then '00':U + string(replace(tqVatNumberPrim.tcVatNumberIdentity, '.':U, '':U), 'x(9)':U)
                        else if vilength = 11            and 
                                substring(tqVatNumberPrim.tcVatNumberIdentity, 4, 1,"CHARACTER":U) = '.':U and 
                                substring(tqVatNumberPrim.tcVatNumberIdentity, 8, 1,"CHARACTER":U) = '.':U
                             then '00':U
                                 + substr (tqVatNumberPrim.tcVatNumberIdentity, 1, 3,"CHARACTER":U)
                                 + substr (tqVatNumberPrim.tcVatNumberIdentity, 5, 3,"CHARACTER":U)
                                 + substr (tqVatNumberPrim.tcVatNumberIdentity, 9, 3,"CHARACTER":U)
                        else string(tqVatNumberPrim.tcVatNumberIdentity, 'x(11)':U)
                   else '00000000000':U) +
/* XS BTS 1782 01/04/2005 JirHol */
                   (if vlIsDuplicate
                    then 'D':U
/* XE BTS 1782 01/04/2005 JirHol */
                    else ' ':U) + 
                   '3':U +
                   fill(' ':U,12) +
                   '0':U +
                   fill(' ':U, 4) +
                   '1':U +
                   fill(' ':U,52).
                   
put stream sExpStream unformatted vcExpLine skip.

/* ============== */
/* Export lines   */
/* ============== */                   
<M-24 run ExportBEAbroadDetailLines (input  itPayDate (itPayDate), 
                                     output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.