View previous topic :: View next topic
|
Author |
Message |
nightbuzzz
New User
Joined: 04 May 2007 Posts: 21 Location: kuala lumpur
|
|
|
|
Hi,
I want to read an element's last 3 characters which is present in an array variable.
Please let me know how can i do it.
eg:-
an array element ws-array(1) contains 'ABCDEFGH'. I want to move just FGH to another variable, then how can i do it.
Thanks in advance
Mayank |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
10 nicely-named-item-in-a-table pic x(8).
10 filler redefines nicely-named-item-in-a-table.
15 filler pic x(5).
15 nicely-name-end-of-item-in-a-table PIC XXX.
MOVE nicely-name-end-of-item-in-a-table ( subscripted ) TO wherever-you-need-it |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Mayank, your post left MANY unanswered questions:
1. Are the variables in the table always 8 bytes long?
2. Are you always wanting bytes 6 through 8 moved (assuming the table element variables are always 8 bytes long)?
3. If either of these questions is negative, you need to more fully explain what you want.
You could use reference modification as well:
Code: |
MOVE TABLE-ELEMENT (tbl-ndx) (6 : 3) TO ... |
would move bytes 6 through 8 of the TABLE-ELEMENT variable pointed to by tbl-ndx, for example. |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
Code: |
* Assuming Ws-array is Pic X(08)
Move Ws-array(1)(6:) to wherever-you-need-it
* else
Move Ws-array(1)(6:3) to wherever-you-need-it
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Looks like I'm outnumbered :-)
I like a program to tell it's own story to the next reader. Not leave them having to wonder "what was at 6 for a length of 3? Anyone any idea?" They'll be posting the question here :-)
If you can do it without reference-modification, do so, with nice names. I know there is all that extra thinking, and typing, but I've never found that thinking about a program is a problem, and the typing doesn't really amount to much. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Bill,
I agree with you, REFERENCE MODIFICATION is not something to be used, freely.
Often it is the easiest solution
when a design is changed (suddenly a need for a part of a field).
but it is very poor if it is part of the original design.
and that is where you find most reference modification,
in the original design.
that is the trouble with programmers who want to HLASM in COBOL.
they are of the same mentality as the jerks who insist on referencing
the structures within an FD instead of using the WORK-AREA Option with i/o. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
I concur on good names.
Programmers produce programs - readable (elegant?) documents.
It's the programs that produce files. |
|
Back to top |
|
|
|