project QadFinancials > class BDebtor > method ApiCheckCreditLimit


Parameters


iiDebtorIdinputinteger
icDebtorCodeinputcharacter
idCurrentAmountinputdecimal
idOldAmountinputdecimal
icCurrencyCodeinputcharacter
icContextinputcharacter
itExchangeRateDateinputdateThis date is used to retrieve the exchange rate. If the date is not filled, it will be defaulted by today.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.DefaultValuesDebtor
method BDInvoice.ValidateComponentAll


program code (program9/bdebtor.p)

if iiDebtorId         = ? then assign iiDebtorId         = 0.
if icDebtorCode       = ? then assign icDebtorCode       = "":U.
if idCurrentAmount    = ? then assign idCurrentAmount    = 0.
if idOldAmount        = ? then assign idOldAmount        = 0.
if icCurrencyCode     = ? then assign icCurrencyCode     = "":U.
if itExchangeRateDate = ? then assign itExchangeRateDate = today.

if icContext = {&DEBTORCREDITLIMIT-BEFORESQ}
then do:
    assign
        icContext = {&DEBTORCREDITLIMIT-BEFORESO}
        vlIsSalesQuote = true.
end.

if icContext = {&DEBTORCREDITLIMIT-AFTERSQ}
then do:
    assign
        icContext = {&DEBTORCREDITLIMIT-AFTERSO}
        vlIsSalesQuote = true.
end.

/* We need a debtor, or we cannot continue */
if iiDebtorId   = 0 and
   icDebtorCode = "":U
then do:
    <M-2 run SetMessage
       (input  trim(#T-1'If you want to continue the credit limit check, you must enter a customer code.':255(999890128)T-1#) (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-3049':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    assign oiReturnStatus = -1.
    return.
    
end.

/* If a current or old amount is specified, we need their currency code */
if (idCurrentAmount <> 0  or
    idOldAmount     <> 0) and
    icCurrencyCode   = "":U
then do:
    <M-6 run SetMessage
       (input  trim(#T-3'If you want to continue the credit limit check, you must enter a currency code for the current and for the old amount.':255(999890129)T-3#) (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-3056':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    assign oiReturnStatus = -1.
    return.
    
end.

/* Get the credit limit info for the debtor */
<Q-50 run DebtorByCreditLimitInfo (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input iiDebtorId, (DebtorId)
    input icDebtorCode, (DebtorCode)
    output dataset tqDebtorByCreditLimitInfo) in BDebtor >

find first tqDebtorByCreditLimitInfo where
           tqDebtorByCreditLimitInfo.tiDebtor_ID  = (if iiDebtorId = 0
                                                     then tqDebtorByCreditLimitInfo.tiDebtor_ID
                                                     else iiDebtorId) and
           tqDebtorByCreditLimitInfo.tcDebtorCode = (if iiDebtorId = 0
                                                     then icDebtorCode
                                                     else tqDebtorByCreditLimitInfo.tcDebtorCode)
           no-error.

if not available tqDebtorByCreditLimitInfo
then do:
    <M-4 run SetMessage
       (input  trim(#T-2'Invalid customer (ID: $1, code $2). Unable to continue the credit limit check.':255(999890127)T-2#) (icMessage), 
        input  string(iiDebtorId) + chr(2) + string(icDebtorCode) (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-3051':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    assign oiReturnStatus = -1.
    return.
  
end.

/* If debtor is on "Credit hold", no any other SO or Inv can be created for him */
if tqDebtorByCreditLimitInfo.tlDebtorIsLockedCredLim = true
then do:

    <M-51 run SetMessage
       (input  #T-53'This customer is on credit hold.':150(64033)T-53# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8115':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    assign oiReturnStatus = -1.
    return.        
end.

/* If no credit check options are true, stop here */
if tqDebtorByCreditLimitInfo.tlDebtorIsFixedCredLim      <> true and
   tqDebtorByCreditLimitInfo.tlDebtorIsMaxDaysDueCredLim <> true and
   tqDebtorByCreditLimitInfo.tlDebtorIsTurnOverCredLim   <> true
then return.

/* Return if check is not to be performed for specified context */
if (icContext = {&DEBTORCREDITLIMIT-BEFORESO} and not tqDebtorByCreditLimitInfo.tlDebtorIsCheckBefSOCredLim) or
   (icContext = {&DEBTORCREDITLIMIT-AFTERSO} and not tqDebtorByCreditLimitInfo.tlDebtorIsCheckAftSOCredLim) or
   (icContext = {&DEBTORCREDITLIMIT-BEFOREDI} and not tqDebtorByCreditLimitInfo.tlDebtorIsCheckBefDICredLim) or
   (icContext = {&DEBTORCREDITLIMIT-AFTERDI} and not tqDebtorByCreditLimitInfo.tlDebtorIsCheckAftDICredLim) 
then return.

/* Determine whether overrule is set for specified context */
/*IN SALES ORDER CONTEXT OVERRULE ALLOWED FLAG IS NOT USED AND WILL BE SET TO TRUE ALWAYS. 
IT HAS TO GIVE ERROR IREESPECTIVE OF FLAG. 
THIS PROGRAM GIVE ERROR WHEN VLOVERRULEALLOWED IS FALSE. SO SET IT TO FALSE IN CASE OF SALES ORDER*/
if (icContext = {&DEBTORCREDITLIMIT-BEFORESO} or icContext = {&DEBTORCREDITLIMIT-AFTERSO}) then 
  vlOverruleAllowed = false.
  
if (icContext = {&DEBTORCREDITLIMIT-BEFOREDI}  or icContext = {&DEBTORCREDITLIMIT-AFTERDI} ) then 
  vlOverruleAllowed = tqDebtorByCreditLimitInfo.tlDebtorIsOverruleDICredLim.
  
/* Calculate the balances if necessary */
if tqDebtorByCreditLimitInfo.tlDebtorIsFixedCredLim or
   tqDebtorByCreditLimitInfo.tlDebtorIsTurnOverCredLim
then do:
    <M-5 run CalculateBalances
       (input  tqDebtorByCreditLimitInfo.tiDebtor_ID (iiDebtorId), 
        input  tqDebtorByCreditLimitInfo.tcDebtorCode (icDebtorCode), 
        input  tqDebtotrByCreditLimitInfo.tcCurrencyCode (icCurrencyCode), 
        input  tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim (ilSalesOrders), 
        input  tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim (ilOpenItems), 
        input  tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim (ilDrafts), 
        input  tqDebtorByCreditLimitInfo.tlDebtorIsTurnOverCredLim (ilCreditOnTurnover), 
        input  tqDebtorByCreditLimitInfo.tdDebtorPercTurnOverCredLim (idPercentageOfTurnover), 
        output vdSOBalance (odSOBalance), 
        output vdOIBalance (odOIBalance), 
        output vdDraftBalance (odDraftBalance), 
        output vdCreditOnTurnover (odCreditOnTurnover), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.

    assign vdTotalBalance = 
        (if(tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim) then vdSOBalance else 0) + 
        (if(tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim) then vdOIBalance else 0) +
        (if (tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim) then vdDraftBalance else 0).

    if idCurrentAmount <> 0 or
       idOldAmount     <> 0
    then do:
        if tqDebtorByCreditLimitInfo.tcCurrencyCode = icCurrencyCode
        then assign vdTotalBalance = vdTotalBalance + idCurrentAmount - idOldAmount.
        else do:
            
            <M-77 run GetExchangeRate
               (input  viCompanyID (iiCompanyID), 
                input  ? (iiFromCurrencyID), 
                input  icCurrencyCode (icFromCurrencyCode), 
                input  ? (iiToCurrencyID), 
                input  tqDebtorByCreditLimitInfo.tcCurrencyCode (icToCurrencyCode), 
                input  ? (iiExchangeRateTypeID), 
                input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                input  itExchangeRateDate (itValidityDate), 
                output vdRate (odExchangeRate), 
                output vdRateScale (odExchangeScaleFactor), 
                output viFcReturnSuper (oiReturnStatus)) in BDebtor>
                
            if viFcReturnSuper < 0 or
               oiReturnStatus  = 0
            then assign oiReturnStatus = viFcReturnSuper.

            if oiReturnStatus < 0
            then return.

            assign vdTotalBalance = vdTotalBalance +
                                    <M-38 RoundAmount
                                       (input  (idCurrentAmount - idOldAmount) * vdRate * vdRateScale (idUnroundedAmount), 
                                        input  0 (iiCurrencyID), 
                                        input  tqDebtorByCreditLimitInfo.tcCurrencyCode (icCurrencyCode)) in BApplicationProperty>.
        end.
    end.
    
end.

if icContext = {&DEBTORCREDITLIMIT-BEFORESO} and idCurrentAmount <> 0 
then vdSOBalance = vdSOBalance + idCurrentAmount.           


/* Fixed Ceiling check */
if tqDebtorByCreditLimitInfo.tlDebtorIsFixedCredLim
then do:
    assign vcMessage = "":U
           vlWarning = false.
    /* Error */
    if vdTotalBalance > tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC
    then do: 

        assign vcMessage = subst(#T-8'The credit limit for customer &1 &2 has been reached.':250(13759)T-8#, tqDebtorByCreditLimitInfo.tcDebtorCode, tqDebtorByCreditLimitInfo.tcBusinessRelationCode) + " ":U +
                           subst(#T-9'The fixed credit amount is &1 &2.':250(13764)T-9#, tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC, tqDebtorByCreditLimitInfo.tcCurrencyCode)
               vlWarning = vlOverruleAllowed.

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-10'and open items are &1 &2':250(591258605)T-10#), vdOIBalance, tqDebtorByCreditLimitInfo.tcCurrencyCode).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-12'and current sales orders are &1 &2':250(332038630)T-12#), vdSOBalance, tqDebtorByCreditLimitInfo.tcCurrencyCode).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-46'and current drafts are &1 &2':250(413933509)T-46#), vdDraftBalance, tqDebtorByCreditLimitInfo.tcCurrencyCode).

        assign vcMessage = vcMessage + ".":U.
    end.
    else 

    /* Warning */
    if tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim <> 0 and
       tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim <> ? and
       vdTotalBalance >= tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC * tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim / 100
    then do:
    
        assign vcMessage = subst(trim(#T-14'Customer &1 &2 is approaching the credit limit. &3 percent of the credit amount &4 &5 has been used.':250(13786)T-14#), tqDebtorByCreditLimitInfo.tcDebtorCode, tqDebtorByCreditLimitInfo.tcBusinessRelationCode, tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim, tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC, tqDebtorByCreditLimitInfo.tcCurrencyCode)
               vlWarning = true.

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-15'and open items are &1 &2':250(591258605)T-15#), vdOIBalance, tqDebtorByCreditLimitInfo.tcCurrencyCode).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-17'and current sales orders are &1 &2':250(332038630)T-17#), vdSOBalance, tqDebtorByCreditLimitInfo.tcCurrencyCode).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-47'and current drafts are &1 &2':250(413933509)T-47#), vdDraftBalance, tqDebtorByCreditLimitInfo.tcCurrencyCode).

        assign vcMessage = vcMessage + ".":U.
    end.

    if vcMessage <> "":U
    then do:
        <M-13 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  if vlWarning then 'W':U else 'E':U (icType), 
            input  if vlWarning then 4 else 3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3059':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtor>

        assign oiReturnStatus = if vlWarning
                                then if oiReturnStatus = 0
                                     then 1
                                     else oiReturnStatus
                                else -1.   
                                                               
    end.   
end.

/* Percentage Of Turnover check */
if tqDebtorByCreditLimitInfo.tlDebtorIsTurnOverCredLim
then do:
    assign vcMessage = "":U
           vlWarning = false.

    /* Error */
    if vdTotalBalance > vdCreditOnTurnover
    then do:
        assign vcMessage = subst(#T-19'The credit limit for customer &1 &2 has been reached.':250(13759)T-19#, tqDebtorByCreditLimitInfo.tcDebtorCode, tqDebtorByCreditLimitInfo.tcBusinessRelationCode) + " ":U +
                           subst(#T-20'Turnover-based credit is &1 &2.':250(13788)T-20#, vdCreditOnTurnover, tqDebtorByCreditLimitInfo.tcCurrencyCode)
               vlWarning = vlOverruleAllowed.

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-21'and open items are &1':250(13767)T-21#), vdOIBalance).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-23'and current sales orders are &1':250(13771)T-23#), vdSOBalance).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-48'and current drafts are &1':250(69480)T-48#), vdDraftBalance).

        assign vcMessage = vcMessage + ".":U.
    end.
    else

    /* Warning */
    if tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim <> 0 and
       tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim <> ? and
       vdTotalBalance >= tqDebtorByCreditLimitInfo.tdDebtorFixedCredLimTC * tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim / 100
    then do:
        assign vcMessage = subst(trim(#T-24'Customer &1 &2 is approaching the credit limit. &3 percent of the credit amount &4 &5 has been used.':250(13786)T-24#), tqDebtorByCreditLimitInfo.tcDebtorCode, tqDebtorByCreditLimitInfo.tcBusinessRelationCode, tqDebtorByCreditLimitInfo.tdDebtorPercWarningCredLim, vdCreditOnTurnover, tqDebtorByCreditLimitInfo.tcCurrencyCode)
               vlWarning = true.

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclOpenItmCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-25'and open items are &1':250(13767)T-25#), vdOIBalance).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclSOCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-27'and current sales orders are &1':250(13771)T-27#), vdSOBalance).

        if tqDebtorByCreditLimitInfo.tlDebtorIsInclDraftCredLim
        then assign vcMessage = vcMessage + " ":U +
                                subst(trim(#T-49'and current drafts are &1':250(69480)T-49#), vdDraftBalance).

        assign vcMessage = vcMessage + ".":U.
    end.

    if vcMessage <> "":U
    then do:
        <M-18 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  if vlWarning then 'W':U else 'E':U (icType), 
            input  if vlWarning then 4 else 3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3060':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtor>

        assign oiReturnStatus = if vlWarning
                                then if oiReturnStatus = 0
                                     then 1
                                     else oiReturnStatus
                                else -1.
   
    end.
end.

/* Maximum Days Overdue check */
if tqDebtorByCreditLimitInfo.tlDebtorIsMaxDaysDueCredLim
then do:
    assign vtDueDate = ?.

    <Q-28 run DInvoiceByDebtorIsOpen (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input tqDebtorByCreditLimitInfo.tiDebtor_ID, (DebtorId)
        input true, (DInvoiceIsOpen)
        input {&INVOICETYPE-INVOICE}, (DInvoiceType)
        output dataset tqDInvoiceByDebtorIsOpen) in BDInvoice >

    <Q-37 run DInvoiceStageByDebtorIsOpen (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input tqDebtorByCreditLimitInfo.tiDebtor_ID, (DebtorId)
        input true, (DInvoiceIsOpen)
        input {&INVOICETYPE-INVOICE}, (DInvoiceType)
        output dataset tqDInvoiceStageByDebtorIsOpen) in BDInvoice >

    for each tqDInvoiceByDebtorIsOpen where
             tqDInvoiceByDebtorIsOpen.tiDebtor_ID      = tqDebtorByCreditLimitInfo.tiDebtor_ID and
             tqDInvoiceByDebtorIsOpen.tlDInvoiceIsOpen = true                                  and
             tqDInvoiceByDebtorIsOpen.tcDInvoiceType   = {&INVOICETYPE-INVOICE}
             by tqDInvoiceByDebtorIsOpen.ttDInvoiceDueDate:
        if can-find(first tqDInvoiceStageByDebtorIsOpen where
                          tqDInvoiceStageByDebtorIsOpen.tiDInvoice_ID = tqDInvoiceByDebtorIsOpen.tiDInvoice_ID)
        then next.

        assign vtDueDate = tqDInvoiceByDebtorIsOpen.ttDInvoiceDueDate.
        leave.
    end.

    for each tqDInvoiceStageByDebtorIsOpen where
             tqDInvoiceStageByDebtorIsOpen.tiDebtor_ID      = tqDebtorByCreditLimitInfo.tiDebtor_ID and
             tqDInvoiceStageByDebtorIsOpen.tlDInvoiceIsOpen = true                                  and
             tqDInvoiceStageByDebtorIsOpen.tcDInvoiceType   = {&INVOICETYPE-INVOICE}
             break by tqDInvoiceStageByDebtorIsOpen.tiDInvoice_ID
                   by tqDInvoiceStageByDebtorIsOpen.ttDInvoiceStageDueDate:
        if last-of(tqDInvoiceStageByDebtorIsOpen.tiDInvoice_ID) and
           tqDInvoiceStageByDebtorIsOpen.ttDInvoiceStageDueDate < vtDueDate
        then assign vtDueDate = tqDInvoiceStageByDebtorIsOpen.ttDInvoiceStageDueDate.
    end.

    if vtDueDate        <> ? and
       today - vtDueDate > tqDebtorByCreditLimitInfo.tiDebtorMaxNumDaysCredLim
    then do:
        assign vcMessage = subst(#T-29'The credit limit for customer &1 &2 has been reached.':250(13759)T-29#, tqDebtorByCreditLimitInfo.tcDebtorCode, tqDebtorByCreditLimitInfo.tcBusinessRelationCode) + " ":U +
                           subst(#T-30'The maximum days overdue is &1. Invoice &2 &3 &4 is &5 days overdue.':250(13810)T-30#, tqDebtorByCreditLimitInfo.tiDebtorMaxNumDaysCredLim, tqDInvoiceByDebtorIsOpen.tiPeriodYear, tqDInvoiceByDebtorIsOpen.tcJournalCode, tqDInvoiceByDebtorIsOpen.tiDInvoiceVoucher, today - tqDInvoiceByDebtorIsOpen.ttDInvoiceDueDate).

        <M-31 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  if vlOverruleAllowed then 'W':U else 'E':U (icType), 
            input  if vlOverruleAllowed then 4 else 3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3063':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtor>

        assign oiReturnStatus = if vlOverruleAllowed
                                then if oiReturnStatus = 0
                                     then 1
                                     else oiReturnStatus
                                else -1.
    
    end.
end.

/* Lock the debtor if necessary */
if ((vlOverruleAllowed and oiReturnStatus = 1) or oiReturnStatus = -1)   and
   tqDebtorByCreditLimitInfo.tlDebtorIsToBeLockedCredLim = true and
   tqDebtorByCreditLimitInfo.tlDebtorIsLockedCredLim    <> true and
   vlIsSalesQuote <> true
then do:
    <M-32 run DataLoad
       (input  '':U (icRowids), 
        input  '':U (icPkeys), 
        input  tqDebtorByCreditLimitInfo.tiDebtor_ID (icObjectIds), 
        input  '':U (icFreeform), 
        input  false (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BDebtor>

    if viFcReturnSuper < 0 then return.

    find tDebtor where
         tDebtor.Debtor_ID = tqDebtorByCreditLimitInfo.tiDebtor_ID
         no-error.

    if not available tDebtor
    then do:
        <M-33 run SetMessage
           (input  trim(#T-31'The previously loaded customer (ID: $1) could not be found.':255(999890130)T-31#) (icMessage), 
            input  tqDebtorByCreditLimitInfo.tiDebtor_ID (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3064':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDebtor>

        return.
        
    end.

    assign tDebtor.DebtorIsLockedCredLim = true
           tDebtor.tc_Status             = "C":U.

    <M-34 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    if viFcReturnSuper < 0 then return.

    <M-35 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    if viFcReturnSuper < 0 then return.

    <M-36 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
    if viFcReturnSuper < 0 then return.

end.


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 = "BDebtor".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiCheckCreditLimit".
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/bdebtor.apicheckcreditlimit.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiDebtorId = <parameter value>
       vhParameter::icDebtorCode = <parameter value>
       vhParameter::idCurrentAmount = <parameter value>
       vhParameter::idOldAmount = <parameter value>
       vhParameter::icCurrencyCode = <parameter value>
       vhParameter::icContext = <parameter value>
       vhParameter::itExchangeRateDate = <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.