  Seeking COBOL coding examples? 
 The Question is:
 
Cobol/SYS$QIO/TCPip.  Any examples?  Trying to do gethostbyname, and getting
 iosb status of 2160 x'870'.  Help
 
 The Answer is :
 
  There is some information on calling OpenVMS system services from
  COBOL in the Compaq COBOL User Manual -- pointers to this are in
  the OpenVMS documentation set (URL referenced in the OpenVMS FAQ).
 
  Related topics include (1091), (3061),
  Code examples for various operations in various languages are available
  in the AskQ support database, with the URL references for AskQ and for
  the documentation included in the OpenVMS FAQ.  (COBOL code examples are
  quite definitely represented within the articles in the support database.)
 
  Some existing pointers to source code examples are referenced in topics
  (881), (1091), (1846), (4541), (6608), and (6764), and various other
  COBOL-specific discussions are in topics (1091), (1134), (2228), (3061),
  and (6353).
 
  Attached is a general example of calling SYS$QIO from COBOL -- though
  not for TCP/IP purposes.  The example traps BROADCAST messages from
  COBOL. The example consists of three modules seperated by formfeeds:
 
   1) TRAP_BROADCAST.COB
       Create mailbox,
       Associate with terminal,
       Get &amp; save terminal characteristics,
       Set Termanil /NOBROAD/BRDCSTMBX,
       Declare write attention ast,
       Hiber
       Restore terminal characteristics,
       Exit.
 
    2) SETWRTAST.COB
       Subroutine to declare MAILBOX_AST AS write attention ast.
 
    3) MAILBOX_AST.COB
       Activated for each AST
       Read message
       When a message is successfully retrieved:
         Display message
         Read message
       (Re)declare write attention ast
       Wake if message contains "EXIT PLEASE"
       Return
 
 
 
 
IDENTIFICATION DIVISION.
PROGRAM-ID. HEIN.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01	ONE		PIC S9(9) COMP VALUE 1.
01	TT2$V_BRDCSTMBX	PIC S9(9) COMP VALUE 4.
01	TT$V_NOBRDCST	PIC S9(9) COMP VALUE 17.
01	IO$_SETMODE	PIC S9(9) COMP VALUE EXTERNAL IO$_SETMODE.
01	IO$_SENSEMODE 	PIC S9(9) COMP VALUE EXTERNAL IO$_SENSEMODE.
01	SS$_NORMAL	PIC S9(9) COMP VALUE EXTERNAL SS$_NORMAL.
01	ALL_CHARACTERISTICS.
  03	FILLER		PIC S9(9) COMP.
  03	CHARACTERISTICS	PIC S9(9) COMP.
  03	EXTENDED_CHAR	PIC S9(9) COMP.
01	ALL_CHAR REDEFINES ALL_CHARACTERISTICS PIC X(12).
01	SAVE_CHAR	PIC X(12).
01	IO_STATUS_BLOCK.
  03	IO_STAT		PIC S9(4) COMP.
  03	FILLER		PIC X(6).
01	TT_CHAN		PIC S9(9) COMP.
01	MBX_CHAN	PIC S9(9) COMP.
01	ST		PIC S9(9) COMP.
*	SETWRTAST		PIC S9(4) COMP VALUE EXTERNAL acms$k_proc_io_method.
PROCEDURE DIVISION.
MAIN-program SECTION.
BEGIN-HERE.
	CALL "SYS$CREMBX" USING 	OMITTED,
			BY REFERENCE	MBX_CHAN,
					OMITTED,OMITTED,OMITTED,OMITTED,
			BY DESCRIPTOR	"BROADCAST_MAILBOX"
			GIVING ST.
			IF ST IS FAILURE THEN CALL "SYS$EXIT" USING BY VALUE ST.
	CALL "SYS$ASSIGN" USING
			BY DESCRIPTOR	"TT",
			BY REFERENCE	TT_CHAN, OMITTED,
			BY DESCRIPTOR	"BROADCAST_MAILBOX"
			GIVING ST.
			IF ST IS FAILURE THEN CALL "SYS$EXIT" USING BY VALUE ST.
	CALL "SETWRTAST" USING MBX_CHAN, IO_STAT.
 
* Get and save current terminal characteristics, then
* Set NOBROADCAST and BRDCSTMBX characteristics.
 
	CALL "SYS$QIOW" USING		OMITTED,
			BY VALUE 	TT_CHAN,
			BY VALUE 	IO$_SENSEMODE,
			BY REFERENCE	IO_STAT, OMITTED, OMITTED, ALL_CHAR,
			BY VALUE	12, OMITTED, OMITTED, OMITTED, OMITTED
			GIVING ST.
			IF ST IS FAILURE THEN CALL "SYS$EXIT" USING BY VALUE ST.
	MOVE ALL_CHAR TO SAVE_CHAR
 
* How the F*** does one simply set a single bit in cobol ??!!
 
	CALL "LIB$INSV" USING ONE, TT$V_NOBRDCST, ONE, CHARACTERISTICS.
	CALL "LIB$INSV" USING ONE, TT2$V_BRDCSTMBX, ONE, EXTENDED_CHAR.
	CALL "SYS$QIOW" USING		OMITTED,
			BY VALUE 	TT_CHAN,
			BY VALUE 	IO$_SETMODE,
			BY REFERENCE	IO_STAT, OMITTED, OMITTED, ALL_CHAR,
			BY VALUE	12, OMITTED, OMITTED, OMITTED, OMITTED
			GIVING ST.
			IF ST IS FAILURE THEN CALL "SYS$EXIT" USING BY VALUE ST.
	CALL "SYS$HIBER".
 
* Clean up, Restore terminal characteristics.
 
	CALL "SYS$QIOW" USING		OMITTED,
			BY VALUE 	TT_CHAN,
			BY VALUE 	IO$_SETMODE,
			BY REFERENCE	IO_STAT, OMITTED, OMITTED, SAVE_CHAR,
			BY VALUE	12, OMITTED, OMITTED, OMITTED, OMITTED
			GIVING ST.
			IF ST IS FAILURE THEN CALL "SYS$EXIT" USING BY VALUE ST.
	EXIT PROGRAM.
 
IDENTIFICATION DIVISION.
PROGRAM-ID. SETWRTAST.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01	MAILBOX_AST	PIC S9(9) COMP VALUE EXTERNAL MAILBOX_AST.
01	IO$_SETMODE	PIC S9(9) COMP VALUE EXTERNAL IO$_SETMODE.
01	IO$M_WRTATTN	PIC S9(9) COMP VALUE EXTERNAL IO$M_WRTATTN.
01	IO_ATTENTION	PIC S9(9) COMP.
LINKAGE SECTION.
01	MBX_CHAN	PIC S9(9) COMP.
01	MBX_STAT	PIC S9(9) COMP.
PROCEDURE DIVISION USING MBX_CHAN, MBX_STAT.
A.
	MOVE IO$_SETMODE TO IO_ATTENTION.
	ADD IO$M_WRTATTN TO IO_ATTENTION.
	CALL "SYS$QIOW" USING		OMITTED,
			BY VALUE 	MBX_CHAN,
			BY VALUE 	IO_ATTENTION,
			BY REFERENCE	MBX_STAT, OMITTED, OMITTED,
			BY VALUE	MAILBOX_AST,
			BY REFERENCE	MBX_CHAN,
					OMITTED, OMITTED, OMITTED, OMITTED
	EXIT PROGRAM.
 
IDENTIFICATION DIVISION.
PROGRAM-ID. MAILBOX_AST.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01	MBX_BUFSIZ	PIC S9(9) COMP VALUE 200.
01	SS$_NORMAL	PIC S9(9) COMP VALUE EXTERNAL SS$_NORMAL.
01	SS$_ENDOFFILE	PIC S9(9) COMP VALUE EXTERNAL SS$_ENDOFFILE.
01	IO$M_NOW	PIC S9(9) COMP VALUE EXTERNAL IO$M_NOW.
01	IO$_READVBLK	PIC S9(9) COMP VALUE EXTERNAL IO$_READVBLK.
01	IO_READ		PIC S9(9) COMP.
01	EXIT_FLAG	PIC S9(9) COMP.
01	MBX_STATUS_BLOCK.
  03	MBX_STATUS	PIC S9(4) COMP.
  03	MBX_BYTECOUNT	PIC S9(4) COMP.
  03	FILLER		PIC S9(9) COMP.
01	MBX_MESSAGE.
  03	MESSAGE_TYPE	PIC S9(4) COMP.
  03	UNIT_NUMBER	PIC S9(4) COMP.
  03 	NAME_LENGTH	PIC X.
  03	CONTROLLER_NAME	PIC X(15).
  03	MESSAGE_LENGTH	PIC S9(4) COMP.
  03	MESSAGE_TEXT	PIC X(200).
01	ST		PIC S9(9) COMP.
LINKAGE SECTION.
01	MBX_CHAN	PIC S9(9) COMP.
01	R0		PIC S9(9) COMP.
01	R1		PIC S9(9) COMP.
01	PC		PIC S9(9) COMP.
01	PSL		PIC S9(9) COMP.
PROCEDURE DIVISION USING MBX_CHAN, R0, R1, PC, PSL.
A.
	MOVE IO$_READVBLK TO IO_READ.
	ADD IO$M_NOW TO IO_READ.
       	DISPLAY "MAILBOX message!"
	MOVE SPACES TO MESSAGE_TEXT.
	CALL "SYS$QIOW" USING		OMITTED,
			BY VALUE 	MBX_CHAN,
			BY VALUE 	IO_READ,
			BY REFERENCE	MBX_STATUS, OMITTED, OMITTED,
					MBX_MESSAGE,
			BY VALUE	MBX_BUFSIZ,
					OMITTED, OMITTED, OMITTED, OMITTED,
			GIVING ST.
			IF ST IS FAILURE THEN CALL "SYS$EXIT" USING BY VALUE ST.
	PERFORM PRINT_MESSAGE UNTIL MBX_STATUS IS NOT EQUAL TO SS$_NORMAL.
    	IF MBX_STATUS IS EQUAL TO SS$_ENDOFFILE THEN
		CALL "SETWRTAST" USING MBX_CHAN, MBX_STATUS
	ELSE
		CALL "SYS$EXIT" USING BY VALUE ST.
	INSPECT MESSAGE_TEXT TALLYING EXIT_FLAG FOR ALL "EXIT PLEASE".
	IF EXIT_FLAG IS GREATER THAN ZERO THEN
		CALL "SYS$WAKE" USING OMITTED, OMITTED.
	EXIT PROGRAM.
 
PRINT_MESSAGE.
	DISPLAY "MESSAGE_TYPE : ", MESSAGE_TYPE WITH CONVERSION.
	DISPLAY "NAME         : ", CONTROLLER_NAME.
        DISPLAY "LENGTH       : ", MESSAGE_LENGTH WITH CONVERSION.
        DISPLAY "MESSAGE_TEXT : ", MESSAGE_TEXT.
	CALL "SYS$QIOW" USING		OMITTED,
			BY VALUE 	MBX_CHAN,
			BY VALUE 	IO_READ,
			BY REFERENCE	MBX_STATUS, OMITTED, OMITTED,
					MBX_MESSAGE,
			BY VALUE	MBX_BUFSIZ,
					OMITTED, OMITTED, OMITTED, OMITTED,
			GIVING ST.
END_PRINT_MESSAGE.
 
 Answer written or last revised on  8-DEC-2002 
