|
|
|
- We are a cosmopolitan community of 400 members, from around the globe. - Working on writing and publishing articles on CICS. - Special article on "How do I learn Mainframe Programming" |
Sunday, November 28, 2010
Saturday, November 6, 2010
Creating a new IMS Database
| Q. How do COBOL Programs access Data using IMS/DB Software? |
| COBOL-Programs use READ and WRITE Instructions to access Data from Files. This invokes or calls a helper-program called Access-Method. The Access-Method Software actually knows the details of how the data is organized, and the location(place) – where the record is stored physically on the big DASD-Disk. The Access-Method actually gets the Data from the File, in units of raw Blocks like 0001HARRYPOTTER1000MUMBAIINDIA. But, the access-method has no knowledge about the Record's format or structure – what are the fields in the Record. The Data fetched would be useless, or of little value if you don’t know its structure or Format. In an H2O water-Molecule, it is the Atomic-Structure that is important. On the same lines, Data is meaningful and can be processed, if you know its structure like (EMPID,FNAME,LNAME,SALARY,CITY,COUNTRY). In simple COBOL-File IO Programs, this format, structure or File-Layout, that I am stressing on, is hard-coded or embedded in the COBOL-Program. The COBOL-Program sees the same record-format, as that of the actual-record in the File on the Disk. By contrast, when data is stored and managed by the IMS/DB Software(one more layer added to the Onion on the right), the COBOL-Program is now unaware of the Structure or record-format. The COBOL-Program talks with the IMS/DB Software which stores structure-details. The complicated details of the record-format and Structure are now taken care of by IMS/DB Software, and the COBOL-Program is spared and relieved from this botheration. The IMS DB/Software in turn, calls the Access-Method Software to actually GET the Data from the Disk-Dataset. The IMS/DB-Software Interface in return presents this Data to the COBOL-Program in the form of Segments. The IMS/DB Software does provides an Abstraction. |
| Q. How do you create a fresh New Database-File to store Data? Do I go to ISPF Menu Option 3.2? |
| Say that, you wanna store the data about your Shopping-List – the list of items that you want to buy from the Super-Market, in a Mainframe-File, and you want IMS/DB Software to help you manage your Shopping List. This means, if you want to add an item to the Shopping-List, remove an item from the Shopping-List, or take a Print of all the Items in the Shopping-List, you are gonna ask IMS/DB Software to do it for you. The sad part is, IMS/DB Software can't read Sequential-Files. IMS/DB Software has the ability to read and write data to VSAM-ESDS Files. Hence, if you plan to use IMS/DB Software to manage your data, better create blank(empty) VSAM-ESDS Files to hold your valuable-Data. I have created an Empty New VSAM ESDS File IMS810.INVENDB by running the free IBM-Software Tool IDCAMS. I'd use this Empty VSAM Database-File created newly, load my data into it, and then ask IMS/DB Software to manage this data in the future. |
| Q. What are Control-Blocks? |
| Whenever a COBOL Program, sends requests to the IMS-DB Software, to access data from the VSAM Database-File, IMS-DB Software cannot directly service it. To support the request, the IMS-DB Software needs (i) The Blue-print of the Database and (ii)the database privileges, the program has. These details are stored in specialized Load-Modules called Control-Blocks. IMS-DB Software uses the Control-Blocks as a ready-reckoner, and constantly refers to them, for any requests that come along. |
| Q. What is DBD Control-Block? |
| The DataBase Descriptor or DBD Control-Block, contains the Database-Structure details – what are the different segments in this data, what are the fields in this segment etc. The DBD Control-Block contains the design of the database, it's a blue-print. Every Database must have a DBD Control-Block. Say if, there are two hierarchical databases X and Y, there’s got to be two DBDs. |
| Q. What is PSB Control-Block? |
| The Program Specification Block or PSB Control-Block contains details about, the Database Privileges granted to a COBOL-Program. The PSB will specify, what database-segments the program is allowed to access, the type of access(Get, Insert, Update, Delete). The IMS-DB Software uses the PSB Control-Block, to prevent unauthorized access and enforce security. If the Program attempts to access a segment in the database, which is not allowed in the PSB Control-Block, it is a security violation and the IMS-DB Software restricts it. Every Program must have a PSB Control-Block. Say, if there are two Programs, there's got to be two PSBs. Moreover, a Program's PSB internally contains a PCB(Program Control Block). For each database accessed by the Program, there is one PCB in the PSB Control-Block. In the above picture, the first–program can access both Database-X and Database-Y, but the the second-program is only allowed to access the Database-X. |
| Q. Who creates the Control-Blocks? |
| How do you write or code a new Control-Block? You first write the Source-Code of the Control-Block in Assembler Language. But, the Mainframe-Computer doesn't understand Assembler. It knows only Binary Machine Language 0's and 1's. So, after writing the Source-Code, you Assemble-Link it to produce a Binary Load-Module for the Control-Block. IMS/DB Software shall always refer to these Control-Block Load Modules(containing Database structure-details), while storing or retrieving Data from the Database-File. You go about creating two control-blocks - (i) DBD Control Block and (ii) PSB Control-Block. |
| Q. How do you write the Source-Code of the DBD Control-Block? |
| The secret to writing Source-code for DBD-Control Block, is you’ve got to think, "What's the Structure of the Data, that you are going to store in the VSAM-ESDS Database-File?" Say for example, I want to generate DBD Control-Block for the Inventory-Database. A pictorial representation of the Inventory-Database Structure is given below. Here's a brief description of the Inventory-Database. The Inventory-Database has three segments – Vendor, Item and Stock-Location. When you begin to write Assembly Language Source-Code for the DBD Control-Block, ask yourself, "What are the segments in this Database"? For each segment, you code a SEGM Macro. This is how the skeleton of the Source-Code looks like. Code 3 SEGM Macros, one for VENDRSEG, one for ITEMSSEG and the last for STLOCSEG. The PARENT Attribute on the SEGM Macro tells, "who's the Parent of this Segment"? Since, Vendor Segment is the root, I coded PARENT=0 on it. On ITEMSSEG, I coded PARENT=VENDRSEG and likewise on STLOCSEG, I coded PARENT=ITEMSSEG. For each Segment, the BYTES Attribute indicates the total Sum-Length of all the Fields in that Segment. I’ll revisit this attribute a little later. Now, every Segment VENDRSEG, ITEMSSEG and STLOCSEG can have many fields. Code the FIELD Macro once, for each Field. FIELD Macros go under the appropriate SEGM Macros. I am gonna explode each segment one-by-one, and show you how to code its Fields. Vendor Segment is the list of the Vendors, which supply Raw-Materials. Every Vendor has a 3-Character Alphanumeric Code-Number, a name, an address, city, state and Zip-Code where the Vendor is located and Telephone-Number and Contact-No. The BYTES Attribute indicates the length of the Field. The START Attribute indicates the Starting-Position or Offset(Displacement) of the Field. Let me elaborate it : VENDRNAM is 30 Bytes in Length, and starts from Position 34. It implies VENDRNAM spans from Position 34 to Position 63(30 Bytes). Consequently, the next successive Field VENDRADR will start from Position 64 and so on. An easy formula to remember this is – Starting Position = (Previous Field's Start + Previous Field's Length). Moreover, the TYPE Attribute indicate the type of data. Alphanumeric or PIC X Fields have TYPE=C. Numeric Fields(PIC 99) have TYPE=Z. Packed Decimal( PIC S9(05)V99 COMP-3) have TYPE=P. If you sum-up the field-lengths of VENDRCOD, VENDRNAM, VENDRADR, VENDRCIT , VENDRSTA, VENDRZIP, VENDRTEL and VENDRCON = (3+30+30+17+02+09+10+30) = 131 Bytes. It means the One Vendor's data will be 131 Bytes in size. So, you code BYTES=131 on the Vendor Segment's SEGM Macro. When you write a COBOL-Program to fetch the Vendor-Data from the IMS-Database, the Vendor-Data received from the IMS/DB Software into the COBOL-Program needs to be stored or kept somewhere. You need COBOL-Variables corresponding to each of these VENDRSEG Fields that will store or hold the data in the COBOL-Program, when it received from the IMS Vendor Segment. Here, is the COBOL Copy-Book(a separate Mainframe File) containing the COBOL Variables corresponding these VENDRSEG FIELDs. One Vendor may supply several Items. Item Segment represents the list of the Items, which a Vendor supplies. Every Item has an Item-Name, a short description, unit-price or cost of the Item and the average cost of the Items. Here’s the DBD Source-code for the ITEMSSEG Segment. The COBOL Copy-Book Layout(a Separate Mainframe File) corresponding to the Above ITEMSSEG, is shown below. One Item may be stocked or stored at multiple-locations or warehouses. Stock-Location segment represents the list of the locations, where an item is stored or stocked. Each Location is identified by a 3-character alphanumeric code. At every location, important-details about the inventory such as what is the quantity-on-hand, what is reorder-point, what is the quantity-on-order, and the last re-order date is recorded. This picture shows, how I wrote the DBD Source-Code for the Stock-Location Segment. The COBOL Copy-Book Layout(A Separate Mainframe File) corresponding to the above Stock-Location Fields, is in the snap below. |
| Q. How do I assemble and Link the above DBD Macros? |
| I have the following setup at my shop. I have created a Library(PDS) for storing the DBD Macro Source-Codes called IMS810.DBDSRC. I have keyed in my DBD Source-code in a Member INVDBD, under the Source Library. I have another Library(PDS), which will contain the corresponding DBD Control-Blocks Load Modules, which are produced after assembling the source-code. My DBD Load-Library is IMS810.DBDLIB. Before you run the assemble-link job, you should have your own personal DBD-Source and Load-Libraries setup. To Assemble and Link your DBD-Code, you run the Assembler-Software (EXEC PGM=ASMA90) first and followed by the Linker-Software(EXEC PGM=IEWL). So, you write a simple two-step Assemble-Link job. You can download this JCL by clicking here. This is how it looks. There are four-variables that you need to set. The DBDNAME Parameter is the name of the DBD. The SRCLIB Variable is the DBD Source-Library. The MACLIB Variable is the IMS Macro-Library. You should ask the System Programmers at your shop and find out, the name of the IMS Macro Library. Last, the DBDLIB is the name of the DBD Load-Library. |
| Q. How do you write the PSB Macro Source Code? |
| A PSB Control-Block is like a Entry Pass(Ticket). The PSB helps prevent any unauthorized Access to the Data. IMS/DB Software checks PSB Control-Block to enforce Access-Control. Every COBOL Program that accesses IMS/DB Database, has its own PSB(Entry Pass). In fact, it is customary to have the PSB-Name same as the Program-Name. Inside each PSB, there are several PCBs. Suppose there are two Databases –Employee Database EMPDBD and Inventory Database INVDBD, that the program needs access to. You code a PCB-Macro for each Database, that the program accesses. The PCB Macro, essentially tells the Processing Options PROCOPT=G. PROCOPT Parameter is damn important and indicates the Access-Privilege. For example, to authorize the program to only read the data from the Database, code PROCOPT=G. On the other hand, for a Program to initially load data into the the Database, coding a PROCOPT=LS is necessary, and so on.. Look, how I have written the Source-Code for the a simple PSB which has one-PCB for the Inventory-Database. If a Program uses this PSB, the program will only be able to access Inventory Database(and not Customer Database). You may also download this Source-Code by clicking here. Following the PCB-Macro, you may code the SENSEG or Segment Sensitivity Macros. You code one SENSEG Macro for each Segment. The NAME Parameter indicates the name of the Segment. I have coded three SENSEG Macros for VENDRSEG, ITEMSSEG and STLOCSEG. |
| Q. How do I assemble and link the above PSB Macros? |
| I have the following setup at my end. I have created a Library(PDS) for storing my PSB Macro Source-Codes IMS810.PSBSRC. I have keyed in my PSB Source-Code in a Member INVPSB under the Source-Library. I have another Load Library or PDS IMS810.PSBLIB, which will contain the PSB Control-Blocks Load-Modules, produced on assembling the Source-Code. My advise to you is, go ahead and first setup your Own personal PSB Source-Library and Load-Library before you run the Assemble-Link Job. Just like the DBDGEN Job, I have written a PSBGEN Job to Assemble-and-Link the PSB Code. See below how the PSBGEN Job looks. You may also download this JCL Code by clicking here. There are four variables, that you need to set. PSBNAME is the name of the PSB. SRCLIB is the Source-Library containing the PSB Macros Source-Code. MACLIB is the IMS Macro Library. PSBLIB is the Load-Library where the PSB Control-Blocks reside. |
Thursday, November 4, 2010
Comparing COBOL and Assembler Programs
| Q. What are the different types of Assembler Statements? |
| There are three types of Assembler Statements – (i) Instructions : These are actual Machine Instructions, which when executed by the Mainframe, perform some operation on the Data for example MVC(Move characters) and AP(Add Packed). (ii) Assembler Directives : These are directions, commands or orders meant for the Assembler Software(ASMA90) rather than the Mainframe Computer, for example SPACE(to space out lines on the listing – like SKIP in COBOL) and END(to mark the end of the Assembler Program). (iii) Macros : These are instructions which are further expanded(substituted) by the Assembler to produce more Instructions, for example OPEN(for opening a file), GET(for reading a record), PUT(for writing a record). In COBOL, words are grouped together to form a Clause. COBOL-Clause is just like an Assembler-Statement. Several clauses form a Sentence. Many sentences go on to make up a Paragraph, many para's give a SECTION, and many sections form a DIVISION. |
| Q. What's the syntax of the Assembler Language like? |
| An Assembler Instruction is made up of 5 different Parts. 1. An Optional-Name or Label – You can assign a name to every Assembler Instruction. This corresponds to a COBOL File-Name, data-name or Paragraph-Name in the DATA and PROCEDURE DIVISION. For example, in the below snap PRINTER is the Internal File-Name. 2. A required Operation-Code – The Operation-Code or OPCODE, represents the Assembler Statement that you want to execute – it may be Machine Instruction, Assembler Directive or a Macro. Generally, the convention followed is to start coding the Opcode from Column 10. In the above snap, DCB is the operation-code. 3. Optional Operands – Any Assembler Instruction can carry one or more Operands. Each Operand follows the format Parameter=Value. The list of parameters are separated by commas. DDNAME=OUTFILE,DEVD=DA,MACRF=(PM), are all operands. You normally start coding the first operand from Column-16. 4. Optional Comments – You can write anything you want describing the code as Comments. Comments can begin anywhere after the Operands, but there must be at-least one blank space between the Last Operand and the beginning of the Comment Line. 5. An Optional Continuation-Indicator – When you want to continue an Assembler Instruction over to the next-line, you code a continuation character in Position 72 of the Assembler Statement. The continuation character could be anything other than a blank(white-space). The continued lines should begin normally in Position 16. |
| Q. Is there any restriction on the length of File-names, data-names or paragraph names in Assembler? |
| It is most likely that you are using High-Level Assembler Assembler H at your shop. Assembler H allows labels upto 63 characters. In certain cases only names of length 8 are allowed, for example program-name or sub-routine names. Many old Assembler programmer continue to use the older limit of 8 characters out of habit. I personally feel, its wise to stick to the 8-Character Limit. |
| Q. What are the important positions in an Assembler Statement? |
| Position 01 is called the Begin-Column, Position 71 is called the End-Column. You code Assembler statements between the Begin-Column and End-Column. If the instruction is longer, you should put a continuation character in column-72 known as continuation-indicator field. Position 16 is called the Continue-Column. |
| Q. Do I need to watch out for anything? |
| Absolutely, there's no room for errors. A goof-up could be costly, and sometimes unlike JCL or COBOL, the errors would not even show up. I would like to warn you, that when a Assembler statement is continues onto the next Line, one needs to put a comma at the end of the first Line. In the snap below, forgetting to put a comma after MACRF=(PM), makes Assembler think RECFM, LRECL, BLKSIZE and DSORG are comments. As seen, they’ve been highlighted in Turquoise. Another typo that you are likely to commit, when start coding Assembler is putting extra-commas. |
| Q. How do you form a valid Label in Assembler? |
| A Label in Assembler is textual character-string, made of A-Z, 0-9, @, $ and #. Assembler H also supports the underscore sign '_'. Generally, in COBOL Programs, you find paragraph names such as 300-HOUSEKEEPING, 2500-PRIMING-READ, 2450-CHECK-RC etc. Paragraph-names start with digits, because it aids the COBOL Programmer to know the direction in which to find the paragraph, when he looks at the COBOL Program Listing. In Assembler, labels cannot start with a Digit. The underlying reason for this is because, Assembler-Programmers don't need to have something in the Label, to tell them the place where the Label is Located. The Assembler Listing automatically tells them where the Label is. More on this later. The assembler software puts the address each label referred to in a Branch Instruction, in the ADDR1 Column. By looking at this value, and comparing it with the current LOC Value, you can determine whether the Label precedes or succeeds the current Line. You have to get into the habit of looking the Address in ADDR1 and ADDR2 Columns of the Assembler Listing to locate Labels, and be a productive Assembler Programmer. |
| Q. A COBOL Program has a definite Layout IDENTIFICATION, ENVIRONMENT, DATA and PROCEDURE DIVISION. What about Assembler? |
| Assembler does not follow a strict, rigid layout for writing Programs. It is far more relaxed than COBOL's organization of Programs. Below, I have enlisted what each DIVISION of a COBOL Program does. What I do is, I write Assembler Programs in a sequence, which roughly approximates the above structure. Program-name Program-description(comments) Actual Instructions File I-O Areas, working-storage areas File-names and Dataset Control Blocks(DCB) External–record and data descriptions(in dummy sections-DSECTS) |
| Q. How do you decode the Assembler Listing? |
| I am gonna elaborate the Assembler-Listing that was produced for the Program ASPROG02. The complete assembler-listing can be found, by clicking here. The first-page of your Assembler Listing should be titled External-Symbol Dictionary, commonly abbreviated as "ESD". 1. The SYMBOL Column shows any Control-Section(CSECT) names and ENTRY Names inside your Program. 2. The ADDR Column shows where the name under the SYMBOL Column is located. In this case ASPROG02 begins at Address 0 within the Program. 3. The LENGTH Column tells the Length of the name in the SYMBOL. In this case, the size of Program ASPROG02 is hexadecimal X'3CC'(972 Bytes). The next Page and several subsequent, contain the listings of instructions in your Program. This is the same information provided in a COBOL PMAP or CLIST. LOC – This contains the location, or hexadecimal Displacement of the Statement from the beginning of the Program. Object Code – This contains 3 columns. Not all the 3 columns are always filled. This is the Actual Machine Instruction generated by the Assembler, which you would find in memory in the Dump. ADDR1 – This column will contain the Hexadecimal address of the first operand in the instruction that you have coded. This is what is printed in the LOC Column of where the Label is actually coded. ADDR2 – This column will contain the Hexadecimal address of the second operand in the Instruction. STMT – This column will contain the Line-Number or Statement-Number. SOURCE STATEMENT – This is the actual 80-Byte Assembler Source Statement. Understanding the Assembler Listing is very important to be a good Assembler-Programmer. 1. Take a look at Statement 15. LA 2,SAVEAREA For the second-operand SAVEAREA, the assembler has substituted the hexadecimal address ADDR2=X'DC'. Now find the, hexadecimal Address X'DC' in the LOC Column. That's, where SAVEAREA is defined. 2. Locate the Statement AP RECNUM,ONE Both ADDR1 and ADDR2 Columns should have a printed value there. RECNUM is substituted by ADDR1=X'304' and ONE is substituted by ADDR2=X'309'. Scan the Program until you find these addresses. You should try practicing this a few more times, till you've mastered it. Following the Assembler Instruction Listing, there will be the Relocation-Dictionary or "RLD". The RLD will be used by the Loader when it brings your program into Memory for Execution. For the moment, I’ll skip the RLD. Next, you shall find the Cross-Reference Listing. SYMBOL – The name of the field, or Instruction-Label, just like the name in a COBOL Cross-Reference XREF Listing. LEN – The Assembler’s computed Length for that symbol. How much storage space does it occupy in Bytes? VALUE – This contains the Hexadecimal address of the location of the Symbol. DEFN – The Statement number where the Symbol was defined. If you accidentally define a Symbol twice, the Assembler will list it in the Cross-reference and flag the second definition as duplicates. References – The statement where the symbol was referred. When the Assembler-Program contains errors, the Assembler provides diagnostic information about the error at two-places. First a line containing, * * * ERROR * * * is printed following the statement with the error. Secondly, after the Cross-Reference, a summary of all un-acceptable erroneous statements that were flagged is printed as Statistics. |
