Reference modification allows you to move part of a sending field to part of a receiving field.
move field1 (1:4) to field2 (5:4).
If you had an 8 character field1 that was "11111111"
and an 8 character field2 that was "00000000"
after the above command field2 would be:
"00001111".
This allows you to move part of a field. It comes in handy for rearranging a date without using a redefine for the month, day and year.
I have a quesion about redefines. How would that look for the date (or any variable)? I can't find much info in my textbook about the refefines clause.
Adding to what Bird said, the really sexy (and usefull) part of ref mod is that you can code it with variables, e.g.:
MOVE 1 TO LEN-S LEN-R
READ IN-FILE INTO SEND-REC
PERFORM UNTIL WS-EOR
IF MUST-MOVE-FLD
PERFORM 2000-FIND-LEN-OF-SEND-FLD *** this pops len fld
MOVE FLD-A(POS-S:LEN) TO FLD-B(POS-R:LEN)
ADD LEN TO POS-R
END-IF
ADD LEN TO POS-S
END-PERFORM
It's good for parsing data strings. Moving data elements that may be variable (e.g. N&A). And hundreds of other things; the only limit is the imagination. You don't have to redefine a fld as pic x occurs n.
a redefines means to describe the same memory in a different way. The memory remains the same. What was put in it, will stay there, the only thing is that you can look at it in a different way. Like the example of Jack you see the same 8 bytes divided into 4 portions of 2 bytes. (warning: The word DATE is reserved and can not be used like in the example above.)
With reference modification you can reference to the date in a similar way, sending and receiving.
So you can do something like:
MOVE '2001' TO DATE-FIELD(1:4).
MOVE DATE-FIELD(1:4) TO DATE-CCYY.
It's SUPPOSED to take a string in the I/P rec and determine if it should be moved to an O/P field. If it is to be moved, move it to the next available spot in the O/P rec.
The 2000-... rtn scans the I/P fld and calcs the len of the next string. If it s/b moved a flag is set to "must-move-fld". This rtn is not shown. Upon return from this rtn the length of the string (len) is used in the mod refed move stmt and also used to bump the position ptr(s), s-pos & r-pos, where necessary.
so, if an I/P fld looked like:
maaa mcccccccccc dddddd me mfffffffffffffffffff ggg
and only the strings beginning w/m were to be moved, the O/P fld looks like:
maaamccccccccccmemffffffffffffffffffff
I didn't count the chars, so they may be off by 1 or 2.
Now this can be accomplished by other means, but it IS an example of using variables in a ref mod stmt. Also I may not have initialized flds, etc. For example, s-pos s/b also bumped by +1 to account for the space. Remember I'm making up both sides of this as I go along; but it should give you an idea.
Sorry, I haven't replied...I went out of town. By the way Jack, the project went great! Thanks again for all of the help...I'll try half.com too.
Redefines is what I thought it was. I think when I tryed it in the past, I used incorrect level numbers or pic x and decided to give up when I couldn't figure it out without help. We of course, never really covered it in class.
Slade wrote:
------------ 01 date pic x(8).
01 segmented-date redefines date.
05 cc pic xx.
05 mm pic xx.
05 dd pic xx.
05 yy pic xx.
------------
Another use for redefines is for displaying a value that originally was in a comp field. Or for that matter, displaying something such as an index.
Here is some code I used recently to do this. I had an indexed table, and I had to move the value of the index to a PIC X field. So in Working Storage, I defined it thusly:
When I got to the place where I had to place the index value into a PIC X field, I coded:
SET WS-IDX TO T-IDX.
MOVE WS-IDX-OCCUR TO PICK-X-FIELD.
This sort of thing can be truly handy if you are trying to move a COMP or packed decimal field into a PIC X field for eventual display. You have to use 2 steps, redefine the COMP/packed decimal field into a PIC 9, then move the PIC 9 redefined field into the PIC X field.
You don't need to move a pic9 to a picx to display it. It will display the same as a picX.
But if you try to display a picS9 the sign will display as a zone overpunch in the low order position, e.g. 1 displays as A, 2 as B, etc.
slade, you are absolutely correct. Actually, as I recall, I think that it was a COMP or packed decimal field I was trying to display. You can use the REDEFINES clause for this sort of thing.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.