project QadFinancials > class BPosting > method ApiMassDeletePeriodicCostingPostings

Description

ApiMassDeletePeriodicCostingPostings; this api-method is called from the Periodic-costing module to delete a bunch of postings of a certain company, journal (type periodic costing) and period.
The method returns a temp-table holding the main info of the postings that are deleted.


Parameters


icCompanyCodeinputcharacterCompanyCode: Mandatory.
This should be the current company
icJournalCodeinputcharacterJornalCode: Mandatory.
The type of this journal should be Periodic-costing
iiPostingYearinputintegerPostingYear: Mandatory. accounting-year format 9999
iiPostingPeriodinputintegerPostingPeriod: Mandatory. accounting-period format 99
tApiPeriodicCostingPostingsoutputtemp-tableOutput temp-table holding the main references on the postings that will be removed by this method.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ApiMassDeletePeriodicCostingPostingsTest


program code (program8/bposting.p)

/* =============================== */
/* Exception handling - main block */
/* Empty output table              */
/* =============================== */
empty temp-table tApiPeriodicCostingPostings.
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
MAINPCDELETIONBLOCK: DO :
    
    /* ================================================================ */
    /* Replace unknown values in the input parameters and then validate */
    /* the input as stated in the descriptions of the parameters itself */
    /* ================================================================ */
    if icCompanyCode   = "":U or 
       icCompanyCode   = ?    or
       icJournalCode   = "":U or 
       icJournalCode   = ?    or
       iiPostingYear   = 0    or
       iiPostingYear   = ?    or
       iiPostingPeriod = 0    or
       iiPostingPeriod = ? 
    then do :
        assign vcMessage           = trim(substitute(#T-1'The entity (&1), daybook (&2), year (&3) and period (&4) are all mandatory parameters for the API method.':255(73479107)T-1#,icCompanyCode,icJournalCode,iiPostingYear,iiPostingPeriod))
               viLocalReturnStatus = -3.
        <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-9771':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave MAINPCDELETIONBLOCK.
    end. /* if icCompanyCode = "":U or */
    if icCompanyCode <> vcCompanyCode /* removing this check would alos mean you have to check the complete method on using viCompanyID and vcCompanyCode */
    then do :
        assign vcMessage           = trim(substitute(#T-4'The entity (&1) passed as input to API method must be the current entity (&2).':255(413971746)T-4#,icCompanyCode,vcCompanyCode))
               viLocalReturnStatus = -3.
        <M-3 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-9772':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave MAINPCDELETIONBLOCK.
    end. /* if icCompanyCode <> vcCompanyCode */
    assign vcMessage = "":U.
    <Q-5 run JournalByJournalCodeWithLayer (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input icJournalCode, (JournalCode)
        output dataset tqJournalByJournalCodeWithLayer) in BJournal >
    Find first tqJournalByJournalCodeWithLayer where 
               tqJournalByJournalCodeWithLayer.tcJournalCode = icJournalCode 
               no-lock no-error.
    if not available tqJournalByJournalCodeWithLayer
    then assign vcMessage = trim(substitute(#T-6'The daybook (&1) passed as input to the API method cannot be found.':255(591295504)T-6#,icJournalCode)).
    if vcMessage = "":U and 
       available tqJournalByJournalCodeWithLayer and 
       tqJournalByJournalCodeWithLayer.tlJournalIsActive <> true
    then assign vcMessage = trim(substitute(#T-7'The daybook (&1) passed as input to the API method is not active.':255(332075615)T-7#,icJournalCode)).
    if vcMessage = "":U and 
       available tqJournalByJournalCodeWithLayer and 
       tqJournalByJournalCodeWithLayer.tcJournalTypeCode <> {&JOURNALTYPE-PERIODICCOSTING}
    then assign vcMessage = trim(substitute(#T-9'The daybook (&1) passed as input to the API method has daybook type &2. The daybook type must be &3.':255(227658115)T-9#,icJournalCode,tqJournalByJournalCodeWithLayer.tcJournalTypeCode,{&JOURNALTYPE-PERIODICCOSTING-TR})).
    if vcMessage = "":U and 
       available tqJournalByJournalCodeWithLayer and 
       tqJournalByJournalCodeWithLayer.tcLayerTypeCode <> {&LAYERTYPECODE-TRANSIENT}
    then assign vcMessage = trim(substitute(#T-10'The daybook (&1) passed as input to the API method is not defined in the transient layer.':255(825527502)T-10#,icJournalCode,tqJournalByJournalCodeWithLayer.tcLayerTypeCode,{&LAYERTYPECODE-TRANSIENT-TR})).
    if vcMessage <> "":U
    then do :
        assign viLocalReturnStatus = -3.
        <M-11 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-9773':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave MAINPCDELETIONBLOCK.
    end. /* if vcMessage <> "":U */
    
    /* ================================================================ */
    /* Run a ClearData to make sure we start from scratch               */
    /* ================================================================ */
    <M-12 run ClearData  (output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Leave MAINPCDELETIONBLOCK.
    
    /* ================================================================================================= */
    /* Call method to delete the transient Periodic Costings postings in the selected company and period */
    /* ================================================================================================= */
    <M-61 run MassDeletePeriodicCostingPostings
       (input  icCompanyCode (icCompanyCode), 
        input  icJournalCode (icJournalCode), 
        input  iiPostingYear (iiPostingYear), 
        input  iiPostingPeriod (iiPostingPeriod), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Leave MAINPCDELETIONBLOCK.

    /* ================================================================ */
    /* Call ValidateBC, AdditionalUpdates and DataSave.                 */
    /* ================================================================ */
    <M-16 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Leave MAINPCDELETIONBLOCK.
    <M-17 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Leave MAINPCDELETIONBLOCK.
    <M-18 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Leave MAINPCDELETIONBLOCK.
    
/* =============================== */
/* Exception handling - main block */
/* =============================== */
END. /* MAINPCDELETIONBLOCK */
assign oiReturnStatus = viLocalReturnStatus.


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 = "BPosting".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiMassDeletePeriodicCostingPostings".
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/bposting.apimassdeleteperiodiccostingpostings.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icCompanyCode = <parameter value>
       vhParameter::icJournalCode = <parameter value>
       vhParameter::iiPostingYear = <parameter value>
       vhParameter::iiPostingPeriod = <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.