Coding MPP Programs to Process IMS Transactions

48
5.4 Coding MPP Programs to Process IMS Transactions: A COBOL Programmer’s Practicum NE Canadian IMS Regional User Group September 16 – 19 Deepak Kohli ([email protected]) © Copyright IBM Corporation 2016

Transcript of Coding MPP Programs to Process IMS Transactions

Page 1: Coding MPP Programs to Process IMS Transactions

5.4

Coding  MPP  Programs  to  Process  IMS  Transactions:  

A  COBOL  Programmer’s  Practicum

NE  Canadian  IMS  Regional  User  GroupSeptember  16  – 19

Deepak  Kohli  ([email protected])

©  Copyright  IBM  Corporation  2016

Page 2: Coding MPP Programs to Process IMS Transactions

• IMS  Architecture• IMS  Transaction  Queuing  &  Scheduling• Coding  MPPs  – Getting  the  Transaction  Message– Sending  the  reply  message  to  the  originating  terminal– Sending  the  reply  message  to  an  alternate  destination• Alternate  PCBs• Program  to  Program  Message  switch• Express  Alternate  PCBs

– SYNC  or  COMMIT  Point– Abnormal  Termination  /  Error  Handling– Programming  Tips

Agenda

©  Copyright  IBM  Corporation  2016 2

Page 3: Coding MPP Programs to Process IMS Transactions

TERMINALSMASTER  TERMINAL TERMINALSTERMINALS

TELE-­COMMUNI-­CATIONS

MESSAGE  SCHEDULING

CHECKPOINT

RESTARTCOMMON  SERVICE

CONTROLREGION

MESSAGE  QUEUES

MESSAGE  QUEUES

DBRC

APPLICATION  PROGRAM

APPLICATION  PROGRAM

MESSAGEPROCESSING  REGION(“MPR”,  0  or  more)

BATCHMESSAGE

PROCESSINGREGION(“BMP”,0  or  more)

IMS  DATABASES

DATA  LANGUAGE/1

DL/I  SUBORDINATEADDRESSSPACE

(“DLISAS”)

IMS  architecture

IMS  System  Log

©  Copyright  IBM  Corporation  2016 3

Page 4: Coding MPP Programs to Process IMS Transactions

Transaction  Message  Queuing

Page 5: Coding MPP Programs to Process IMS Transactions

CLASSES                                                            TRANSACTIONS  (PRIORITY)

004 SKILLUPD    (8)SKILLINQ    (5)PAYROLL    (4)

002 INVENT    (10)STOKSTAT    (8)

003 ORDER    (6)RECEIVE    (4)

Transaction  Class  &  Priority

©  Copyright  IBM  Corporation  2016 5

• Transactions  are  queued  by  Class  and• Within  class  by  priority

• Classes:  1  – 999• Priority:      0  -­ 14

Page 6: Coding MPP Programs to Process IMS Transactions

NORMAL  PRIORITYLIMIT  PRIORITYLIMIT  COUNTQUEUE  COUNTPROCESSING  LIMIT

NORMAL  PRIORITYLIMIT  PRIORITYLIMIT  COUNTQUEUE  COUNTPROCESSING  LIMIT

TIME TIME            TIME1                              2                          3

5                                    10                                                          1030                        30                          308                          31                              020                        20                          20

TIME TIME            TIME1                              2                          3

12 12 124 4 42 1 35 5 5

5 510

8 8 8

CLASS  001SKILLINQ  

TRANSACTION

MESSAGE  1

MESSAGE  N

CLASS  001

~~

MESSAGE  1

SKILLUPD  TRANSACTION

MESSAGE  N

~~

Transaction  Priorities

©  Copyright  IBM  Corporation  2016 6

Page 7: Coding MPP Programs to Process IMS Transactions

Application  programs  are  automatically  scheduled  into  Message  Processing  Regions    (MPRs)

MESSAGE  1

SKILLUPDCLASS=1,PRTY=8

MESSAGE  N

SKILLINQCLASS=1,PRTY=5

MESSAGE  1

MESSAGE  N

~~

~~

Sch      Te      ad      su      kler

IMS/MPR1

Classes2,3,4,1

IMS/MPR2

Classes4,5,6,7

IMS/MPR3

Classes3,4,5,6

CLASS  001

CLASS  001

Transaction  Scheduling

©  Copyright  IBM  Corporation  2016 7

Page 8: Coding MPP Programs to Process IMS Transactions

Reply  (outbound)  Message  Queuing

Page 9: Coding MPP Programs to Process IMS Transactions

LOGICAL  TERMINAL  

ABC

LOGICAL  TERMINAL  

XYZ

MESSAGES

PHYSICAL  TERMINAL  1

MESSAGES

PHYSICAL  DEVICE  2

APPLICATION  PROGRAM

PHYSICAL  TERMINAL  3

IMS/TM(Control  Region)

Transaction  Manager

IMS/MPR(Message  Processing  Region)

Logical  terminal  concept

©  Copyright  IBM  Corporation  2016 9

Page 10: Coding MPP Programs to Process IMS Transactions

X Y

X  (LTERMA)X  (LTERMX)X  (LTERMO)X  (LTERMX)

Y  (LTERMB)Y  (LTERMZ)Y  (LTERMA)

LTERM  QUEUES

LTERMA LTERMB

REPLY  (X)REPLY  (Y) REPLY  (Y)

Queuing  Transaction  &  Reply  messages  

©  Copyright  IBM  Corporation  2016 10

1 2 3 … Classes

Transaction  Codes

Page 11: Coding MPP Programs to Process IMS Transactions

11

Coding  MPP  Programs

Page 12: Coding MPP Programs to Process IMS Transactions

MESSAGE  REGIONREGION  CONTROLLER  (DFSRRC00)

APPLICATION  PROGRAM

GET  TRAN  MESSAGE

PROCESSACCESS  DBs

SEND  REPLY  MESSAGE

RETURN  IF  NO  MORE

LANGUAGE  INTERFACE(DFSLI000)

MPP  Program  flow

12©  Copyright  IBM  Corporation  2016

Page 13: Coding MPP Programs to Process IMS Transactions

Getting  the  Transaction  Message

Page 14: Coding MPP Programs to Process IMS Transactions

PCBs  (in  PSBs)  for  Transaction  processing    #1 <      -­-­-­-­ I/O  PCB            >

#2 PCB TYPE=TP,MODIFY=YES

#3 PCB TYPE=DB……

PSBGEN PSBNAME=PSB_name,

• TP– IOPCB• Not  explicitly  coded  in  PSB– Will  be  the  first  of  the  list  of  PCBs  passed  to  an  IMS  program  at  entry  in  almost  all  cases,  but  will  always  be  the  first  PCB  for  application  programs  that  execute  with  an  Online  system

• Used  to  receive  or  send  a  message  in  IMS  TM  programs– Alternate  TP  PCB• Used  to  receive  or  send  a  messages  to  destinations  other  than  where  input  transaction  was  received  from• Two  sub-­types:  MODIFY-­able  and  un-­MODIFY-­able

• DB– Used  to  read  or  update  a  database  -­ same  as  with  IMS  DB  only

14©  Copyright  IBM  Corporation  2016

Page 15: Coding MPP Programs to Process IMS Transactions

LOGICAL  TERMINAL

PAYROLL

Application  program

DATABASEPCB

MASK

MASK TPPCB

ADDRESS

NAME

Logical  structures  and  logical  terminals

©  Copyright  IBM  Corporation  2016 15

Page 16: Coding MPP Programs to Process IMS Transactions

I/O  PCB

TP  PCB1

DB  PCB1

I/O  PCB

TP  PCB

DB  PCB

APPLICATION  PROGRAM PSB

PROCEDURE  DIVISION.

ENTRY  'DLITCBL'  USING  I-­O-­PCB,  TP-­PCB1,  DB-­PCB1.

ENTRY  statement

16©  Copyright  IBM  Corporation  2016

Page 17: Coding MPP Programs to Process IMS Transactions

LOGICAL  TERMINAL  NAME 8RESERVED 2STATUS  CODE 2DATE 4TIME 4INPUT  SEQUENCE  NUMBER 4MESSAGE  FORMAT  NAME 8USERID 8GROUP 8TIMESTAMP 12

I/O  PCB  

17©  Copyright  IBM  Corporation  2016

Page 18: Coding MPP Programs to Process IMS Transactions

18©  Copyright  IBM  Corporation  2016

LINKAGE  SECTION.

01  IO-­PCB.          03  IO-­LTERM       PIC  X(8).                                                                      03  FILLER PIC  XX.                                            03  IO-­STATUS-­CODE PIC  XX.                                                                    03  IO-­DATE-­YYDDD PIC  S9(7)  COMP-­3.                                                                      03  IO-­TIME-­HHMMSS-­T  PIC  S9(6)V9  COMP-­3.                                                              03  IO-­MSG-­NO PIC  S9(9)  COMP.                                                                  03  IO-­MOD-­NAME PIC  X(8).                                          03  IO-­USERID                           PIC  X(8).                                      

I/O  PCB  defined  in  the  Linkage  Section

Page 19: Coding MPP Programs to Process IMS Transactions

Getting  Tran  Message  – Single  Segment      • GET  UNIQUE

CALL  ‘CBLTDLI’  USING  GUIO-­PCBMESSAGE-­INPUT

• MESSAGE-­INPUT  defined  in  WORKING-­STORAGE  SECTION

• Successful  call  results  in  ‘bb’  status  code• ‘QC’  status  code  – no  more  transactions

19©  Copyright  IBM  Corporation  2016

Page 20: Coding MPP Programs to Process IMS Transactions

Getting  Tran  Message  -­ Multi-­Segment  message      • GET  UNIQUE  – for  first  segment

CALL  ‘CBLTDLI’  USING  GUIO-­PCBMESSAGE-­INPUT

• GET  NEXT  – for  subsequent  segments

CALL  ‘CBLTDLI’  USING  GNIO-­PCBMESSAGE-­NEXT-­SEGMENT

– ‘QD’  status  code  – no  more  segments  for  this  transaction  message.

20©  Copyright  IBM  Corporation  2016

Page 21: Coding MPP Programs to Process IMS Transactions

GET  UNIQUE

GET  NEXT

PROCESS  MESSAGE

INSERT

GO  GET  NEXT  MESSAGE

GO  BACK/RETURN  IF  NO  MORE

Call  sequence

21©  Copyright  IBM  Corporation  2016

Page 22: Coding MPP Programs to Process IMS Transactions

SINGLE  SEGMENT

LL    ZZ    PARTSTAT  123456789

MULTI  SEGMENTLL  ZZ  ORDER  HEADER

LL  ZZ  ITEM  1•••LL  ZZ  ITEM  N

Message  LayoutsLL    ZZ    TRANCODE  SEGMENT

LL    ZZ    SEGMENT  2•••LL    ZZ    SEGMENT  N

SINGLESEGMENTMESSAGE

MULTISEGMENTMESSAGE

22©  Copyright  IBM  Corporation  2016

Page 23: Coding MPP Programs to Process IMS Transactions

Sending  the  Reply  MessageBack  to  the  originating  LTERM

Page 24: Coding MPP Programs to Process IMS Transactions

Sending  Output  message

1. Build  and  format  reply  in  I/O  area

2. Calculate  length  (LL)  and  store  in  I/O  area  prefix– LL  includes  LLZZ  (that  is,    Message  +  4)                          

3. CALL  ‘CBLTDLI’  USING  ISRTIO-­PCBOUTPUT-­MESSAGE.

24©  Copyright  IBM  Corporation  2016

Page 25: Coding MPP Programs to Process IMS Transactions

OUTPUT  MESSAGE  2

INPUT  MESSAGE  3

(no  more)  INPUT  MESSAGE  

'QD'  STATUS  CODE

'QC'  STATUS  CODE

Message  processing  flowGET  UNIQUEGET  NEXTGET  NEXT

INSERTINSERTINSERT

GET  UNIQUEGET  NEXT

INSERTINSERT

GET  UNIQUEGET  NEXTGET  NEXT

INSERT

GET  UNIQUE

RETURN

INPUT  MESSAGE  1

OUTPUT  MESSAGE  1

INPUT  MESSAGE  2'QD'  STATUS  CODE

'QD'  STATUS  CODE

OUTPUT  MESSAGE  3

*  All  status  codes  'bb'  except  where  noted25©  Copyright  IBM  Corporation  2016

Page 26: Coding MPP Programs to Process IMS Transactions

Sending  the  Reply  MessageTo  an  alternate  destination

Page 27: Coding MPP Programs to Process IMS Transactions

LL    ZZ    RECEIPT 1000  WIDGETS

LL    ZZ  TRANSACION  SUCCESSSFULY  PROCESSED

LL    ZZ  PAYMT XYZ  COMPLETE

LL    ZZ  ORDER  XYZ  GOODS  RECEIVED

ACCOUNTS  PAYABLE  LTERM            (PCB  #2)

RECEIVING  LTERM  (I/O  PCB)

RECEIVING  LTERM  (I/O  PCB)

PAYMT  TRAN  QUEUE  (PCB  #3)

RECEIPT  PROGRAM

Alternate  output  destinations

optional

27©  Copyright  IBM  Corporation  2016

Page 28: Coding MPP Programs to Process IMS Transactions

RECEIVE

PAYABLE

PAYMT

RECEIVING  TERMINAL

ACCOUNTS  PAYABLE  TERMINAL

PAYMENTS  PROGRAM

I/O  PCB

ALTERNATE  PCB

ALTERNATE  PCB

Alternate  PCBs

28©  Copyright  IBM  Corporation  2016

Page 29: Coding MPP Programs to Process IMS Transactions

Alternate  PCBs  for  Transaction  processing    PCB       TYPE=TP,  LTERM=WXYZ

PCB TYPE=TP,  NAME=PAYMT

PCB TYPE=TP,MODIFY=YES

PCB TYPE=DB

PSBGEN PSBNAME=PSB_name

29©  Copyright  IBM  Corporation  2016

Page 30: Coding MPP Programs to Process IMS Transactions

Alternate  PCB  Types    • Fixed  (or  Un-­modifiable)  Alternate  TP  PCB– Destination  is  hard  coded  in  the  PSB

• Modifiable  Alternate  TP  PCBs– Destination  will  be  specified  by  the  program  via  a  CHANGE  DL/I  call.

• Express  PCBs

30©  Copyright  IBM  Corporation  2016

Page 31: Coding MPP Programs to Process IMS Transactions

PROCEDURE  DIVISION.

ENTRY  'DLITCBL'  USING  I-­O-­PCB,  ALT1,  ALT2,  DB-­PCB.

ENTRY  Statement  with  Alternate  PCBs

31©  Copyright  IBM  Corporation  2016

Page 32: Coding MPP Programs to Process IMS Transactions

LOGICAL  TERMINAL  NAME/TRAN  CODE  8

RESERVED2

STATUS  CODE2

Alternate  PCB  format

32©  Copyright  IBM  Corporation  2016

Page 33: Coding MPP Programs to Process IMS Transactions

33©  Copyright  IBM  Corporation  2016

LINKAGE  SECTION.

01  ALT-­PCB.          03  ALT_DESTINATION       PIC  X(8).                                                                      03  FILLER PIC  XX.                                            03  ALT-­STATUS-­CODE PIC  XX.                                                                    

ALT  PCB  defined  in  the  Linkage  Section

Page 34: Coding MPP Programs to Process IMS Transactions

Sending  Output  message  to  Alternate  Destination

1. Build  and  format  reply  in  I/O  area

2. Calculate  length  (LL)  and  store  in  I/O  area  prefix– LL  includes  LLZZ  (that  is,    Message  +  4)                          

3. CALL  ‘CBLTDLI’  USING  ISRTALT-­PCBOUTPUT-­MESSAGE.

34©  Copyright  IBM  Corporation  2016

Page 35: Coding MPP Programs to Process IMS Transactions

Using  a  Modifiable  PCB  for  

Alternate  destination

Page 36: Coding MPP Programs to Process IMS Transactions

'CBLTDLI'

CHNG

MODIFIABLE  ALT  PCB

LTERM/TRANCODE

bbbbbbbb

PCB  BEFORE

LTERMAbb

PCB  AFTER

'CHANGE'  REMAINS  UNTIL:GU  TO  I/O  PCBOR

PGM  TERMINATIONOR

ANOTHER  CHNG

-­ RESET  TO  BLANKS

-­ PURG  REQUIRED  BEFORE  NEW  CHNG

}

CALL

Change  call

36©  Copyright  IBM  Corporation  2016

• Call  ‘CBLTDLI’  USING  CHNG  ALT-­PCB  DEST

Page 37: Coding MPP Programs to Process IMS Transactions

What’s  a  Program  to  Program  Message  Switch

• When  one  application  program  kicks  of  another  transaction

1. Application  program  build  the  transaction  message

2. If  using  a  fixed  Alternate  PCB,  the  application  issues  a  ISRT  call  to  the  ALT  PCB      or                    

3. If  using  modifiable  Alternate  PCB,  the  application  issues  a  CHNG  call  to  the  ALT  PCB,  followed  by  a  ISRT  of  the  message  to  the  ALT  PCB.

37©  Copyright  IBM  Corporation  2016

Page 38: Coding MPP Programs to Process IMS Transactions

ISRT

ALTERNATE  PCBPAYMT

LL    ZZ  PAYMT  XYZ  COMPLETE

I/O  PCBRECEIVE

GUI/O  PCB                (AFTER)RECEIVE

LL    ZZ    PAYMT  XYZ  COMPLETE               (AFTER)

RECEIPT  PROGRAM

CALL

PAYMT  PROGRAM

'CBLTDLI'

CALL 'CBLTDLI'

Program  to  Program  Message  Switching

38©  Copyright  IBM  Corporation  2016

Page 39: Coding MPP Programs to Process IMS Transactions

PURG  DL/I  Call

• A  Purge  Call  (Function  Code  “PURG”)  must  be  issued  after  sending  the  last  message  segment  to  a  Modifiable  PCB  before  another  CHNG  call  can  be  issued  to  specify  a  different  destination  for  subsequent  messages.

– i.e.  Used  to  indicate  a  message  is  “complete”  for  a  destination.    

39©  Copyright  IBM  Corporation  2016

Page 40: Coding MPP Programs to Process IMS Transactions

PURG

I/O  PCB      OR        ALT    PCB

LL    ZZ    SEGMENT        -­ OPTIONAL  (INSERTS)

GET  UNIQUEINSERTINSERTPURGE  (TERMINATES  FIRST  MESSAGE)

PURGE  (With  SEGMENT  1  in  I/O  Area)  

'CBLTDLI'

MESSAGE  1SEGMENT  1SEGMENT  2

MESSAGE  2

SEGMENT  1

CALL

Purge  call

Inserts  then  PURGE

PURGE  ONLY

40©  Copyright  IBM  Corporation  2016

Page 41: Coding MPP Programs to Process IMS Transactions

EXPRESS  PCBs

• There  is  an  option  associated  with  Alternate  TP  PCBs  (modifiable  or  not).– EXPRESS=YES

• Permits  IMS  to  send  messages  before  the  program  has  reached  a  Commit  Point (but  after  the  PURG  call  has  been  issued).

41©  Copyright  IBM  Corporation  2016

Page 42: Coding MPP Programs to Process IMS Transactions

Use  of  Purge  &  “EXPRESS=YES”  PCBs• PCB      TYPE=TP,  MODIFY=YES,EXPRESS=YES

• CALL  ‘CBLTDLI’  USING  CHNGALT-­PCBLTERM_NAME.

• CALL  ‘CBLTDLI’  USING  ISRTALT-­PCBMESSAGE-­O-­AREA.

• CALL  ‘CBLTDLI’  USING  PURGALT-­PCB.

42©  Copyright  IBM  Corporation  2016

Page 43: Coding MPP Programs to Process IMS Transactions

SYNC  Point  or  Commit  Point• MPP  Programs  are  called  MODE=SNGL  programs– After  ever  transaction  is  processed,  you  have  reached  a  SYNC  point  or  Commit  point

– i.e.  at  every  GU  IOPCB,  a  SYNC  or  Commit  point  is  reached

• At  SYNC  or  Commt  Point:– Database  updates  are  committed– Log  records  are  written– Output  messages  are  placed  on  their  output  queues– Locks  are  released

43©  Copyright  IBM  Corporation  2016

Page 44: Coding MPP Programs to Process IMS Transactions

Abnormal  Termination• When  program  abnormally  terminates:

– Database  updates  are  thrown  away– Messages  (those  not  sent  express),  are  deleted– Input  message  thrown  away– Abend  is  recorded  on  the  IMS  log– Abend  message  is  sent  by  IMS  to  the  terminal– Transaction  &  program  are  stopped  so  that  no  other  messages  for  that  program  will  be  scheduled.

• It’s  as  if  the  transaction  never  happened.

44©  Copyright  IBM  Corporation  2016

Page 45: Coding MPP Programs to Process IMS Transactions

Error  Handling• MPPs  should  attempt  to  handle  exceptions  without  abending  as  often  as  possible.

• When  error  is  encountered,  the  application  program  can  ask  IMS  to  reverse  any  database  updates  since  the  last  sync  point

• ROLL  DL/I  call:– CALL  ‘CBLTDLI’  USING  ROLL– A  U778  abend  is  issued  to  the  terminal  &  the  input  message  is  deleted.

45©  Copyright  IBM  Corporation  2016

Page 46: Coding MPP Programs to Process IMS Transactions

ROLB  DL/I  call• ROLB  causes  IMS  to  reverse  all  updates,  but  the  transaction  does  not  abend.

• To  reverse  updates  &  delete  the  incoming  message:– CALL  ‘CBLTDLI’  USING  ROLB  IO-­PCB.

• To  reverse  updates  &  reschedule  the  message:– CALL  ‘CBLTDLI’  USING  ROLB  IOPCB  INPUT-­MESSAGE-­AREA.– The  INPUT-­MESSAGE-­AREA  will  return  the  current  input  message.

46©  Copyright  IBM  Corporation  2016

Page 47: Coding MPP Programs to Process IMS Transactions

Programming  tips• All  programs  should  be  written  to  go  back  and  get  another  message  (GU  I/O  PCB)    ('QC'  status  returned  if  no  more  exist)

• Database  requests  should  be  handled  with  the  fewest  number  of  calls

• Message  processing  programs  should  not  do  lengthy  database  scans  or  updates

• Never  issue  file  open/close  operations  -­ beware  of  COBOL  DISPLAYs.

• Issue  all  message  segment  gets/inserts  as  consecutive  calls  if  possible

• Large,  single  segment  replies  take  fewer  calls  and  less  overhead  than  smaller,  multi  segment  ones– check  system  standard  for  maximum  segment  size

47©  Copyright  IBM  Corporation  2016

Page 48: Coding MPP Programs to Process IMS Transactions

Thank  You!

48