It is currently Thu Mar 28, 2024 2:58 pm


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Unit 1 - Lesson 6: Basic MUMPS Commands
PostPosted: Tue May 24, 2011 5:41 am 
User avatar

Joined: Wed Nov 17, 2010 8:37 am
Posts: 136
Real Name: Terry L. Wiechmann
Began Programming in MUMPS: 0- 0-1971
The goal of this lesson is to teach you some basic MUMPS commands that you can use in programming mode and in writing a basic routine in the next lesson. The commands will be used in their simplest form and without a formal description. Unit 2 explains the concept of an expression in detail which is fundamental to all commands.

At this point you should log into your MUMPS system in programming mode. As we go through each of the commands listed in the student guides, you should execute each of the examples.

Set Command

First the SET command is probably the most frequently used command in the language. It is used to bind values to array nodes including the name. The examples in the guide bind values to the array name. Arrays will be covered extensively in Unit 2. They form the structural foundation of a MUMPS database.

IO Commands

The next two commands are the WRITE and READ commands. They are part of the IO commands. There are five IO commands. They are:

OPEN
USE
READ
WRITE
CLOSE

These five commands are used to perform IO to any supported IO device.

MUMPS systems support relevant devices which are supported by the underlying Operating System. It forms a pool of devices that are available to all MUMPS jobs (processes). If a job executes the OPEN command on a particular device, the device is removed from the pool and the job owns it (unless the device is sharable in which case multiple jobs can use it). If another job owns the device, you will not get ownership of the device. Any job can own multiple devices.

If your job owns a multiple devices, you must USE a device before you can direct IO to it. When you log into a MUMPS process, you have unknowingly performed an OPEN of the device you are logging into. It is called the principle device and is the default.

When a READ command is executed, it reads a record of information from the currently used device. The record is defined as a sequence of characters terminated by a specific terminator character or characters that usually can be defined. By default, a read without a preceding USE reads from the principle device. This is what you will be doing when you work at the principle terminal device. So, when you read from a device, where is the data stored? It is bound to an array name or node (often referred to as a variable).
Once you READ or SET data to an array name, you can WRITE it to any device. Without getting into the details at this point, executing the USE with the READ and WRITE commands is dependent upon how you are executing them – in programming mode or within a routine. More later...
When you have finished using a device, you should return it to the system pool by executing the CLOSE command.

Post Conditionals

Read the Post-Conditional section. In my view, post conditionalizing commands should be minimized. When written tersely(using only the first letter of command, function, etc.,), the MUMPS language can be viewed as esoteric, written for only the few to comprehend. It is better to use the IF command since it makes your code much more readable.

FOR and QUIT Commands

This section contains very simple examples of the FOR and QUIT commands. The FOR command very important for setting up iteration loops. Execute these examples in direct programming mode.

After doing these examples, go back to the MUMPS Routines section and look at the MYRTN routine. You should be able to read it now. Notice the GOTO at the end of the routine. We will study that in the next lesson, however, it does exactly that, it goes one way to a specified label – TOP in this case.

In older MUMPS code, the GOTO was used extensively. Mostly because it was suppose to be faster on the machines and implementations at the time because it minimized stack usage. However, the side effect was a condition often referred to as “spaghetti code”. There are conditions where the GOTO is useful (e.g. dispatching in a table). However, you should never use it to create loops.

Exercise

How would you rewrite this routine to eliminate the GOTO loop using the FOR loop?

Go to the next section where you will learn how to create and execute MUMPS Routines.

_________________
Terry L. Wiechmann


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net