The Secret of PUTs and GETs

PUTs and GETs are easy, right? PUT FILEOUT,RECOUT adds the contents of RECOUT as a new record in FILEOUT. GET FILEIN,RECIN reads a record off FILEIN and stores it in RECIN. Simple, yes? But there is a little known fact about the PUT and GET macros that you might find interesting. It really doesn’t matter which macro you choose to code (PUT or GET) because both macros generate identical code. Hard to believe, but these macros are interchangeable. You can see this in the example below. Lines 90-94 were generated by a PUT macro and lines 97-01 were generated by a GET macro. See for yourself: Both macros generate the same code.
87 PRINT ON,NODATA,GEN
88 PUT FILEIN,RECORDIN
90+ LA 1,FILEIN
91+ LA 0,RECORDIN
92+ SLR 15,15
93+ ICM 15,7,49(1)
94+ BALR 14,15
95 GET FILEIN,RECORDIN
97+ LA 1,FILEIN
98+ LA 0,RECORDIN
99+ SLR 15,15
00+ ICM 15,7,49(1)
01+ BALR 14,15
02 PRINT ON,NODATA,NOGEN
So how does the machine distinguish when you want to read a record, and when you want to write a record if PUT and GET are equivalent? The answer lies in the OPEN macro which does all the heavy lifting. It’s in the OPEN macro that you indicate the type of operation you intend to invoke on the file: OPEN (PRINTER,(OUTPUT)) or OPEN (FILEIN,(INPUT)).
A little knowledge is sometimes a dangerous thing, so while PUT and GET may generate the same code, I don’t recommend coding PUT when you want to read a file, or GET when you want to write to one. That would be unnecessarily confusing to the programmers coming behind you. After all, one of those programmers is likely to be you.

Leave a comment

Filed under IBM Mainframe Assembler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s