A DTS Programming Example in PASCAL

You may download the original source files from here.

The application front-end module in PASCAL
The application back-end module in PASCAL



Front-end

[INHERIT   ('SYS$LIBRARY:STARLET.PEN')]
PROGRAM    EXAMPLEFE (OUTPUT);

(***************************************************************************)
(*                                                                         *)
(*         Example DTS front-end application                               *)
(*                                                                         *)
(*         Perform a simple query to the remote handler HELLO              *)
(*                                                                         *)
(*         Language:            VAX PASCAL                                 *)
(*         Date:                26-NOV-1991                                *)
(*                                                                         *)
(***************************************************************************)

(**************************** Type definitions *****************************)

[HIDDEN] TYPE  
 
    $UWORD = [WORD] 0..65535;               (* Unsigned word (16-bit)      *)

    DTS_INP_MSG =                           (* DTS input message format    *)
    RECORD                               
      HEADER : RECORD                       (* 39-byte DTS header block    *)
        TIMESTAMP : ARRAY [1..12] OF CHAR;  (* -  unique message timestamp *)
        STATUS    : CHAR;                   (* -  resend status            *)
        SENDER    : ARRAY [1..8] OF CHAR;   (* -  sender node name         *)
        RECEIVER  : ARRAY [1..8] OF CHAR;   (* -  receiver node name       *)
        FUNC_CODE : ARRAY [1..2] OF CHAR;   (* -  function code            *)
        HANDLER   : ARRAY [1..8] OF CHAR;   (* -  remote handler name      *)
      END;
      USER_DATA : ARRAY [1..31900] OF CHAR; (* Rest of the data - user msg *) 
    END;

    DTS_OUT_MSG =                           (* DTS output message format   *)
    RECORD             
      RETURN_CODE : ARRAY [1..2] OF CHAR;   (* 2-byte DTS return code      *)
      USER_DATA : ARRAY [1..31900] OF CHAR; (* Rest of the data - user msg *)
    END;

(**************************** External routines ****************************)

[EXTERNAL] PROCEDURE YFIAPPC
                      (VAR INPUT_BUFFER  : DTS_INP_MSG; 
                       VAR INPUT_LENGTH  : $UWORD;
                       VAR OUTPUT_BUFFER : DTS_OUT_MSG;
                       VAR OUTPUT_LENGTH : $UWORD); EXTERNAL;

(******************************* Constants *********************************)

CONST      
    OUR_NAME = 'TestProgram';               (* Our name for the remote rtn *)
    RECEIVER_NODE = 'REMOTE  ';             (* Receiver DTS node name      *)
    FUNCTION_CODE = '01';                   (* Inquiry-type transaction    *)
    REMOTE_HANDLER = 'HELLO   ';            (* Remote user handler name    *)

(******************* Data structures and global variables ******************)

VAR 
    INPUT_MESSAGE  : DTS_INP_MSG;           (* Input buffer                *)
    OUTPUT_MESSAGE : DTS_OUT_MSG;           (* Output buffer               *)

    INPUT_LENGTH   : $UWORD;                (* Input msg actual length     *)
    OUTPUT_LENGTH  : $UWORD;                (* Output msg actual length    *)

    RESULT_STRING  :                        (* String variable for         *)
      PACKED ARRAY [1..75] OF CHAR;         (* received response data      *)

(***************************** Begin of code *******************************)

BEGIN
    UNPACK
      (RECEIVER_NODE,                       (* Set receiver node name      *)
       INPUT_MESSAGE.HEADER.RECEIVER,1);
    UNPACK
      (FUNCTION_CODE,                       (* Set DTS function code       *)
       INPUT_MESSAGE.HEADER.FUNC_CODE,1);
    UNPACK
      (REMOTE_HANDLER,                      (* Set remote handler name     *)
       INPUT_MESSAGE.HEADER.HANDLER,1);
    UNPACK
      (OUR_NAME,INPUT_MESSAGE.USER_DATA,1); (* Put user data to inp buffer *)
    INPUT_LENGTH := 
      LENGTH(OUR_NAME)+                     (* Input message length =      *)
      SIZE(INPUT_MESSAGE.HEADER);           (* our data + DTS header       *)

    YFIAPPC(INPUT_MESSAGE,INPUT_LENGTH,     (* Call DTS front-end service  *)
            OUTPUT_MESSAGE,OUTPUT_LENGTH);  (* routine YFIAPPC             *)

    PACK(OUTPUT_MESSAGE.USER_DATA,          (* Get the response message to *)
         1,RESULT_STRING);                  (* a string variable           *)

    IF OUTPUT_MESSAGE.RETURN_CODE[1] <> '0' (* If nonzero return status,   *)
    THEN BEGIN
      WRITELN('Call failed : ',             (* Display DTS return code and *)
              OUTPUT_MESSAGE.RETURN_CODE[1],(* error message               *)
              OUTPUT_MESSAGE.RETURN_CODE[2],
              RESULT_STRING);
    END ELSE BEGIN                          (* Successful call:            *)
      WRITELN('Message received :');        (* Display received response   *)
      WRITELN(RESULT_STRING);               (* message                     *)
    END;
END.                                        (* Terminate the program       *)

(****************************** End of source ******************************)


Back-end

[INHERIT   ('SYS$LIBRARY:STARLET.PEN')]
MODULE     HELLO;

(***************************************************************************)
(*                                                                         *)
(*         Example DTS back-end application HELLO                          *)
(*                                                                         *)
(*         Return a simple 'Hello' message to the calling f/e.             *)
(*                                                                         *)
(*         Language:            VAX PASCAL                                 *)
(*         Date:                27-NOV-1991                                *)
(*                                                                         *)
(***************************************************************************)

(**************************** Type definitions *****************************)

[HIDDEN] TYPE  
 
    $UWORD = [WORD] 0..65535;               (* Unsigned word (16-bit)      *)

    DTS_INP_MSG =                           (* DTS input message format    *)
    RECORD                               
      HEADER : ARRAY [1..39] OF CHAR;       (* 39-byte DTS header block    *)
      USER_DATA : ARRAY [1..31900] OF CHAR; (* Rest of the data - user msg *) 
    END;

    DTS_OUT_MSG =                           (* DTS output message format   *)
    RECORD             
      RETURN_CODE : ARRAY [1..2] OF CHAR;   (* 2-byte DTS return code      *)
      USER_DATA : ARRAY [1..31900] OF CHAR; (* Rest of the data - user msg *)
    END;

(************************* Subroutine entry point **************************)

[GLOBAL]  PROCEDURE  HELLO  (VAR INPUT_MESSAGE  : DTS_INP_MSG;
                             VAR INPUT_LENGTH   : $UWORD;
                             VAR OUTPUT_MESSAGE : DTS_OUT_MSG;
                             VAR OUTPUT_LENGTH  : $UWORD);

(**************************** Local variables ******************************)

VAR
    RESPONSE_STRING  :                      (* String variable for         *)
      PACKED ARRAY [1..75] OF CHAR;         (* response data formatting    *)
    CALLER_NAME :                           (* Caller name given in the    *)
      PACKED ARRAY [1..40] OF CHAR;         (* input message user area     *)

(***************************** Begin of code *******************************)

BEGIN
    PACK(INPUT_MESSAGE.USER_DATA,            (* Convert user input message *)
         1,CALLER_NAME);                     (* to a string for processing *)
    RESPONSE_STRING :=
      'Hello '+                              (* Format response message    *)
      SUBSTR(CALLER_NAME,1,                  
             INPUT_LENGTH-
             SIZE(INPUT_MESSAGE.HEADER))+
      '. I''m your remote Routine';
    UNPACK(RESPONSE_STRING,                 (* Copy it to output buffer   *)
           OUTPUT_MESSAGE.USER_DATA,1);    
    OUTPUT_LENGTH :=                        (* Output message length =    *)
      SIZE(OUTPUT_MESSAGE.RETURN_CODE)+     (* DTS return code +          *)
      (INPUT_LENGTH-                        (* our response data          *)
       SIZE(INPUT_MESSAGE.HEADER))+31;      

END;                                        (* End of subroutine task      *)

END.                                        (* End of module               *)

(****************************** End of source ******************************)
© Copyright 2000 Tascomm Engineering Oy Home  Company  Products  Services  Customers  News