1 SUB M11SRT 2 !******************************************************************** & ! & ! & ! M11SRT & ! & ! Sorts the addresses & ! & ! & !******************************************************************** & ! 3 ! Program : M11SRT & ! Version : 1.1 11-May-84 & ! Programmer : Mike Brown & ! Releaser : & ! & ! & !--------------------------------------------------------------------- 11 ! & ! & ! C O P Y R I G H T & ! & ! & !--------------------------------------------------------------------- 20 ! ! MODIFICATION HISTORY ! ! rev date by ! !--------------------------------------------------------------------- 100 ! ! ! Summary ! ! This module sets up sorting parameters in core common, declares ! itself a receiver, spawns SMSORT and then enters a sleep/receiver ! state. ! ! SMSORT retrieves the sort instructions from core common, calls ! SORT/MERGE V3.0 routines to perform the sort, and sends a message ! when the sort operation is completed. SMSORT then kills itself. ! ! The message from SMSORT awakens the current job and processing ! continues. ! ! ! Assumptions: XBUF is required to create a logged in job. It is ! used to store a copy of the calling job's core common ! and user logicals. ! ! The sorting program, SMSORT, is located in the ! Smart Mailer account. ! ! A pseudo keyboard is available for the detached job. ! ! A job slot is available for the detached job. ! !--------------------------------------------------------------------- 1000 !******************************************************************** & ! & ! & ! S T A R T P R O G R A M L O G I C & ! & ! & !******************************************************************** & 1010 ON ERROR GOTO 19000 & \ ERR.CALLNAM$ = ERR.PROGNAM$ & \ ERR.PROGNAM$ = "M11SRT VER:00" & \ ERR.SUBNAM$ = "" & \ ERR.MSG$ = "Unexpected fatal error" & ! Set up common for error reporting. 1020 V$ = SYS( CHR$(12%) ) SEND_JOBNO$ = SEG$ ( V$, 1%, 1% ) ! Get job no (times 2). 1040 IF SEG$ (M11.SORT.CODE$, 1%, 2%) = "PR" OR M11.FUNC$ = "R" THEN SORT_CODE$ = "R" SORTED.FILE$ = EDIT$(M11.SORTED.FILE$, 2%) & + "/SE/FO:F:11" ELSE SORT_CODE$ = " " SORTED.FILE$ = EDIT$(M11.SORTED.FILE$, 2%) & + "/SE/FO:F:6" END IF ! Determine which sort is required. For PRESORT and for address ! distribution reports, the sorted output file must contain the ! Zip Code. Otherwise, the output file contains only the ! sorted RFA's. The SORT switches specify a sequential, fixed ! output file. SORT_COMMAND$ = SORTED.FILE$ + " = " + M11.SORT.FILE$ + "/FI:3/CS:M" SORT_COMMAND$ = EDIT$ ( SORT_COMMAND$, 2% ) ! Define the SORT command string. The SORT switches specify the ! number of work files and multinational collating sequence. 1050 SIZE$ = FORMAT$( M11.SORT.FIELD.SIZE%, "##" ) ! Define the size of the sort field. 2000 CORE_COMMON$ = SEND_JOBNO$ & + SORT_CODE$ & + SIZE$ & + SORT_COMMAND$ ! Set up core common string 2010 V$ = SYS (CHR$(8%) + CORE_COMMON$ ) ! Put core common SYS call. A copy of core common is passed ! to the sorting job spawned at line 4000. 2100 SORT_PROGRAM$ = M11.TSK.ACCT$ + "SMSORT.TSK" FILE_SCAN$ = SYS ( CHR$ (6%) & + CHR$ (-10%) & + SORT_PROGRAM$ ) ! File name string scan. Data is returned in proper format ! for the create job call at line 4000. 3000 GOSUB 12000 ! Remove receiver. This prevents an '? ACCOUNT OR DEVICE IN USE' ! error if there has been an abnormal exit. 3010 V$ = SYS ( CHR$ (6%) ! FIP call & + CHR$ (22%) ! Send/Receive function code & + CHR$ (1%) ! Declare subfunction code & + CHR$ (0%) ! Reserved & + " " ! Blank receiver name & + STRING$ (11%, 0%) ! Reserved or not needed here & + CHR$ (1%) ! Receive from local sender & + STRING$ ( 2%, 0% ) ! Use XBUF for now & + CHR$ (1%) ! Message Maximum = 1 & + STRING$ ( 15%, 0%) ) ! Reserved or not needed here ! Declare receiver call 4000 V$ = SYS( CHR$ ( 6%) ! FIP call & + CHR$ (24%) ! Create job function code & + CHR$ (64%) ! Create job logged & + CHR$ ( 0%) ! Create deteched job & + SEG$ ( FILE_SCAN$, 5%, 12% ) ! Program to run & + STRING$ ( 10%, 0% ) ! Reserved or not needed here & + SEG$ ( FILE_SCAN$, 23%, 26% ) ! Sort program device & + STRING$ ( 4%, 0% ) ) ! Reserved or not needed here ! SYS call to create logged in job. 5000 V$ = SYS ( CHR$ (6%) ! FIP call & + CHR$ (22%) ! Send/Receive function code & + CHR$ (2%) ! Receive subfunction code & + CHR$ (1%) ! Sleep/ Receive local & + STRING$ (26%, 0%) ) ! Reserved or not needed here ! Receive sys call. The job will be placed in a sleep receiver ! state until a message is pending. The job will awake with ! ERR = 5%. It must reissue the receive to process the message. 8000 SMSORT_MSG$ = SEG$ ( V$, 21%, 40% ) GOTO 9000 IF SEG$ (SMSORT_MSG$, 1%, 1% ) = "S" ! The message from SMSORT is simply "S" if the sort was successful. IF SEG$ ( SMSORT_MSG$, 2%, 7% ) = "SMSORT" THEN ERR.MSG$ = "Error in sort task - SMSORT" + CR + LF & + "ERR = " + SEG$(SMSORT_MSG$, 8%, 10%) + CR + LF & + "ERL = " + SEG$(SMSORT_MSG$, 11%, 15%) GOTO 19900 ELSE ERR.CODE% = 200% ERR.SUBNAM$ = SEG$(SMSORT_MSG$, 2%, 7%) ERR_SORT_ERRBUF$ = SEG$(SMSORT_MSG$, 8%, 15%) GOTO 19910 END IF ! Set up error reporting if the sort operation was not successful. ! ! If an error occurred in SMSORT.TSK the message is: ! byte 1 "F" ! bytes 2-7 "SMSORT" ! bytes 8-10 numeric string containing error number ! bytes 11-13 numeric string containing error line ! If the error occurred in one of the SORT subroutines, the message is: ! byte 1 "F" ! bytes 2-7 The name of the SORT subroutine where the ! error occurred ("SRTINB", "SRTSRB" or "SRTENB") ! bytes 8-15 Contents of the SORT error buffer. ! 9000 !******************************************************************* & ! & ! & ! E N D O F P R O C E S S I N G & ! & ! & !******************************************************************* & KILL M11.SORT.FILE$ & ! Close and delete the Sort File. & ERR.SUBNAM$ = "" & \ ERR.PROGNAM$ = ERR.CALLNAM$ & ! Reset traceback sequence. & 9020 OPEN "KB:" AS FILE #CH.KB%, MODE 8% 9990 GO TO 32767 & ! Jump around the junk and leave. & 10000 !******************************************************************** ! ! Local Subroutines ! !******************************************************************** 12000 V$ = SYS ( CHR$ (6%) ! FIP call & + CHR$ (22%) ! Send/Receive function code & + CHR$ (0%) ! Remove subfunction code & + CHR$ (0%) ! Remove this job & + STRING$ ( 26%, 0% )) ! Reserved or not needed here ! Remove receiver call RETURN 19000 !******************************************************************** & ! & ! & ! S T A N D A R D E R R O R H A N D L I N G & ! & ! & !******************************************************************** & 19005 IF ERR = 5% AND ERL = 5000 THEN RESUME 5000 END IF 19010 GOTO 19990 IF ERN$ <> SEG$ (ERR.PROGNAM$, 1%, 6%) ! Only tracing back an error from another subprogram. 19200 ERR.MSG$ = "Problem in sort task name." IF ERL = 2100 ERR.MSG$ = "M11SRT could not declare itself a receiver" IF ERL = 3010 ERR.MSG$ = "M11SRT could not spawn sort task" IF ERL = 4000 ERR.MSG$ = "Problem receiving message from sort task" IF ERL = 5000 ! Identify errors that can't be handled here. 19900 ERR.CODE% = FATAL.ERROR% & ! Define fatal code here, but only for non-sort fatals. & 19910 ERR.ERL% = ERL & \ ERR.ERR% = ERR & ! On fatal error, set the error code. & 19990 ON ERROR GO BACK & ! Return to calling program for fatal error processing. & & 32767 SUBEND