project QadFinancials > class BBankNumber > method DataLoadByInput

Description

This method loads database records corresponding to input values (records found in the t_s*** tables).
When nothing found in the database, a new record should be initialised.
Input values should also be updated with :
- identity fields (override input values)
- tc_Rowid / tc_ParentRowid / tc_Status

Annotation

This template can be used to implement the code for this method.

* Replace [MainTableName] with the name of the main table in the class dataset (no prefixes).
* This template assumes that the main table has an identity field, and this field is the only field of the primary index of the table. Replace [PrimaryKeyFieldName] with the name of this field.
* This template assumes that the table has one logical alternate key (a key that is visible and editable to end-users) with one field. Replace [LogicalKeyFieldName] with the name of this field. If the logical key contains more than one field, repeat the code with this tag for every field in the key.
* The run statement following [METHOD CALL] should not be copied literally, but inserted as a method call (run the method in your own component).




for each t_s[MainTableName] by rowid(t_s[MainTableName]) on error undo, throw:

/* ================================================================= */
/* Lookup object by logical key */
/* When in create mode, skip lookup. */
/* ================================================================= */
if vcActivityCode <> "Create":U
then do:
vcFreeform = "for each [MainTableName] where [MainTableName].[LogicalKeyFieldName] = '":U + t_s[MainTableName].[LogicalKeyFieldName] + "'":U.
[METHOD CALL]
run DataLoad
(input '' (icRowids),
input '' (icPkeys),
input '' (icObjectIds),
input vcFreeform (icFreeform),
input yes (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus))
if viFcReturnSuper >= 0
then do:
/* DataLoad succeeded, no no-error needed */
find first t[MainTableName] where t[MainTableName].[LogicalKeyFieldName] = t_s[MainTableName].[LogicalKeyFieldName].
if t[MainTableName].tc_Status <> ""
then do:
[METHOD CALL]
run SetMessage
(input [duplicate key error] (icMessage),
input t_s[MainTableName].[LogicalKeyFieldName] (icArguments),
input 't[MainTableName].[LogicalKeyFieldName]':U (icFieldName),
input t_s[MainTableName].[LogicalKeyFieldName] (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_s[MainTableName].tc_Rowid (icRowid),
input 'ERR-xyz':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus))
assign oiReturnStatus = -1.
return.
end.
end.
end.

/* ================================================================= */
/* When in delete mode, ignore input data. */
/* When object not found, do not return an error. */
/* ================================================================= */
if vcActivityCode = "Delete":U
then do:
if viFcReturnSuper = -4
then delete t_s[MainTableName].
else do:
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* keep the UI rowid for usage in error messages (tFcMessages.tcFcRowid) */
[METHOD CALL]
run SetRowidConvert
(input t_s[MainTableName].tc_Rowid (icOldRowid),
input t[MainTableName].tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus))

/* ================================================================= */
/* Update input to allow correct matching */
/* ================================================================= */
assign t_s[MainTableName].tc_Rowid = t[MainTableName].tc_Rowid
t_s[MainTableName].tc_ParentRowid = ""
opPrimeKey = (if opPrimeKey = "" then "" else opPrimeKey + chr(4))
+ string(t[MainTableName].[PrimaryKeyFieldName]).
end.

next.
end.

if vcActivityCode = "Create":U
or viFcReturnSuper = -4
then do:
/* ================================================================= */
/* When object not found and in modify only mode, return an error. */
/* ================================================================= */
if vcActivityCode = "Modify":U
then do:
[METHOD CALL]
run SetMessage
(input #T'Object with key $1 does not exist.':100T# (icMessage),
input t_s[MainTableName].[LogicalKeyFieldName] (icArguments),
input 't[MainTableName].[LogicalKeyFieldName]':U (icFieldName),
input t_s[MainTableName].[LogicalKeyFieldName] (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_s[MainTableName].tc_Rowid (icRowid),
input 'ERR-xyz':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus))
assign oiReturnStatus = -1.
return.
end.

/* ================================================================= */
/* When object not found or in create mode, create it. */
/* ================================================================= */
[METHOD CALL]
run AddDetailLine
(input '[MainTableName]':U (icTable),
input '' (icParentRowid),
output viFcReturnSuper (oiReturnStatus))

/* ================================================================= */
/* Update input to allow correct matching */
/* ================================================================= */
assign t_s[MainTableName].tc_Status = "N":U.
end.
else do:
/* ================================================================= */
/* Update input to allow correct matching */
/* ================================================================= */
assign t_s[MainTableName].tc_Status = "C":U
t[MainTableName].tc_Status = "C":U.
end.

if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* insert code for subtables here */

/* keep the UI rowid for usage in error messages (tFcMessages.tcFcRowid) */
[METHOD CALL]
run SetRowidConvert
(input t_s[MainTableName].tc_Rowid (icOldRowid),
input t[MainTableName].tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus))

/* ================================================================= */
/* override value for identity fields in input */
/* ================================================================= */
assign t_s[MainTableName].[PrimaryKeyFieldName] = t[MainTableName].[PrimaryKeyFieldName]

/* ================================================================= */
/* Update input to allow correct matching */
/* ================================================================= */
t_s[MainTableName].tc_Rowid = t[MainTableName].tc_Rowid
t_s[MainTableName].tc_ParentRowid = ""

opPrimeKey = (if opPrimeKey = "" then "" else opPrimeKey + chr(4))
+ string(t[MainTableName].[PrimaryKeyFieldName]).
end.






If the class dataset contains more than one table, insert this code for every additional table.

/* ================================================================= */
/* Delete existing detail */
/* ================================================================= */
for each t[ChildTableName] where
t[ChildTableName].tc_ParentRowid = t[ParentTableName].tc_Rowid:
assign t[ChildTableName].tc_Status = "D":U.
end.

/* ================================================================= */
/* Update / add detail */
/* ================================================================= */
for each t_s[ChildTableName] where
t_s[ChildTableName].tc_ParentRowid = t_s[ParentTableName].tc_Rowid
on error undo, throw:

find first t[ChildTableName] where
t[ChildTableName].tc_ParentRowid = t[ParentTableName].tc_Rowid and
t[ChildTableName].[LogicalKeyFieldName] = t_s[ChildTableName].[LogicalKeyFieldName] no-error.
if available t[ChildTableName]
then if t[ChildTableName].tc_Status = "D":U
then assign t_s[ChildTableName].tc_Status = "C":U
t[ChildTableName].tc_Status = "C":U.
else do:
[METHOD CALL]
run SetMessage
(input [duplicate key error] (icMessage),
input t_s[ChildTableName].[LogicalKeyFieldName] (icArguments),
input 't[ChildTableName].[LogicalKeyFieldName]':U (icFieldName),
input t_s[ChildTableName].[LogicalKeyFieldName] (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_s[ChildTableName].tc_Rowid (icRowid),
input 'ERR-xyz':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus))
assign oiReturnStatus = -1.
return.
end.
else do:
[METHOD CALL]
run AddDetailLine (input '[ChildTableName]':U (icTable),
input t[ParentTableName].tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus))
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
assign t_s[ChildTableName].tc_Status = "N":U
t[ChildTableName].[LogicalKeyFieldName] = t_s[ChildTableName].[LogicalKeyFieldName].
end.

/* keep the UI rowid for usage in error messages (tFcMessages.tcFcRowid) */
[METHOD CALL]
run SetRowidConvert
(input t_s[ChildTableName].tc_Rowid (icOldRowid),
input t[ChildTableName].tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus))

/* ================================================================= */
/* override value for identity fields in input */
/* ================================================================= */
assign t_s[ChildTableName].[ChildPrimaryKeyFieldName] = t[ChildTableName].[ChildPrimaryKeyFieldName]

/* ================================================================= */
/* Update input to allow correct matching */
/* ================================================================= */
t_s[ChildTableName].[ParentPrimaryKeyFieldName] = t[ChildTableName].[ParentPrimaryKeyFieldName]
t_s[ChildTableName].tc_Rowid = t[ChildTableName].tc_Rowid
t_s[ChildTableName].tc_ParentRowid = t[ParentTableName].tc_Rowid.
end.

PreCondition

The code of this method must always be overridden, not extended.


Parameters


opPrimeKeyoutputlongcharPrimary Key field value of loaded record(s).
Keys are chr(4) separated.
Key fields are chr(2) separated.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program2/bbanknumber.p)

if oiReturnStatus = 0
then oiReturnStatus = -98.

/* Initial the variables */
assign vcBlankFieldsName = "":U.

/* start queires */
<Q-31 run DebtorPrim  (Start) in BDebtor >
<Q-32 run CreditorPrim  (Start) in BCreditor >
<Q-33 run EmployeePrim  (Start) in BEmployee >
<Q-34 run GLPrim  (Start) in BGL >
<Q-35 run PayFormatGroupPrim  (Start) in BPaymentFormat >
<Q-17 run BankNumberForParentObject  (Start) in BBankNumber >
        
PROCESSBLOCK:
for each t_sBankNumber break by t_sBankNumber.tc_Rowid:
    /* Test if following fields are specified as they are part of unique index and can never be blank */
    /* Remark also BankPayFormat_ID and BankNumberExtension are part of primary key - but they can be blank */
    if t_sBankNumber.tcParentObjectCode  = '':U or
       t_sBankNumber.tcParentObjectCode  = ?
    then assign vcBlankFieldsName = (if vcBlankFieldsName = "":U then vcBlankFieldsName + trim(#T-39'Customer / Supplier Code':60(71235)T-39#)
                                     else vcBlankFieldsName + ", ":U + trim(#T-40'Customer / Supplier Code':60(71235)T-40#)).
    assign vlDuplicateGl = false .
    if t_sBankNumber.BankNumber  = '':U or
       t_sBankNumber.BankNumber  = ?
    then assign vcBlankFieldsName = (if vcBlankFieldsName = "":U then vcBlankFieldsName + trim(#T-43'Bank Number':255(69715)T-43#)
                                     else vcBlankFieldsName + ", ":U + trim(#T-44'Bank Number':255(69715)T-44#)).

    if vcBlankFieldsName <> "":U
    then do:
        assign vcMessage = trim(#T-12'Some key elements to identify the Bank Number are missing :':150(71233)T-12#) + trim(vcBlankFieldsName).

        <M-11 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sBankNumber.tc_Rowid (icRowid), 
            input  'QadFin-8626':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankNumber>                      
        assign oiReturnStatus = -1.
        leave PROCESSBLOCK.
    end.

    /* get the parent object id */
    case t_sBankNumber.BankNumberParentType:
            when {&BANKNUMBERPARENTTYPE-CREDITOR}
            then do:
                if t_sBankNumber.BankNumberIsBankCharge = yes 
                then do:
                    assign vcMessage = trim(substitute(#T-42'Bank charges should not be enabled for bank number &1.':255(123388855)T-42#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                           oiReturnStatus = -1.
                    <M-2 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-433048':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end.
                if t_sBankNumber.tcBankChargeGLCode <> "":U and t_sBankNumber.tcBankChargeGLCode <> ?
                then do:
                    assign vcMessage = trim(substitute(#T-19'The bank charge account must be blank for bank number &1.':255(694890854)T-19#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                           oiReturnStatus = -1.
                    <M-80 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-856023':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end.
                <Q-13 run CreditorPrim (all) (Read) (Cache)
                   (input viCompanyId, (CompanyId)
                    input ?, (CreditorId)
                    input t_sBankNumber.tcParentObjectCode, (CreditorCode)
                    output dataset tqCreditorPrim) in BCreditor >
                find first tqCreditorPrim no-error.
                if available tqCreditorPrim
                then assign t_sBankNumber.ParentObject_ID = tqCreditorPrim.tiCreditor_ID. 
                else do:
                   assign vcMessage = trim(substitute(#T-73'The specified supplier (bank account: &1) is not defined.':200(398)T-73#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                          oiReturnStatus = -1.
                   <M-81 run SetMessage
                      (input  vcMessage (icMessage), 
                       input  '':U (icArguments), 
                       input  '':U (icFieldName), 
                       input  '':U (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  '':U (icRowid), 
                       input  'qadfin-881046':U (icFcMsgNumber), 
                       input  '' (icFcExplanation), 
                       input  '' (icFcIdentification), 
                       input  '' (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end. /*else do*/
            end. /* Creditor */
            when {&BANKNUMBERPARENTTYPE-DEBTOR}
            then do:
                if t_sBankNumber.BankNumberIsBankCharge = yes 
                then do:
                    assign vcMessage = trim(substitute(#T-68'Bank charges should not be enabled for bank number &1.':255(123388855)T-68#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                           oiReturnStatus = -1.
                    <M-77 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-900682':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end.
                if t_sBankNumber.tcBankChargeGLCode <> "":U and t_sBankNumber.tcBankChargeGLCode <> ?
                then do:
                    assign vcMessage = trim(substitute(#T-84'The bank charge account must be blank for bank number &1.':255(694890854)T-84#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                           oiReturnStatus = -1.
                    <M-91 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'qadfin-910003':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end.
                <Q-14 run DebtorPrim (all) (Read) (Cache)
                   (input viCompanyId, (CompanyId)
                    input t_sBankNumber.tcParentObjectCode, (DebtorCode)
                    input ?, (Debtor_ID)
                    output dataset tqDebtorPrim) in BDebtor >
                find first tqDebtorPrim no-error.
                if available tqDebtorPrim
                then assign t_sBankNumber.ParentObject_ID = tqDebtorPrim.tiDebtor_ID. 
                else do:
                   assign vcMessage = trim(substitute(#T-56'The specified customer (bank account: &1) is not defined.':200(399)T-56#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                          oiReturnStatus = -1.
                   <M-53 run SetMessage
                      (input  vcMessage (icMessage), 
                       input  '':U (icArguments), 
                       input  '':U (icFieldName), 
                       input  '':U (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  '':U (icRowid), 
                       input  'qadfin-853266':U (icFcMsgNumber), 
                       input  '' (icFcExplanation), 
                       input  '' (icFcIdentification), 
                       input  '' (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end. /*else do*/            
            end. /* Debtor */
            when {&BANKNUMBERPARENTTYPE-EMPLOYEE}
            then do:    
                <Q-15 run EmployeePrim (all) (Read) (Cache)
                   (input ?, (EmployeeId)
                    input t_sBankNumber.tcParentObjectCode, (EmployeeCode)
                    input viCompanyId, (CompanyId)
                    output dataset tqEmployeePrim) in BEmployee >
                find first tqEmployeePrim no-error.
                if available tqEmployeePrim
                then assign t_sBankNumber.ParentObject_ID = tqEmployeePrim.tiEmployee_ID. 
                else do:
                   assign vcMessage = trim(substitute(#T-90'The specified employee (bank account: &1) is not defined.':200(400)T-90#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                          oiReturnStatus = -1.
                   <M-45 run SetMessage
                      (input  vcMessage (icMessage), 
                       input  '':U (icArguments), 
                       input  '':U (icFieldName), 
                       input  '':U (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  '':U (icRowid), 
                       input  'qadfin-483938':U (icFcMsgNumber), 
                       input  '' (icFcExplanation), 
                       input  '' (icFcIdentification), 
                       input  '' (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end. /*else do*/            
            end. /* Employee */
            when {&BANKNUMBERPARENTTYPE-GL}
            then do:
                <Q-16 run GLPrim (all) (Read) (Cache)
                   (input viCompanyId, (CompanyId)
                    input t_sBankNumber.tcParentObjectCode, (GLCode)
                    input ?, (GLId)
                    output dataset tqGLPrim) in BGL >
                find first tqGLPrim no-error.
                if available tqGLPrim
                then assign t_sBankNumber.ParentObject_ID = tqGLPrim.tiGL_ID. 
                else do:
                   assign vcMessage = trim(substitute(#T-229'The specified  GL account (bank account: &1) is not defined.':200(401)T-229#, 
                                      trim(t_sBankNumber.BankNumber))) + chr(10) + program-name(1)
                          oiReturnStatus = -1.
                   <M-92 run SetMessage
                      (input  vcMessage (icMessage), 
                       input  '':U (icArguments), 
                       input  '':U (icFieldName), 
                       input  '':U (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  '':U (icRowid), 
                       input  'qadfin-800824':U (icFcMsgNumber), 
                       input  '' (icFcExplanation), 
                       input  '' (icFcIdentification), 
                       input  '' (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                end. /*else do*/
            end. /* G/L */
            otherwise assign t_sBankNumber.ParentObject_ID = ?.
    end case.

    /* If tlExistRecord is true, the program will try to find a unique existing record
     * using BankNumber and Supplier/Customer. Then do the update.
     * If it is false, the program will create a new bank number for the Supplier/Customer.
     */
     <Q-82 run BankNumberForParentObject2 (all) (Read) (NoCache)
        (input viCompanyId, (CompanyId)
         input t_sBankNumber.ParentObject_ID, (ParentObjectID)
         input t_sBankNumber.BankNumber, (BankNumber)
         input t_sBankNumber.tcOwnBankNumber, (OwnBankNumber)
         input t_sBankNumber.tcPayFormatTypeCode, (PayFormatTypeCode)
         output dataset tqBankNumberForParentObject2) in BBankNumber>
    if t_sBankNumber.tlExistRecord = false 
    then do :
        find first  bt_sBankNumber where 
                     bt_sBankNumber.ParentObject_ID     = t_sBankNumber.ParentObject_ID     and
                     bt_sBankNumber.BankNumber          = t_sBankNumber.BankNumber          and
                     bt_sBankNumber.tcOwnBankNumber     = t_sBankNumber.tcOwnBankNumber     and
                     bt_sBankNumber.tcPayFormatTypeCode = t_sBankNumber.tcPayFormatTypeCode and
                     bt_sBankNumber.BankNumberExtension = t_sBankNumber.BankNumberExtension and
                     bt_sBankNumber.tcOwnGLCode         = t_sBankNumber.tcOwnGLCode         and
                     bt_sBankNumber.tc_Rowid            <> t_sBankNumber.tc_Rowid
                     no-error .
          if available  bt_sBankNumber 
          then assign vlDuplicateGl = true .
          
          if vlDuplicateGl = false 
          then do : 
              <Q-69 run BankNumberForOwnBankNumber (all) (Read) (NoCache)
                 (input viCompanyId, (CompanyId)
                  input t_sBankNumber.tcOwnBankNumber, (OwnBankNumber)
                  input t_sBankNumber.tcOwnGLCode, (OwnGLCode)
                  input t_sBankNumber.tcPayFormatTypeCode, (PayFormatTypeCode)
                  output dataset tqBankNumberForOwnBankNumber) in BBankNumber>        
                   
            find first tqBankNumberForOwnBankNumber where
                       tqBankNumberForOwnBankNumber.tcOwnBankNumber     = t_sBankNumber.tcOwnBankNumber and
                       tqBankNumberForOwnBankNumber.tcPayFormatTypeCode = t_sBankNumber.tcPayFormatTypeCode
                       no-error.
            if available tqBankNumberForOwnBankNumber
            then assign t_sBankNumber.BankPayFormat_ID = tqBankNumberForOwnBankNumber.tiBankPayFormat_ID .
             
            if can-find(first tqBankNumberForParentObject2 where
                              tqBankNumberForParentObject2.tiParentObject_ID     = t_sBankNumber.ParentObject_ID     and
                              tqBankNumberForParentObject2.tcBankNumber          = t_sBankNumber.BankNumber          and
                              tqBankNumberForParentObject2.tcOwnBankNumber       = t_sBankNumber.tcOwnBankNumber     and
                              tqBankNumberForParentObject2.tcPayFormatTypeCode   = t_sBankNumber.tcPayFormatTypeCode and 
                              tqBankNumberForParentObject2.tiBankPayFormat_ID    = t_sBankNumber.BankPayFormat_ID    and 
                              tqBankNumberForParentObject2.tcBankNumberExtension = t_sBankNumber.BankNumberExtension )
            then  assign vlDuplicateGl = true .
         end .
         
         if vlDuplicateGl = true 
         then do :
                        
             assign oiReturnStatus = -1.
             assign vcMessage = #T-6'This GL account appears at least twice.  Please check your input for duplicate GL accounts.':255(742970880)T-6# .
             <M-527 run SetMessage
                (input  vcMessage (icMessage), 
                 input  '':U (icArguments), 
                 input  't_sBankNumber.tcOwnGLCode':U (icFieldName), 
                 input  t_sBankNumber.tcOwnGLCode (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  t_sBankNumber.tc_Rowid (icRowid), 
                 input  'qadfin-798429':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BBankNumber>   
                    
        end.
    end.
    if t_sBankNumber.tlExistRecord = true
    then do:
       
        /* Check whether it can find the records via the Customer/Supplier and BankNumber */
        if can-find(first tqBankNumberForParentObject2 where
                          tqBankNumberForParentObject2.tiParentObject_ID     = t_sBankNumber.ParentObject_ID  and
                          tqBankNumberForParentObject2.tcBankNumber          = t_sBankNumber.BankNumber       and 
                          tqBankNumberForParentObject2.tcOwnBankNumber       =  t_sBankNumber.tcOwnBankNumber and 
                          tqBankNumberForParentObject2.tcPayFormatTypeCode   = t_sBankNumber.tcPayFormatTypeCode and 
                          tqBankNumberForParentObject2.tcBankNumberExtension = t_sBankNumber.BankNumberExtension)
        then do:
            /* Check whether it can find a unique record via the Customer/Supplier and BankNumber */
            find tqBankNumberForParentObject2 where
                 tqBankNumberForParentObject2.tiParentObject_ID     = t_sBankNumber.ParentObject_ID and
                 tqBankNumberForParentObject2.tcBankNumber          = t_sBankNumber.BankNumber      and 
                 tqBankNumberForParentObject2.tcOwnBankNumber       = t_sBankNumber.tcOwnBankNumber and 
                 tqBankNumberForParentObject2.tcPayFormatTypeCode   = t_sBankNumber.tcPayFormatTypeCode and 
                 tqBankNumberForParentObject2.tcBankNumberExtension = t_sBankNumber.BankNumberExtension no-error.
            if not available tqBankNumberForParentObject2
            then do:
                if vcActivityCode = "SupplierBankNumberExcelIntegration":U
                then do:
                    assign vcMessage = trim(substitute(#T-67'More than one BankNumber found for the combination of Supplier &1 and BankNumber &2. Update of existing record is not possible.':255(591319374)T-67#, 
                                                       trim(t_sBankNumber.tcParentObjectCode), 
                                                       trim(t_sBankNumber.BankNumber) )).
                end.
                else if vcActivityCode = "CustomerBankNumberExcelIntegration":U
                then do:
                    assign vcMessage = trim(substitute(#T-79'More than one BankNumber found for the combination of Customer &1 and BankNumber &2. Update of existing record is not possible.':255(779893960)T-79#, 
                                                       trim(t_sBankNumber.tcParentObjectCode), 
                                                       trim(t_sBankNumber.BankNumber) )).
                end.
                assign oiReturnStatus = -1.
                <M-65 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sBankNumber.tc_Rowid (icRowid), 
                    input  'QadFin-9826':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
                next PROCESSBLOCK.
            end. /* if not available tqBankNumberForParentObject2 */
        end.
        else do:
            if vcActivityCode = "SupplierBankNumberExcelIntegration":U
            then do:
                assign vcMessage = trim(substitute(#T-64'No BankNumber found for the combination of Supplier &1 and BankNumber &2. Update of existing record is not possible.':255(332099381)T-64#, 
                                                   trim(t_sBankNumber.tcParentObjectCode), 
                                                   trim(t_sBankNumber.BankNumber) )).
            end.
            else if vcActivityCode = "CustomerBankNumberExcelIntegration":U
            then do:
                assign vcMessage = trim(substitute(#T-87'No BankNumber found for the combination of Customer &1 and BankNumber &2. Update of existing record is not possible.':255(954600931)T-87#, 
                                                   trim(t_sBankNumber.tcParentObjectCode), 
                                                   trim(t_sBankNumber.BankNumber) )).
            end.
            assign oiReturnStatus = -1.
            <M-62 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sBankNumber.tc_Rowid (icRowid), 
                input  'QadFin-9825':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            next PROCESSBLOCK.
        end. /* if can-find(first tqBankNumberForParentObject2 where */
    end. /* if t_sBankNumber.tlExistRecord = true */

    if vcActivityCode <> "Create":U
    then do:
        if last(t_sBankNumber.tc_Rowid)
        then assign vlRunCalculate = true.
        else assign vlRunCalculate = false.
        
        find first tqBankNumberForParentObject2 where
            tqBankNumberForParentObject2.tiParentObject_ID     = t_sBankNumber.ParentObject_ID     and
            tqBankNumberForParentObject2.tcBankNumber          = t_sBankNumber.BankNumber          and
            tqBankNumberForParentObject2.tcOwnBankNumber       = t_sBankNumber.tcOwnBankNumber     and 
            tqBankNumberForParentObject2.tcPayFormatTypeCode   = t_sBankNumber.tcPayFormatTypeCode and 
            tqBankNumberForParentObject2.tcBankNumberExtension = t_sBankNumber.BankNumberExtension no-error.    
        if available tqBankNumberForParentObject2
        then do:        
            <M-57 run DataLoad
               (input  '' (icRowids), 
                input  string(tqBankNumberForParentObject2.tiBankNumber_ID) (icPkeys), 
                input  '' (icObjectIds), 
                input  '' (icFreeform), 
                input  yes (ilKeepPrevious), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            if viFcReturnSuper >= 0
            then find first tBankNumber where tBankNumber.BankNumber_ID = t_sBankNumber.BankNumber_ID no-error.
        end.
    end.

    /* ================================================================= */
    /* When in delete mode, ignore input data.                           */
    /* When object not found, do not return an error.                    */
    /* ================================================================= */
    if vcActivityCode = "Delete":U
    then do:
        if viFcReturnSuper = -4
        then delete t_sBankNumber.
        else do:
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then leave PROCESSBLOCK.
    
            /* ================================================================= */
            /* Update input to allow correct matching                            */
            /* ================================================================= */
            assign t_sBankNumber.tc_Rowid  = tBankNumber.tc_Rowid
                   t_sBankNumber.tc_ParentRowid = ""
                   opPrimeKey   = (if opPrimeKey = "" then "" else opPrimeKey + chr(4))
                                + string(tBankNumber.BankNumber_ID).
        end.

        next.
    end.

    if vcActivityCode = "Create":U
    or viFcReturnSuper = -4
    or not available tBankNumber
    or  (t_sBankNumber.tlExistRecord = false
    and (vcActivityCode = "SupplierBankNumberExcelIntegration":U
    or   vcActivityCode = "CustomerBankNumberExcelIntegration":U))
    then do:
        /* ================================================================= */
        /* When object not found and in modify only mode, return an error.   */
        /* ================================================================= */
        if vcActivityCode = "Modify":U
        then do:
            assign
                vcMessage = trim(#T-60'Object with key $1 does not exist.':100(48021)T-60#).
            <M-58 run SetMessage
               (input  vcMessage (icMessage), 
                input  t_sBankNumber.BankNumber (icArguments), 
                input  'tBankNumber.BankNumber':U (icFieldName), 
                input  t_sBankNumber.BankNumber (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sBankNumber.tc_Rowid (icRowid), 
                input  'QadFin-9824':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber>                      
            assign oiReturnStatus = -1.
            leave PROCESSBLOCK.
        end.
        
        /* ================================================================= */
        /* When object not found or in create mode, create it.               */
        /* ================================================================= */
        <M-59 run AddDetailLine (input  'BankNumber':U (icTable), 
                        input  '' (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>                

        /* ================================================================= */
        /* Update input to allow correct matching                            */
        /* ================================================================= */
        assign t_sBankNumber.tc_Status = "N":U.
    end.
    else do:
        /* ================================================================= */
        /* Update input to allow correct matching                            */
        /* ================================================================= */
        assign t_sBankNumber.tc_Status = "C":U.
    end.

    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave PROCESSBLOCK.

    /* insert code for subtables here: BankNumberPayCode */

    /* ================================================================= */
    /* Delete existing detail                                            */
    /* ================================================================= */
    for each tBankNumberPayCode where
             tBankNumberPayCode.tc_ParentRowid = tBankNumber.tc_Rowid:
        assign tBankNumberPayCode.tc_Status = "D":U.
    end.
    /* C/S Bank Conversion  begin */
    
    assign t_sBankNumber.BankNumber_ID = tBankNumber.BankNumber_ID.

    /* ================================================================= */
    /* Update / add detail                                               */
    /* ================================================================= */
    for each t_sBankNumberPayCode where
             t_sBankNumberPayCode.tc_ParentRowid = t_sBankNumber.tc_Rowid and
             t_sBankNumberPayCode.tc_Status      <> "D":U:
        assign t_sBankNumberPayCode.BankNumber_ID = t_sBankNumber.BankNumber_ID.
        /* We need payformatgroup_id */
        <Q-7 run PayFormatGroupPrim (all) (Read) (NoCache)
           (input ?, (PayFormatGroupID)
            input t_sBankNumberPayCode.tcPayFormatTypeCode, (PayFormatTypeCode)
            input t_sBankNumberPayCode.tiPayFormatGroupSequence, (PayFormatGroupSequence)
            output dataset tqPayFormatGroupPrim) in BPaymentFormat >
        find first tqPayFormatGroupPrim where
                   tqPayFormatGroupPrim.tcPayFormatTypeCode      = t_sBankNumberPayCode.tcPayFormatTypeCode and
                   tqPayFormatGroupPrim.tiPayFormatGroupSequence = t_sBankNumberPayCode.tiPayFormatGroupSequence
                   no-error.
        if not available tqPayFormatGroupPrim 
        then do:
            assign vcMessage    = trim(substitute(#T-51'The Payment Format Group with type &1 and sequence &2 was not found.':255(999890815)T-51#, 
                                                  trim(t_sBankNumberPayCode.tcPayFormatTypeCode), 
                                                  trim(string(t_sBankNumberPayCode.tiPayFormatGroupSequence)) ))
                   oiReturnStatus = -1.
            <M-52 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sBankNumberPayCode.tc_Rowid (icRowid), 
                input  'QadFin-9342':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            leave PROCESSBLOCK.
        end. /* if not available tqPayFormatGroupPrim */
        
        find first tBankNumberPayCode where 
                   tBankNumberPayCode.tc_ParentRowid     = tBankNumber.tc_Rowid               and 
                   tBankNumberPayCode.BankNumber_ID      = t_sBankNumberPayCode.BankNumber_ID and 
                   tBankNumberPayCode.PayFormatGroup_ID  = t_sBankNumberPayCode.PayFormatGroup_ID
                   no-error.
        if available tBankNumberPayCode
        then assign t_sBankNumberPayCode.tc_Status = "C":U.
        else do:
            <M-5 run AddDetailLine (input  'BankNumberPayCode':U (icTable), 
                        input  tBankNumber.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then leave PROCESSBLOCK.
            assign t_sBankNumberPayCode.BankNumber_ID     = tBankNumber.BankNumber_ID
                   tBankNumberPayCode.BankNumber_ID       = tBankNumber.BankNumber_ID
                   t_sBankNumberPayCode.PayFormatGroup_ID = tqPayFormatGroupPrim.tiPayFormatGroup_ID
                   tBankNumberPayCode.PayFormatGroup_ID   = tqPayFormatGroupPrim.tiPayFormatGroup_ID
                   t_sBankNumberPayCode.tc_Status         = "N":U.
        end.
        

        /* ================================================================= */
        /* override value for identity fields in input                       */
        /* ================================================================= */
        assign 
            t_sBankNumberPayCode.BankNumberPayCode_ID = tBankNumberPayCode.BankNumberPayCode_ID

            /* ================================================================= */
            /* Update input to allow correct matching                            */
            /* ================================================================= */
            t_sBankNumberPayCode.BankNumber_ID = tBankNumberPayCode.BankNumber_ID
            t_sBankNumberPayCode.tc_Rowid       = tBankNumberPayCode.tc_Rowid
            t_sBankNumberPayCode.tc_ParentRowid = tBankNumber.tc_Rowid.
            
        if vcActivityCode = "SupplierBankNumberExcelIntegration":U or 
           vcActivityCode = "CustomerBankNumberExcelIntegration":U
        then do:
            <Q-49 run PayFormatCodebyGroupID (all) (Read) (NoCache)
               (input ?, (PayFormatCodeID)
                input t_sBankNumberPayCode.BankNumberPayCodeValue, (PayFormatCode)
                input t_SBankNumberPayCode.PayFormatGroup_ID, (PayFormatGroupID)
                output dataset tqPayFormatCodebyGroupID) in BPaymentFormat>
           
            if vcActivityCode = "SupplierBankNumberExcelIntegration":U
            then do:
                find first tqPayFormatCodebyGroupID where 
                           tqPayFormatCodebyGroupID.tlPayFormatCodeIsDefault = True
                no-error.
                
                if available tqPayFormatCodebyGroupID
                then do:
                    assign t_sBankNumberPayCode.PayFormatCode_ID       = tqPayFormatCodebyGroupID.tiPayFormatCode_ID
                           t_sBankNumberPayCode.BankNumberPayCodeValue = tqPayFormatCodebyGroupID.tcPayFormatCode.
                end. /* if available tqPayFormatCodebyGroupID */
            end. /* if vcActivityCode = "SupplierBankNumberExcelIntegration" */
            else do:
                find first tqPayFormatCodebyGroupID no-error.
                
                if available tqPayFormatCodebyGroupID
                then assign t_sBankNumberPayCode.PayFormatCode_ID = tqPayFormatCodebyGroupID.tiPayFormatCode_ID.
            end. /* else do */       
        end. /* if vcActivityCode = "SupplierBankNumberExcelIntegration":U */
    end.  /* for each t_sBankNumberPayCode */
    
    
    /* END of C/S Bank Conversion */
    
    /* ================================================================= */
    /* override value for identity fields in input                       */
    /* ================================================================= */
    assign t_sBankNumber.BankNumber_ID = tBankNumber.BankNumber_ID

    /* ================================================================= */
    /* Update input to allow correct matching                            */
    /* ================================================================= */
           t_sBankNumber.tc_Rowid  = tBankNumber.tc_Rowid
           t_sBankNumber.tc_ParentRowid = ""

           opPrimeKey       = (if opPrimeKey = "" then "" else opPrimeKey + chr(4))
                            + string(tBankNumber.BankNumber_ID).
end.
/* stop quries */
<Q-25 run DebtorPrim  (Stop) in BDebtor >
<Q-26 run CreditorPrim  (Stop) in BCreditor >
<Q-27 run EmployeePrim  (Stop) in BEmployee >
<Q-28 run GLPrim  (Stop) in BGL >
<Q-29 run PayFormatGroupPrim  (Stop) in BPaymentFormat >
<Q-63 run BankNumberForParentObject  (Stop) in BBankNumber >

if oiReturnStatus = -98
then oiReturnStatus = 0.