project QadFinancials > class BBusinessRelation > method DataLoadOnlyFinanceAddress

Description

Do partial load of the business relation. Load only those addresses, which are maintenable in the Business Relation Maintenance. (thise are all except Dock, Ship-to, End-user)


Parameters


iiBusinessRelationIdinputintegerBusiness relation ID
ilKeepPreviousinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/bbusinessrelation.p)

/* ====================================================================================== *
 * Method       : DataLoadOnlyFinanceAddress                                              *
 * Description  : Do partial load of the business relation. Load only those addresses,    *
 *                which are maintenable in the Business Relation Maintenance.             *
 *                (thise are all except Dock, Ship-to, End-user)                          *
 * -------------------------------------------------------------------------------------- *
 * Parameters   : (I) BusinessRelation_Id                                                 *
 *                (I) KeepPrevious             keep previous records in the instance      *
 * ====================================================================================== */
assign oiReturnStatus        = -98
       viLocalReturn         = 0
       viAddressMaxThreshold = 20.

MAIN_BLOCK:
do on error undo, return:
    /* =============================================================================== *
     * Pre-validation block                                                            *
     * =============================================================================== */
    if iiBusinessRelationId = 0 then assign iiBusinessRelationId = ?.
    if ilKeepPrevious       = ? then assign ilKeepPrevious       = false.

    if iiBusinessRelationId = ? then leave MAIN_BLOCK.
    
    /* =============================================================================== * 
     * Get list of all address types                                                   *
     * =============================================================================== */
    <Q-64 run AddressTypePrim (all) (Read) (NoCache)
       (input 0, (AddressTypeId)
        input '':U, (AddressTypeCode)
        output dataset tqAddressTypePrim) in BAddressType >
    
    assign vcAddressFinanceTypes = "":U
           vlIsFirstIteration    = true.

    for each tqAddressTypePrim:
        if tqAddressTypePrim.tcAddressTypeCode      = {&ADDRESSTYPECODESYSTEM-DELIVERY}
        then assign viAddressTypeDelivery = tqAddressTypePrim.tiAddressType_ID.
        else if tqAddressTypePrim.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-DOCK}
        then assign viAddressTypeDock = tqAddressTypePrim.tiAddressType_ID.
        else if tqAddressTypePrim.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-ENDUSER}
        then assign viAddressTypeEndUser = tqAddressTypePrim.tiAddressType_ID.
        else do:

            if vlIsFirstIteration 
            then assign vcAddressFinanceTypes = vcAddressFinanceTypes 
                                                + 'lookup(string(Address.AddressType_ID),"' + string(tqAddressTypePrim.tiAddressType_ID)
 
                        vlIsFirstIteration = false.
            else assign vcAddressFinanceTypes = vcAddressFinanceTypes + ',' + string(tqAddressTypePrim.tiAddressType_ID).
         end.
     end.
         
     assign vcAddressFinanceTypes = vcAddressFinanceTypes  + '") > 0' when not vlIsFirstIteration. 

            
    
    /* Check, if the business relation has more then 20 addresses, if yes, then */
    /* load only the Finance types of the addresses. There will be created one  */
    /* new extra record with the information "There are also Operational type   */
    /* of addresses, which were not read becuase of performance."               */
    <Q-30 run AddressByIDsForCount (all) (Read) (NoCache)
       (input iiBusinessRelationId, (BusinessRelationId)
        input ?, (AddressId)
        output dataset tqAddressByIDsForCount) in BBusinessRelation >
        
    assign viAddressCount = 0.
    for each tqAddressByIDsForCount:
        if tqAddressByIDsForCount.tiAddressType_ID = viAddressTypeDelivery or
           tqAddressByIDsForCount.tiAddressType_ID = viAddressTypeDock     or
           tqAddressByIDsForCount.tiAddressType_ID = viAddressTypeEndUser
        then do:
            assign viAddressCount = viAddressCount + 1.
            if viAddressCount > viAddressMaxThreshold then leave.
        end.
    end.

    /* if there is more operational addresses then treshold, read only financial one */
    if viAddressCount > viAddressMaxThreshold 
    then do:
        assign vcDataLoadAddressExtraFilter = "(":U + vcAddressFinanceTypes + ")":U.
    
        /* Make also error message to inform end-user about limited load */
        assign vcMessage = #T-44'Not all Address records are displayed because there is large number of the Operational addresses (more then &1 records). Only Financial types are displayed. If you want to see also Operational types, you can go to the Ship-to, End-user .... browsers.':255(81958519)T-44#
               vcMessage = substitute(vcMessage, viAddressMaxThreshold).
        <M-66 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'W':U (icType), 
            input  4 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-921807':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
        assign viLocalReturn = (if viLocalReturn = 0 then 1 else viLocalReturn).
    end. /* if viAddressCount > viAddressMaxThreshold */
    
    /* Load data from database */
    <M-3 run DataLoad
       (input  '':U (icRowids), 
        input  string(iiBusinessRelationId) (icPkeys), 
        input  '':U (icObjectIds), 
        input  '':U (icFreeform), 
        input  ilKeepPrevious (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
    assign vcDataLoadAddressExtraFilter = ?.
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper <  0 then leave MAIN_BLOCK.
end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.