Google
 

Trailing-Edge - PDP-10 Archives - BB-H137D-BM - uetp/lib/spdbms.cbl
There are 11 other files named spdbms.cbl in the archive. Click here to see a list.
IDENTIFICATION DIVISION.
PROGRAM-ID.  PBDBMS.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.



	SELECT POSTAL-FILE ASSIGN TO DSK.





DATA DIVISION.



FILE SECTION.



FD  POSTAL-FILE 
	LABEL RECORDS ARE STANDARD
	VALUE OF ID CRT12-REPORT-FILE-NME
	DATA RECORD IS POSTAL-REC.
01  POSTAL-REC.
	05  PARENT-P		PIC X(4).
	05  BRANCH-P		PIC X(4).
	05  METER-P		PIC X(5).
	05  UPDATED-P		PIC X(5).
	05  ACT-RECS-P		PIC X(5).
	05  CUSTOMER-P	PIC X(5).
	05  DATE-P		PIC X(6).
SCHEMA SECTION.


*SINGLE	INVOKE SUB-SCHEMA SUBPIT OF SCHEMA PITNEY.
*SHARED	INVOKE SUB-SCHEMA SUBPIT OF SCHEMA SPDAVE.
*NOJOUR INVOKE SUB-SCHEMA SUBPIT OF SCHEMA PBLOAD.
	INVOKE SUB-SCHEMA SUBPIT OF SCHEMA SPDAVE.
WORKING-STORAGE SECTION.


01  CRT12-REPORT-FILE-NME		PIC X(9).
01  DATA-BASE-IS-OPEN		PIC X  VALUE "N".
01  THIS-TRANSACTION-UPDATES	PIC X.
01 DONE-FLAG			PIC X(3).
01 NEXT-ACTIVITY-RECORD		PIC S9(10) COMP.
01  MAXIMUM-RECORDS		PIC S9(10) COMP.
01  MESSAGE-CONTROL-WS.
	05  MESSAGE-KEY-WS.
		10  MCS-KEY-WS	PIC X(5).
		10  MCS-ERROR-STATUS-WS PIC 9(5).
		10  MCS-ESM-WS		PIC X(10).
	05  MESSAGE-WS.		
		10  MCS-WS	PIC X(30).
		10  MCS-TRANS-WS	PIC X(30).



01  CUST-LS			PIC X(10) VALUE "CUSTOMER".
01  METER-LS			PIC X(10) VALUE "METER".
01  ACTIVITY-LS			PIC X(10) VALUE "ACTIVITY".
01  PARENT-LS			PIC X(10) VALUE "PARENT".
01  BRANCH-LS 			PIC X(10) VALUE "BRANCH".

01 COMPUTATIONAL-COUNTERS COMPUTATIONAL.
  02 PARENT-COUNT	PIC S9(10).
  02 BRANCH-COUNT	PIC S9(10).
  02 METER-COUNT	PIC S9(10).
  02 TRANSACTION-COUNT	PIC S9(10).
	02  CALL-COUNT	PIC S9(10).
  02 LAST-T12-COUNT	PIC S9(10).
  02 THE-ERROR-COUNT	PIC S9(10).

01 TRANSACTION-ID.
  02 CR-user-application	PIC X(8).
  02 CR-user-job-number		PIC X(3).
  02 CR-user-identity		PIC X(8).
  02 CR-user-terminal-number	PIC X(3).
  02 FILLER			PIC X.
  02 CR-user-transaction-count	PIC X(4).
  02 FILLER			PIC X.
  02 TI-user-transaction-type	PIC X(2).
LINKAGE SECTION.



01  COMMUNICATION-RECORD  COPY  COMREC.


PROCEDURE DIVISION USING COMMUNICATION-RECORD.


DECLARATIVES.
DBMS-ERROR SECTION.
	USE IF ERROR-STATUS.
DBMS-ERROR-CHECK.
	IF ERROR-STATUS = 307 OR 326
		GO TO DBMS-ERROR-EXIT.
	DISPLAY "ERROR STATUS " ERROR-STATUS.
	DISPLAY "ERROR AREA " ERROR-AREA.
	DISPLAY "ERROR RECORD " ERROR-RECORD.
	DISPLAY "ERROR SET " ERROR-SET.
DBMS-ERROR-EXIT.
	EXIT.
END DECLARATIVES.


	GO TO S06-RETURN-ROUTINE.

S00-OPENING SECTION.

ENTRY DBOPEN USING COMMUNICATION-RECORD.

P00-CHECK-SWITCH.
	IF DATA-BASE-IS-OPEN = "N"
*	    THEN
*SINGLE		OPEN ALL USAGE-MODE  UPDATE
*SHARED		OPEN JOURNAL USAGE-MODE EXCLUSIVE UPDATE
*SHARED		OPEN ALL USAGE-MODE EXCLUSIVE  UPDATE
*NOJOUR		OPEN JOURNAL USAGE-MODE EXCLUSIVE UPDATE
		OPEN JOURNAL USAGE-MODE EXCLUSIVE UPDATE
		OPEN ALL USAGE-MODE EXCLUSIVE  UPDATE
		MOVE 0 TO TRANSACTION-COUNT CALL-COUNT
		IF ERROR-STATUS > 0
*		    THEN  ---ERROR ON DATA BASE OPEN---
			MOVE 99 TO CR-return-code
			DISPLAY '[Could not open data base.  Error='
				ERROR-STATUS , ']'
		    ELSE
			MOVE "Y" TO DATA-BASE-IS-OPEN
	    ELSE
		NEXT SENTENCE.
	GO TO S06-RETURN-ROUTINE.



S03-CLOSE-ROUTINE SECTION.

ENTRY DBCLOS USING COMMUNICATION-RECORD.
P00-DBMS-CLOSE.
	IF DATA-BASE-IS-OPEN = "Y"
		CLOSE RUN-UNIT.
	IF ERROR-STATUS > 0
*	    THEN
		MOVE 99 TO CR-return-code
		DISPLAY '[Could not close data base.  Error='
				ERROR-STATUS , ']'
	    ELSE
		MOVE 'N' TO DATA-BASE-IS-OPEN.
	ENTER MACRO STATS.
	GO TO S06-RETURN-ROUTINE.
*************************************
S04-ACCESS-ROUTINES SECTION.
*************************************


P01-FIND-CUSTOMER.
	FIND CUSTOMER-RECORD RECORD.
	IF ERROR-STATUS NOT = ZERO
		GO TO P02-CUSTOMER-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P03-FIND-CUSTOMER-EXIT.
P02-CUSTOMER-ERROR.
	MOVE 3 TO CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-CUSTOMER ERROR' TO MCS-WS.
P03-FIND-CUSTOMER-EXIT.
	EXIT.



P04-FIND-METER.
	FIND METER-RECORD RECORD.
	IF ERROR-STATUS NOT = ZERO
		GO TO P05-METER-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P06-FIND-METER-EXIT.
P05-METER-ERROR.
	MOVE 1 TO CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-METER ERROR' TO MCS-WS.
P06-FIND-METER-EXIT.
	EXIT.




P07-FIND-PARENT-PO.
	FIND PARENT-PO-RECORD RECORD.
	IF ERROR-STATUS NOT = ZERO
		GO TO P08-PARENT-PO-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P09-FIND-PARENT-PO-EXIT.
P08-PARENT-PO-ERROR.
	MOVE 8 TO CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-PARENT ERROR' TO MCS-WS.
P09-FIND-PARENT-PO-EXIT.
	EXIT.




P10-FIND-BRANCH-PO.
	FIND BRANCH-PO-RECORD RECORD.
	IF ERROR-STATUS NOT = ZERO
		GO TO P11-BRANCH-PO-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P12-FIND-BRANCH-PO-EXIT.
P11-BRANCH-PO-ERROR.
	MOVE 5 TO CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-BRANCH ERROR' TO MCS-WS.
P12-FIND-BRANCH-PO-EXIT.
	EXIT.




P13-FIND-ACTIVITY.
	FIND NEXT METER-ACT-RECORD RECORD OF METER-SET SET.
	IF ERROR-STATUS NOT = ZERO
		GO TO P14-ACTIVITY-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P15-FIND-ACTIVITY-EXIT.
P14-ACTIVITY-ERROR.
	MOVE 99 TO CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-ACTIVITY ERROR' TO MCS-WS.
P15-FIND-ACTIVITY-EXIT.
	EXIT.





P16-FIND-CUSTOMER-HISTORY.
	FIND CUSTOMER-HISTORY-RECORD RECORD.
	IF ERROR-STATUS NOT = ZERO
		GO TO P17-CUSTOMER-HISTORY-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P18-FIND-CUSTOMER-HISTORY-EXIT.
P17-CUSTOMER-HISTORY-ERROR.
	MOVE 99 TO  CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-CUSTOMER-HISTORY ERROR' TO MCS-WS.
P18-FIND-CUSTOMER-HISTORY-EXIT.
	EXIT.





P19-FIND-BRANCH-HISTORY.
	FIND BRANCH-HISTORY-RECORD RECORD.
	IF ERROR-STATUS NOT = ZERO
		GO TO P20-BRANCH-HISTORY-ERROR.
	GET.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P21-FIND-BRANCH-HISTORY-EXIT.
P20-BRANCH-HISTORY-ERROR.
	MOVE 99 TO CR-RETURN-CODE.
	PERFORM P52-MCS-MESSAGE.
	MOVE ' FIND-BRANCH-HISTORY ERROR' TO MCS-WS.
P21-FIND-BRANCH-HISTORY-EXIT.
	EXIT.




P22-STORE-CUSTOMER.
	MOVE ZERO TO CR-RETURN-CODE.
	STORE CUSTOMER-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS

		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-CUSTOMER ERROR' TO MCS-WS.


P23-STORE-CUSTOMER-EXIT.
	EXIT.




P24-STORE-METER.
	MOVE ZERO TO CR-RETURN-CODE.
	STORE METER-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-METER ERROR' TO MCS-WS.


P25-STORE-METER-EXIT.
	EXIT.




P26-STORE-PARENT-PO.
	MOVE ZERO TO CR-RETURN-CODE.
	STORE PARENT-PO-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-PARENT ERROR' TO MCS-WS.


P27-STORE-PARENT-PO-EXIT.
	EXIT.




P28-STORE-BRANCH-PO.
	MOVE ZERO TO CR-RETURN-CODE.
	STORE BRANCH-PO-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-BRANCH ERROR' TO MCS-WS.


P29-STORE-BRANCH-PO-EXIT.
	EXIT.




P30-STORE-ACTIVITY.
	MOVE  ZERO TO CR-RETURN-CODE.
	STORE METER-ACT-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-ACTIVITY ERROR' TO MCS-WS.


P31-STORE-ACTIVITY-EXIT.
	EXIT.




P32-STORE-CUSTOMER-HISTORY.
	MOVE ZERO TO CR-RETURN-CODE.
	MOVE METER-NUMBER TO METER-CUSTOMER-HISTORY-NUMBER.
	MOVE CUSTOMER-NUMBER TO CUSTOMER-HISTORY-NUMBER.
	STORE CUSTOMER-HISTORY-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-CUSTOMER-HISTORY ERROR'
			TO MCS-WS.


P33-STORE-CUST-HISTORY-EXIT.
	EXIT.


P34-STORE-BRANCH-HISTORY.
	MOVE ZERO TO CR-RETURN-CODE.
	MOVE METER-NUMBER TO METER-BRANCH-HISTORY-NUMBER.
	MOVE BRANCH-NUMBER TO BRANCH-HISTORY-NUMBER.
	STORE BRANCH-HISTORY-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' STORE-BRANCH-HISTORY ERROR'
			TO MCS-WS.


P35-STORE-BRANCH-HISTORY-EXIT.
	EXIT.





P36-MODIFY-CUSTOMER.
	MOVE ZERO TO CR-RETURN-CODE.
	MODIFY CUSTOMER-RECORD; CUST-DATE, CUST-UPDATE-FLAG.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' MODIFY-CUSTOMER ERROR' TO MCS-WS.


P37-MODIFY-CUSTOMER-EXIT.
	EXIT.




P38-MODIFY-METER.
	MOVE ZERO TO CR-RETURN-CODE.
	MOVE CRB-HHMM TO METER-LAST-UPDATE.
	MODIFY METER-RECORD; METER-ACT-RECORDS; METER-LAST-UPDATE;
				METER-UPDATE-FLAG.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE

		MOVE ' MODIFY-METER ERROR' TO MCS-WS.


P39-MODIFY-METER-EXIT.
	EXIT.




P40-MODIFY-PARENT-PO.
	MOVE ZERO TO CR-RETURN-CODE.
	MODIFY PARENT-PO-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' MODIFY-PARENT ERROR' TO MCS-WS.


P41-MODIFY-PARENT-PO-EXIT.
	EXIT.




P42-MODIFY-BRANCH-PO.
	MOVE ZERO TO CR-RETURN-CODE.
	MODIFY BRANCH-PO-RECORD.
	IF ERROR-STATUS NOT = ZERO
		PERFORM P50-ERROR-STATUS
		PERFORM P52-MCS-MESSAGE
		MOVE ' MODIFY-BRANCH ERROR' TO MCS-WS.


P43-MODIFY-BRANCH-PO-EXIT.
	EXIT.
















******************************************
S06-RETURN-ROUTINE SECTION.
******************************************

P44-NORMAL-RETURN.
	IF THE-ERROR-COUNT > 0
*	     THEN   --ERROR HAS OCCURED---
		GO TO P45-ERROR-RETURN
	      ELSE
		NEXT SENTENCE.

	MOVE ZERO TO CR-RETURN-CODE.
	IF THIS-TRANSACTION-UPDATES = 'Y'
*	    THEN  ---NEED TO END TRANSACTION--
		ENTER MACRO JETRAN USING TRANSACTION-ID, TRANSACTION-COUNT
	    ELSE
		NEXT SENTENCE.

	GO TO DO-THE-RETURN.


P45-ERROR-RETURN.
	IF CR-RETURN-CODE = 0
*	  THEN
		MOVE 99 TO CR-RETURN-CODE
	  ELSE
		NEXT SENTENCE.

	IF THIS-TRANSACTION-UPDATES = 'Y'
*	    THEN   --- MUST BACKOUT THE TRANSACTION ---
		DISPLAY '[backing out Transaction #' TRANSACTION-COUNT,
			' with ID=' TRANSACTION-ID ']'
		ENTER MACRO JBTRAN USING 0
	    ELSE
		NEXT SENTENCE.

	GO TO DO-THE-RETURN.



DO-THE-RETURN.
	GOBACK.




P50-ERROR-STATUS.
	MOVE 99 TO CR-RETURN-CODE.
	ADD 1 TO THE-ERROR-COUNT.


P51-EXIT.
	EXIT.



P52-MCS-MESSAGE.
	MOVE ERROR-STATUS TO MCS-ERROR-STATUS-WS.
	MOVE ' ERR STAT' TO MCS-ESM-WS.
	MOVE TRANSACTION-ID TO MCS-TRANS-WS.


P53-EXIT.
	EXIT.
**************************************
S08-TRANSACTION-PROCESSING SECTION.
**************************************


ENTRY DBTRAN USING COMMUNICATION-RECORD.



P100-TRANS-CONTROL.


	IF CR-OPEN-DATA-BASE
*	    THEN
		IF DATA-BASE-IS-OPEN = "Y"
*		    THEN
			MOVE 0 TO CR-RETURN-CODE
			GO TO S06-RETURN-ROUTINE
		    ELSE
			MOVE 99 TO CR-RETURN-CODE
			GO TO S06-RETURN-ROUTINE
	    ELSE
		IF CR-CLOSE-DATA-BASE
*		    THEN
			IF DATA-BASE-IS-OPEN = 'NO'
*			    THEN
				MOVE 0 TO  CR-RETURN-CODE
				GO TO S06-RETURN-ROUTINE
			     ELSE
				MOVE 99 TO CR-RETURN-CODE
				GO TO S06-RETURN-ROUTINE
		    ELSE
			NEXT SENTENCE.


	IF DATA-BASE-IS-OPEN = 'N'
*	    THEN
		MOVE 99 TO CR-return-code
		GO TO P45-ERROR-RETURN
	     ELSE
		NEXT SENTENCE.
* Dispatch to the transaction handler as specified by the
* value in the COMMUNICATION-RECORD variable CR-transaction-number.


*SINGLE	MOVE 'N' TO THIS-TRANSACTION-UPDATES.
*SHARED	MOVE 'N' TO THIS-TRANSACTION-UPDATES.
*NOJOUR	MOVE 'Z' TO THIS-TRANSACTION-UPDATES.
	MOVE 'N' TO THIS-TRANSACTION-UPDATES.
	MOVE 0 TO THE-ERROR-COUNT.
	MOVE SPACES TO CR-USER-MESSAGE.




	ADD 1 TO CALL-COUNT.



	GO TO		P101-TRANS-CR-T01
			P111-TRANS-CR-T02
			P116-TRANS-CR-T03
			P122-TRANS-CR-T04
			P126-TRANS-CR-T05
			P128-TRANS-CR-T06
			P134-TRANS-CR-T07
			P135-TRANS-CR-T08
			P200-TRANS-CR-T09
			P300-TRANS-CR-T10
			P400-TRANS-CR-T11
			P500-TRANS-CR-T12
			P600-TRANS-CR-T13
			P700-TRANS-CR-T14

	DEPENDING ON CR-TRANSACTION-NUMBER.



P100A.
	GO TO P45-ERROR-RETURN.
**********                             ***************
*            TRANSACTION TYPE 1
*
* FUNCTION: Link a meter to a customer and branch
*
* Verify the customer, meter, and branch numbers.
* If the meter is currently linked to a customer and/or a
*   branch, break the links.
* Link the meter to the specified customer and branch.
*
**********                             ***************

* Verify customer, meter, and branch numbers:

P101-TRANS-CR-T01.
	MOVE CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.
	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	IF CR-RETURN-CODE > ZERO 
		GO TO S09-RETURN-ROUTINE.
P102.
	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.
P103.
	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.
	PERFORM P10-FIND-BRANCH-PO THRU
		P12-FIND-BRANCH-PO-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.


* At this point this transaction will cause some updating

	PERFORM P1000-MARK-UPDATE-TRANSACTION.

* If meter already linked to customer, break the link.

P103-CUST-METER-LINK.
	FIND OWNER IN CUSTOMER-METER-SET 
		OF CURRENT OF METER-RECORD RECORD.
P103A.
	IF ERROR-STATUS > 0
*	   THEN   assume records not linked.
		GO TO P105-PO-METER-LINK
	   ELSE
		NEXT SENTENCE.
	GET.

P104-ERROR.

	PERFORM P32-STORE-CUSTOMER-HISTORY THRU
		P33-STORE-CUST-HISTORY-EXIT.

	IF CR-RETURN-CODE > ZERO 
		GO TO S09-RETURN-ROUTINE.

	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO P110A-ERROR.
	MOVE 6 TO CR-RETURN-CODE.
	PERFORM S13-DELETE-ROUTINES.

* If meter already linked to branch, break the link.

P105-PO-METER-LINK.
	FIND OWNER IN BRANCH-METER-SET
		OF CURRENT OF METER-RECORD RECORD.
P105A.
	IF ERROR-STATUS > 0
*	    THEN assume record has no owner
		GO TO P107-INSERT-CUST-METER
	    ELSE
		NEXT SENTENCE.

	GET.

P106-ERROR.

	PERFORM P34-STORE-BRANCH-HISTORY THRU
		P35-STORE-BRANCH-HISTORY-EXIT.


	IF CR-RETURN-CODE > ZERO 
		GO TO S09-RETURN-ROUTINE.


	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO P110A-ERROR.
	MOVE 7 TO CR-RETURN-CODE.
	PERFORM S13-DELETE-ROUTINES.

* Link meter to customer and branch



*first reestablish correct current customers, branches and make
* meter current of run unit.

P107-INSERT-CUST-METER.
	MOVE CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.
	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.
	PERFORM P10-FIND-BRANCH-PO THRU P12-FIND-BRANCH-PO-EXIT.
	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.

* link customer and meter

	
	INSERT METER-RECORD INTO CUSTOMER-METER-SET.

* Link the meter to the branch.

P108.
	INSERT METER-RECORD INTO BRANCH-METER-SET.
P110.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.

P110A-ERROR.
	MOVE 99 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 2
*
* FUNCTION: Add a new meter activity.
*
* Verify the meter number exists.
* Create a meter activity record and link to the meter.
*
**********                             ***************

* Verify the meter record.


P111-TRANS-CR-T02.
	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.
P112.


* An update is sure to follow

	PERFORM P1000-MARK-UPDATE-TRANSACTION.

* Set up the information in the activity record.

	MOVE CRB-date TO METER-ACT-DATE.
	MOVE CRB-ACTIVITY-CODE TO METER-ACT-CODE.
	MOVE ACTIVITY-LS TO METER-ACT-REC-DESC.
P113.

* Store the activity record and insert in meter set (Automatic).

	PERFORM P30-STORE-ACTIVITY
		THRU P31-STORE-ACTIVITY-EXIT.



	IF CR-RETURN-CODE > ZERO
		GO TO P115.


P114.

* Update the count of meter activity records.

	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	ADD 1 TO METER-ACT-RECORDS.
	PERFORM P38-MODIFY-METER THRU P39-MODIFY-METER-EXIT.
P115.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 3
*
* FUNCTION: Establish links between parent and branch po.
*
* Verify the the branch and parent exist.
* If the branch is currently linked, then unlink it.
* Link the branch and parent together.
*
**********                             ***************


P116-TRANS-CR-T03.
	MOVE CRB-PARENT-PO-NUMBER TO PARENT-NUMBER.
	PERFORM P07-FIND-PARENT-PO THRU P09-FIND-PARENT-PO-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.
P117.
	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.
	PERFORM P10-FIND-BRANCH-PO THRU P12-FIND-BRANCH-PO-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.

* At this point it is probable that the transaction will be updated.

	PERFORM P1000-MARK-UPDATE-TRANSACTION.

P118-PARENT-BRANCH-PO-LINK.
	FIND OWNER IN PARENT-SET OF CURRENT OF BRANCH-PO-RECORD RECORD.
P118A.
	IF ERROR-STATUS > 0
*	    THEN
		 GO TO P120-INSERT-PARENT-BRANCH-PO
	     ELSE
		NEXT SENTENCE.

	GET.
	IF PARENT-NUMBER = CRB-PARENT-PO-NUMBER
*	   THEN  ---OLD PARENT SAME AS NEW----
		MOVE 0 TO CR-RETURN-CODE
		MOVE 'N' TO THIS-TRANSACTION-UPDATES
		GO TO S09-RETURN-ROUTINE
	    ELSE
		NEXT SENTENCE.

P119-ERROR.

	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.



	PERFORM P10-FIND-BRANCH-PO THRU
		P12-FIND-BRANCH-PO-EXIT.
	MOVE 9 TO CR-RETURN-CODE.
	PERFORM S13-DELETE-ROUTINES.

P120-INSERT-PARENT-BRANCH-PO.
	MOVE ZERO TO CR-RETURN-CODE.
	MOVE CRB-PARENT-PO-NUMBER TO PARENT-NUMBER.
	PERFORM P07-FIND-PARENT-PO THRU P09-FIND-PARENT-PO-EXIT.
	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.
	PERFORM P10-FIND-BRANCH-PO THRU P12-FIND-BRANCH-PO-EXIT.
	INSERT BRANCH-PO-RECORD INTO PARENT-SET.
P121.
	MOVE 0 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 4
*
* FUNCTION: Delete a customer from the disk.
*
* Verify the customer number.
* Break any  links between it and post history records.
* Delete the customer.
*
**********                             ***************


* Validate the customer number

P122-TRANS-CR-T04.
	MOVE CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.
	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.

* Mark this, an update transaction

	PERFORM P1000-MARK-UPDATE-TRANSACTION.

P123-CUST-METER-LINK.

* for each meter linked to customer, post a history record.

	FIND NEXT RECORD OF CUSTOMER-METER-SET SET.
	IF ERROR-STATUS > 0
*	    THEN
		GO TO P125-DELETE-CUST
	    ELSE
		NEXT SENTENCE.

	GET.
	PERFORM P32-STORE-CUSTOMER-HISTORY THRU
		P33-STORE-CUST-HISTORY-EXIT.


	IF CR-RETURN-CODE > ZERO
		GO TO P125-DELETE-CUST.


	GO TO P123-CUST-METER-LINK.

P125-DELETE-CUST.

* Delete the customer, thereby removing all links to meters



	MOVE CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.

	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	MOVE 11 TO CR-RETURN-CODE.
	PERFORM S13-DELETE-ROUTINES.
P125A.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 5
*
* FUNCTION: Add a customer.
*
* Verify the customer does not exists and add.
*
**********                             ***************


P126-TRANS-CR-T05.
	MOVE  CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.
	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	IF CR-RETURN-CODE = 3 GO TO P127-ADD-CUST.
P126A.
	MOVE 4 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.
P127-ADD-CUST.
	PERFORM P1000-MARK-UPDATE-TRANSACTION.
	MOVE  CRB-DATE TO CUST-DATE.
	MOVE CUST-LS TO CUST-REC-DESC.
	PERFORM P22-STORE-CUSTOMER THRU P23-STORE-CUSTOMER-EXIT.
P127A.
	GO TO  S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 6
*
* FUNCTION: Delete a meter from the disk.
*
* Verify meter number exists.
* Break all links with customers and branches.
* Delete all history and activity records associated with meter.
* Delete the meter.
*
**********                             ***************


P128-TRANS-CR-T06.

* Verify meter exists

	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE > ZERO
		GO TO S09-RETURN-ROUTINE.


P133-DELETE-METER.
	PERFORM P1000-MARK-UPDATE-TRANSACTION.

* Delete meter thereby taking with it all history and activity records
*   and also removing it from sets with customer and branch records.

	MOVE 12 TO CR-RETURN-CODE.
	PERFORM S13-DELETE-ROUTINES.
P133A.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 7
*
* FUNCTION: Add a meter.
*
* Verify meter does not exist.
* Add the meter.
*
**********                             ***************


P134-TRANS-CR-T07.
	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE = ZERO 
		GO TO P134C-ERROR.
P134A-CREATE-METER.

	PERFORM P1000-MARK-UPDATE-TRANSACTION.
	MOVE METER-LS TO METER-REC-DESC.
	MOVE CRB-HHMM TO METER-LAST-UPDATE.
	PERFORM P24-STORE-METER THRU P25-STORE-METER-EXIT.
P134B.
	GO TO S09-RETURN-ROUTINE.
P134C-ERROR.
	MOVE 2 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.
**********                            ***************
*            TRANSACTION TYPE 8
*
* FUNCTION: Update information associated with a meter
*
* Verify that meter and customer exist.
* Create activity record and update meter and customer records.
*
**********                            ***************


P135-TRANS-CR-T08.
*	DISPLAY "ENTER IN CR-TRANSACTION-SUBTYPE PIC 9".
*	ACCEPT CR-TRANSACTION-SUBTYPE.

* If whole transaction type 8 --- (from interactive user) then
*   all information here---- do everything

	IF CR-T08-DO-EVERYTHING
		GO TO P136-DO-EVERYTHING.

* If getting piecemeal transactions from VRU then do one thing
*  at a time.

	GO TO 

		P137-VERIFY-CUSTOMER
		P138-VERIFY-METER
		P139-VERIFY-CM-LINK
*GROUP -- AFTER DISCUSSIONS WITH PB, ALL UPDATES SHOULD BE DONE AT ONCE
*GROUP		P140-UPDATE-CM-RECS
*GROUP		P145-CREATE-ACTIVITY
		P139B
		P136B

	   DEPENDING ON CR-transaction-subtype.

* illegal subtype -- tell caller

	MOVE 99 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.


P136-DO-EVERYTHING.
	PERFORM P137-VERIFY-CUSTOMER.
	   IF CR-RETURN-CODE > ZERO
		GO TO P147-TRANS-08-EXIT.
	PERFORM P138-VERIFY-METER.
	   IF CR-RETURN-CODE > ZERO
		GO TO P147-TRANS-08-EXIT.
	PERFORM P139-VERIFY-CM-LINK.
	   IF CR-RETURN-CODE > ZERO
		GO TO P147-TRANS-08-EXIT.

	PERFORM P141-UPDATE-CUSTOMER.
	PERFORM P143-UPDATE-DATA.
	PERFORM P145-CREATE-ACTIVITY.
P136A.
	GO TO S09-RETURN-ROUTINE.

P136B.
	PERFORM P137-VERIFY-CUSTOMER.
	PERFORM P141-UPDATE-CUSTOMER.
	PERFORM P143-UPDATE-DATA.
	PERFORM P145-CREATE-ACTIVITY.


P137-VERIFY-CUSTOMER.
	MOVE CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.
	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	IF CR-RETURN-CODE = ZERO
		MOVE CUST-UPDATE-FLAG TO
		CRT08-CUSTOMER-UPDATE-COUNT.
P137A.
	GO TO P147-TRANS-08-EXIT.

P138-VERIFY-METER.
	MOVE CRB-METER-NUMBER TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-RETURN-CODE = ZERO
		MOVE METER-UPDATE-FLAG TO
		CRT08-METER-UPDATE-COUNT.
P138A.
	GO TO P147-TRANS-08-EXIT.

P139-VERIFY-CM-LINK.
	IF NOT CR-T08-DO-EVERYTHING
*	    THEN   --MUST GET METER AGAIN--
		PERFORM P138-VERIFY-METER
		IF CR-return-code NOT = 0
*		   THEN  --COULD NOT FIND METER--
			GO TO P147-TRANS-08-EXIT
		    ELSE
			NEXT SENTENCE
	    ELSE
		NEXT SENTENCE.

	FIND OWNER IN CUSTOMER-METER-SET OF CURRENT OF METER-RECORD RECORD.
	IF ERROR-STATUS > 0
*	    THEN   -- NO OWNER --
		MOVE 10 TO CR-RETURN-CODE
	    ELSE
		GET
		IF CUSTOMER-NUMBER NOT = CRB-customer-number
*		    THEN --- wrong owner--
			MOVE 10 TO CR-RETURN-CODE
		    ELSE
			NEXT SENTENCE.

P139A.
	GO TO P147-TRANS-08-EXIT.




P139B.
	PERFORM P138-VERIFY-METER.
	ADD 1 METER-UPDATE-FLAG GIVING CRT08-METER-UPDATE-COUNT.

	PERFORM P137-VERIFY-CUSTOMER.
	ADD 1 CUST-UPDATE-FLAG GIVING
		CRT08-CUSTOMER-UPDATE-COUNT.


	GO TO P147-TRANS-08-EXIT.




P140-UPDATE-CM-RECS.
	PERFORM P138-VERIFY-METER.
	IF CR-RETURN-CODE > ZERO
		GO TO P147-TRANS-08-EXIT.
	PERFORM P137-VERIFY-CUSTOMER.
	IF CR-RETURN-CODE > ZERO
		GO TO P147-TRANS-08-EXIT.

P141-UPDATE-CUSTOMER.
	PERFORM P1000-MARK-UPDATE-TRANSACTION.
	ADD 1 TO CUST-UPDATE-FLAG.
	MOVE CUST-UPDATE-FLAG TO CRT08-CUSTOMER-UPDATE-COUNT.
	MOVE CRB-DATE TO CUST-DATE.
	PERFORM P36-MODIFY-CUSTOMER THRU
		P37-MODIFY-CUSTOMER-EXIT.


P143-UPDATE-DATA.
	PERFORM P138-VERIFY-METER.
	ADD 1 TO METER-UPDATE-FLAG.
	MOVE METER-UPDATE-FLAG TO CRT08-METER-UPDATE-COUNT.
	ADD 1 TO METER-ACT-RECORDS.
	MOVE CRB-hhmm TO METER-LAST-UPDATE.
	PERFORM P38-MODIFY-METER THRU P39-MODIFY-METER-EXIT.
P144.
	GO TO P147-TRANS-08-EXIT.


P145-CREATE-ACTIVITY.

*GROUP IF DOING ALL UPDATES AT ONCE, THEN METER WAS LAST THING FOUND.
*GROUP	IF NOT CR-T08-DO-EVERYTHING
*GROUP*	    THEN   --MUST GET METER AGAIN--
*GROUP		PERFORM P138-VERIFY-METER
*GROUP		IF CR-return-code NOT = 0
*GROUP*		   THEN  --COULD NOT FIND METER--
*GROUP			GO TO S09-RETURN-ROUTINE
*GROUP		    ELSE
*GROUP			NEXT SENTENCE
*GROUP	    ELSE
*GROUP		NEXT SENTENCE.
*GROUP
	PERFORM P1000-MARK-UPDATE-TRANSACTION.
	MOVE CRB-date TO METER-ACT-DATE.
	MOVE CRB-activity-code TO METER-ACT-CODE.
	MOVE ACTIVITY-LS TO METER-ACT-REC-DESC.
	PERFORM P30-STORE-ACTIVITY THRU
		P31-STORE-ACTIVITY-EXIT.
P146.
	GO TO P147-TRANS-08-EXIT.


P147-TRANS-08-EXIT.
	EXIT.
P148.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 9
*
* FUNCTION: Retrieve recent activities associated with a meter.
*
* Verify meter number.
* Return activity information for last (up to) 10 updates.
*
**********                             ***************

P200-TRANS-CR-T09.


	MOVE CRB-meter-number TO METER-NUMBER.
	PERFORM P04-FIND-METER THRU P06-FIND-METER-EXIT.
	IF CR-return-code > ZERO
*	    THEN
		GO TO S09-RETURN-ROUTINE
	    ELSE
		NEXT SENTENCE.
* FIND-METER   also does a dbms GET.

	MOVE METER-LAST-UPDATE TO CRB-hhmm.
	MOVE 0 TO CRT09-NUMBER-OF-ACTIVITIES.
	IF METER-ACT-RECORDS = 0
*	    THEN  --- NO ACTIVITY RECORDS---
		GO TO S09-RETURN-ROUTINE
	    ELSE
		NEXT SENTENCE.

	MOVE 'NO' TO DONE-FLAG.
	MOVE 10 TO MAXIMUM-RECORDS.
	MOVE 0 TO NEXT-ACTIVITY-RECORD.
	PERFORM P250-GET-NEXT-ACTIVITY-RECORD UNTIL DONE-FLAG = 'YES'.
	MOVE 0 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.

P250-GET-NEXT-ACTIVITY-RECORD.
	IF NEXT-ACTIVITY-RECORD = MAXIMUM-RECORDS
*	    THEN
		MOVE 'YES' TO DONE-FLAG
		MOVE MAXIMUM-RECORDS TO CRT09-NUMBER-OF-ACTIVITIES
	    ELSE
		PERFORM P13-FIND-ACTIVITY THRU P15-FIND-ACTIVITY-EXIT
		IF CR-RETURN-CODE NOT = 0
*		    THEN
			MOVE 'YES' TO DONE-FLAG
			MOVE NEXT-ACTIVITY-RECORD TO CRT09-NUMBER-OF-ACTIVITIES
		    ELSE
			ADD 1 TO NEXT-ACTIVITY-RECORD
			MOVE METER-ACT-CODE TO CRT09-ACTIVITY-CODE (NEXT-ACTIVITY-RECORD)
			MOVE  METER-ACT-DATE TO CRT09-DATE (NEXT-ACTIVITY-RECORD).
**********                             ***************
*            TRANSACTION TYPE 10
*
* FUNCTION: Determine meter that specified customer is linked to.
*
* Verify customer on disk.
* Find first meter customer is linked to.
*
**********                             ***************


P300-TRANS-CR-T10.
	MOVE CRB-CUSTOMER-NUMBER TO CUSTOMER-NUMBER.
	PERFORM P01-FIND-CUSTOMER THRU P03-FIND-CUSTOMER-EXIT.
	IF CR-RETURN-CODE > 0
*	    THEN
		GO TO S09-RETURN-ROUTINE
	    ELSE
		NEXT SENTENCE.

* Here with customer record found and retrieved.

	MOVE CUST-DATE TO CRB-DATE.
	MOVE CUST-DATE TO CRT10-METER-DATE.
	MOVE ZERO TO CRB-METER-NUMBER.
P301-READ-SET.
	FIND NEXT RECORD OF CUSTOMER-METER-SET SET.
	IF ERROR-STATUS NOT = 0
*	    THEN
		GO TO P305.
	GET.
P302-CHECK.
	IF METER-NUMBER > CRB-METER-NUMBER
		PERFORM P304.
P303.
	GO TO P301-READ-SET.
P304.
		MOVE METER-NUMBER TO CRB-METER-NUMBER.
		MOVE METER-LAST-UPDATE TO CRB-hhmm.
P305.


	MOVE CRB-METER-NUMBER TO METER-NUMBER.

		PERFORM P13-FIND-ACTIVITY THRU P15-FIND-ACTIVITY-EXIT
			VARYING NEXT-ACTIVITY-RECORD FROM 0
			BY 1 UNTIL CR-RETURN-CODE NOT = 0.
		MOVE 0 TO CR-RETURN-CODE.
		MOVE NEXT-ACTIVITY-RECORD TO CRT10-METER-UPDATE-COUNT.

P399-RETURN.


	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 11
*
* FUNCTION: Find parent po that the specified branch is linked to.
*
* Verify branch exists.
* Find parent associated with branch.
*
**********                             ***************


P400-TRANS-CR-T11.

	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.
	PERFORM P10-FIND-BRANCH-PO THRU P12-FIND-BRANCH-PO-EXIT.
	IF CR-RETURN-CODE > 0
*	    THEN
		GO TO S09-RETURN-ROUTINE
	    ELSE
		NEXT SENTENCE.

* branch po record has been found and is available

	GET.
	FIND OWNER IN PARENT-SET OF CURRENT OF BRANCH-PO-RECORD RECORD.
	IF ERROR-STATUS > 0
*	  THEN 
		MOVE 0 TO CRB-PARENT-PO-NUMBER
		MOVE 8 TO CR-RETURN-CODE
	  ELSE
	GET

		MOVE PARENT-NUMBER TO CRB-PARENT-PO-NUMBER.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 12
*
* FUNCTION: Generate report of data base of all records link
*		thru a parent po.
*
* Verify at least one parent po exists.
* Dump the data base by following links to a file.
* Write one record at a time.
*
**********                             ***************
P500-TRANS-CR-T12.
	IF CR-transaction-subtype = 0
*	    THEN  -- this is the first call --
		NEXT SENTENCE
	    ELSE
		GO TO P505-CONTINUE-TRANSACTION.

	MOVE 0 TO PARENT-COUNT, BRANCH-COUNT, METER-COUNT.
*
* do data base dump starting at first PARENT-PO-RECORD.
*
	FIND FIRST PARENT-PO-RECORD RECORD OF PARENT-PO-AREA AREA.
	IF ERROR-STATUS > 0
*	    THEN
		MOVE 8 TO CR-RETURN-CODE
		GO TO S09-RETURN-ROUTINE
	    ELSE
		MOVE CRT12-REPORT-FILE-NAME TO CRT12-REPORT-FILE-NME
		OPEN OUTPUT POSTAL-FILE
		MOVE CALL-COUNT TO LAST-T12-COUNT
		GO TO P520-PARENT-LOOP-2.


P505-CONTINUE-TRANSACTION.
	ADD 1 TO LAST-T12-COUNT.
	IF LAST-T12-COUNT = CALL-COUNT
*	    THEN  -- NO OTHER CALLS HAVE BEEN MADE SINCE US--
		GO TO 
			P510-PARENT-LOOP-1
			P530-BRANCH-LOOP
			P540-BRANCH-METER-LOOP
		  DEPENDING ON CR-transaction-subtype
	    ELSE 
		NEXT SENTENCE.

	MOVE CALL-COUNT TO LAST-T12-COUNT.
	IF CR-transaction-subtype = 1
*	    THEN ---WE MUST GET THE PARENT BACK---
		MOVE PARENT-P TO PARENT-NUMBER
		GO TO P510-PARENT-LOOP-1
	    ELSE
		IF CR-transaction-subtype=2
*		    THEN ---NEED TO GET PARENT AND BRANCH BACK---
			MOVE PARENT-P TO PARENT-NUMBER
			FIND PARENT-PO-RECORD RECORD
			MOVE BRANCH-P TO BRANCH-NUMBER
			FIND BRANCH-PO-RECORD RECORD
			GO TO P530-BRANCH-LOOP
		    ELSE
*			  --NEED TO GET PARENT, BRANCH, METER---
			MOVE PARENT-P TO PARENT-NUMBER
			FIND PARENT-PO-RECORD RECORD
			MOVE BRANCH-P TO BRANCH-NUMBER
			FIND BRANCH-PO-RECORD RECORD
			MOVE METER-P TO METER-NUMBER
			FIND METER-RECORD RECORD
			GO TO P540-BRANCH-METER-LOOP.

P510-PARENT-LOOP-1.
	MOVE 0 TO BRANCH-COUNT.
	FIND PARENT-PO-RECORD RECORD.
	FIND NEXT PARENT-PO-RECORD RECORD OF PARENT-PO-AREA AREA.
	IF ERROR-STATUS > 0
*	  THEN  last parent po was found
		CLOSE POSTAL-FILE
		MOVE 4 TO CR-transaction-SUBTYPE
	        GO TO S09-RETURN-ROUTINE
	  ELSE
		NEXT SENTENCE.

P520-PARENT-LOOP-2.

	GET.
	MOVE SPACES TO POSTAL-REC.
	MOVE PARENT-NUMBER TO PARENT-P.

P530-BRANCH-LOOP.
	MOVE 0 TO METER-COUNT.
	FIND NEXT BRANCH-PO-RECORD RECORD OF PARENT-SET SET.
	IF ERROR-STATUS > 0
*	   THEN  no more branches for this parent po.
		IF BRANCH-COUNT = 0
*		    THEN   ---NO BRANCHES- OUTPUT ONLY PARENT
			WRITE POSTAL-REC
			MOVE 1 TO CR-transaction-subtype
			GO TO DO-THE-RETURN
*			GO TO P510-PARENT-LOOP-1
		    ELSE
			GO TO P510-PARENT-LOOP-1
	    ELSE
		NEXT SENTENCE.

	GET.
	ADD 1 TO BRANCH-COUNT.
	MOVE BRANCH-NUMBER TO BRANCH-P.

P540-BRANCH-METER-LOOP.

	FIND NEXT METER-RECORD RECORD OF BRANCH-METER-SET SET.
	IF ERROR-STATUS > 0
*	    THEN  no more meters for this branch
		IF METER-COUNT = 0
*		    THEN    --NO METERS THIS BRANCH--
			WRITE POSTAL-REC
			MOVE 2 TO CR-transaction-subtype
			GO TO DO-THE-RETURN
*			GO TO P530-BRANCH-LOOP
		     ELSE
			GO TO P530-BRANCH-LOOP

	    ELSE
		NEXT SENTENCE.


	GET.
	ADD 1 TO METER-COUNT.
	MOVE METER-NUMBER TO METER-P.
	MOVE METER-UPDATE-FLAG TO UPDATED-P.
	MOVE METER-ACT-RECORDS TO ACT-RECS-P.


*	PERFORM P13-FIND-ACTIVITY THRU P15-FIND-ACTIVITY-EXIT
*		VARYING ACT-RECS-P FROM 0  BY 1
*		UNTIL CR-RETURN-CODE NOT = 0.
		
	FIND OWNER RECORD OF CUSTOMER-METER-SET SET.
	IF ERROR-STATUS > 0
*	    THEN
		NEXT SENTENCE
	    ELSE
		GET
		MOVE CUSTOMER-NUMBER TO CUSTOMER-P
		MOVE CUST-DATE TO DATE-P.

	WRITE POSTAL-REC.
	MOVE 3 TO CR-transaction-subtype.
	GO TO DO-THE-RETURN.
*	GO TO P540-BRANCH-METER-LOOP.


	
**********                             ***************
*            TRANSACTION TYPE 13
*
* FUNCTION: Add a new parent po
*
* Verify that parent does not exist.
* Add parent po.
*
**********                             ***************
P600-TRANS-CR-T13.

* ADD NEW PARENT PO

	MOVE CRB-PARENT-PO-NUMBER TO PARENT-NUMBER.
	PERFORM P07-FIND-PARENT-PO THRU  P09-FIND-PARENT-PO-EXIT.
	IF CR-RETURN-CODE = 8
*	    THEN
		GO TO P610-ADD-PARENT
	    ELSE 
		NEXT SENTENCE.

P605.
	MOVE 11 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.


P610-ADD-PARENT.
	PERFORM P1000-MARK-UPDATE-TRANSACTION.
	MOVE 0 TO CR-RETURN-CODE.
	PERFORM P26-STORE-PARENT-PO THRU  P27-STORE-PARENT-PO-EXIT.
P615.
	GO TO S09-RETURN-ROUTINE.
**********                             ***************
*            TRANSACTION TYPE 14
*
* FUNCTION: Add a new branch po.
*
* Verify that branch does not exist.
* add branch po.
**********                             ***************

P700-TRANS-CR-T14.
	MOVE CRB-BRANCH-PO-NUMBER TO BRANCH-NUMBER.
	PERFORM P10-FIND-BRANCH-PO THRU P12-FIND-BRANCH-PO-EXIT.
	IF CR-RETURN-CODE = 5
*	    THEN   did not find it
		GO TO P710-ADD-BRANCH
	    ELSE
		NEXT SENTENCE.
P705.
	MOVE 12 TO CR-RETURN-CODE.
	GO TO S09-RETURN-ROUTINE.


P710-ADD-BRANCH.
	PERFORM P1000-MARK-UPDATE-TRANSACTION.
	MOVE 0 TO CR-RETURN-CODE
	PERFORM P28-STORE-BRANCH-PO THRU P29-STORE-BRANCH-PO-EXIT.
	GO TO S09-RETURN-ROUTINE.
****************************************
S09-RETURN-ROUTINE SECTION.
****************************************

P900-CHECK-CODE-CONTROL.
	IF CR-RETURN-CODE = ZERO
		GO TO S06-RETURN-ROUTINE.
	GO TO P45-ERROR-RETURN.









************************************
S13-DELETE-ROUTINES SECTION.
************************************



P900-DELETE-CONTROL-ROUTINE.
P901-DELETE-CHECK.
	IF CR-RETURN-CODE = 6 GO TO P902-DELETE-CM.
	IF CR-RETURN-CODE = 7 GO TO P904-DELETE-BM.
	IF CR-RETURN-CODE = 9 GO TO P905-DELETE-PB.
	IF CR-RETURN-CODE = 11 GO TO P906-DELETE-CUST.
	IF CR-RETURN-CODE = 12 GO TO P907-DELETE-METER.
P901A-DELETE-CHECK-END.
	GO TO P999-DELETE-ROUTINES-EXIT.


P902-DELETE-CM.
	EXIT.
P903-DELINK-CUST-METER.
	REMOVE METER-RECORD FROM CUSTOMER-METER-SET.
	GO TO P999-DELETE-ROUTINES-EXIT.


P904-DELETE-BM.
	REMOVE METER-RECORD FROM BRANCH-METER-SET.
	GO TO P999-DELETE-ROUTINES-EXIT.
P905-DELETE-PB.
	REMOVE BRANCH-PO-RECORD FROM PARENT-SET.
	GO TO P999-DELETE-ROUTINES-EXIT.


P906-DELETE-CUST.
	DELETE CUSTOMER-RECORD ONLY.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P999-DELETE-ROUTINES-EXIT.
P907-DELETE-METER.
	DELETE METER-RECORD ALL.
	MOVE ZERO TO CR-RETURN-CODE.
	GO TO P999-DELETE-ROUTINES-EXIT.
P999-DELETE-ROUTINES-EXIT.
	EXIT.







P1000-MARK-UPDATE-TRANSACTION.

* Here to indicate that the transaction will cause an update

	IF THIS-TRANSACTION-UPDATES = 'N'
*	    THEN ---WE HAVE NOT BEEN HERE BEFORE---
		MOVE 'Y' TO THIS-TRANSACTION-UPDATES
		MOVE CORRESPONDING CR-user-information TO
			TRANSACTION-ID
		EXAMINE TRANSACTION-ID REPLACING ALL SPACES BY '-'
		ADD 1 TO TRANSACTION-COUNT
		MOVE CR-transaction-number to TI-user-transaction-type
		ENTER MACRO JSTRAN USING TRANSACTION-ID, TRANSACTION-COUNT
	    ELSE
		NEXT SENTENCE.

P1000-MARK-TRANSACTION-EXIT. EXIT.