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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A newbie question about : symbol 1

Status
Not open for further replies.

JebusRocks

Programmer
Sep 14, 2004
30
CA
Hello all

I am new to cobol programming(some schooling but little in the way of real world experience) I am looking at a piece of code and need it clarified if you could.

the code is
IF X
MOVE A (1:20) TO B
MOVE A (21:20) TO D
ELSE
DO SOMETHING
END IF

I understand the logic but am wondering about the
(1:20) and (21:20) statements

does
(1:20) mean move 20 characters of A to B starting in position 1
and
(21:20)mean move 20 characters to of A to D starting in position 21
?

Thanks


 
Yes.

That is called "reference modification", and is a very usefull facility on todays COBOL's.

it is source/destination(start_position:size) where size is optional and if omitted will mean until the end of source/destination.
e.g.
move a to d(10:)
move b(5:) to c

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
does (1:20) mean move 20 characters of A to B starting in position 1 and (21:20)mean move 20 characters to of A to D starting in position 21
Your guess is right.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You are absolutely right. In other programming languages this
is called subscripting an example would be:

Let $ABC = Substr($DEF:1,20) where $ABC value will now
becomes the first 20 chars of $DEF.

You could also try if COBOL will replace a character by
using INSPECT whose field is subscripted.
where you inspect a field(n,n) and replace the characters
found.
 
But, since it is not substringing, it would be incorrect to call it that!

Reference modification not only provides the capability to modify the reference to a portion of a data-item, but it also casts the reference to be alphanumeric.

Consider:
[tt]01 my-data pic 999V99.
...
move my-data (1:) to something[/tt]


Tom Morrison
 
It's not the same as substringing, but it is a lot closer to that thans subscripting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top