Thursday, 14 May 2020

DB2 data types


DATE:

The ISO format date in DB2 is CCYY-MM-DD in the range of 0001-01-01 to 9999-12-31.

COBOL host variable equivalent: PIC X(10)

DB2 supports ISO data format CCYY-MM-DD.

Example:

CREATE TABLE reading_lists(
     user_id INT NOT NULL,
    book_id INT NOT NULL,
    added_on DATE DEFAULT CURRENT_DATE,
    PRIMARY KEY(user_id, book_id)

);

INSERT INTO reading_lists(user_id, book_id) VALUES(1,1);

Converting COBOL field data to DB2 host variable format:

Example: 20200514

01 WS-DATE.
   05 WS-YEAR     PIC X(04).
   05 FILLER           PIC X VALUE ‘-‘.     
   05 WS-MONTH     PIC X(02).
   05 FILLER           PIC X VALUE ‘-‘.
   05 WS-DAY        PIC X(02).
   05 FILLER           PIC X VALUE ‘-‘.

MOVE 2020 TO WS-YEAR
MOVE 05     TO WS-MONTH
MOVE 14     TO WS-DAY

MOVE WS-DATE TO WS-HOST-VARIABLE

When date is 0, we need to insert NULL value in date field. Then please code like below

IF WS-DATE = ZEROS
    MOVE ‘0001-01-01’    TO WS-HOST-VARIABLE  => Moving null

TIME:

The ISO format time in DB2 is HH.MM.SS in the range of 00.00.00 to 24.00.00

Example:

CREATE TABLE daily_routines(
    routine_id INT
    GENERATED BY DEFAULT AS IDENTITY 
    NOT NULL PRIMARY KEY,
    routine VARCHAR(100) NOT NULL,
    start_at TIME NOT NULL
);

INSERT INTO daily_routines(routine, start_at) VALUES
    ('Get up','06:00'),
    ('Brush your teeth','06:05'),
    ('Have breakfast','06:15'),
    ('Go to school','06:45'),
    ('Go home','17:00');

COBOL host variable equivalent: PIC X(8).

01 WS-TIME.
   05 WS-HOURS         PIC X(02).
   05 FILLER           PIC X VALUE ‘.‘.     
   05 WS-MINUTES       PIC X(02).
   05 FILLER           PIC X VALUE ‘.‘.
   05 WS-SECONDS        PIC X(02).
   05 FILLER           PIC X VALUE ‘.‘.

Converting COBOL field data to DB2 host variable format:

After moving time to ws-time, then

MOVE WS-DATE TO HOST-VARIABLE

TIMESTAMP:

The ISO format time in DB2 is HH.MM.SS in the range of 0001-01-01-00.00.00.000000000 to 9999-12-31-24.00.00.000000000

Example:

CREATE TABLE logs(
    log_id INT GENERATED ALWAYS AS IDENTITY NOT NULL,
    message VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY(log_id)
);


INSERT INTO logs(message)
VALUES('Testing timestamp');

COBOL host variable equivalent: PIC X(26).

VARCHAR:

This data type in db2 is used to store VARIABLE-LENGTH character strings.

Syntax:  column-name VARCHAR(n)

'n' is positive integer which represents maximum length of bytes a column can store. It should be greater than 0 and less than 32740.

Example:

CREATE TABLE db2_varchars (
     v VARCHAR(20) NOT NULL
);

INSERT INTO db2_varchars (v) VALUES ('Db2 Tutorial');

Converting COBOL field data to DB2 host variable format:

VARCHAR field representation in COBOL (provided by DCLGEN) is like below (COBOL host variable equivalent)

01 column-name.
    49 column-len                  pic S9(4) comp.
    49 column-text                 pic x(n).

How to move data to a varchar field in DB2 from COBOL:

Rules: 

o   Remove padded spaces from the text
o   Populate the actual length of the text

Example:

77  WS-INDI             PIC X(7).
77  WS-INDCTR           PIC S9(4) COMP.
77  WS-ACT-INDI         PIC X(7).

MOVE 'A Z H' TO WS-INDI
INSPECT FUNCTION REVERSE(WS-INDI) TALLYING WS-INDCTR
                 FOR LEADING SPACES  => COUNT THE LEADING SPACES 
DISPLAY 'WS-INDCTR1: ' WS-INDCTR                        
SUBTRACT WS-INDCTR FROM 7 GIVING WS-INDCTR => SUBTRACTING LEADING SPACES FROM THE TOTAL LENGTH AND STORE THE ACTUAL LENGTH (ACTUAL LENGTH-LEADING SPACES)
DISPLAY 'WS-INDCTR2: ' WS-INDCTR        
MOVE WS-INDI(1:WS-INDCTR) TO WS-ACT-INDI => MOVING ACTUAL VALUE WITHOUT LEADING SPACES TO HOST-VARIABLE            
DISPLAY 'WS-ACT-INDI: ' WS-ACT-IND

Output:

WS-INDCTR1: +0002
WS-INDCTR2: +0005
WS-ACT-INDI: A Z H

SMALLINT:

To store small integers in 2 bytes.

Syntax: col-name SMALLINT

COBOL host variable equivalent: S9(4) COMP.

INT:

To store large integers in 4 bytes.

Syntax: col-name INT

COBOL host variable equivalent: S9(9) COMP.

BIGINT:

To store big integers in 8 bytes.

Syntax: col-name INT

COBOL host variable equivalent: S9(18) COMP.

Example:

CREATE TABLE db2_integers( 
             smallint_col SMALLINT
             int_col INT
             bigint_col BIGINT );

db2_integers represents table-name

INSERT INTO db2_integers (
    smallint_col, 
    int_col, 
    bigint_col )
VALUES (
    32767,
    2147483647,
    9223372036854775807
);

CHAR:

To store FIXED-LENGTH character strings in database.

Syntax: col-name CHAR(n)

COBOL host variable equivalent: PIC X(n)

Example:

CREATE TABLE db2_characters(
    char_col CHAR(3)
);

INSERT INTO db2_characters(char_col)VALUES('abc');

DECIMAL:

To store decimal type values in database.

The decimal number consists of two parts viz. the whole part and fractional part. They both are separated by comma.

Syntax: dec_col DECIMAL(m,n) or
        dec_col NUMERIC(m,n)

‘m’ represents whole part, ‘n’ represents fractional part.

ex. DECIMAL(5,3) => 12.345

Example:

CREATE TABLE db2_decimals(
    dec_col NUMERIC(5,3)
);

INSERT INTO db2_decimals(dec_col)
VALUES(12.345);

COBOL host variable equivalent: S9(m-n)V(n) COMP-3




Thursday, 2 May 2019

How to check the limit of GDG file

Goto 3.4 and type in the GDG name. Press Enter.
Then where u give B for Browse , E for Edit

type in LISTCAT ENT(/) ALL and press ENTER.

Or

The ISPF Dataset Utility (=3.2) can generate the LISTCAT command for you and then execute it.

Take option 3.2
Enter the name of the GDG base and take option V (VSAM Utilities).
Under "Process Request" take option 3. Under "Data Type" you can leave it blank or take option 4 and hit enter.
On the next screen make sure there is a (/) slash next to "Edit IDCAMS command". Under "Name, History, Volume, ALLOcation, All" put ALL and hit enter.
This will generate a LISTCAT command essentially the same as used above:
/* IDCAMS COMMAND */
LISTCAT ENTRIES(ZZJR001.TEMP.GDG) -
GENERATIONDATAGROUP -


Then enter the EXEC command to execute it.

Or

Go to command prompt and type 
TSO LISTC ENT('GDG-BASE-NAME') ALL

Alter GDG file

The maximum limit of a GDG file is 255 generations.

Say, you have created a GDG base with the limit of 50 generations and later you want to increase its limit to maximum (255 generations), then you need to Alter GDG base like below.

//STEP01 EXEC PGM=IDCAMS      
//SYSPRINT DD SYSOUT=*        
//SYSIN    DD *               
  ALTER GDG.BASE.NAME LIMIT(255)
/*

Once the above job is successful, the limit of GDG file GDG.BASE.NAME will be increased from 50 to 255.

Friday, 15 February 2019

Removing duplicates from VB file


Consider I have a VB file of length 321 bytes (4 for RDW + 317 actual length) and wanted to remove duplicate records from a file.

Here is the sample JCL: 

//REMODUPL   EXEC PGM=SORT                                     
//SORTIN   DD DSN=INPFILE1,DISP=SHR                 
//SYSIN    DD *                                                
  OPTION VLSHRT                                                
  SORT FIELDS=(5,317,CH,A)                                     
  SUM FIELDS=NONE                                              
/*                                                             
//SORTOUT  DD DSN=OUTFILE1,DISP=(NEW,CATLG,DELETE),           
//         RECFM=VB,LRECL=321,AVGREC=K
//SYSOUT   DD SYSOUT=* 

VLSHRT tells DFSORT to temporarily replace any missing control field bytes with binary zeros.

For eg.       

As you are aware that VB file will have records of different lengths and the maximum length of the record in the VB file will be treated as LRECL of that VB file.

During the sort say i have two records one with length 300 and another with 317, then the record with 300 bytes will be temporarily replaced with extra 17 binary zeros (300+17 binary zeros) to run the sort smoothly.  These binary zeros are temporary and will NOT be copied to output dataset. 

The default OPTION is NOVLSHRT (reverse of VLSHRT) which terminates the sort if it finds shorter record than the one specified in SORT FIELDS.          

Sunday, 13 January 2019

SDSF

SDSF means System Display and Search Facility

It is a utility that allows user to monitor, control or view the output of jobs in the system.

It is a component of IBM's mainframe operating system, z/OS.

Once the job is submitted, it is common to use SDSF to check the status of the job like completed/running/failed...

To start using SDSF, 

type SDSF;ST or S;ST on the start window/command line

ST :Displays current status of all the jobs

Following are the most commonly used SDSF options:

DA : Displays Active/currently running jobs

I : Input Queue - Shows jobs waiting for execution 

H : Jobs on HOLD - either waiting to be released into input or output.

PR : Displays printers

INIT : Displays initiators (areas where jobs execute or run)

On the ST panel, SDSF supports following options for each batch Job. The user should type the desired option against the job and press enter to see the result

C : Cancel the job

S : Select the job (view only)

SJ : Show Job (View the original JCL of the job) - In this mode, you can edit the JCL as you required and SUBmit it in case of failures.

P : Purge job (Remove the job)

SE : Select Edit job (view in edit mode) 

XDC : Writes the spool content of the job into a data set. The data set name should be provided in the dialog window that gets popped up after pressing enter.

Following operations can be performed on SDSF panel. The desired command should be provided in "COMMAND INPUT" and press enter 

OWNER * - Displays all the jobs submitted by the owner if any.

OWNER ABC* - Filter jobs with owner name starting with ABC

PRE XYZ* - Filter jobs starting with XYZ.
PRE represents PREFIX

PRE AB%%PQ - Filter jobs starting with AB and ends with PQ

WHO - Provides basic information about SDSF user

SET CONFIRMATION ON/OFF - This command will enable/disable the confirmation for any action like P(Purge), C(Cancel)….

In SDSF, we can purge multiple jobs at a time using Block //. The jobs to purge should be in sequence to perform the same.
How - Say I have jobs JOB1, JOB2, JOB3, JOB4, JOB5 in SDSF. To purge JOB3, JOB4 and JOB5 at a time, Type //p against JOB3 and // against JOB5 and press enter.


Friday, 4 January 2019

IEBEDIT(Edit Job stream) Utility:

1. It is used to run selected job step(s) in particular JCL.

Ex. I have a JCL with 10 steps and wanted to run only STEP10, 


//IEBEDITX JOB (MVSQuest),'IEBEDIT TEST',
//            CLASS=N,MSGCLASS=H,NOTIFY=7SYSUID
//*
//SUBMIT   EXEC PGM=IEBEDIT
//SYSUT1   DD DSN=USERID.TEST.JCL(JCLINP),DISP=SHR
//SYSUT2   DD SYSOUT=(*,INTRDR)
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
 EDIT START=JOBA,TYPE=INCLUDE,STEPNAME=(STEP10)
//*

JCLINP contains 10 steps

START => specifies job name of JCLINP

TYPE=INCLUDE => runs only those steps specified in STEPNAME

If TYPE=EXCLUDE, it runs all the steps except for the one specified in STEPNAME

If i want to run step09 and step10, then

EDIT START=JOBA,TYPE=INCLUDE,STEPNAME=(STEP09,STEP10)

2. Copies the complete job including all its steps to the output data set
    
    EDIT START=JOBA

3. Copies different steps from different jobs to output data set
    
    Example: If i have 3 jobs (JOBA, JOBB,JOBC)  in input dataset and wanted to copy different steps from all the 3 jobs

EDIT START=JOBA,TYPE=INCLUDE,STEPNAME=(STEPC,STEPD)
EDIT START=JOBB,TYPE=INCLUDE,STEPNAME=STEPE
EDIT START=JOBC,TYPE=INCLUDE,STEPNAME=STEPJ   

Points to remember:


Instream procedure should be defined before EXEC statement.

Example:

//INSTPROC  PROC
//    statements
//    ----
//    ----
//          PEND
//STEP01 EXEC PGM=pgm1
//FILE1  DD DSN=file-name
//STEP02 DD INSTPROC
//STEP03 DD INSTPROC

Cataloged Procedure:

Cataloged procedures will be stored in separate PDS. This PDS name should be specified in JCLLIB ORDER. If the procedure is not found in the specified library, then SYS1.PROCLIB will be checked.

We can add/modify the parmeters in steps of Cataloged procedure without even changing it. 

Ex. I have a cataloged proc name MYPROC and wanted to add Region parameter to STEP02 in that
proc, i can code like below in corresponding JCL

//MYSTEP EXEC MYPROC, REGION.STEP10=56K

To apply region parameter for all the steps in MYPROC

//MYSTEP EXEC MYPROC, REGION=56K

To nullify a parameter of a particular step in MYPROC, override the same through JCL and just don't give any value like below

//MYSTEP EXEC MYPROC, TIME.STEP10=

- The DSN and UNIT parameters must be coded for new generation data sets.





Thursday, 3 January 2019

VSAM Intro

VSAM - Virtual Storage Access Method

A VSAM cluster is a logical definition for a VSAM data set and has one or two components. viz.,
Index component - Contains pointers to all data records to access them
Data component - Contains actual records


VSAM commands:

All the following operations (including CREATE and DELETE) should be done through IDCAMS utility.

ALTER - To modify the attributes of VSAM file.
REPRO - To load the data into VSAM data set (from sequential file to VSAM file), to copy the data from one VSAM file to another VSAM file.
LISTCAT - To get the catalog information of a VSAM dataset like dataset attributes, allocation information, volume information...  
EXAMINE - Checks the structural integrity of a given KSDS cluster. It checks index and data components and reports if there are any issues.
VERIFY - Checks and fix VSAM files which are not closed properly after an error

An Alternate Index provides access to records using more than one key. The key of an alternate Index can be a unique/non-unique key. We define alternate index for a given VSAM cluster.

Sunday, 26 August 2018

DB2 LOAD error : INPUT FIELD 'field-name' NOT ENTIRELY WITHIN INPUT RECORD

Whenever you get an error 'INPUT FIELD 'field-name' NOT ENTIRELY WITHIN INPUT RECORD' while LOADing the data to a DB2 table,

Please check whether the length of the field-name in DB2 table is equal to the length of the corresponding field-name in LOAD file. The length of both the fields SHOULD match. 



COBOL cheat sheet


  1. ENVIRONMENT DIVISION is optional.
  2. DATA DIVISION is optional.
  3. In IDENTIFICATION DIVISION, except PROGRAM-ID. everything else is optional.
  4. From Column 8-11, we call AREA-A where we should code DIVISIONS, SECTIONS, PARAGRAPHS and 01 group level items.
  5. From column 12-72, we call AREA-B where we will code rest of the Cobol statements other than DIVISIONS, SECTIONS, PARAGRAPHS and 01 group level items.
  6. If you specify SELECT OPTIONAL file ASSIGN TO filename, and if filename is not present physically then the program will NOT abend. Files with OPTIONAL can be opened with EXTEND, I/O or INPUT mode so that the file will be created else it return status code 35.
  7. FILE STATUS is used to identify the status of each operation performed against the file. FILE STATUS IS ws-status, where ws-status can be declared in working storage section with length of 2 bytes.  
  8. SELECT empfile ASSIGN TO empfileo where empfile is a logical file and empfileo is physical file. Inside the cobol program, for any operation on this file we have to use logical file name which is empfile and later all these operations will be reflected in physical file empfileo.
  9. If you are passing data from JCL to cobol program using PARM parameter, please declare two variables in linkage section viz., one is to store length of the data and the other one for actual data.
  10. Main program will have 'PROCEDURE DIVISION' where as sub-program or called program will have 'PROCEDURE DIVISION using [data-items]...
  11. USAGE clause reduce the storage space indirectly increasing the efficiency of the program. The default usage is DISPLAY and its not applicable for 66,77 and 88 level items. 
  12. COMP-1 => Left most 8 bits for exponent and remaining 24 bits for mantissa. COMP-2 => Left most 12 bits for exponent and 52 bits for mantissa. Both of the items store data in the format of Mantissa and exponent.
  13. Comp-3 => also called as packed decimal form where the data will be stored in memory as BCD (Binary Coded Decimal) format. Two digits can be stored in each byte and the number of bytes required for a variable is calculated using formula (n+1)/2. The low nybble of the least significant byte contains a sign. So even though we didn't define sign variable for COMP-3, a nibble is reserved for it. 
    Examples: 

    PIC S9(7) COMP-3.     Byte size = (7 + 1) / 2 = 4

    PIC S9(5)V99 COMP-3.  Byte size = (5 + 2 + 1) / 2 = 4

    PIC S9(6) COMP-3.     Byte size = (6 + 1) / 2 = 3.5, rounded to 4
Comp-3 fields reserve a nybble for the sign, even for "unsigned" values, so the following fields are still 4 bytes:
    PIC 9(7) COMP-3.     Byte size = (7 + 1) / 2 = 4
    PIC 9(6) COMP-3.     Byte size = (6 + 1) / 2 = 3.5, rounded to 4

You can also use the the formula (N/2) + 1, but just consider integer part as total number of bytes.
For instance, 
PIC S9(7) COMP-3   => Byte size = 7/2  + 1 => 3.5 + 1 => 4.5 => integer part means, 4.


14. START command is used in DYNAMIC mode to read the KSDS file. It will set the pointer to the next read for reading the record.
     START file-name KEY <relational-operator> <data-name>
             [INVALID KEY statements]
             [NOT INVALID KEY statements]
     END-EVALUATE.
     First key-value will be moved to data name and once START commands executes, the pointer will be placed at the starting of matched record.

15. READ NEXT is used to read the records sequentially after the record to which pointer was set by the START command based on key value.




       

Thursday, 2 November 2017

SYNCPOINT

SYNCPOINT divides a long-running task into smaller units of work. 

It specifies that all  the changes made by the task since its last syncpoint are to be committed. 

SYNCPOINT ROLLBACK

It specifies that all the changes made to recoverable resources by the task since its last syncpoint are to be backed out.

In order to reset all CICS recoverable resources because the transaction is not finished, we back out the current unit of work (UOW) by performing the following command

EXEC CICS SYNCPOINT ROLLBACK
END-EXEC

Monday, 30 October 2017

WHENEVER Clause


WHENEVER specifies the host language statement to be executed when an exception condition occurs.

Three types of WHENEVER :-

1.WHENEVER NOT FOUND

Example:

go to the label ENDDATA for any statement does not return

EXEC SQL
     WHENEVER NOT FOUND
        GO TO ENDDATA
END-EXEC.

NOT FOUND => Identifies any condition that results in an SQLCODE of +100.

2.WHENEVER SQLERROR

Go to label handler for any statement that produces an error

EXEC SQL
     WHENEVER SQLERROR
     GO TO HANDLER
END-EXEC.

SQLERROR => Identifies any condition that results in negative SQLCODE.

3.WHENEVER SQLWARNING 

Continue the processing when any statement produces a warning

EXEC SQL
     WHENEVER SQLWARNING
     CONTINUE
END-EXEC.

SQLWARNING => Identifies any condition that results in warning condition (SQLWARN0 is W) or that results in Positive SQLCODE other than +100.

Tuesday, 1 August 2017

IEBCOMPR Utility

IEBCOMPR utility is used to

  • Compare two PS (Physical Sequential) Datasets
  • Compare two PDS (Partitioned Data Set)/PDSE (Partitioned Data Set Extended)

If we want to compare two PS files using this utility, both must have same record length. 

Ex. Comparing two PS files

//STEP1  EXEC PGM=IEBCOMPR
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD DSN=PSFILE1,DISP=SHR
//SYSUT2 DD DSN=PSFILE2,DISP=SHR
//SYSIN   DD *
  COMPARE TYPORG=PS
/*

The two PS files which are to be compared must be given in SYSUT1 and SYSUT2

COMPARE TYPORG=PS specifies that the input data sets are PS files.

If they are PDS/PDSE files, then we should give COMPARE TYPORG=PO

Ex. Comparing two PDS files

//STEP1  EXEC PGM=IEBCOMPR
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD DSN=PDSFILE1,DISP=SHR
//SYSUT2 DD DSN=PDSFILE2,DISP=SHR
//SYSIN   DD *
  COMPARE TYPORG=PO
/*


Monday, 24 July 2017

MVS Abbrevations


MVS - Multiple Virtual Storage, is an operating system from IBM that runs on system/370 and system/390 IBM mainframe computers.

TSO - Time Sharing Option, lets remote terminal users invoke MVS facilities interactively.

ISPF - Interactive System Productivity Facility, runs a part of TSO and utilizes full screen capability of 3270 terminals.

PDF - Program Development Facility, part of the ISPF.

RACF - Resource Access Control Facility, identifies both users and resources.

SMF - System Management Facility, facilitates billing and monitoring.
           Ex. CPU time used, amount of DASD etc..

SMS - Storage Management Subsystem, automates data management services of             MVS.

JES - Job Entry Subsystem, provides job management facilities on MVS.

DASD - Direct Access Storage Device

Tuesday, 9 February 2016

Copying PDS members to PS file


  • Open the PDS
  • In the command line, type save <name1> 
  • Now you can see all the members saved in PS file                          USERID.<name1>.MEMBERS


You can use this file to export the members to excel.

Tuesday, 17 November 2015

QMF ( Query Management Facility)

QMF is an MVS based query tool which allows end users to enter SQL queries to produce a variety of reports and graphs as a result of the query. 

In other words, this tool is used to issue SQL commands against DB2 database. The data results can be formatted as reports, charts etc. 

There are three different ways you can supply input to QMF viz., 

1. Entering SQL in Query Editor
2. By using prompted queries
3. Query by example (QBE)

Wednesday, 28 October 2015

DB2 Isolation levels

UR (Uncommitted Read) : 
  
  - For read only queries. 
  - No record locking. 
  - Good for accessing read only tables.

CS (Cursor Stability) :

- Default isolation level. 
- It locks and unlocks each row , 1 at a time. 
- Guaranteed to only return the data which was committed at the time of read

RS (Read Stability):

- Keeps all the qualifying rows locked until the transaction is complete.
- Releases the lock on those rows which doesn't satisfy the query

RR (Repeatable Read):

- Not just the rows that satisfy the query, but keeps the entire table locked until  the unit   of work is done.
- No other application program can update, insert or delete the row from the  table.



Tuesday, 22 September 2015

MQSeries basics

MQSeries allows different applications to communicate asynchronously through queues across different operating systems, different processors and different application systems.

MQSeries includes Message Queue Interface (MQI), a common low level programming Application Program Interface (API). Applications use MQI to read and write messages to the queues.

What is MQSeries ?

A middleware product that implements a messaging and queuing framework.

Messaging - Programs communicate by sending data in messages rather than by calling each other directly

Queuing - Messages are put on queues in storage, eliminating the need for programs to be logically connected.

A messaging and queuing framework is inherently asynchronous. 

MQSeries Objects

1.1 Queue manager

A queue manager is the part of MQSeries product which provides messaging and queuing services to application programs through MQI program calls. 

It controls access to the queues and serves as transaction coordinator for all queue operations.

Queue manager names must be unique.

1.2 Queues

MQSeries defines four types of queues

Local queue - an actual queue for which storage is allocated

Remote queue - A definition of queue on a different queue manager

Alias queue - Another name for local or remote queue. Typically used to switch queue destinations without modifying the program code.

Model queue - A template whose properties are copied when creating a new dynamic local queue.

1.3 Channels

A channel provide communication path between queue managers.

1.4 Messages

Any arbitrary data that one program wants to send to another. This data is called application data.

A message need to include other information such as its destination and possibly a return address. This type of data is called message descriptor

There are four types of messages

A request message is used by one program requesting something to another program. A request message needs a reply

A reply message is used in response to the request message

A one way message doesn't need a reply though it carries data

A report message is used when something unexpected occurs. For example, if the reply message doesn't contain any data then receiving program might issue a report message.

  • Most useful report messages are generated by queue manager. Ex., delivery confirmation.                                                                                                                      
  • Every message has an expiry. The message that has not been reached before its expiration will be removed.                                                                                                 
  • Message correlator - Select which message to get from queue.                                      
  • Message priority - Retrieve messages in different order.                                                  
  • Segmented messages - Allows ending of very large messages ( > 100 MB ).                  
  • A message can contain "reply to" address (the name of the queue manager and queue). This tells the receiving application where any response should be sent.             
  • Messages are added and removed from queues in units of work.                                    
  • The smallest unit of work is one message.                                                                        
  • When an app reads a message from queue, a message "appears" to be removed but in fact, it's still in storage until the app "commits" the unit of work.

1.5 Pic : Message flow between applications

   
Frequently used APIs’ in Application Programs

(MQI – The MQSeries Programming Interface)


  • MQCONN – Connect to queue manager 
  • MQDISC – Disconnect from queue manager 
  • MQOPEN – Open object
  • MQCLOSE – Close object
  • MQPUT – Put message
  • MQPUT1 – Put one message
  • MQGET – Get message
  • MQBEGIN – Begin unit of work
  • MQCMIT – Commit
  • MQBACK – Back out
  • MQINQ – Inquire about object attributes
  • MQSET – Set object attributes
The application program can put many messages in queue before it closes or gets disconnected.

API command sequence for sending MQ messages

Step-1:

MQCONN - The MQCONN call connects the application program to a queue manager

Syntax :

MQCONN(QMgrName, Hconn, CompCode, Reason)

QMgrName(MQCHAR48) - input => Queue manager name
Hconn(MQHCONN) - output => Connection handle
CompCode(MQLONG) - output => Completion code
Reason(MQLONG) - output => Reason code qualifying CompCode



Step-2:

MQOPEN - The MQOPEN call establishes access to an object.

Syntax:

MQOPEN(Hconn,ObjDesc,Options,Hobj,CompCode,Reason)

Hconn(MQHCONN) - Output => Connection Handle
ObjDesc(MQOD) - Input/Output => Object descriptor
Options(MQLONG) - Input =>Options that control the action of MQOPEN
Hobj(MQHOBJ) - output => Object handle
CompCode(MQLONG) - Output => Completion Code
Reason(MQLONG) - Output => Reason code qualifying compcode 



Step-3:

The MQPUT call puts message on queue or distribution list. The queue or distribution list must already be open.

Syntax:

MQPUT(Hconn, Hobj, MsgDesc, PutMsgOpts,BufferLength,Buffer, CompCode, Reason)

Hconn (MQHCONN) – output =>Connection handle.
Hobj (MQHOBJ) – input => Object handle.
MsgDesc (MQMD) – input/output => Message descriptor.
PutMsgOpts (MQPMO) – input/output => Options that control the action of MQPUT.
BufferLength (MQLONG) – input => Length of the message in Buffer 
Buffer (MQBYTE×BufferLength) – input => Message data.
CompCode (MQLONG) – output => Completion code.
Reason (MQLONG) – output => Reason code qualifying CompCode 


















Step-4:

The MQCLOSE call relinquishes access to an object.

Syntax:

MQCLOSE(Hconn,Hobj,Options,CompCode,Reason)

Hconn (MQHCONN) – output => Connection handle.
Hobj (MQHOBJ) – input/output => Object handle.
Options (MQLONG) – input => Options that control the action of MQCLOSE.
CompCode (MQLONG) – output => Completion code.
Reason (MQLONG) – output => Reason code qualifying CompCode








Step-5:

The MQDISC call breaks the connection between the queue manager and application program.

Syntax:

MQDISC(Hconn,CompCode,Reason)

Hconn (MQHCONN) – output => Connection handle.
CompCode (MQLONG) – output => Completion code.
Reason (MQLONG) – output => Reason code qualifying CompCode






 API Command sequence for receiving MQ messages

Step-1:

MQCONN - The MQCONN call connects the application program to a queue manager

Syntax :

MQCONN(QMgrName, Hconn, CompCode, Reason)

QMgrName(MQCHAR48) - input => Queue manager name
Hconn(MQHCONN) - output => Connection handle
CompCode(MQLONG) - output => Completion code
Reason(MQLONG) - output => Reason code qualifying CompCode










Step-2:

MQOPEN - The MQOPEN call establishes access to an object.

Syntax:

MQOPEN(Hconn,ObjDesc,Options,Hobj,CompCode,Reason)

Hconn(MQHCONN) - Output => Connection Handle
ObjDesc(MQOD) - Input/Output => Object descriptor
Options(MQLONG) - Input =>Options that control the action of MQOPEN
Hobj(MQHOBJ) - output => Object handle
CompCode(MQLONG) - Output => Completion Code
Reason(MQLONG) - Output => Reason code qualifying compcode














Step-3:

The MQGET retrieves a messages from a local queue that has been opened using the MQOPEN call.

Syntax:

MQGET (Hconn, Hobj, MsgDesc, GetMsgOpts, BufferLength, Buffer,DataLength, CompCode, Reason)

Hconn (MQHCONN) – output => Connection handle.
Hobj (MQHOBJ) – input => Object handle.
MsgDesc (MQMD) – input/output => Message descriptor
GetMsgOpts (MQGMO) – input/output => Options that control the action of MQGET
BufferLength (MQLONG) – input => Length of the message in Buffer 
Buffer (MQBYTE×BufferLength) – input => Message data
CompCode (MQLONG) – output => Completion code




































Step-4:

The MQCLOSE call relinquishes access to an object.

Syntax:

MQCLOSE(Hconn,Hobj,Options,CompCode,Reason)

Hconn (MQHCONN) – output => Connection handle.
Hobj (MQHOBJ) – input/output => Object handle.
Options (MQLONG) – input => Options that control the action of MQCLOSE.
CompCode (MQLONG) – output => Completion code.
Reason (MQLONG) – output => Reason code qualifying CompCode








Step-5:

The MQDISC call breaks the connection between the queue manager and application program.

Syntax:

MQDISC(Hconn,CompCode,Reason)

Hconn (MQHCONN) – output => Connection handle.
CompCode (MQLONG) – output => Completion code.
Reason (MQLONG) – output => Reason code qualifying CompCode