From the course: Migrating COBOL Apps

Self-modifying code - COBOL Tutorial

From the course: Migrating COBOL Apps

Start my 1-month free trial

Self-modifying code

- [Instructor] From the earliest days of coding with assembler, programmers took advantage of code that modified itself in order to save space and reduce the amount of code written. However, this has the potential to make problem diagnosis and subsequent maintenance more difficult, and some organizations banned the practice. Where self-modifying code still exists, it certainly adds complexity to migration. In COBOL, we can modify Go To statements using alter. Let's take a look at a small demonstration program which shows how alter works. I'm in my COBOL folder in Ubuntu, let's look at a self-modifying program called SpaceX. Nano minus L, spacex.cob. Okay, we can see the expected start to the COBOL program, followed at line six by a statement which alters the Go To following the label, SpaceX, at line nine, to uncalled launchpad, then jumps to SpaceX. At line 10, the go to despair statement has been replaced with the new go to launchpad, and so the program jumps to the launchpad label. The code immediately after the launchpad label displays a launch message, and then at line 16 changes the SpaceX label to be a jump to the label, orbit. It then jumps back to SpaceX, which then jumps to orbit at line 18. This continues through to the last change at line 22, when SpaceX is changed to a Go To to Mars and the program terminates after landing. Note the abbreviated form that drops the words, proceed to. Okay, let's compile and run this. Cobc minus X, spacex.cob. Okay, that compiled without error, ./spacex, and we can see we made the voyage to Mars without despair. Of course, there may be some despair when we need to migrate code like this.

Contents