my code stock.com

Snippet options

Download: Download snippet as newcvpf.as.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/**************** PROGRAM HEADER ************************************/
/* Program ID: EX716PF      Version: 1.00                           */
/********************************************************************/
/* Description: Client Account Summary                              */
/*    -Compute trade_acct.trxamt excluding doctype = "CA,PI,DI,WI"  */
/*    -Exclude also clearing house and entry date greater than the  */
/*         the date entered                                         */
/*    -Deduct from the accumulated trade_acct.trxamt the cash acct  */
/*         (trade_acct - curracct)                                  */
/*                                                                  */
/* Author: Thess Meniado         Date created: 02/17/1997           */
/********************************************************************/

/********************************************************************/
/* INCLUDE FILES Declarations                                       */
/********************************************************************/
{global.i}
{rformat.i}                  
{printctl.i}
{stockpos.i}
{meter.i}

/********************************************************************/
/* GLOBAL & SCOPED DEFINE Declarations                              */
/********************************************************************/
&GLOBAL-DEFINE report-title "       Client Account Summary"
&GLOBAL-DEFINE program-id   "NewCVpf.p"
&GLOBAL-DEFINE prt-time     STRING(TIME,"HH:MM:SS")

&SCOPED-DEFINE STOCK-POSITION {&SCRIP-QTY} + {&PCD-QTY}

/********************************************************************/
/* LOAD FILE FROM pseindex.csv                                      */
/********************************************************************/
&SCOPED-DEFINE RECORD-LENGTH  170
DEF VAR fi-deals AS CHAR NO-UNDO.
DEF VAR line-rec     AS CHAR FORMAT "x(170)"              NO-UNDO.
DEF VAR xline          AS INT                NO-UNDO.
DEF VAR x              AS INT                NO-UNDO.
DEF VAR c              AS CHAR               NO-UNDO.

/********************************************************************/
/* INPUT PARAMETER Definition                                       */
/********************************************************************/
DEF INPUT PARAM In_parameter AS CHAR NO-UNDO.

/********************************************************************/
/* LOCAL VARIABLE Definitions                                       */
/********************************************************************/
DEF VAR comp-name      LIKE company.NAME        NO-UNDO.
DEF VAR v_cltpcd       LIKE client.cltpcd       NO-UNDO.
DEF VAR cname          LIKE client.acctname     NO-UNDO.
DEF VAR nQtyOnhand     LIKE clportfl.qtypurc    NO-UNDO.
DEF VAR nRunningQty    LIKE clportfl.qtypurc    NO-UNDO.
DEF VAR curr_input     LIKE currency.currcode   NO-UNDO.
DEF VAR currdesc       LIKE currency.descriptn  NO-UNDO.
DEF VAR xcurr-amt      LIKE curracct.trxamt     NO-UNDO.
DEF VAR t_phisix	   LIKE os_trades.cnbalamt  NO-UNDO.
DEF VAR t_xbuyamt      LIKE os_trades.cnbalamt  NO-UNDO.
DEF VAR t_xsellamt     LIKE os_trades.cnbalamt  NO-UNDO.
DEF VAR t_xcshamt      LIKE os_trades.cnbalamt  NO-UNDO.
DEF VAR t_xrecamt      LIKE os_trades.cnbalamt  NO-UNDO.
DEF VAR t_tpayamt      LIKE os_trades.cnbalamt  NO-UNDO.
DEF VAR v-prdcd        LIKE product.productcd   NO-UNDO.
DEF VAR clacno1        LIKE trade_acct.clacno   NO-UNDO.
DEF VAR clacno2        LIKE trade_acct.clacno   NO-UNDO.
DEF VAR xtradeamt      LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xrecamt        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xphisix        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xpayamt        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xfinprd        LIKE trade_acct.finprd   NO-UNDO.
DEF VAR xfinyear       LIKE trade_acct.finyear  NO-UNDO.
DEF VAR xdealercd      LIKE trade_acct.dealercd NO-UNDO.
DEF VAR xtrade-nopse   LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xtrade-inpse   LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xtrade-outpse  LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xtrade-buy     LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR xtrade-sell    LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR tot-buy        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR tot-sell       LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR tot-cash       LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR trecamt        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR tpayamt        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR mdebit         LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR mcrdit         LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR nRunningAmt    LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR ngrsamt        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR nValueAvePrice LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR drcrAmt        LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR tot_price      LIKE product.closing_price NO-UNDO.
DEF VAR cltot_amt      LIKE trade_acct.trxamt   NO-UNDO.
DEF VAR tcolval        LIKE trade_acct.trxamt   NO-UNDO.

DEF VAR m_name     	AS CHAR FORM "X(30)" NO-UNDO.
DEF VAR bf_partic  	AS CHAR              NO-UNDO.
DEF VAR print-type 	AS CHAR              NO-UNDO.
DEF VAR xclrhse    	AS CHAR              NO-UNDO.
DEF VAR tgl_haircut AS CHAR				 NO-UNDO.
DEF VAR PSEAcctType AS CHAR				 NO-UNDO.


DEF VAR m_net     AS DEC FORM "->>>,>>>,>>>,>>>,>>9.99" NO-UNDO.
DEF VAR xquantity AS DEC FORM "->>>,>>>,>>>,>>>"        NO-UNDO.
DEF VAR InPhisix  AS DEC FORM "->>>,>>>,>>>,>>9.99"		NO-UNDO.
DEF VAR OutPhisix AS DEC FORM "->>>,>>>,>>>,>>9.99"		NO-UNDO.
DEF VAR xhaircut1 AS DEC FORM "->>>,>>>,>>>,>>9.99"		NO-UNDO.
DEF VAR xhaircut2 AS DEC FORM "->>>,>>>,>>>,>>9.99"		NO-UNDO.
DEF VAR nAvePrice AS DEC FORM ">>>9.9999"               NO-UNDO.
DEF VAR closing_price  AS DEC NO-UNDO.

DEF VAR rec-count AS INT FORM ">>>>9" NO-UNDO.
DEF VAR tempctr   AS INT INIT 0       NO-UNDO.
DEF VAR tot-rec   AS INT INIT 0       NO-UNDO.
DEF VAR v-nCtr    AS INT              NO-UNDO.
DEF VAR mainf_ctr AS INT INIT 0       NO-UNDO.

DEF VAR no-transaction AS LOG INIT TRUE  NO-UNDO.
DEF VAR crbal          AS LOG INIT TRUE  NO-UNDO.

DEF VAR def_date AS DATE NO-UNDO.

/********************************************************************/
/* TEMP-TABLE Declarations                                          */
/********************************************************************/
DEF TEMP-TABLE tt-product LIKE product.

DEF TEMP-TABLE tmpProduct
	FIELD productcd LIKE product.productcd
	FIELD descriptn LIKE product.descriptn
	INDEX tmpProduct_ak1 productcd.

DEF TEMP-TABLE tmpTrade
    FIELD clacno     LIKE trade_acct.clacno
    FIELD cCltpcd    LIKE client.cltpcd
    FIELD descriptn  LIKE clienttype.descriptn
    FIELD trade-buy  LIKE trade_acct.trxamt
    FIELD trade-sell LIKE trade_acct.trxamt
    FIELD trade-inphisix LIKE trade_acct.trxamt
    FIELD trade-outphisix LIKE trade_acct.trxamt
    FIELD trade-nophisix LIKE trade_acct.trxamt
    FIELD curr-amt   LIKE curracct.trxamt
    FIELD record_id  AS RECID
    INDEX tmpTrade_ak1 clacno.

DEF TEMP-TABLE bf-file
    FIELD productcd   LIKE producthst.productcd
    FIELD quantity    AS DEC  FORM "->>>,>>>,>>>,>>>"
    FIELD description AS CHAR FORM "X(30)"
    FIELD runbal      LIKE trade_acct.trxamt
    FIELD runqty      AS INT  FORM "->>>,>>>,>>>,>>>,>>>,>>9"
    FIELD qtyhand     AS INT  FORM "->>>,>>>,>>>,>>>,>>>,>>9"
    FIELD aveprc      AS DEC  FORM "->,>>>,>>>,>>>9.9999"
    INDEX quantity  description quantity.

DEF TEMP-TABLE aveprice
    FIELD productcd LIKE product.productcd
    FIELD runbal    LIKE trade_acct.trxamt
    FIELD runqty    AS INT FORM "->>>,>>>,>>>,>>>,>>>,>>9"
    FIELD qtyhand   AS INT FORM "->>>,>>>,>>>,>>>,>>>,>>9"
    FIELD aveprc    AS DEC FORM "->,>>>,>>>,>>>9.9999".

DEF TEMP-TABLE main-file
    FIELD canceltn           LIKE trade_acct.canceltn
    FIELD printed            LIKE trade_acct.printed
    FIELD char-fill2         LIKE trade_acct.char-fill2
    FIELD rcdstat            LIKE trade_acct.rcdstat
    FIELD entry_date         LIKE producthst.entry_date
    FIELD docdate            LIKE trade_acct.docdate
    FIELD trxcd              AS CHAR FORM "X(4)"
    FIELD ref-no             AS CHAR FORM "X(10)"
    FIELD product-name       LIKE product.descriptn
    FIELD particulars        AS CHAR FORM "X(20)"
    FIELD noshares           AS DEC  FORM "->>>,>>>,>>>,>>>,>>9.99"
    FIELD doctype            LIKE trade_acct.doctype
    FIELD docpx1             LIKE trade_acct.docpx1
    FIELD docpx2             LIKE trade_acct.docpx2
    FIELD docno              LIKE trade_acct.docno
    FIELD docsx              LIKE trade_acct.docsx
    FIELD docvs              LIKE trade_acct.docvs
    FIELD docdate1           LIKE trade_acct.docdate
    FIELD cltpcd             LIKE client.cltpcd
    FIELD clacno             LIKE trade_acct.clacno
    FIELD productcd          LIKE trade_acct.productcd
    FIELD price              LIKE trade_acct.tradeprc
    FIELD finyear            LIKE trade_acct.finyear
    FIELD finprd             LIKE trade_acct.finprd
    FIELD vcancel            AS LOG
    FIELD unit-price         AS DEC FORM "->>>,>>>,>>>,>>>,>>9.99"
    FIELD debit              AS DEC FORM "->>>,>>>,>>>,>>>,>>9.99"
    FIELD credit             AS DEC FORM "->>>,>>>,>>>,>>>,>>9.99"
    FIELD duedate            LIKE trade_acct.payduedate
    FIELD vrecid             AS RECID
    FIELD vtime              AS INT
    FIELD avepurch           AS DEC FORM "->>>,>>>,>>>,>>>,>>9.99"
    FIELD trxamt             AS DEC FORM "->>>,>>>,>>>,>>>,>>9.99"
    INDEX cd-entry AS PRIMARY
          entry_date 
          trxcd
          ref-no
    INDEX clacno
          productcd
          finyear
          finprd
          doctype
          docpx1
          docpx2
          docno
          docsx
          docvs.

/********************************************************************/
/* FRAME Definitions                                                */
/********************************************************************/
DEF FRAME report-header HEADER
    comp-name       FORM "X(28)"      AT  1
    "EXCALIBR/6000"                   AT 34
    TODAY           FORM "99/99/9999" AT 54
    {&prt-time}                       AT 65
    "Page"                            AT 75
    PAGE-NUMBER     FORM ">>9"        AT 80
    SKIP
    {&program-id}                     AT  1
    {&report-title}                   AT 23
    "Requested by:"                   AT 54
    USERID                            AT 68
    SKIP
    "As of"                           AT 33
    def_date        FORM "99/99/9999"
    SKIP(1)
    "Client                                   PSE        Receivable           Payable             Colateral                     " AT 2
    "A/C      Name of client                  Type         Amount             Amount              With Phisix             Total " AT 2
    SKIP(1)
WITH WIDTH 132 PAGE-TOP NO-LABEL STREAM-IO USE-TEXT.

DEF FRAME report-header1 HEADER
    comp-name       FORM "X(28)"      AT  1
    "EXCALIBR/6000"                   AT 34
    TODAY           FORM "99/99/9999" AT 54
    {&prt-time}                       AT 65
    "Page"                            AT 75
    PAGE-NUMBER     FORM ">>9"        AT 80
    SKIP
    {&program-id}                     AT  1
    {&report-title}                   AT 23
    "Requested by:"                   AT 54
    USERID                            AT 68
    SKIP
    "As of"                           AT 33
    def_date        FORM "99/99/9999"
    SKIP(1)
    "Client                                   PSE        Receivable           Payable             Colateral" AT 2
    "A/C      Name of client                  Type         Amount             Amount              With Phisix" AT 2
    SKIP(1)
WITH WIDTH 132 PAGE-TOP NO-LABEL STREAM-IO USE-TEXT.

DEF FRAME report-header2 HEADER
    comp-name       FORM "X(28)"      AT  1
    "EXCALIBR/6000"                   AT 34
    TODAY           FORM "99/99/9999" AT 54
    {&prt-time}                       AT 65
    "Page"                            AT 75
    PAGE-NUMBER     FORM ">>9"        AT 80
    SKIP
    {&program-id}                     AT  1
    {&report-title}                   AT 23
    "Requested by:"                   AT 54
    USERID                            AT 68
    SKIP
    "As of"                           AT 33
    def_date        FORM "99/99/9999"
    SKIP(1)
    "Client                                   PSE        Receivable           Payable                                " AT 2
    "A/C      Name of client                  Type         Amount             Amount              Total              " AT 2
    SKIP(1)
WITH WIDTH 132 PAGE-TOP NO-LABEL STREAM-IO USE-TEXT.
/********************************************************************/
/* MAIN PROGRAM LOGIC                                               */
/********************************************************************/
ASSIGN clacno1    	= ENTRY(1, In_parameter, ";")
       clacno2    	= ENTRY(2, In_parameter, ";")
       def_date   	= DATE(ENTRY(3, In_parameter, ";"))
       xfinprd    	= INT(ENTRY(4, In_parameter, ";"))
       xfinyear   	= INT(ENTRY(5, In_parameter, ";"))
       xclrhse    	= ENTRY(6, In_parameter, ";")
       print-type 	= ENTRY(7, In_parameter, ";")
       curr_input 	= ENTRY(8,In_parameter, ";")
       tgl_haircut 	= ENTRY(9,In_parameter,";").

FIND FIRST appparm WHERE appparm.company_id = def_company AND
						 appparm.branch_id  = def_branch  AND
						 appparm.parmkey   = "INPHISIX"  NO-LOCK NO-ERROR.
IF AVAIL appparm THEN
	ASSIGN InPhisix = DEC(appparm.paramvalc).
ELSE
	ASSIGN InPhisix = 0.25.
	
FIND FIRST appparm WHERE appparm.company_id = def_company AND
						 appparm.branch_id  = def_branch  AND
						 appparm.parmkey   = "OUTPHISIX"  NO-LOCK NO-ERROR.
IF AVAIL appparm THEN
	ASSIGN OutPhisix = DEC(appparm.paramvalc).
ELSE
	ASSIGN OutPhisix = 0.35.
       
	
FIND FIRST company WHERE company.company_id = def_company NO-LOCK NO-ERROR.
ASSIGN comp-name = company.name.

IF print-type = "printer" THEN DO:
   OUTPUT TO PRINTER PAGE-SIZE 60 PAGED.
   PUT CONTROL {&cpi12} + {&decompress}.
END. /* IF print-type = "printer" */
ELSE
   OUTPUT TO excalibu.txt PAGE-SIZE 60 PAGED.

RUN load-data-from-PSEINDEX.
   
RUN meter("Processing...", INPUT tot-rec, TRUE).

IF tgl_haircut = "2" THEN
	VIEW FRAME report-header2.
ELSE IF tgl_haircut = "1" THEN
	VIEW FRAME report-header1.
ELSE
	VIEW FRAME report-header.
	
FOR EACH product WHERE product.mrktid     = def_market AND
                       product.fill-char1 = curr_input NO-LOCK:
    CREATE tt-product.
    FIND FIRST mrktprc WHERE mrktprc.trxdate   <= def_date         AND
                             mrktprc.mrktid    = product.mrktid    AND
                             mrktprc.productcd = product.productcd NO-LOCK NO-ERROR.
    ASSIGN tt-product.mrktid        = def_market
           tt-product.productcd     = product.productcd
           tt-product.descriptn     = product.descriptn
           tt-product.prodclass     = product.prodclass
           tt-product.closing_price = IF AVAIL mrktprc THEN mrktprc.lastdoneprc
                                      ELSE product.closing_price.
END. /* FOR EACH product */

FOR EACH client WHERE client.company_id = def_company AND
                      client.branch_id  = def_branch  AND
                      (client.clacno    >= clacno1    AND
                       client.clacno    <= clacno2)   AND
                      (IF xclrhse = "NO" THEN client.actype <> "L" ELSE client.actype <> "") NO-LOCK:

    FOR EACH os_trades WHERE os_trades.company_id = def_company AND
    						 os_trades.branch_id  = def_branch  AND
    						 os_trades.clacno     = client.clacno AND
    						 os_trades.cnbalamt  <> 0 NO-LOCK:
	   /* IF LOOKUP(os_trades.doctype, "DI,PI,CA,WI") = 0 AND os_trades.entry_date <= def_date THEN DO: */
		FIND FIRST tmpTrade WHERE tmpTrade.clacno = os_trades.clacno NO-ERROR.
		IF NOT AVAIL tmpTrade THEN DO:   
			FIND FIRST clienttype WHERE clienttype.cltpcd = client.cltpcd NO-LOCK NO-ERROR.
			
			CREATE tmpTrade.
			ASSIGN tmpTrade.clacno    = os_trades.clacno
			tmpTrade.cCltpcd   = client.cltpcd
			tmpTrade.descriptn = IF AVAIL clienttype THEN clienttype.descriptn ELSE ""
			tot-rec            = tot-rec + 1.
			
			FIND FIRST tmpProduct WHERE tmpProduct.productcd = os_trades.productcd NO-LOCK NO-ERROR.
	        IF AVAIL tmpProduct THEN
				ASSIGN tmpTrade.trade-inphisix = tmpTrade.trade-inphisix + (os_trades.cnbalamt * inPhisix).
			ELSE
				ASSIGN tmpTrade.trade-outphisix = tmpTrade.trade-outphisix + (os_trades.cnbalamt * outPhisix).

		END. /* IF NOT AVAIL tmpTrade */
		

	END. 
	
    FOR EACH trade_acct WHERE trade_acct.company_id = def_company   AND
                              trade_acct.branch_id  = def_branch    AND
                              trade_acct.finyear    = xfinyear      AND
                              trade_acct.finprd     = xfinprd       AND
                              trade_acct.currcode   = curr_input    AND
                              trade_acct.clacno     = client.clacno NO-LOCK:
        IF LOOKUP(trade_acct.doctype, "DI,PI,CA,WI") = 0 AND trade_acct.entry_date <= def_date THEN DO:
           FIND FIRST tmpTrade WHERE tmpTrade.clacno = trade_acct.clacno NO-ERROR.
           IF NOT AVAIL tmpTrade THEN DO:
              FIND FIRST clienttype WHERE clienttype.cltpcd = client.cltpcd NO-LOCK NO-ERROR.

              CREATE tmpTrade.
              ASSIGN tmpTrade.clacno    = trade_acct.clacno
                     tmpTrade.cCltpcd   = client.cltpcd
                     tmpTrade.descriptn = IF AVAIL clienttype THEN clienttype.descriptn ELSE ""
                     tot-rec            = tot-rec + 1.
           END. /* IF NOT AVAIL tmpTrade */
           
           IF trade_acct.trxamt > 0 THEN
              ASSIGN tmpTrade.trade-buy = tmpTrade.trade-buy + trade_acct.trxamt.
           ELSE
              ASSIGN tmpTrade.trade-sell = tmpTrade.trade-sell + ABS(trade_acct.trxamt).

           /* FIND FIRST tmpProduct WHERE tmpProduct.productcd = trade_acct.productcd NO-LOCK NO-ERROR.
           IF AVAIL tmpProduct THEN
              ASSIGN tmpTrade.trade-inphisix = tmpTrade.trade-inphisix + ABS(trade_acct.gross-amt * inPhisix).
           ELSE
              ASSIGN tmpTrade.trade-outphisix = tmpTrade.trade-outphisix + ABS(trade_acct.gross-amt * outPhisix).
             */
           ASSIGN record_id = RECID(trade_acct).
        END. /* IF LOOKUP(trade_acct.doctype, "DI,PI,CA,WI") = 0 */
    END. /* FOR EACH trade_acct */

    FOR EACH curracct WHERE curracct.company_id = def_company   AND
                            curracct.branch_id  = def_branch    AND
                            curracct.finyear    = xfinyear      AND
                            curracct.finprd     = xfinprd       AND
                            curracct.currcode   = curr_input    AND
                            curracct.clacno     = client.clacno NO-LOCK:
        IF curracct.entry_date <= def_date THEN DO:
           FIND FIRST tmpTrade WHERE tmpTrade.clacno = curracct.clacno NO-ERROR.
           IF NOT AVAIL tmpTrade THEN DO:
              FIND FIRST clienttype WHERE clienttype.cltpcd = client.cltpcd NO-LOCK NO-ERROR.

              CREATE tmpTrade.
              ASSIGN tmpTrade.clacno    = curracct.clacno
                     tmpTrade.cCltpcd   = client.cltpcd
                     tmpTrade.descriptn = IF AVAIL clienttype THEN clienttype.descriptn ELSE ""
                     tot-rec            = tot-rec + 1.
           END. /* IF NOT AVAIL tmpTrade */
           
           ASSIGN tmpTrade.curr-amt = tmpTrade.curr-amt + curracct.trxamt.
        END. /* IF curracct.entry_date <= def_date */
    END. /* FOR EACH curracct */
END. /* FOR EACH client */

ASSIGN t_phisix   = 0.

FOR EACH tmpTrade BREAK BY tmpTrade.clacno:
    RUN meter("Sending Data to Printer...", INPUT tot-rec, FALSE).

    IF FIRST-OF(tmpTrade.clacno) THEN DO:
       FIND FIRST client WHERE client.company_id = def_company     AND
                               client.branch_id  = def_branch      AND
                               client.clacno     = tmpTrade.clacno NO-LOCK NO-ERROR.
       IF AVAIL client THEN
          ASSIGN cname = client.acctname.
       ELSE
          ASSIGN cname = "".

       ASSIGN xtrade-buy 	= 0            	xtrade-sell 	= 0         xcurr-amt 		= 0
              xpayamt    	= 0            	xrecamt     	= 0			cltot_amt 		= 0
              xtrade-inpse 	= 0			   	xtrade-outpse 	= 0		    xtrade-nopse 	= 0
       	      xhaircut1  	= 0.

       ASSIGN xtrade-buy  = xtrade-buy + tmpTrade.trade-buy
              xtrade-sell = xtrade-sell + tmpTrade.trade-sell
              xcurr-amt   = xcurr-amt + tmpTrade.curr-amt
              tot-buy     = tot-buy + xtrade-buy
              tot-sell    = tot-sell + xtrade-sell
              tot-cash    = tot-cash + xcurr-amt
              xtrade-inpse = xtrade-inpse + tmpTrade.trade-inphisix
              xtrade-outpse = xtrade-outpse + tmpTrade.trade-outphisix
              xtrade-nopse = xtrade-nopse + tmpTrade.trade-nophisix.

       IF xtrade-buy - xtrade-sell - xcurr-amt > 0 THEN
          ASSIGN xrecamt = xtrade-buy - xtrade-sell - xcurr-amt.
       ELSE
          ASSIGN xpayamt = xtrade-buy - xtrade-sell - xcurr-amt.
          
       ASSIGN xphisix = xtrade-inpse + xtrade-outpse + xtrade-nopse.
       
         /* MESSAGE xphisix SKIP xtrade-inpse SKIP xtrade-outpse VIEW-AS ALERT-BOX. */
	   FIND FIRST client2 WHERE client2.company_id = def_company AND
	   							client2.branch_id  = def_branch AND
	   							client2.clacno      = tmpTrade.clacno NO-LOCK NO-ERROR.
	   IF AVAIL client2 THEN
	   	 ASSIGN PSEAcctType = client2.char-fill2.
    END. /* IF FIRST-OF(tmpTrade.clacno) */

    ASSIGN trecamt    = trecamt + xrecamt
           tpayamt    = tpayamt + xpayamt
           t_xbuyamt  = t_xbuyamt + xtrade-buy
           t_xsellamt = t_xsellamt + xtrade-sell
           t_xcshamt  = t_xcshamt + xcurr-amt
           t_xrecamt  = t_xrecamt + xrecamt
           t_tpayamt  = t_tpayamt + xpayamt.

    IF xtrade-buy - xtrade-sell - xcurr-amt <> 0 THEN DO:
       FOR EACH producthst WHERE producthst.company_id = client.company_id AND
                                 producthst.branch_id  = client.branch_id  AND
                                 producthst.finyear    = xfinyear          AND
                                 producthst.finprd     = xfinprd           AND
                                 producthst.clacno     = client.clacno     AND
                                 producthst.entry_date <= def_date         NO-LOCK
                        BREAK BY producthst.clacno
                              BY producthst.productcd:
			IF FIRST-OF(producthst.productcd) THEN
				ASSIGN closing_price = 0.
				
			ASSIGN closing_price = closing_price + ({&SCRIP-QTY1} + {&PCD-QTY1}).
			
			IF LAST-OF(producthst.productcd) AND closing_price <> 0  THEN
			DO:
				FIND FIRST tt-product WHERE tt-product.mrktid 		= def_market              AND
				                            tt-product.productcd 	= producthst.productcd NO-LOCK NO-ERROR.
				IF AVAIL tt-product THEN
					ASSIGN tot_price = tt-product.closing_price.
				ELSE
					ASSIGN tot_price = 0.
					
				ASSIGN cltot_amt       =cltot_amt + (closing_price * tot_price)
				       xhaircut2 = (closing_price * tot_price)
				       closing_price = 0.
				       
				FIND FIRST tmpProduct WHERE tmpProduct.productcd = producthst.productcd NO-LOCK NO-ERROR.
				IF AVAIL tmpProduct THEN
					ASSIGN xhaircut1 = xhaircut1 + (xhaircut2 - (xhaircut2 * InPhisix)).
				ELSE
					ASSIGN xhaircut1 = xhaircut1 + (xhaircut2 - (xhaircut2 * OutPhisix)).
					
					/* MESSAGE cltot_amt - (cltot_amt * OutPhisix) SKIP cltot_amt VIEW-AS ALERT-BOX. */
			END.
		END.
       	ASSIGN rec-count = rec-count + 1.
       	RUN report-detail.
       	
       	ASSIGN tcolval    = tcolval + cltot_amt
       	       t_phisix   = t_phisix + xhaircut1.
    END. /* IF xtrade-buy - xtrade-sell - xcurr-amt <> 0 */
END. /* FOR EACH tmpTrade */

RUN report-total.
OUTPUT CLOSE.

/********************************************************************/
/* PROCEDURE Declarations                                           */
/********************************************************************/
PROCEDURE report-detail:
   PUT tmptrade.clacno    AT  2
       cname FORM "X(30)" AT 11
       PSEAcctType	FORM "X(3)"	  AT 43.
   IF xrecamt <> 0 THEN
      PUT xrecamt FORM "->>>,>>>,>>>,>>9.99" AT 47.
      
   IF xpayamt <> 0 THEN
      PUT ABS(xpayamt) FORM "->>>,>>>,>>>,>>9.99" AT 66.
      
IF tgl_haircut = "1" THEN
	PUT xhaircut1 FORM "->>>,>>>,>>>,>>9.99" AT 86.
	
IF tgl_haircut = "2" THEN
	PUT cltot_amt FORM "->,>>>,>>>,>>>,>>9.99" AT 89.
END PROCEDURE.

PROCEDURE report-total:

IF tgl_haircut = "2" THEN
   PUT SKIP(1)
       "** Grand Total **"                     		AT 25
       trecamt      FORM "->>>,>>>,>>>,>>9.99" 		AT 47
       ABS(tpayamt) FORM "->>>,>>>,>>>,>>9.99" 		AT 66
       tcolval      FORM "->,>>>,>>>,>>>,>>9.99" 	AT 89
       "=================="                    		AT 48
       "=================="                    		AT 67
       "====================="                 		AT 89
       SKIP(1)
       rec-count                               		AT  1
       " records listed"                       		
       "*** End of Report ***"                 		AT 30.
ELSE IF tgl_haircut = "1" THEN
   PUT SKIP(1)
       "** Grand Total **"                     		AT 25
       trecamt      FORM "->>>,>>>,>>>,>>9.99" 		AT 47
       ABS(tpayamt) FORM "->>>,>>>,>>>,>>9.99" 		AT 66
       t_phisix     FORM "->>>,>>>,>>>,>>9.99"		AT 86
       "=================="                    		AT 48
       "=================="                    		AT 67
       "=================="                    		AT 87
       SKIP(1)
       rec-count                               		AT  1
       " records listed"                       		
       "*** End of Report ***"                 		AT 30.
ELSE
   PUT SKIP(1)
       "** Grand Total **"                     		AT 25
       trecamt      FORM "->>>,>>>,>>>,>>9.99" 		AT 47     
       t_phisix     FORM "->>>,>>>,>>>,>>9.99"		AT 81
       tcolval      FORM "->,>>>,>>>,>>>,>>9.99" 	AT 99       
       ABS(tpayamt) FORM "->>>,>>>,>>>,>>9.99" 		AT 66
       ABS(xhaircut1) FORM "->>>,>>>,>>>,>>9.99" 	AT 81
       ABS(cltot_amt) FORM "->>>,>>>,>>>,>>9.99" 	AT 101       
       "=================="                    		AT 48
       "=================="                    		AT 67
       "==============="                    		AT 88
       "=================="                    		AT 106
       SKIP(1)
       rec-count                               		AT  1
       " records listed"                       		
       "*** End of Report ***"                 		AT 30.
END PROCEDURE.

PROCEDURE load-data-from-PSEINDEX:
ASSIGN fi-deals = "pseindex.csv".

INPUT FROM VALUE(fi-deals).
ASSIGN xline = 0.

    ABC:
    REPEAT:
        ASSIGN xline    = xline + 1
               line-rec = "".
               
        DO x = 1 TO {&RECORD-LENGTH}:
           READKEY.
           IF LASTKEY = 13 THEN LEAVE.
           
           c    = CHR(LASTKEY).
           line-rec = line-rec + c.
        END. /* DO x = 1 TO 250 */ 
   
        IF line-rec = "" THEN LEAVE ABC.
        /* IF xline = 1 THEN NEXT ABC.*/
        
        IF TRIM(ENTRY(1,line-rec,",")) = "" THEN NEXT.
        ELSE
        DO:
            CREATE  tmpProduct.
            ASSIGN  tmpProduct.productcd = TRIM(ENTRY(1,line-rec,","))
                    tmpProduct.descriptn = TRIM(ENTRY(2,line-rec,",")).
        END.
    END.
INPUT CLOSE.
END PROCEDURE.

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.