project QadFinancials > class BBankEntry > method GetNewBankStateNumberIncrease


Parameters


icBankStateNumberinputcharacterThis method increases the numerical part of the BankStateNumber with 1. The formatting is very important here.
ocNewBankStateNumberoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.GetNewBankStateNumber


program code (program6/bbankentry.p)

/* ======================================================================================== */
/* Make the split (if any) between the last numerical part and the first alfanumerical part */
/* ======================================================================================== */
assign vcAlphaNumericPart = '':U
       vcNumericPart      = icBankStateNumber.

do viCounter = LENGTH(icBankStateNumber,"CHARACTER":U) TO 1 BY -1 :

    if substring(icBankStateNumber,viCounter,1,"CHARACTER":U) < "0":U or
       substring(icBankStateNumber,viCounter,1,"CHARACTER":U) > "9":U 
    then do :
        assign vcAlphaNumericPart = substring(icBankStateNumber,1,viCounter,"CHARACTER":U)
               vcNumericPart      = substring(icBankStateNumber,viCounter + 1,-1,"CHARACTER":U).
        leave.
    end. 

end. /* do */

/* =========================================================================================================*/
/* Calculate the max limit which can be hold within this format - for a format of 99999 this will be 100000 */
/* =========================================================================================================*/
assign viLimit = 1.
do viCounter = LENGTH(vcNumericPart,"CHARACTER":U) TO 1 BY -1 :
    assign viLimit = viLimit * 10.
end.
            
if vcNumericPart = '':U or vcNumericPart = '0':U
then assign viHighestNumericPart = 0.
else do :
    assign viHighestNumericPart = integer(vcNumericPart) no-error.
    if error-status:error
    then assign viHighestNumericPart = 0.
end.

/* =========================================================================================================*/
/* Increase the numeric part with 1                                                                         */
/* =========================================================================================================*/
assign viHighestNumericPart = viHighestNumericPart + 1.

/* =========================================================================================================*/
/* Format the new number                                                                                    */
/* - if it is a new numberdefault of 5 positions is used                                                    */
/* - if the highest (limit) is reached for this format, just return without formatting:  abc-999-->abc1000  */
/* - apply the current format when it is less than 9 positions                                              */
/* =========================================================================================================*/
if viHighestNumericPart = 1
then do:
    /* This is a new number - the default format is with 5 positions */
    assign ocNewBankStateNumber = string(viHighestNumericPart,"999999":U).
end.
else
IF  viHighestNumericPart < viLimit /* the new number still fits the format */
then do :
    if LENGTH(vcNumericPart,"CHARACTER":U) = 1
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"9":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 2
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"99":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 3
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"999":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 4
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"9999":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 5
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"99999":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 6
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"999999":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 7
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"9999999":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 8
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"99999999":U).
    else
    if LENGTH(vcNumericPart,"CHARACTER":U) = 9
    then assign ocNewBankStateNumber = string(viHighestNumericPart,"999999999":U).
    else ocNewBankStateNumber = string(viHighestNumericPart).
end.
else do:
    assign ocNewBankStateNumber = string(viHighestNumericPart).
end.

/* =========================================================================================================*/
/* Add the AlphaNumericPart again                                                                           */
/* =========================================================================================================*/
if vcAlphaNumericPart <> ''
then assign ocNewBankStateNumber = vcAlphaNumericPart + ocNewBankStateNumber.