Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reference modification 3

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
hi, what is a reference modification ?
thanks
 
A normal move is

move field1 to field2.

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.
 
Hi there,

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.

Thanks.

-Tyler
 
Hi Claude,

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.

The code above just tries to get the idea across.

Regards, Jack
 
Hi Tyler,

How'd your project go?

The redefines goes something like this:

01 date.
05 mm pic xx.
05 dd pic xx.
05 yy pic xx.

If you can't find REDEFINES in your book, get another book quick. Try half.com they sell POed books that look brand new for peanuts.

Regards, Jack.
 
I,m sorry Tyler. That was not a redfines. It could be coded that way and it's probably preferable. The redefines goes like this:


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.

Jack
 
Hi,

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.

Regards,

Crox
 
hello Slade,
i am not going to pretend that i understood. could you tell me what the small code you wrote does ?
thanks
 
it is a fancy word for sub-stringing.

Thats what annoys me so much about computers in general, so many different terms for what equates to the same thing. What a bunch of arse.

 
Hi Claude,

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.

Regards, Jack.
 
Hey all,

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(n) and decided to give up when I couldn't figure it out without help. We of course, never really covered it in class.

I know I can always find help here!

Cheers!

-Tyler

 
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:

01 WS-IDX PIC 9(1).
01 WS-IDX-OCCURRENCE REDEFINES WS-IDX.
05 WS-IDX-OCCUR PIC X(1).

O1 THIS-TABLE OCCURS 100 TIMES INDEXED BY T-IDX.

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.

Hope this helps, Nina Too
 
Hi Nina,

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top