You are on page 1of 29

!----------------------------------------------------------------------!

! Report Name: AR30006.SQR - Aging by Chartfield !


!----------------------------------------------------------------------!
! !
! !
! !
! This software and related documentation are provided under a !
! license agreement containing restrictions on use and !
! disclosure and are protected by intellectual property !
! laws. Except as expressly permitted in your license agreement !
! or allowed by law, you may not use, copy, reproduce, !
! translate, broadcast, modify, license, transmit, distribute, !
! exhibit, perform, publish or display any part, in any form or !
! by any means. Reverse engineering, disassembly, or !
! decompilation of this software, unless required by law for !
! interoperability, is prohibited. !
! The information contained herein is subject to change without !
! notice and is not warranted to be error-free. If you find any !
! errors, please report them to us in writing. !
! !
! *
! Copyright (C) 1992, 2010, Oracle and/or its affiliates. !
! All Rights Reserved. !
!***********************************************************************
! *
! $Date: 2010/01/08:08:24:25 !
! $Release: FSCM91 !
! $Resolution: 810574 !
! !
!----------------------------------------------------------------------!
! Program Desc: The Aging Detail Report lists aged open item balances. !
! All balances reported are base currency amounts. !
! If the posted date on the item is on or before the !
! 'as of' date for the report, the item balance is !
! retrieved from the PS_ITEM table. If the posted date !
! on the item is later than the as of date for the !
! report, the item balance is established by looking at !
! the item activity (PS_ITEM_ACTIVITY) up to the !
! 'as of' date. !
!----------------------------------------------------------------------!
! Prompts: As Of Date; Sorting Option; Dynamic CF's,Set Id and !
! Aging Id !
!----------------------------------------------------------------------!
! Tables: PS_ITEM, PS_ITEM_ACTIVITY,PS_AGING_TBL !
! PS_AGING_CATEG_TBL, PS_ENTRY_TYPE_TBL, PS_DISPUTE_TBL !
!----------------------------------------------------------------------!
! Modifications: 1) At request of JFMIP, removed from printing !
! columns Document and Total Item Amount, and added 2 !
! additional Aging Category columns instead. !
! Report will only age and disply Chartfield Selected. !
! To undo change & add the columns back in, just !
! uncomment all lines marked !ITEM and put commented !
! changes back in. !
!----------------------------------------------------------------------!
!02/15/07 ICE 1566050001 !
! Changed The Aging By ChartField Report aggregates all Aging !
! Category columns in CSV.To undo change look for all lines !
! marked !CSV Request-begin !
!----------------------------------------------------------------------!
#include 'setenv.sqc' ! Set Environment Procedure
#IFNDEF INFORMIX
begin-setup
#include 'setupdb.sqc'
end-setup
#ENDIF
#include 'sqrtrans.sqc' ! Set Translation environment
#include 'number.sqc' ! Formats Numbers
#define DESCR-LENGTH 30
#include 'fsrptcf.sqc' ! Dynamic chartfield access
#include 'glgetshr.sqc' !shared table procedures
begin-setup
#include 'ptset02.sqc' ! Printer and Page-Size Initialization
end-setup
begin-report
do INIT-REPORT
do MAIN-PROCESS
do END-PROCESS
end-report

begin-heading 9
#include 'arhdg01.sqc'
print $DateHeading (3,) center
print $xvaging_id (3,1,9)
print $xvagingid (3,+1,15)
print $xvcf_parms (4,1,21)
print $xvcfparms (4,+1,100)
print $xvagedisplayoption (5,1,#xfwagedisplayoption)
print $AgeDisplayName (0,+1,19)
LET $BUSINESS_UNIT = RTRIM($BUSINESS_UNIT,' ')
print $xv_bus_unit (6,1,14)
if $BUSINESS_UNIT <> ''
print $BUSINESS_UNIT (0,+1,10)
else
print $xv_all_vals (0,+1,10)
END-IF

! print $xvdisplay (5,1,20)


! print $xvdisplayopn (0,+1,19) !ITEM
! print $xvtotal (7,69,5)
print $xvtotal (7,52,5) !ITEM (7,87,5)
print $xventry (8,37,5)
! print $xventry (8,+3,5) !ITEM
! print $xvitem (8,69,5)
print $xvselected (8,52,9) !ITEM (8,85,9)
print $xvitem (+1,1,13)
print $xvitemline (0,+1,4)
print $xvas_of_dt (0,+3,8)
print $xvtype (0,+1,5)
print $xvreason (0,+1,6)
print $xvterms (0,+2,5)
! print $xvdocument (0,+3,10)
print $xvamount (0,52,13) !ITEM (0,68,13)
! print $xvamount (0,+2,16)
!CSV Request-begin
! print $category-headings (0,0,115)
move 1 to #i
while #i < 9 !ITEM 6
get $descrshort from categories(#i) descrshort
let $category-headings = $descrshort
print $category-headings (0,+1,13)
add 1 to #i
end-while
! print '-' (0,1,13) fill
!CSV Request-end
print '-' (+1,1,13) fill
print '-' (0,+1,4) fill
print '-' (0,+3,8) fill
print '-' (0,+1,5) fill
print '-' (0,+1,6) fill
print '-' (0,+2,5) fill
! print '-' (0,+1,10) fill
print '-' (0,+2,13) fill
! print '-' (0,+3,15) fill
move 1 to #i
while #i < 9 !ITEM 6
print '-------------' (0,+1,13) !ITEM (0,+2,13)
add 1 to #i
end-while
move 1 to #i
end-heading

!***********************************************************************
! Procedure: CREATE-ARRAYS
! Description: Establish arrays used to store aging categories and
! report sub-totals.
!***********************************************************************
begin-procedure CREATE-ARRAYS
create-array name=categories size=20
field=category:char
field=descrshort:char
field=start-day:number
field=end-day:number
create-array name=ITEM-TOTALS size=12
field=amt:number
create-array name=customer-total size=12
field=amt:number
create-array name=CF-TOTAL size=12
field=amt:number
create-array name=CF-TOTAL2 size=12
field=amt:number

create-array name=REPORT-TOTALS size=12


field=amt:number

end-procedure
!***********************************************************************
! Procedure: INIT-REPORT
! Description: Prompt for run-time parameters and populate aging
! categories array with aging 'buckets'
!***********************************************************************
begin-procedure INIT-REPORT
DO INIT-DATETIME
do Init-Number
do GET-CURRENT-DATETIME
do INITIALIZE-CF-ARRAY
do DEFINE-PRCS-VARS
do GET-RUN-CONTROL-PARMS
do INITIALIZE-VARIABLES
do SELECT-PARAMETERS
do AGE-DISPLAY-OPTION
do GET-XLAT-FIELDS
do SET-HDR-OPTIONS
do BUILD-CF-ARRAY
do BUILD-WHERE-CLAUSE
do CREATE-ARRAYS
do LOAD-CATEGORIES
do GET-SUBTOTALS
do GET-CF-PARAMETERS
do BuildCF-WHERE-CLAUSE

end-procedure
!***********************************************************************
! Procedure: READ-AGING-TABLE
! Description: This procedure reads the aging table for the aging setid
! and aging id entered.
!***********************************************************************
begin-procedure READ-AGING-TABLE
begin-select
A.EFFDT
A.BASIS_DT
A.DISPUTE_AGING
A.DISPUTE_CATEGORY
A.DISPUTE_PRTY
A.DEDUCTION_AGING
A.DEDUCTION_CTGY
A.DEDUCTION_PRTY
A.COLLECTION_AGING
A.COLLECTION_CTGY
A.COLLECTION_PRTY
move &a.effdt to $aging-effdt
move &a.basis_dt to $basis-dt
move &a.dispute_aging to $dispute-aging
move &a.dispute_category to $dispute-category
move &a.dispute_prty to #dispute-priority
move &a.deduction_aging to $deduction-aging
move &a.deduction_ctgy to $deduction-category
move &a.deduction_prty to #deduction-priority
move &a.collection_aging to $collection-aging
move &a.collection_ctgy to $collection-category
move &a.collection_prty to #collection-priority
FROM PS_AGING_TBL A
WHERE A.EFF_STATUS = 'A'
AND A.AGING_ID = $agingid
AND A.SETID = $setid
AND A.EFFDT = (SELECT MAX(B.EFFDT) FROM PS_AGING_TBL B
WHERE B.AGING_ID = $agingid
AND B.SETID = $setid
AND B.EFFDT <= $asofdate)
end-select
end-procedure
!***********************************************************************
! Function: AGE-DISPLAY-OPTION
! Description: This procedure stores additional where clause criteria
! to a string, so it may be used in the main select.
!***********************************************************************
begin-procedure AGE-DISPLAY-OPTION
if $agedisplayoption = 'A'
move '' to $agedisplaystring
end-if
if $agedisplayoption = 'D'
move 'AND A.DISPUTE_STATUS <> '' ''' to $agedisplaystring
end-if
if $agedisplayoption = 'E'
move 'AND A.DEDUCTION_STATUS <> '' ''' to $agedisplaystring
end-if
if $agedisplayoption = 'C'
move 'AND A.COLLECTION_STATUS <> '' ''' to $agedisplaystring
end-if
move 'AGE_DISPLAY_OPTION' to $FieldName
move $agedisplayoption to $FieldValue
do Read-Translate-Table
move $XLATLongName to $AgeDisplayName

end-procedure

!-----------------------------------------------------------------------!
! Procedure: BuildCF-WHERE-CLAUSE !
! Descr: This procedure stores SQL is used to dynamically build the !
! where clause !
!-----------------------------------------------------------------------!
begin-procedure BuildCF-WHERE-CLAUSE
let $ANDCFS = ''
BEGIN-SELECT
JLNCF.FIELDNAME
let $Chartfield = RTRIM(&JLNCF.FIELDNAME,' ')
let $ANDCFS = $ANDCFS || ' AND I.' || $Chartfield ||'=B.'||$Chartfield
FROM PS_FS_RPTCF JLNCF
WHERE JLNCF.OPRID = $prcs_oprid
AND JLNCF.RUN_CNTL_ID = $prcs_run_cntl_id
AND JLNCF.PNLGRPNAME='RUN_AR30006'
AND JLNCF.CF_SELECT_OPT = 'Y'
END-SELECT
#debugx show '$ANDCFS = |' $ANDCFS '|'
end-procedure

!***********************************************************************
! Procedure: MAIN-PROCESS
! Description: This is the main report procedure. It is executed once.
! The 'post' date on the item (PS_ITEM) is compared with
! 'as of' date. If the 'as of' date is on or before the
! 'post' date, the item balance is determined by looking
! at the item activity (PS_ITEM_ACTIVITY).
!***********************************************************************
begin-procedure MAIN-PROCESS
begin-select
[$CF_SUBTOTAL2] &CF_SUBTOTAL2=CHAR () on-break print=ne
ver level=1 AFTER=CF-TOTAL2
[$CF_SUBTOTAL] &CF_SUBTOTAL=CHAR () on-break print=ne
ver level=2 AFTER=CF-TOTAL
A.CUST_ID () on-break print=ne
ver level=3 AFTER=CUSTOMER-TOTAL
A.ITEM () on-break print=ne
ver level=4 AFTER=ITEM-TOTAL SAVE=$OLD-ITEM
A.ITEM_LINE () on-break print=ne
ver level=5 AFTER=ITEM-LINE-TOTAL
A.ITEM_SEQ_NUM
A.BAL_AMT_BASE
B.MONETARY_AMOUNT
A.BAL_CURRENCY
A.POST_DT
A.DUE_DT
A.ACCOUNTING_DT
A.ASOF_DT
A.DISPUTE_STATUS
A.DEDUCTION_STATUS
A.COLLECTION_STATUS
A.DUE_DAYS
A.ENTRY_TYPE
A.ENTRY_REASON
A.PYMNT_TERMS_CD
A.DOCUMENT
C.NAME1
B.ACCOUNT
B.ALTACCT
B.OPERATING_UNIT
B.FUND_CODE
B.DEPTID
B.PROGRAM_CODE
B.CLASS_FLD
B.BUDGET_REF
B.PROJECT_ID
B.CURRENCY_CD
B.PRODUCT
B.DST_SEQ_NUM
move &A.CUST_ID to $custid
move &A.item to $item
move &A.BAL_CURRENCY to $report-currency
move &A.item_line to #item-line
move &A.ITEM_SEQ_NUM to #item_seq_num
move &A.bal_amt_base to #bal-amt-base
move &B.MONETARY_AMOUNT to #monetary_amt
move &A.post_dt to $post-dt
move &A.due_dt to $due-dt
move &A.accounting_dt to $accounting-dt
move &A.asof_dt to $item-asof-dt
move &A.dispute_status to $dispute-status
move &A.due_days to #grace-days
move &A.entry_type to $entrytype
move &A.entry_reason to $entryreason
move &A.PYMNT_TERMS_CD to $pymnt-terms
move &A.document to $document
move &C.name1 to $cust-name
move &B.ACCOUNT to $account
move &B.ALTACCT to $altacct
move &B.OPERATING_UNIT to $operating_unit
move &B.FUND_CODE to $fund_code
move &B.DEPTID to $deptid
move &B.PROGRAM_CODE to $program_code
move &B.CLASS_FLD to $class_fld
move &B.BUDGET_REF to $budget_ref
move &B.PROJECT_ID to $project_id
move &B.CURRENCY_CD to $currency_cd
move &B.PRODUCT to $product
move &B.DST_SEQ_NUM to #DST_SEQ_NUM
IF #item_seq_num > 1 or
#item_seq_num = 1 and #DST_SEQ_NUM > 1
do CALC-REMAIN-BALANCE
end-if
do DIFF-DATE($asofdate,$post-dt,#diff-years,#diff-months,#diff-days)
if #diff-days < 0
do SELECT-ITEM-ACTIVITY
end-if

let $CF_SUBTOTAL = RTRIM($CF_SUBTOTAL,' ')


move &CF_SUBTOTAL to $CF_DETAILVALUE
let $CF_SUBTOTAL2= RTRIM($CF_SUBTOTAL2,' ')
if #CFCount > 1
move &CF_SUBTOTAL2 to $CF_DETAILVALUE2
else
move ' ' to $Chartfieldname2
end-if
do Format-DateTime($item-asof-dt, $item-asof-dt-p, {DefDate}, '', '')
IF $CF-TOTAL2-PRINTED = 'Y'
print $Chartfieldname2 (+1,2,16)
print $CF_DETAILVALUE2 (0,+2,8)
END-IF
if $FIRSTITEM_ITEMLINE = 'N' and
$CF_DETAILVALUE2_OLD <> $CF_DETAILVALUE2
print $Chartfieldname2 (+2,1,16)
print $CF_DETAILVALUE2 (0,+2,8)
end-if
IF $CF-TOTAL-PRINTED = 'Y'
print $Chartfieldname (+2,10,10)
print $CF_DETAILVALUE (0,+1,15)
let $CF-TOTAL-PRINTED = 'N'
END-IF

IF $CUSTOMER-TOTAL-PRINTED = 'Y'
print $xvcust_id (+2,19,11)
print $CUSTID (0,+2,15)
print $xvcust_name (0,+10,30)
print $cust-name (0,+2,30)
let $CUSTOMER-TOTAL-PRINTED = 'N'
END-IF

let $exclude = 'N'


do CATEGORIZE-AMT
Let $DISPLAY_OPN = 'I'
if #CFCount > 0 and #monetary_amt >= 0
EVALUATE $DISPLAY_OPN
WHEN = 'I'
!PUT #bal-amt-base INTO ITEM-TOTALS(#BUCKET-NUM) !Age by Item Balance A
mount
PUT #monetary_amt INTO ITEM-TOTALS(#BUCKET-NUM)
WHEN = 'C'
PUT #monetary_amt INTO ITEM-TOTALS(#BUCKET-NUM) !Age by Selected Amoun
t
END-EVALUATE
else
PUT #bal-amt-base INTO ITEM-TOTALS(#BUCKET-NUM) !Age by Selected Amount
END-IF

FROM PS_ITEM A, PS_ITEM_DST B,PS_CUSTOMER C


WHERE A.BUSINESS_UNIT = B.BUSINESS_UNIT
AND A.CUST_ID = B.CUST_ID
AND A.ITEM = B.ITEM
AND A.ITEM_LINE = B.ITEM_LINE
!AND A.ITEM_SEQ_NUM = B.ITEM_SEQ_NUM
AND A.CUST_ID = C.CUST_ID
AND B.PRIMARY_LEDGER = 'Y'
AND C.SETID = (SELECT SETID FROM PS_SET_CNTRL_REC WHERE RECNAME = 'CUSTOMER' AND
SETCNTRLVALUE = A.BUSINESS_UNIT)
[$WHERE_BU_CUST]
[$CFPARMS]
[$WHERE_LEDGER]
[$AGEDISPLAYSTRING]
AND B.SYSTEM_DEFINED NOT IN ('U','C','L','I','H', 'Y') ! (USER,CASH,CASH CLEARIN
G)
AND $asofdate >= ( SELECT min(ACCOUNTING_DT)
FROM PS_ITEM_ACTIVITY WHERE ITEM = A.ITEM
AND ITEM_LINE = A.ITEM_LINE
AND CUST_ID = A.CUST_ID
AND BUSINESS_UNIT = A.BUSINESS_UNIT)
AND NOT EXISTS( SELECT 'X' FROM PS_INSTALLATION WHERE
$asofdate >= ( SELECT max(ACCOUNTING_DT) FROM PS_ITEM_ACTI
VITY
WHERE ITEM = A.ITEM
AND ITEM_L
INE = A.ITEM_LINE
AND CUST_I
D = A.CUST_ID
AND BUSINESS_UNIT = A.BUSINESS_UNIT
AND A.ITEM_STATUS = 'C'))
AND NOT EXISTS(
SELECT 'X'
FROM PS_ITEM_DST_CF_VW I
WHERE I.BUSINESS_UNIT = B.BUSINESS_UNIT
AND I.CUST_ID = B.CUST_ID
AND I.ITEM = B.ITEM
AND I.ITEM_LINE = B.ITEM_LINE
[$ANDCFS])
ORDER BY 1, 2, 3, 4, 5,10
END-SELECT
! Print complete report totals
do PRINT-REPORT-TOTALS
end-procedure
!***********************************************************************
! Procedure: CALC-REMAIN-BALANCE
! Description: This procedure is called in the event when the item has undergone
some
! transaction like write off, partial payment to reduce the item ba
lance
! This procedure calculates the remaining aging balance of the item
.
!***********************************************************************
begin-procedure CALC-REMAIN-BALANCE
MOVE 0 TO #monetary_amt
MOVE #item_seq_num to #item_seq_num_2
WHILE #item_seq_num_2 >= 1
begin-select
M.MONETARY_AMOUNT
ADD &M.MONETARY_AMOUNT to #monetary_amt
FROM PS_ITEM_DST M
WHERE M.ITEM = $item
AND M.ITEM_LINE = #item-line
AND M.ITEM_SEQ_NUM = #item_seq_num_2
AND M.CUST_ID = $CUSTID
AND M.BUSINESS_UNIT = $BUSINESS_UNIT
AND M.ACCOUNT = $account
AND M.ALTACCT = $altacct
AND M.OPERATING_UNIT = $operating_unit
AND M.FUND_CODE = $fund_code
AND M.DEPTID = $deptid
AND M.PROGRAM_CODE = $program_code
AND M.CLASS_FLD = $class_fld
AND M.BUDGET_REF = $budget_ref
AND M.PROJECT_ID = $project_id
AND M.CURRENCY_CD = $currency_cd
AND M.PRODUCT = $product
AND M.PRIMARY_LEDGER = 'Y'
AND M.SYSTEM_DEFINED NOT IN ('U','C','L','I','H','Y') ! (USER,CASH,CASH CLEARI
NG)
end-select
subtract 1 from #item_seq_num_2
END-WHILE
end-procedure

!***********************************************************************
! Procedure: SELECT-ITEM-ACTIVITY
! Description: This procedure is called in the event that the posted
! date on the item is later than the run-time as-of date
! (so that the item balance reported accurately reflects
! the item activity at the time of the as of date).
!***********************************************************************
begin-procedure SELECT-ITEM-ACTIVITY
MOVE 0 TO #bal-amt-base
begin-select
C.ENTRY_AMT_BASE
C.ACCOUNTING_DT
C.POST_DT
move &C.ENTRY_AMT_BASE to #activity-amt-base
move &C.ACCOUNTING_DT to $activity-acctg-dt
move &C.POST_DT to $ACTIVITY-POST-DT
! if the ACCTG date on the item activity is on or before the as of date
! we include it in the item balance. If you want to use the POSTED date
! of the activity instead, comment out the first line below and uncomment
! the second line.
do DIFF-DATE($asofdate,$activity-acctg-dt,#diff-years,#diff-months,#diff-day
s)
! do DIFF-DATE($asofdate,$activity-post-dt,#diff-years,#diff-months,#diff-days
)
if #diff-days >= 0
add #activity-amt-base to #bal-amt-base
end-if
FROM PS_ITEM_ACTIVITY C
WHERE C.ITEM = $item
AND C.ITEM_LINE = #item-line
!AND c.ITEM_SEQ_NUM = #item_seq_num
AND C.CUST_ID = $CUSTID
AND C.BUSINESS_UNIT = $BUSINESS_UNIT
end-select
end-procedure

!************************************************************************
! Function: CATEGORIZE-AMT
! Description: This function establishes which method should be used to
! to categorize the item balance into an aging bucket.
! If the item is not in dispute,a deduction, or a collection,
! the item balance is aged normally (by date) unless there
! is an entry type override. If the item is in dispute,a
! deduction, or a collection, it is aged according the
! corresponding aging parameter defined on the aging id.
!************************************************************************
begin-procedure CATEGORIZE-AMT
move '' to $aging-status
if not isblank($dispute-status)
and ((#dispute-priority < #deduction-priority) or isblank($deduction-st
atus)or isnull($deduction-status))
and ((#dispute-priority < #collection-priority) or isblank($collection-
status) or isnull($collection-status))
let $aging-status = 'D'
let $aging-option = $dispute-aging
end-if
if not isblank($deduction-status)
and ((#deduction-priority < #dispute-priority) or isblank($dispute-stat
us) or isnull($dispute-status))
and ((#deduction-priority < #collection-priority) or isblank($collectio
n-status) or isnull($collection-status))
let $aging-status = 'E'
let $aging-option = $deduction-aging
end-if

if not isblank($collection-status)
and ((#collection-priority < #deduction-priority) or isblank($deduction
-status)or isnull($deduction-status))
and ((#collection-priority < #dispute-priority) or isblank($dispute-sta
tus) or isnull($dispute-status))
let $aging-status = 'C'
let $aging-option = $collection-aging
end-if

let #agingisblank = isblank($aging-status)


if(#agingisblank = 1)
do STD-CATEGORY
else
evaluate $aging-option
when = 'A' !Age Normally
do STD-CATEGORY
when = 'C'
evaluate $aging-status !Use Category
when = 'D' !Retrieve dispute category from agin
g id definition
do GET-DISPUTE-BUCKET
when = 'E' !Retrieve deduction category
do GET-DEDUCTION-BUCKET
when = 'C' !Retrieve collection category
do GET-COLLECTION-BUCKET
end-evaluate
when = 'D' !Vary aging category by item aging sta
tus
evaluate $aging-status
when = 'D' !Retrieve dispute reason aging cate
gory
do EVALUATE-DISPUTE-STATUS
when = 'E' !Retrieve deduction reason aging cat
egory
do EVALUATE-DEDUCTION-STATUS
when = 'C' !Retrieve collection reason aging ca
tegory
do EVALUATE-COLLECTION-STATUS
end-evaluate
when = 'X' !Exclude from aging
let $exclude = 'Y'
when-other
do STD-CATEGORY
end-evaluate
end-if
end-procedure
!***********************************************************************
! Procedure: STD-CATEGORY
! Description: This Procedure checks of there is an aging bucket override
! defined for the entry type related to the item. If so,
! that bucket is used. If not, the item is aged by date.
!***********************************************************************
begin-procedure STD-CATEGORY
do GET-ENTRYTYPE-BUCKET
if $entrytype-aging = 'N'
do GET-BASISDATE-BUCKET
end-if

end-procedure

!***********************************************************************
! Procedure: GET-ENTRYTYPE-BUCKET
! Description: This Procedure is called to establish whether the entry
! type for item has aging exceptions set up to place the
! item in a specific aging bucket.
!***********************************************************************
begin-procedure GET-ENTRYTYPE-BUCKET
move 0 to #i
move 8 to #bucket-num !ITEM 6
move 'N' to $entrytype-aging
move ' ' to $entrytype-category
begin-select
D.AGING_CATEGORY
let $entrytype-category = RTRIM(&d.aging_category, ' ')
FROM PS_ENTRY_TYPE_TBL D
WHERE D.ENTRY_TYPE = $entrytype
AND D.SETID = $setid
ORDER BY D.AGING_CATEGORY
end-select
if $entrytype-category = ''
move ' ' to $entrytype-category
end-if
if $entrytype-category <> ' '
move 'Y' to $entrytype-aging
while #i < 8 !ITEM 6
get $category from categories(#i)
if $category = $entrytype-category
move #i to #bucket-num
move 8 to #i !ITEM 6
end-if
add 1 to #i
end-while
end-if

end-procedure

!***********************************************************************
! Procedure: GET-BASISDATE-BUCKET
! Description: This Procedure is called in the event that an item is
! neither categorized by 'dispute category' nor by entry
! type category. The aging category into which the item
! is placed is determined by comparing the days overdue
! with the start and end dates for the aging categories.
!***********************************************************************
begin-procedure GET-BASISDATE-BUCKET
move 1 to #i
move 8 to #bucket-num !ITEM 6
evaluate $basis-dt
when = 'A'
do DIFF-DATE($asofdate,$item-asof-dt,#diff-years,#diff-months,#diff-days)
when = 'I'
do DIFF-DATE($asofdate,$accounting-dt,#diff-years,#diff-months,#diff-days
)
when-other
do DIFF-DATE($asofdate,$due-dt,#diff-years,#diff-months,#diff-days)

end-evaluate
let #days-overdue=#diff-days - #grace-days

while #i < 8 !ITEM 6


get #start-day #end-day from categories(#i) start-day end-day
if #days-overdue >= #start-day and #days-overdue <= #end-day
move #i to #bucket-num
move 8 to #i !ITEM 6
end-if
add 1 to #i
end-while

end-procedure

!***********************************************************************
! Procedure: GET-DISPUTE-BUCKET
! Description: This Procedure is called if the item is in dispute and
! disputed items are flagged to be placed in a specific
! category (defined when setting up the aging id).
!***********************************************************************
begin-procedure GET-DISPUTE-BUCKET
move 8 to #bucket-num !ITEM 6
move 0 to #i
move 'N' to $dispute-aged
while #i < 8 !ITEM 6
get $category from categories(#i)
if $category = $dispute-category
move #i to #bucket-num
move 8 to #i !ITEM 6
move 'Y' to $dispute-aged
end-if
add 1 to #i
end-while
end-procedure

!***********************************************************************
! Procedure: EVALUATE-DISPUTE-STATUS
! Description: This Procedure is called if the the dispute method on the
! aging id is 'D' (vary by dispute code).
!***********************************************************************
begin-procedure EVALUATE-DISPUTE-STATUS
begin-select
F.SETID
move &f.setid to $dispute-setid
FROM PS_SET_CNTRL_REC F
WHERE F.SETCNTRLVALUE = $BUSINESS_UNIT
AND F.RECNAME = 'DISPUTE_TBL'
end-select
begin-select
G.DISPUTE_AGE_TYPE
move &g.dispute_age_type to $dispute-age-type
FROM PS_DISPUTE_TBL G
WHERE G.DISPUTE_STATUS = $DISPUTE-STATUS
AND G.SETID = $dispute-setid
AND G.EFFDT = (SELECT MAX(H.EFFDT) FROM PS_DISPUTE_TBL H
WHERE H.DISPUTE_STATUS = $DISPUTE-STATUS
AND H.SETID = $dispute-setid
AND H.EFFDT <= $asofdate)
end-select
evaluate $dispute-age-type
when = 'A'
do STD-CATEGORY
when = 'C'
do GET-DISPUTE-BUCKET
when = 'X'
let $exclude = 'Y'
when-other
do STD-CATEGORY
end-evaluate
end-procedure
!***********************************************************************
! Function: GET-DEDUCTION-BUCKET
! Description: This function is called if the item is a deduction and
! deduction items are flagged to be placed in a specific
! category (defined when setting up the aging id).
!***********************************************************************
begin-procedure GET-DEDUCTION-BUCKET
move 8 to #bucket-num !ITEM 6
move 0 to #i
move 'N' to $deduction-aged
while #i < 8 !ITEM 6
get $category from categories(#i)
if $category = $deduction-category
move #i to #bucket-num
move 8 to #i !ITEM 6
move 'Y' to $deduction-aged
end-if
add 1 to #i
end-while
end-procedure
!***********************************************************************
! Function: EVALUATE-DEDUCTION-STATUS
! Description: This function is called if the the deduction method on the
! aging id is 'D' (vary by deduction code).
!***********************************************************************
begin-procedure EVALUATE-DEDUCTION-STATUS
begin-select
X.SETID
move &X.setid to $deduction-setid
FROM PS_SET_CNTRL_REC X
WHERE X.SETCNTRLVALUE = $business-unit
AND X.RECNAME = 'DEDUCTION_TBL'
end-select
move ' ' to $deduction-age-type
begin-select
G.DEDUCTION_AGE_TYPE
move &g.deduction_age_type to $deduction-age-type
FROM PS_DEDUCTION_TBL G
WHERE G.DEDUCTION_STATUS = $DEDUCTION-STATUS
AND G.SETID = $deduction-setid
AND G.EFFDT = (SELECT MAX(H.EFFDT) FROM PS_DEDUCTION_TBL H
WHERE H.DEDUCTION_STATUS = $DEDUCTION-STATUS
AND H.SETID = $deduction-setid
AND H.EFFDT <= $asofdate)
end-select
evaluate $deduction-age-type
when = 'A'
do STD-CATEGORY
when = 'C'
do GET-DEDUCTION-BUCKET
when = 'X'
let $exclude = 'Y'
when-other
do STD-CATEGORY
end-evaluate
end-procedure

!***********************************************************************
! Function: GET-COLLECTION-BUCKET
! Description: This function is called if the item is a collection and
! collection items are flagged to be placed in a specific
! category (defined when setting up the aging id).
!***********************************************************************
begin-procedure GET-COLLECTION-BUCKET
move 8 to #bucket-num !ITEM 6
move 0 to #i
move 'N' to $collection-aged
while #i < 8 !ITEM 6
get $category from categories(#i)
if $category = $collection-category
move #i to #bucket-num
move 8 to #i !ITEM 6
move 'Y' to $collection-aged
end-if
add 1 to #i
end-while
end-procedure

!***********************************************************************
! Function: EVALUATE-COLLECTION-STATUS
! Description: This function is called if the the collection method on the
! aging id is 'D' (vary by collection code).
!***********************************************************************
begin-procedure EVALUATE-COLLECTION-STATUS
begin-select
Y.SETID
move &y.setid to $collection-setid
FROM PS_SET_CNTRL_REC Y
WHERE Y.SETCNTRLVALUE = $business-unit
AND Y.RECNAME = 'COLLECTION_TBL'
end-select
move ' ' to $collection-age-type
begin-select
G.COLLECT_AGE_TYPE
move &g.collect_age_type to $collection-age-type
FROM PS_COLLECTION_TBL G
WHERE G.COLLECTION_STATUS = $COLLECTION-STATUS
AND G.SETID = $collection-setid
AND G.EFFDT = (SELECT MAX(H.EFFDT) FROM PS_COLLECTION_TBL H
WHERE H.COLLECTION_STATUS = $COLLECTION-STATUS
AND H.SETID = $collection-setid
AND H.EFFDT <= $asofdate)
end-select
evaluate $collection-age-type
when = 'A'
do STD-CATEGORY
when = 'C'
do GET-COLLECTION-BUCKET
when = 'X'
let $exclude = 'Y'
when-other
do STD-CATEGORY
end-evaluate
end-procedure
!***********************************************************************
! Procedure: LOAD-CATEGORIES
! Description: This Procedure is called to retrieve the aging categories
! from the PS_AGING_TBL table. The category data is used
! to determine which aging category an item is placed in,
! depending on the start and end dates for each category.
!***********************************************************************
begin-procedure LOAD-CATEGORIES
move 1 to #i
begin-select
AGING_CATEGORY
DESCRSHORT
START_DAY
END_DAY
IF #i<8
PUT &aging_category &descrshort &start_day &end_day INTO CATEGORIES(#I) CA
TEGORY DESCRSHORT START-DAY END-DAY
ELSE
PUT &aging_category 'Others' &start_day &end_day INTO CATEGORIES(#I) CATEG
ORY DESCRSHORT START-DAY END-DAY
END-IF
add 1 to #i
FROM PS_AGING_CATEG_TBL
WHERE AGING_ID = $agingid
AND SETID = $setid
AND EFFDT = $aging-effdt
ORDER BY START_DAY
end-select
! let $category-headings = $category-headings || $xvother !ITEM
end-procedure
!***********************************************************************
! Procedure: ITEM-TOTAL
! Description: This Procedure prints out the item,item-line totals, adds the
! item totals to the customer totals
!***********************************************************************
begin-procedure ITEM-TOTAL
IF $ITEM <> $OLD-ITEM
do DIFF-DATE($asofdate,$post-dt,#diff-years,#diff-months,#diff-days)
if #diff-days < 0
do SELECT-ITEM-ACTIVITY
end-if
if $FIRSTITEM_ITEMLINE = 'Y'
print $Chartfieldname2 (+1,1,16)
print $CF_DETAILVALUE2 (0,+2,8)
print $Chartfieldname (+1,10,10)
print $CF_DETAILVALUE (0,+1,15)
print $xvcust_id (+1,19,11)
print $CUSTID (0,+2,15)
print $xvcust_name (0,+10,30)
print $cust-name (0,+2,30)
IF $SUMM_DETAIL_OPTN = 'D'
print $Item (+2,1,13)
END-IF
else
IF $SUMM_DETAIL_OPTN = 'D'
print $Item (+2,1,13)
END-IF
end-if

IF $SUMM_DETAIL_OPTN = 'D'
print #item-line (0,15,4) edit 999
print $item-asof-dt-p (0,20,10)
print $entrytype (0,31,5)
print $entryreason (0,37,5)
print $pymnt-terms (0,45,5)
! print $document (0,51,10)
END-IF

DO PROCESS-AMOUNTS
LET $ITEM-TOTAL-PRINTED = 'Y'
LET $FIRSTITEM_ITEMLINE = 'N'
!Set item values back to zero
move 1 to #i
WHILE #i < 12
put 0 into item-totals(#i) amt
add 1 to #i
END-WHILE
END-IF
end-procedure

!***********************************************************************
! Procedure: ITEM-LINE-TOTAL
! Description: This Procedure prints out the item,item-line totals, adds the
! item totals to the customer totals
!***********************************************************************
begin-procedure ITEM-LINE-TOTAL
do DIFF-DATE($asofdate,$post-dt,#diff-years,#diff-months,#diff-days)
if #diff-days < 0
do SELECT-ITEM-ACTIVITY
end-if
if $FIRSTITEM_ITEMLINE = 'Y'
print $Chartfieldname2 (+1,1,16)
print $CF_DETAILVALUE2 (0,+2,8)
print $Chartfieldname (+1,10,10)
print $CF_DETAILVALUE (0,+1,15)
print $xvcust_id (+1,19,11)
print $CUSTID (0,+2,15)
print $xvcust_name (0,+10,30)
print $cust-name (0,+2,30)
IF $SUMM_DETAIL_OPTN = 'D'
print $Item (+2,1,13)
END-IF
else
IF $SUMM_DETAIL_OPTN = 'D'
print $Item (+2,1,13)
END-IF
end-if

IF $SUMM_DETAIL_OPTN = 'D'
print #item-line (0,15,4) edit 999
print $item-asof-dt-p (0,20,10)
print $entrytype (0,31,5)
print $entryreason (0,37,5)
print $pymnt-terms (0,45,5)
! print $document (0,51,10)
END-IF
LET $CF_DETAILVALUE2_OLD = $CF_DETAILVALUE2
DO PROCESS-AMOUNTS
LET $ITEM-TOTAL-PRINTED = 'Y'
LET $FIRSTITEM_ITEMLINE = 'N'
!Set item values back to zero
move 1 to #i
WHILE #i < 12
put 0 into item-totals(#i) amt
add 1 to #i
END-WHILE
end-procedure
!***********************************************************************
! Procedure: CUSTOMER-TOTAL
! Description: This Procedure prints out the customer totals, adds the
! customer totals to the CF-TOTAL and REPORT-TOTALS
!***********************************************************************
begin-procedure CUSTOMER-TOTAL
print $xvtotal (+2,16,5)
print $cust-name (0,+3,30)
!Get Total Item Amount Column
move 10 to #BUCKET-NUM !ITEM 8
get #AMT from customer-total(#BUCKET-NUM)
ARRAY-ADD #AMT to cf-total(#BUCKET-NUM)
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$amt
,'I')
! print $amt (0,52,15) !ITEM (0,63,15)
move 11 to #BUCKET-NUM !ITEM 9
get #AMT from customer-total(#BUCKET-NUM)
ARRAY-ADD #AMT to cf-total(#BUCKET-NUM)
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$amt
,'I')
!CSV Request-begin
move 1 to #i
move 1 to #col
while #i < 5 !ITEM 1 until item 6
print ' ' (0,#col,1) !Blank column
add 1 to #i
add 1 to #col
end-while
!CSV Request-end
print $amt (0,52,15) !ITEM (0,82,15)
move 1 to #i
while #i < 9 !ITEM 7
get #AMT from customer-total(#i)
!CSV Request-begin
!If #AMT <> 0
!CSV Request-end
LET #BUCKET-NUM = #I
ARRAY-ADD #AMT to cf-total(#BUCKET-NUM)
ARRAY-ADD #AMT to REPORT-TOTALS(#BUCKET-NUM)
DO GET-PRINT-POSITION
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,9
99.99',$amt,'I')
print $amt (0,#COL,15)
!CSV Request-begin
!end-if
!end-Request-end
add 1 to #i
end-while
!Set customer values back to zero
move 1 to #i
WHILE #i < 12
put 0 into customer-total(#i) amt
add 1 to #i
END-WHILE
Let $CUSTOMER-TOTAL-PRINTED = 'Y'
end-procedure

!***********************************************************************
! Procedure: CF-TOTAL
! Description: This Procedure prints out the Chartfield Subtotal Value and adds
the
! Chartfield Subtotal Value to the 2nd Chartfield Totals.
!***********************************************************************
begin-procedure CF-TOTAL
if $PrintCFSubtotal = 'Y'
print $xv_totals (+2,1,10)
print $Chartfieldname (0,+1,10)
print $CF_DETAILVALUE (0,+1,15)
end-if
!Get Total Item Amount Column
move 10 to #BUCKET-NUM !ITEM 8
get #AMT from cf-total(#BUCKET-NUM)
ARRAY-ADD #AMT to CF-TOTAL2(#BUCKET-NUM)
if $PrintCFSubtotal = 'Y'
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$
amt,'I')
! print $amt (0,52,15) !ITEM (0,63,15)
end-if
move 11 to #BUCKET-NUM !ITEM 9
get #AMT from cf-total(#BUCKET-NUM)
ARRAY-ADD #AMT to CF-TOTAL2(#BUCKET-NUM)
if $PrintCFSubtotal = 'Y'
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$
amt,'I')
print $amt (0,52,15) !ITEM (0,82,15)
end-if
!CSV Request-begin
move 1 to #i
move 1 to #col
while #i < 5 !ITEM 1 until item 6
print ' ' (0,#col,1) !Blank column
add 1 to #i
add 1 to #col
end-while
!CSV Request-end
move 1 to #i
while #i < 9 !ITEM 7
get #AMT from cf-total(#i)
if #AMT <> 0
LET #BUCKET-NUM = #I
ARRAY-ADD #AMT to CF-TOTAL2(#BUCKET-NUM)
if $PrintCFSubtotal = 'Y'
do GET-PRINT-POSITION
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,
'B99,999,999.99',$amt,'I')
print $amt (0,#COL,15)
end-if
end-if
add 1 to #i
end-while
print ' ' (+1,1,1) !Blank Line
LET $CF-TOTAL-PRINTED = 'Y'

!Set chartfield values back to zero


move 1 to #i
WHILE #i < 12
put 0 into cf-total(#i) amt
add 1 to #i
END-WHILE
end-procedure

!***********************************************************************
! Procedure: CF-TOTAL2
! Description: This Procedure prints out the report totals for the second
! Chartfield
!***********************************************************************
begin-procedure CF-TOTAL2
if $PrintCFSubtotal2= 'Y'
print $xv_totals (+2,1,10)
print $Chartfieldname2 (0,+1,16)
print $CF_DETAILVALUE2 (0,+1,8)

!Get Total Item Amount Column


move 10 to #BUCKET-NUM !ITEM 8
get #AMT from CF-TOTAL2(#BUCKET-NUM)
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$amt
,'I')
! print $amt (0,52,15) !ITEM (0,63,15)
move 11 to #BUCKET-NUM !ITEM 9
get #AMT from CF-TOTAL2(#BUCKET-NUM)
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$amt
,'I')
print $amt (0,52,15) !ITEM (0,82,15)
move 1 to #i
while #i < 9 !ITEM 7
get #AMT from CF-TOTAL2(#i)
if #AMT <> 0
LET #BUCKET-NUM = #i
DO GET-PRINT-POSITION
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999
,999.99',$amt,'I')
print $amt (0,#COL,15)
end-if
add 1 to #i
end-while
!Uncomment the below line if you want underlines to print under total section
!do PRINT-UNDERLINE
end-if
!Set chartfield values back to zero
move 1 to #i
WHILE #i < 12
put 0 into CF-TOTAL2(#i) amt
add 1 to #i
END-WHILE
end-procedure
!***********************************************************************
! Procedure: PROCESS-AMOUNTS !
! Description: !
!***********************************************************************
begin-procedure PROCESS-AMOUNTS
EVALUATE $DISPLAY_OPN
WHEN = 'I' !Age by item
!Move #bal-amt-base to #AMT
if #CFCount > 0 !and #monetary_amt > 0
!Move #bal-amt-base to #AMT
Move #monetary_amt to #AMT
else
MOVE #bal-amt-base TO #AMT
END-IF
IF $SUMM_DETAIL_OPTN = 'D'
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'99,999,999.99',
$amt,'I')
! print $amt (0,52,15) !ITEM (0,63,15) !Total Item Amount Column
print $amt (0,52,15) !ITEM (0,82,15) !Total Item Select Amount Column
END-IF
move 10 to #bucket-num !8 reserved for Total Item Amount !ITEM 8
ARRAY-ADD #AMT to CUSTOMER-TOTAL(#BUCKET-NUM)
move 11 to #bucket-num !9 reserved for Total Selected Amount !ITEM 9
ARRAY-ADD #AMT to CUSTOMER-TOTAL(#BUCKET-NUM)

move 1 to #i
WHILE #i < 9 !ITEM 7
GET #age-amt from ITEM-TOTALS(#I)
!CSV Request-begin
!If #age-amt <> 0
!CSV Request-end
LET #BUCKET-NUM = #I
DO GET-PRINT-POSITION
move #age-amt to #AMT
ARRAY-ADD #AMT to CUSTOMER-TOTAL(#BUCKET-NUM)
IF $SUMM_DETAIL_OPTN = 'D'
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,99
9.99',$amt,'I')
print $amt (0,#COL,15)
end-if
!CSV Request-begin
!end-if
!CSV Request-end
add 1 to #i
END-WHILE
WHEN = 'C' !Age by CF Selected
Move #bal-amt-base to #AMT
move 10 to #BUCKET-NUM !ITEM 8
ARRAY-ADD #AMT to CUSTOMER-TOTAL(#BUCKET-NUM) !ITEM 10 reserved for Total I
tem Amount
IF $SUMM_DETAIL_OPTN = 'D'
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$a
mt,'I')
! print $amt (0,52,15) !ITEM (0,63,15) !Total Item Amount Column
end-if
move 1 to #i
WHILE #i < 9 !ITEM 7
GET #age-amt from ITEM-TOTALS(#i)
If #age-amt <> 0
LET #BUCKET-NUM = #i
DO GET-PRINT-POSITION
move #age-amt to #AMT
ARRAY-ADD #AMT to CUSTOMER-TOTAL(#BUCKET-NUM)
add #AMT to #totalselected
IF $SUMM_DETAIL_OPTN = 'D'
do Format_Currency_Amt(#AMT,$report-currency,$As
OfToday,'B99,999,999.99',$amt,'I')
print $amt (0,#COL,15)

end-if
end-if
add 1 to #i
END-WHILE
move 11 to #bucket-num !ITEM 11 reserved for Total Selected Amount
ARRAY-ADD #totalselected to CUSTOMER-TOTAL(#BUCKET-NUM)
IF $SUMM_DETAIL_OPTN = 'D'
do Format_Currency_Amt(#totalselected,$report-currency,$AsOfToday,'B99,9
99,999.99',$amt,'I')
print $amt (0,52,15) !ITEM (0,82,15) !Total Item Select Amount Column
end-if
move 0 to #totalselected
END-EVALUATE
end-procedure

!----------------------------------------------------------------------!
! Procedure: PRINT-REPORT-TOTALS !
! Descr: Print overall report totals, summing all customers. !
! Added for JFMIP. !
!----------------------------------------------------------------------!
begin-procedure PRINT-REPORT-TOTALS
move 1 to #i
do GET-PRINT-POSITION
move #COL to #REPORT-TOTALS-BEGINCOL
print $xv_reporttotals (+2,1,50)

!CSV Request-begin
move 1 to #i
while #i < 9 !ITEM 6
get $descrshort from categories(#i) descrshort
let $category-headings = $descrshort
print $category-headings (0,#REPORT-TOTALS-BEGINCOL,13)
let #REPORT-TOTALS-BEGINCOL = #REPORT-TOTALS-BEGINCOL + 14
add 1 to #i
end-while
!print $category-headings (0,#REPORT-TOTALS-BEGINCOL,115)
!CSV Request-end
print ' ' (+1,1,1) !Move to next line
move 1 to #i
while #i < 9
do GET-PRINT-POSITION
print '-------------' (0,#COL,13)
add 1 to #i
end-while
print ' ' (+1,1,1) !Move to next line
move 1 to #i
while #i < 9
do GET-PRINT-POSITION
get #AMT from REPORT-TOTALS(#i)
do Format_Currency_Amt(#AMT,$report-currency,$AsOfToday,'B99,999,999.99',$am
t,'I')
print $amt (0,#COL,14)
add 1 to #i
end-while
!CSV Request-begin
!print '=' (+1,#REPORT-TOTALS-BEGINCOL,110) fill
!CSV Request-end
end-procedure

!----------------------------------------------------------------------!
! Procedure: GET-SUBTOTALS !
! Descr: Gather Subtotals on runcontrol !
!----------------------------------------------------------------------!
begin-procedure GET-SUBTOTALS
if #CFCount > 0
let #CFidx = 0
let #subtotalcnt = 0 !Up to 2 fields can be subtotaled on the runcon
trol page
while #CFidx < #CFCount
get $SubTotal from CFsInfo(#CFidx) SubTotal
get $CFName from CFsInfo(#CFidx) CField
EVALUATE #CFidx
WHEN = 0
let $CF_Subtotal = 'B.'||$CFName
let $Chartfieldname = $CFName
if $SubTotal = 'Y'
let $PrintCFSubtotal = 'Y'
end-if
WHEN = 1
let $CF_SUBTOTAL2 = 'B.'||$CFName
let $Chartfieldname2 = $CFName
if $SubTotal = 'Y'
let $PrintCFSubtotal2 = 'Y'
end-if
end-evaluate
add 1 to #CFidx
end-while
end-if

end-procedure !GET-SUBTOTALS
!----------------------------------------------------------------------!
! Procedure: GET-CF-PARAMETERS !
! Descr: Gathers Chartfield From/To Ranges entered on runcntl page!
!----------------------------------------------------------------------!
begin-procedure GET-CF-PARAMETERS
if #CFCount > 0
let #CFidx = 0
while #CFidx < #CFCount
get $CFIELD from CFsInfo(#CFidx) CFIELD
get $CFValue from CFsInfo(#CFidx) CFVALUE
get $CFVALUETO from CFsInfo(#CFidx) CFVALUETO
Let $CFIELD = RTRIM($CFIELD,' ')
Let $CFvalue = RTRIM($CFvalue,' ')
Let $CFVALUETO = RTRIM($CFVALUETO,' ')
if $CFvalue <> ''
IF $CFVALUE = $CFVALUETO !Single Value
LET $CFPARMS = $CFPARMS||' AND B.'||$CFIELD||' = '||$QUOTE||$CFV
alue||$QUOTE
Let $xvcfparms = $xvcfparms||$CFIELD||' = '||$CFVALUE||','
else !range
LET $CFPARMS = $CFPARMS||' AND B.'||$CFIELD||' BETWEEN '||$QUOTE
||$CFValue||$QUOTE||' AND '||$QUOTE||$CFVALUETO||$QUOTE
Let $xvcfparms = ' '||$xvcfparms||' '||$CFIELD||' = '||$CFVALUE|
|'-'||$CFVALUETO||','
end-if
end-if
add 1 to #CFidx
end-while
else

end-if
let $xvcfparms = rtrim($xvcfparms,',')
end-procedure
!----------------------------------------------------------------------!
! Procedure: BUILD-WHERE-CLAUSE !
! Descr: Build Where Clause for use in program !
!----------------------------------------------------------------------!
begin-procedure BUILD-WHERE-CLAUSE
LET $BUSINESS_UNIT = RTRIM($BUSINESS_UNIT,' ')
LET $CUST_ID = RTRIM($CUST_ID,' ')
IF $BUSINESS_UNIT <> ''
LET $WHERE_BU_CUST = 'AND A.BUSINESS_UNIT ='||$quote||$BUSINESS_UNIT||$quote
END-IF
IF $CUST_ID <> ''
LET $WHERE_BU_CUST = $WHERE_BU_CUST || 'AND A.CUST_ID = '||$quote||$CUST_ID||$qu
ote
END-IF

end-procedure
!----------------------------------------------------------------------!
! Procedure: GET-PRINT-POSITION !
! Descr: !
!----------------------------------------------------------------------!
begin-procedure GET-PRINT-POSITION
Evaluate #i
WHEN = 1
LET #COL = 65 !ITEM 98
WHEN = 2
LET #COL = 79 !ITEM 114
WHEN = 3
LET #COL = 93 !ITEM 130
WHEN = 4
LET #COL = 107 !ITEM 146
WHEN = 5
LET #COL = 121 !ITEM 162
WHEN = 6
LET #COL = 135 !ITEM 162
WHEN = 7
LET #COL = 149 !ITEM
WHEN = 8
LET #COL = 163 !ITEM
END-EVALUATE
end-procedure
!***********************************************************************
! Procedure: INITIALIZE-VARIABLES
! Description: This procedure initializes variables used in the program
!***********************************************************************
begin-procedure INITIALIZE-VARIABLES
let $quote = chr(39)
move 'AR30006' to $ReportID
let $panel_group_name = 'RUN_AR30006'
move '' to $category-headings
move 1 to #i
move '' to $CF_DETAILVALUE2
let $CF-TOTAL-PRINTED = 'N'
let $CF-TOTAL2-PRINTED = 'N'
let $FIRSTITEM_ITEMLINE = 'Y'
let $ITEM-TOTAL-PRINTED = 'N'
let $xvcfparms = ' '
let $CF_Subtotal = $quote||'X'||$quote
let $CF_SUBTOTAL2 = $quote||'X'||$quote
let $PrintCFSubtotal = 'N'
let $PrintCFSubtotal2= 'N'
let $Chartfieldname = ' '
move 0 to #totalselected
do Init_Report_Translation('AR30006', $prcs_language_cd)
end-procedure
!***********************************************************************
! Procedure: PRINT-UNDERLINE
! Description: This Procedure prints underline under totals
!***********************************************************************
begin-procedure PRINT-UNDERLINE
print ' ' (+1,1,100) fill
print '-' (0,65,112) fill
print '' (+1,0)
end-procedure
!***********************************************************************
! Procedure: DEFAULT-LEDGER-GROUP
! Description: This Procedure prints underline under totals
!***********************************************************************
begin-procedure DEFAULT-LEDGER-GROUP
begin-select
B.LEDGER
move &B.LEDGER to $LEDGER
FROM PS_BU_LED_GRP_TBL A , PS_LED_GRP_LED_TBL B
WHERE A.BUSINESS_UNIT = $BUSINESS_UNIT
AND A.LEDGER_GROUP = B. LEDGER_GROUP
AND B.SETID= (
SELECT SETID
FROM PS_SET_CNTRL_REC
WHERE SETCNTRLVALUE = A.BUSINESS_UNIT
AND RECNAME = 'LED_GRP_TBL')
AND A.DEFAULT_LEDGER_GRP = 'Y'
AND B.PRIMARY_LEDGER = 'Y'
end-select

IF RTRIM($LEDGER,' ') <> ''


let $WHERE_LEDGER = 'AND B.LEDGER = '||$quote||$LEDGER||$quote
else
let $WHERE_LEDGER = ' '
END-IF

end-procedure
!***********************************************************************
! Procedure: END-PROCESS
! Desc: Update the process scheduler run control
!***********************************************************************
begin-procedure END-PROCESS
If $prcs_process_instance <> ''
do UPDATE-PRCS-RUN-STATUS
do Commit-Transaction
end-if
end-procedure
!----------------------------------------------------------------------!
! Procedure: get-xlat-fields !
! Desc: Retrieves Translation Values from the STRINGS_TBL !
!----------------------------------------------------------------------!
Begin-Procedure get-xlat-fields

do Get_Field_Information('AR30006','TOTAL',$xvtotal,#xfwtotal)
do Get_Field_Information('AR30006','ENTRY',$xventry,#xfwtotal)
do Get_Field_Information('AR30006','TYPE',$xvtype,#xfwtype)
do Get_Field_Information('AR30006','REASON',$xvreason,#xfwreason)
do Get_Field_Information('AR30006','AGING_ID',$xvaging_id,#xfwaging_id)
do Get_Field_Information('AR30006','AMOUNT', $xvamount, #xfwamount)
do Get_Field_Information('AR30006','AR30006', $xvar30006, #xfwar30006)
do Get_Field_Information('AR30006','ALL_VALS', $xv_all_vals,#xfw_all_vals)
do Get_Field_Information('AR30006','BUS_UNIT', $xv_bus_unit,#xfw_bus_unit)
do Get_Field_Information('AR30006','ASOF_DT', $xvas_of_dt, #xfwas_of_dt)
do Get_Field_Information('AR30006','DOCUMENT',$xvdocument,#xfwdocument)
do Get_Field_Information('AR30006','CUST_ID',$xvcust_id,#xfwcust_id)
do Get_Field_Information('AR30006','CUST_NAME',$xvcust_name,#xfwcust_name)
do Get_Field_Information('AR30006','ITEM',$xvitem,#xfwitem)
do Get_Field_Information('AR30006','SELECTED',$xvselected,#xfwselected)
do Get_Field_Information('AR30006','ITEM_LINE',$xvitemline,#xfwitemline)
do Get_Field_Information('AR30006','OTHER',$xvother,#xfwother)
do Get_Field_Information('AR30006','TERMS',$xvterms,#xfwterms)
do Get_Field_Information('AR30006','DISPLAY_OPN',$xvdisplay,#xfwdisplay)
do Get_Field_Information('AR30006','AGE_DISPLAY_OPTION',$xvagedisplayoption,#
xfwagedisplayoption)
do Get_Field_Information('AR30006','CHARTFIELD_SELECT',$xvcfselected,#xfwcfse
lected)
do Get_Field_Information('AR30006','ITEM_BALANCE',$xvitembal,#xfwitembal)
do Get_Field_Information('AR30006','CF_PARMS',$xvcf_parms,#xfwcf_parms)
do Get_Field_Information('AR30006','TOTALS',$xv_totals,#xfwtotals)
do Get_Field_Information('AR30006','REPORTTOTALS',$xv_reporttotals,#xfwreport
totals)
End-Procedure !get-xlat-fields
!----------------------------------------------------------------------!
! Procedure: Set-hdr-options !
! Desc: Set printing options for header !
!----------------------------------------------------------------------!
Begin-Procedure Set-hdr-options
evaluate $DISPLAY_OPN
when = 'C'
let $xvdisplayopn = $xvcfselected
when = 'I'
let $xvdisplayopn = $xvitembal
end-evaluate
end-procedure
!----------------------------------------------------------------------!
! Called SQC Procedures !
!----------------------------------------------------------------------!
#include 'reset.sqc' ! Reset printer procedure
#include 'curdttim.sqc' ! Get-Current-DateTime procedure
#include 'datetime.sqc' ! Routines for date and time formatting
#include 'prcsapi.sqc' ! Update Process Request API
#include 'prcsdef.sqc' ! Update Process Request Variable Declare
#include 'gar30006.sqc' ! Get Variables entered through Process Scheduler
#include 'tranctrl.sqc' ! Commit transactions
#include 'readxlat.sqc' ! Routing for Getting Translate Value

You might also like