Description
This method is used to import the input bank file into database.
Parameters
icBankFIle | input | character | Bank File to be imported. Input bank file should contain an empty line in the bottom of the file, or the last line would not be imported. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bbankimport.p)
assign oiReturnStatus = -98
icBankFile = search(icBankFile).
/* output to "C:\ych.log". */
if icBankFile = "":U or icBankFile = ?
then do:
assign vcMsg = "No input file or file does not exist":U.
<M-1 run SetMessage
(input vcMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7673':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankImport>
assign oiReturnStatus = -1.
return.
end.
else do:
<M-4 run AddDetailLine
(input 'BankImp':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
assign viTempRowId = 1.
input from value(icBankFile) no-echo.
repeat:
import unformatted vcLine.
if substring(vcLine, 1, 2, "character":U) = "H1":U
then do:
assign vcBankImpOwnBankNumber = trim(substring(vcLine, 4, 10, "character":U)).
end.
else if substring(vcLine, 1, 1, "character":U) = "R":U
then do:
create tBankImportLine.
assign
tBankImportLine.BankImpLineTransType = substring(vcLine, 1, 3, "character":U) + substring(vcLine, 14, 3, "character":U)
tBankImportLine.BankImpLineSeq = integer(substring(vcLine, 4, 10, "character":U))
tBankImportLine.BankImpLineValueDate = date(integer(substring(vcLine, 33, 2, "character":U)),
integer(substring(vcLine, 35, 2, "character":U)),
integer("20":U + substring(vcLine, 37, 2, "character":U)))
tBankImportLine.BankImpLineCreditorName = if substring(vcLine, 14, 2, "character":U) = "05":U
then trim(substring(vcLine, 39, 41, "character":U))
else "":U
tBankImportLine.BankImpLineDebtorName = if substring(vcLine, 14, 2, "character":U) = "00":U
then trim(substring(vcLine, 39, 41, "character":U))
else "":U
tBankImportLine.BankImpLineInfo = trim(substring(vcLine, 80, 80, "character":U))
tBankImportLine.BankImpLineOwnBankNumber = vcBankImpOwnBankNumber
tBankImportLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-NOT-PROCESSED}
tBankImportLine.BankImpLineBusRelType = if substring(vcLine, 14, 2, "character":U) = "00":U
then {&BANKIMPBUSRELTYPE-DEBTOR}
else if substring(vcLine, 14, 2, "character":U) = "05":U
then {&BANKIMPBUSRELTYPE-CREDITOR}
else "":U
tBankImportLine.BankImpLineAmountTC = if substring(vcLine, 14, 2, "character":U) = "00":U
then decimal(substring(vcLine, 23, 10, "character":U)) / 100
else if substring(vcLine, 14, 2, "character":U) = "05":U
then - decimal(substring(vcLine, 23, 10, "character":U)) / 100
else 0
tBankImportLine.BankImpLineCurrencyCode = "USD":U
tBankImportLine.BankImpLineFileFormatCode = "USBank":U
tBankImportLine.BankImp_ID = tBankImp.BankImp_ID
tBankImportLine.tc_ParentRowid = tBankImp.tc_Rowid
tBankImportLine.BankImpLine_ID = viTempRowId
tBankImportLine.tc_Rowid = string(viTempRowId)
viTempRowId = viTempRowId + 1.
end.
else if substring(vcLine, 1, 2, "character":U) = "T1":U
then do:
assign
viBankImpLinesCount = integer(substring(vcLine, 4, 6, "character":U)) + integer(substring(vcLine, 24, 6, "character":U))
vdBankImpTotalAmountInTC = decimal(substring(vcLine, 11, 11, "character":U)) / 100
vdBankImpTotalAmountOutTC = decimal(substring(vcLine, 31, 11, "character":U)) / 100.
end.
end.
input close.
if opsys = "UNIX":U then viPathSeparator = 47. /* Unix - "/" chr(47) */
else if opsys = "WIN32":U then viPathSeparator = 92. /* Windows - "\" chr(92) */
do while index(icBankFile, chr(viPathSeparator)) <> 0:
assign icBankFile = substring(icBankFile, index(icBankFile, chr(viPathSeparator)) + 1, 256, "character":U).
end.
assign tBankImp.BankImpLinesCount = viBankImpLinesCount
tBankImp.BankImpTotalAmountInTC = vdBankImpTotalAmountInTC
tBankImp.BankImpTotalAmountOutTC = vdBankImpTotalAmountOutTC
tBankImp.BankImpLoadedDate = today
tBankImp.BankImpLoadedTime = integer(time)
tBankImp.BankImpCurrencyCode = "USD":U
tBankImp.BankImpFileType = "USBank":U
tBankImp.BankImpFileName = icBankFile.
<I-5 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBankImportLine"}>
<M-6 run UpdateBankImportLine
(input temp-table tBankImportLine:default-buffer-handle (ihBankImportLines),
input tBankImp.tc_Rowid (icParentRowid),
input tBankImp.BankImp_ID (iiBankImpID),
output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-7 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-8 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-9 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-10 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBankImport>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end.
if oiReturnStatus = -98 then assign oiReturnStatus = 0.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BBankImport".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiImportUSBank".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bbankimport.apiimportusbank.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icBankFIle = <parameter value>.
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.