project QadFinancials > class BDInvoice > method ApiStdMaintainTT

Description

This method can create new instances or update existing instances based on the content of the input temp-table. The action that is passed as a parameter will define if the records are saved, saved as draft or just validated.

See method ApiStdMaintainTTInitialDefaulting for all further details

PostCondition

After the execution of the method the records in the temp-tables are created/modified in the database. In case of a delete action (tc_status = 'D'), the records are removed from the database.


Parameters


tApiDInvoiceinputtemp-tableInput temp-table holding the debtor invoice data to be created, updated or deleted.
tApiDInvoiceMovementinputtemp-tableInput temp-table holding the Movement records linked to the debtor invoice to be created, updated or deleted.
tApiDInvoicePostinginputtemp-tableInput temp-table holding the posting records linked to the debtor invoice to be created, updated or deleted.
tApiDInvoiceStageinputtemp-tableInput temp-table holding the stage records linked to the debtor invoice to be created, updated or deleted.
tApiDInvoiceVatinputtemp-tableInput temp-table holding the tax records linked to the debtor invoice to be created, updated or deleted.
tApiDInvoiceBankinputtemp-tableInput temp-table holding the bank records linked to the debtor invoice to be created, updated or deleted.
tApiDInvoiceBankPayCodeinputtemp-tableInput temp-table holding the bank-pay-code records linked to the debtor invoice to be created, updated or deleted.
tApiDInvoiceOpInfoinputtemp-tableInput temp-table holding the operational info records linked to the debtor invoice to be created, updated or deleted.
icActioninputcharacterThis parameter defines what should happen with the input data : -SAVE: Save the data if there were no errors, -SAVESTORE : Save the data if there were no errors. If there were errors, save as draft. -STORE : Save the data as draft -VALIDATE : Validate the input data, but do no save the data.
ocLstPrimKeyoutputcharacterCharacter 4 separated list with the primary keys of the newly created main-table records. The fields of the primary key are separated with Character 2.
ocLstReturnoutputcharacterChar 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred.
ocLstRowidoutputcharacterChar 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.MaintainByDataset
method BDInvoice.MaintainByDatasetWithOutput


program code (program9/bdinvoice.p)

/* ============================================================================ */
/* Clear the instance:                                                          */
/* this will also clear the t_s tables that were filled in ApiMaintainByDataSet */
/* ============================================================================ */
<M-95 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.

/* ==================== */
/* Set Default Return   */
/* Parameter Validation */
/* ==================== */
assign oiReturnStatus         = -98
       vlDraftInstanceCreated = false.
if icAction = ? then assign icAction = "":U.
if icAction <> {&DAEMONACTION-SAVESTORE} and 
   icAction <> {&DAEMONACTION-SAVE}      and 
   icAction <> {&DAEMONACTION-STORE}     and 
   icAction <> {&DAEMONACTION-VALIDATE}
then do:
    assign vcMessage      = trim(subst(#T-78'A customer invoice integration error occurred. The specified action (&1) is not in the list: &2.':255(49394)t-78#, icAction, "{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U))
           oiReturnStatus = -1.
    <M-16 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-930':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    return.
end. /* if icAction <> {&DAEMONACTION-SAVESTORE} and */

/* ============================================================== */
/* Call method that can extend the tApi-tables with some defaults */
/* ============================================================== */
<M-37 run ApiStdMaintainTTInitialDefaulting  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiDInvoice:
    assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each tApiDInvoice */
if viMainTableRecordCount = 0
then do:
    assign vcMessage      = trim(#T-79'A customer invoice integration error occurred. No input record was found. You must define for which records customer invoices must be created.':255(49398)t-79#)
           oiReturnStatus = -1.
    <M-17 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-931':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    return.
end. /* if viMainTableRecordCount = 0 */

/* ================================================================================ */
/* Start and open journal entry (in case the caller already set viBJournalEntryCIID */
/* before calling this method, then this will result in just an Open of BJE)        */
/* ================================================================================ */
if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ?
then do:
    <I-65 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BJournalEntry"}>
    assign vlBJEIsStartedFromDI = true.
end. /* if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ? */
else do:
   <I-73 {bFcOpenInstance
            &CLASS           = "BJournalEntry"}>
end. /* Not if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ? */

/* ====================================================== */
/* Go through all main-table records                      */
/* ====================================================== */
for each tApiDInvoice by tApiDInvoice.tc_Rowid :
    
    MAINAPIDINVOICEBLOCK : DO : 
    
    /* ========== */
    /* Initialize */
    /* ========== */
    if tApiDInvoice.Debtor_ID = ? then assign tApiDInvoice.Debtor_ID = 0.
    if tApiDInvoice.tcDebtorCode = ? then assign tApiDInvoice.tcDebtorCode = "":U.
    if tApiDInvoice.DInvoiceType   = ? then assign tApiDInvoice.DInvoiceType   = "":U.
    assign vcMessage       = "":U
           vcDInvoiceRowId = "":U
           vlWarningsFound = false
           vlSaveAsDraft   = (icAction = {&DAEMONACTION-STORE}).
    
    /* ====================================================== */
    /* Delete balance fields, they will be recalculated again */
    /* ====================================================== */
    assign tApiDInvoice.DInvoiceBalanceDebitTC  = 0
           tApiDInvoice.DInvoiceBalanceCreditTC = 0
           tApiDInvoice.DInvoiceBalanceDebitLC  = 0
           tApiDInvoice.DInvoiceBalanceCreditLC = 0
           tApiDInvoice.DInvoiceBalanceDebitCC  = 0
           tApiDInvoice.DInvoiceBalanceCreditCC = 0
           tApiDInvoice.DInvoiceBalanceTC       = 0
           tApiDInvoice.DInvoiceBalanceLC       = 0
           tApiDInvoice.DInvoiceBalanceCC       = 0.
      
    /* ================================================= */
    /* Check on the link-record between CInvoice-Posting */
    /* ================================================= */
    find first tApiDInvoicePosting where
               tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid and
               tApiDInvoicePosting.Posting_ID     <> 0                    and
               tApiDInvoicePosting.Posting_ID     <> ?
               no-error.
    if available tApiDInvoicePosting
    then do:
        /* ======================================================================================== */
        /* Amount of invoice must be the same as the sum of the amounts of the posting lines for LC */
        /* not for TC because the currency can change for every line of it                          */
        /* ======================================================================================== */
        <M-68 run GetPostingHeaderByPostingId (input  tApiDInvoicePosting.Posting_ID (iiPostingId), 
                                       input  ? (icPostingRowID), 
                                       output viPostingYear (oiPostingYear), 
                                       output viPostingPeriod (oiPostingPeriod), 
                                       output vtPostingDate (otPostingDate), 
                                       output vcPostingJournalCode (ocPostingJournalCode), 
                                       output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper < 0
        then do:
            assign ocLstReturn   = ocLstReturn  + chr(4) + string(viFcReturnSuper)
                   ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
                   ocLstRowid    = ocLstRowid   + chr(4) + "*":U
                   vlSaveAsDraft = false.
            leave MAINAPIDINVOICEBLOCK.
        end. /* if viFcReturnSuper <> 0 */
        else if viFcReturnSuper > 0
             then assign vlWarningsFound = true.
        if tApiDInvoice.DInvoicePostingDate <> vtPostingDate
        then do:
            assign vcMessage     = trim(substitute(#T-91'The posting date of the posting (&1) does not match the posting date of the invoice (&2).':255(13734)T-91#, string(vtPostingDate), string(tApiDInvoice.DInvoicePostingDate))) + chr(10) +
                                   trim(substitute(#T-80'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-80#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
                   ocLstReturn   = ocLstReturn  + chr(4) + string(-1)
                   ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
                   ocLstRowid    = ocLstRowid   + chr(4) + "*":U
                   vlSaveAsDraft = false.
            <M-74 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-1899':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
             leave MAINAPIDINVOICEBLOCK.
        end. /* if tApiDInvoice.DInvoicePostingDate <> vtPostingDate */
        if tApiDInvoice.tcJournalCode <> vcPostingJournalCode
        then do:
            assign vcMessage     = trim(substitute(#T-92'The daybook of the posting (&1) does not match daybook of the invoice (&2).':250(13736)t-92#, vcPostingJournalCode, tApiDInvoice.tcJournalCode)) + chr(10) +
                                   trim(substitute(#T-81'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-81#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
                   ocLstReturn   = ocLstReturn  + chr(4) + string(-1)
                   ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
                   ocLstRowid    = ocLstRowid   + chr(4) + "*":U
                   vlSaveAsDraft = false.
            <M-75 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-1901':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
             leave MAINAPIDINVOICEBLOCK.
        end. /* if tApiDInvoice.tcJournalCode <> vcPostingJournalCode */
        /* ======================================================== */
        /* Check year/period of invoice with year/period of posting */
        /* Check single DI-posting for a DI                         */
        /* ======================================================== */
        if tApiDInvoice.DInvoicePostingYear   <> viPostingYear or
           tApiDInvoice.DInvoicePostingPeriod <> viPostingPeriod
        then do:
            assign vcMessage     = trim(substitute(#T-93'The year and GL period of the customer invoice do not match the year (&1) and GL period (&2) of the posting.':255(13738)T-93#, string(viPostingYear), string(viPostingPeriod))) + chr(10) +
                                   trim(substitute(#T-82'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-82#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
                   ocLstReturn   = ocLstReturn  + chr(4) + string(-1)
                   ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
                   ocLstRowid    = ocLstRowid   + chr(4) + "*":U
                   vlSaveAsDraft = false.
            <M-71 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-1873':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            Leave MAINAPIDINVOICEBLOCK.
        end. /* if tApiDInvoice.DInvoicePostingYear   <> viPostingYear or */
    
        find next tApiDInvoicePosting where
                  tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid and
                  tApiDInvoicePosting.Posting_ID     <> 0                    and
                  tApiDInvoicePosting.Posting_ID     <> ?
                  no-error.
        if available tApiDInvoicePosting
        then do:
            assign vcMessage     = trim(#T-94'A customer invoice integration error occurred. More than one posting record found for this customer invoice':255(49397)t-94#) + chr(10) +
                                   trim(substitute(#T-83'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-83#,string(tAPIDInvoice.DInvoicePostingYear),string(tAPIDInvoice.DInvoicePostingPeriod), tAPIDInvoice.tcJournalCode, string(tAPIDInvoice.DInvoiceVoucher)))
                   ocLstReturn   = ocLstReturn  + chr(4) + string(-1)
                   ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
                   ocLstRowid    = ocLstRowid   + chr(4) + "*":U
                   vlSaveAsDraft = false.
            <M-67 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-1871':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            Leave MAINAPIDINVOICEBLOCK.
        end. /* if available tApiDInvoicePosting */
    
    end. /* if available tApiDInvoicePosting after first find */
      
    /* ======================================== */
    /* Calculate the lc, cc and balance amounts */
    /* ======================================== */
    <M-108 run ApiStdMaintainTTCalcAmounts (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    if viFcReturnSuper < 0
    then do:
        assign ocLstReturn   = ocLstReturn  + chr(4) + string(viFcReturnSuper)
               ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
               ocLstRowid    = ocLstRowid   + chr(4) + "*":U
               vlSaveAsDraft = false.
        leave MAINAPIDINVOICEBLOCK.
    end. /* if viFcReturnSuper <> 0 */
    else if viFcReturnSuper > 0
         then assign vlWarningsFound = true.
      
    /* ========================================================================================================================= */
    /* Call a submethod depending on the fact whether the required postings for the CI are created outside this component or not */
    /* ========================================================================================================================= */
    if not can-find(first tApiDInvoicePosting where
                          tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid and
                          tApiDInvoicePosting.Posting_ID     <> 0                    and
                          tApiDInvoicePosting.Posting_ID     <> ?)
    then do:
        <M-63 run ApiStdMaintainTTWithIntPost (input  icAction (icAction), 
                                       input-output ocLstPrimKey (bcLstPrimKey), 
                                       input-output ocLstRowid (bcLstRowId), 
                                       input-output ocLstReturn (bcLstReturn), 
                                       output vlSaveAsDraft (olSaveAsDraft), 
                                       output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        if viFcReturnSuper < 0
        then leave MAINAPIDINVOICEBLOCK.
        else if viFcReturnSuper > 0
             then assign vlWarningsFound = true.
    end. /* if not can-find */
    else do:
        <M-64 run ApiStdMaintainTTWithExtPost (input  icAction (icAction), 
                                       input-output ocLstReturn (bcLstReturn), 
                                       input-output ocLstPrimKey (bcLstPrimKey), 
                                       input-output ocLstRowid (bcLstRowId), 
                                       output vlSaveAsDraft (olSaveAsDraft), 
                                       output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        if viFcReturnSuper < 0
        then leave MAINAPIDINVOICEBLOCK.
        else if viFcReturnSuper > 0
             then assign vlWarningsFound = true.
    end. /* Not if not can-find */
    
    END. /* MAINAPIDINVOICEBLOCK */
    
    /* ================================================================== */        
    /* Handle errors: Store if SaveAsDraft is needed                      */
    /* Check: only 1 draft is allowed for a single bus-component instance */
    /* ================================================================== */
    if vlSaveAsDraft and 
       index(substr(ocLstReturn, r-index(ocLstReturn, chr(4)) + 1,-1,"CHARACTER":U),"-":U) <> 0 /* Negative return-status for this entry */
    then do:
        if vlDraftInstanceCreated = true
        then do :
            assign vcMessage = trim(#T-98'Only one draft instance can be created per method call.':255(858)T-98#) + chr(10) + trim(#T-99'This second object will not be stored as a draft instance and so is an error.':255(859)t-99#).
            <M-100 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-3349':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            next.
        end. /* if vlDraftInstanceCreated = true */
        <M-96 run StoreState (input  '(':U + tDInvoice.DInvoiceDescription + ') ':U + trim(#T-97'The customer invoice created using an API method.':200(49399)t-97#) (icDescription), 
                      input  ? (icUIClass), 
                      output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign vlDraftInstanceCreated                                         = true
               entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper)
               entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiDInvoice.DInvoice_ID)
               entry(num-entries(ocLstRowid  , chr(4)), ocLstRowid  , chr(4)) = vcDInvoiceRowId.
    end. /* if vlSaveAsDraft and substr */
    
    /*=======================*/
    /* LBO - Gunters request */
    /*=======================*/
    if tApiDInvoice.tiDAVoucher = 0 or 
       tApiDInvoice.tiDAVoucher = ?
    then do:
        <M-109 run DefaultValuesDAVoucher (input  tApiDInvoice.tcDAJournalCode (icNewDAJournalCode), 
                                   input  '':U (icOldDAJournalCode), 
                                   input  tApiDInvoice.DInvoicePostingYear (iiNewPeriodYear), 
                                   input  0 (iiOldPeriodYear), 
                                   input  0 (iiOldDAVoucher), 
                                   output viDAVoucher (oiNewDAVoucher), 
                                   input  tApiDInvoice.tc_Rowid (icRowId), 
                                   output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign  tApiDInvoice.tiDAVoucher = viDAVoucher.
    end. /* if tApiDInvoice.tiDAVoucher = 0 or */
    
end. /* for each tApiDInvoice by tApiDInvoice.tc_Rowid  */

/* =================== */
/* Close Journal Entry */
/* =================== */
if vhBJournalEntryDIInst <> ? and /* Can be closed by a subprocedure */
   valid-handle(vhBJournalEntryDIInst) = true
then.   /* ========================================================================================================= */
        /* Normally we would here close BJournalEntry we will not do it for performance                              */
        /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
        /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
        /* appserver that is executed after each call to the appserver                                               */
        /* ========================================================================================================= */

/* ============================================================ */
/* Trim the first character of ocLstReturn and primkey          */
/* Check for correct number and format of the return-parameters */
/* ============================================================ */
if length(ocLstReturn,"CHARACTER":U)  > 1 then assign ocLstReturn  = substring(ocLstReturn,2,-1,"CHARACTER":U).
if length(ocLstPrimKey,"CHARACTER":U) > 1 then assign ocLstPrimKey = substring(ocLstPrimKey,2,-1,"CHARACTER":U).
if length(ocLstRowid,"CHARACTER":U)   > 1 then assign ocLstRowid   = substring(ocLstRowid,2,-1,"CHARACTER":U).
if num-entries(ocLstReturn,chr(4))  <> viMainTableRecordCount or
   num-entries(ocLstPrimKey,chr(4)) <> viMainTableRecordCount or
   num-entries(ocLstRowid,chr(4))   <> viMainTableRecordCount
then do :
    assign vcMessage      = trim(#T-101'A customer invoice/journal entry integration error ocurred. An API method retruned incomplete information. See other messages for further details.':255(49400)t-101#) + chr(10) + 
                            trim(substitute(#T-102'Main table records: &1.':255(310)T-102#,string(viMainTableRecordCount))) + chr(10) + 
                            trim(substitute(#T-103'Return Statuses: &1.':255(311)T-103#,ocLstReturn))  + chr(10) +
                            trim(substitute(#T-104'Primary keys: &1.':255(312)T-104#,ocLstPrimKey)) + chr(10) +
                            trim(substitute(#T-105'Row IDs: &1.':255(313)T-105#,ocLstRowid)).
           oiReturnStatus = -3.
    <M-19 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-932':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    assign oiReturnStatus = -3.
    return.
end. /* if num-entries(ocLstReturn,chr(4))  <> viMainTableRecordCount or */

/* ===================================================== */
/* Set global return status based on the individual ones */
/* ===================================================== */
if ocLstReturn = substring(fill("0":U + CHR(4),viMainTableRecordCount),1,length(ocLstReturn,"CHARACTER":U),"CHARACTER":U)
then assign oiReturnStatus = 0.
else do : 
    if index(ocLstReturn,"-":U) <> 0        
    then do :
        assign vcMessage      = trim(#T-106'An error has occurred while running this API method. See other error messages for more details.':255(301)T-106#)
               oiReturnStatus = -1.
        <M-20 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-933':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end. /* index(ocLstReturn,"-":U) <> 0 */
    else do : 
        assign vcMessage      = trim(#T-107'A warning occurred when running the API method. See other error messages for more details.':255(14390)t-107#)
               oiReturnStatus = +1.
        <M-55 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'W':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1489':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end. /* not if lookup */
end. /* not if ocLstReturn */


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 = "BDInvoice".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiStdMaintainTT".
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/bdinvoice.apistdmaintaintt.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoice").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoiceMovement").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoicePosting").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoiceStage").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoiceVat").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoiceBank").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoiceBankPayCode").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiDInvoiceOpInfo").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

/* 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.