SERVER PROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE-SERVER.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. TANDEM/16.
OBJECT-COMPUTER. TANDEM/16.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MESSAGE-IN, ASSIGN TO $RECEIVE FILE STATUS IS RECEIVE-FILE-STATUS.
SELECT MESSAGE-OUT, ASSIGN TO $RECEIVE FILE STATUS IS RECEIVE-FILE-STATUS.
RECEIVE-CONTROL. TABLE OCCURS 5 TIMES.
DATA DIVISION.
FILE SECTION.
FD MESSAGE-IN LABEL RECORDS ARE OMITTED.
01 ENTRY-MSG.
02 PW-HEADER.
04 REPLY-CODE PIC S9(4) COMP.
04 FUNCTION-CODE PIC XX.
02 MESSAGE-NUMBER PIC 9.
FD MESSAGE-OUT LABEL RECORDS ARE OMITTED RECORD CONTAINS 1 TO 68 CHARACTERS.
01 ENTRY-REPLY.
02 PW-HEADER.
04 REPLY-CODE PIC S9(4) COMP.
04 FILLER PIC X(2).
02 SERVER-RECORD PIC X(64).
01 ERROR-REPLY.
02 REPLY-CODE PIC S9(4) COMP.
02 FILLER PIC X(2).
02 ERROR-CODE PIC 999 COMP.
WORKING-STORAGE SECTION.
01 RECEIVE-FILE-STATUS.
02 STAT-1 PIC 9.
88 CLOSE-FROM-REQUESTOR VALUE 1.
02 STAT-2 PIC 9.
01 WS.
02 ERROR-CODE PIC 999 COMP.
PROCEDURE DIVISION.
BEGIN-COBOL-SERVER.
OPEN INPUT MESSAGE-IN.
OPEN OUTPUT MESSAGE-OUT SYNCDEPTH 1.
PERFORM B-TRANS UNTIL CLOSE-FROM-REQUESTOR.
STOP RUN.
B-TRANS.
READ MESSAGE-IN, AT END STOP RUN.
MOVE PW-HEADER OF MESSAGE-IN TO PW-HEADER OF MESSAGE-OUT.
MOVE 0 TO ERROR-CODE OF WS
IF FUNCTION-CODE = "01"
PERFORM READ-MESSAGE
ELSE
PERFORM FUNCTION-NOT-SUPPORTED.
IF ERROR-CODE OF WS = 0
MOVE 0 TO REPLY-CODE OF ENTRY-REPLY
WRITE ENTRY-REPLY
ELSE
MOVE 999 TO REPLY-CODE OF ERROR-REPLY
MOVE ERROR-CODE OF WS TO ERROR-CODE OF ERROR-REPLY
WRITE ERROR-REPLY.
READ-MESSAGE.
IF MESSAGE-NUMBER = 0 MOVE "THIS IS MESSAGE ZERO" TO SERVER-RECORD ELSE
IF MESSAGE-NUMBER = 1 MOVE "THIS IS MESSAGE NUMBER ONE" TO SERVER-RECORD ELSE
IF MESSAGE-NUMBER = 2 MOVE "THIS IS MESSAGE NUMBER TWO" TO SERVER-RECORD
ELSE PERFORM INVALID-MESSAGE-NUMBER.
FUNCTION-NOT-SUPPORTED.
MOVE 1 TO ERROR-CODE OF WS.
INVALID-MESSAGE-NUMBER.
MOVE 2 TO ERROR-CODE OF WS.