Monday, October 31, 2011

COBOL: Difference between Subscript and index

Initially for both subscript and index, system has to calculate the location of a entry from the beginining of the table. The real difference starts showing up during subsequent usage of subscript and index. This can be illustrated using the below sample program

WORKING-STORAGE SECTION.                       
01 SUB1                   PIC 9(02).           
01 TAB1.                                       
   05 TAB1-ENTRY OCCURS 5 TIMES.               
      10 TAB1-ELEMENT  PIC X(10).              
01 TAB2.                                       
   05 TAB2-ENTRY OCCURS 5 TIMES INDEXED BY IX2.
      10 TAB2-ELEMENT  PIC X(10).              
PROCEDURE DIVISION.                            
PARA1.                                           
     ACCEPT SUB1.                               1
     MOVE 'AA' TO TAB1-ELEMENT (SUB1)           2
     SET IX2   TO SUB1                          3
     MOVE 'AA' TO TAB2-ELEMENT (IX2)            4
     PERFORM PARA2 10 TIMES                     5
     STOP RUN.                                  6
PARA2.                                          7
     MOVE 'AA' TO TAB1-ELEMENT (SUB1).          8
     MOVE 'AA' TO TAB2-ELEMENT (IX2).           9


For statement 2(MOVE statement in PARA1), behind the scene following operations are carried out.

a. convert SUB1 to packed decimal
b. convert packed decimal value of SUB1 to BINARY
c. multiply the length of a table occurrence with the BINARY value got in previous step and this gives the offset of the table entry within the table
d. it uses the offset value to locate the table entry and populate it

Statements 3 and 4 also, carries out the same above steps.

For statement 8 which uses subscript, it again carries out the same operations carried out in statement-2. But for statement 9, it reloads the register with the offset (index) already stored in memory.

For subscript, it carries out the offset calculation again and again whereever the table entry is accessed.  Where as in the case of index,  after the calculation of offset, it stores the result in the memory. When the table is accessed again using index, then it retrives the offset which is already stored in memory to access the table, thus avoid the offset calculation.

Now you know why index is faster than subscript. 

Machine code generated for the above given program

000016  MOVE                                                           
   00024C  5830 912C               L     3,300(0,9)              BLW=0 
   000250  F271 D0F8 3000          PACK  248(8,13),0(2,3)        TS2=0           SUB1 
   000256  960F D0FF               OI    255(13),X'0F'           TS2=7 
   00025A  4F40 D0F8               CVB   4,248(0,13)             TS2=0 
   00025E  1854                    LR    5,4                           
   000260  4C40 A018               MH    4,24(0,10)              PGMLIT AT +16 
   000264  5A40 A010               A     4,16(0,10)              PGMLIT AT +8 
   000268  1A43                    AR    4,3                           
   00026A  D209 4008 A01A          MVC   8(10,4),26(10)          TAB1-ELEMENT()   PGMLIT AT +18
000017  SET                                                            
   000270  0650                    BCTR  5,0                           
   000272  4C50 A018               MH    5,24(0,10)              PGMLIT AT +16
   000276  5050 9134               ST    5,308(0,9)              IX2   
000018  MOVE                                                           
   00027A  1A53                    AR    5,3                           
   00027C  D209 5040 A01A          MVC   64(10,5),26(10)         TAB2-ELEMENT()   PGMLIT AT +18
000019  PERFORM                                                        
   000282  4100 000A               LA    0,10(0,0)                     
   000286                 GN=8     EQU   *                             
000021  *PARA2                                                         
000022  MOVE                                                           
   000286  5820 912C               L     2,300(0,9)              BLW=0 
   00028A  F271 D0F8 2000          PACK  248(8,13),0(2,2)        TS2=0            SUB1
   000290  960F D0FF               OI    255(13),X'0F'           TS2=7 
   000294  4F30 D0F8               CVB   3,248(0,13)             TS2=0 
   000298  4C30 A018               MH    3,24(0,10)              PGMLIT AT +16
   00029C  5A30 A010               A     3,16(0,10)              PGMLIT AT +8
   0002A0  1A32                    AR    3,2                           
   0002A2  D209 3008 A01A          MVC   8(10,3),26(10)          TAB1-ELEMENT()   PGMLIT AT +18
000023  MOVE                                                           
   0002A8  5830 9134               L     3,308(0,9)              IX2   
   0002AC  1A32                    AR    3,2                            
   0002AE  D209 3040 A01A          MVC   64(10,3),26(10)         TAB2-ELEMENT()   PGMLIT AT +18
   0002B4  4600 B07A               BCT   0,122(0,11)             GN=8(000286)

Friday, October 28, 2011

CICS: Difference between transaction and task

Transaction and Task are interchangeably used.  We programmers/users call it as a "transaction", where as from CICS perspective, CICS calls it as a "task". Task begins when you enter the transaction id in the CICS "blank screen" and ends when the control return back to CICS. A CICS transaction task may execute several programs.

In the below diagram, task begins from the beginning of program 1 and task ends when control is returned to CICS from program 4.

CICS tran id -> Program 1 -> Program 2 -> Program 3 -> Program 4 -> CICS


Android: How to install Custom ROM in Nexus one


What is Stock ROM in Android ?
The operating system shipped with nexus one phone is called Stock ROM.

What is Custom ROM ?
As you know Android is an open source OS.  So,  anyone can download the Android OS and customize it for their personal use.   The customized Android OS is called as Custom ROM.

When I got my nexus one phone, I wanted to install the Custom ROM.   But at that time I do not know where to start.  When I searched the web, I was bombarded with lot of information and it was too much for me to digest it.  Finally after little struggle I have installed CyanogenMod in my phone.  Cyanogenmod is one of the famous Custom ROM.  One of the best of feature of CyanagenMod is, it has FM radio in it.  I dont know if any smart phones have FM radio in it. FM radio will be useful to listen to radio stations while your travel and you have no data plan in your mobile.

Following are the steps you need to follow to install a Custom ROM in nexus one.

1.       Unlock the boot loader. The instructions are present in unlock bootloader 
2.       Now we need to root the phone. Read the instruction present in the post
root nexus one  posted by “soloviyko”.
3.       Now you can install the Custom ROM.  Instructions are present in install custom rom

Mainframe: Run a job at a particular time without the job scheduler

If your shop has Thruput manager (TM), you can use the JTS command in the JCL to direct the TM to run the job at a particular time.


When you submit the below job, the job will be put on hold and system will NOT perform any JCL error checking. The job will be released from "hold" on 06-Nov-2011 at 2.30 AM EST and it will start running.  The beauty is JCL error checking is bypassed until the time is met.



//TESTJOB JOB (MX999),'TEST JOB'...
//*JTS RELEASE DATE=2011.310,TIME=02.30

Let us say you want to run a test job every Monday morning and it takes around 4 hours to complete. Instead of running the job on Monday morning and wait for 4 hours, what you can do is, submit the job with JTS RELEASE command on Friday before you leave, to run the job Monday morning at 1 AM EST. So, by the time you reach the office on Monday morning, the job would have completed and thus you can save your time.