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

Arrays and subscripts?!?!?

Status
Not open for further replies.

DarkParadox

Technical User
Nov 11, 2002
6
0
0
US
I am a beginer in cobol programing. I have this problem in where I have to set up this array with a subscrip that will move the pointer on a name. The thing is that I want it to stop after I hit the space between the First name and the last name.... I just need the last name to put on letters that are sent out. Sample

Perfrom until na-name-in (sub1) = ???????

I don't know what to put so it can equal space. so it can stop. WEll if anyone can give me any sugestions. Thank's
 
Hi DP,

You haven't defined your problem in much detail, so I'm guessing you have a name (na-name-in) of let's say 30 chars. It contains a multi part name, e.g.:

"jack n. d. box"

and you must address an envelope to "Mr. Box".

The problem here is: what is the level of flexiblity available to the creator of the data? Here are some possibilities:

"jack n. d. box jr."
"jack box"
"j box"
"jack n. d. box III"
"j. n. d. box"
"jack n. d. mc box"
"Mr. jack n. d. box"
"Mrs. jack n. d. box"
"Ms. jack n. d. box"
"Mr. jack n. d. box, PhD."

Well, you get the idea. So if your prof says there are only 2 or 3 of these forms you need to address, you can begin to think about solving the problem.

If not, ask him if you can redesign the data field(s), for example:
Code:
      01  na-name-in.
          05  na-title-in      pic  x(005).     
          05  na-1st-name-in   pic  x(020).     
          05  na-init-in       pic  x(001).     
          05  na-last-name-in  pic  x(030).
Regards, Jack.




 
Thanks for the info... I have already setup the variable names in the data div. The problem is that the Dr. wants us to make an array with a sub. Which would break up each letter in the whole name, then use the sub to move from letter to letter until there is a space. Using a loop then adding one after the loop to move the sub pointer to the first letter of the last name. In this prog. there is only first and last names.
example
01 name-in.
05 name-char occours 25 times pic x(01).

Then useing the sub that was setup in WS to move through the letters.

Perform until name-char (sub) = """"space"""""

The big problem is that I don't now the code to make the perform line equal space. It's kind of hard to explain for a newbie.... sorry .... but any thing will help turn the wheels in my head. Thanks...

 
Hi DP,

If i had understood your problem correctly....Check whether what i say is correct.

Suppose there is a name like ABC DEF. You want to break it into ABC and DEF. Right.

So i think you can use the statment which reads as below
Perform until name-char (sub) IS SPACE or = SPACE,
where SPACE is a figurative constant.

Hope this works.

Thanks
Karthik
 
Hi DarkParadox,

To extract the last name from your array, using a subscript:
Code:
 WORKING-STORAGE SECTION.
 01 names     PIC X(40) VALUE "John Smith       ".
 01 sub       PIC S9(04) COMP.
 01 sub2      PIC S9(04) COMP VALUE ZERO.
 01 last-name PIC X(20).

 PROCEDURE DIVISION.
 MAIN-0000.
* Skip over FIRST NAME
     PERFORM VARYING sub FROM 1 BY 1 
     UNTIL names (sub: 1) = SPACE
       CONTINUE
     END-PERFORM

* Skip over space(s) between FIRST and LAST NAMES
     PERFORM VARYING sub FROM sub BY 1 
     UNTIL names (sub: 1) NOT = SPACE
       CONTINUE
     END-PERFORM

* Extract LAST NAME
     PERFORM VARYING sub FROM sub BY 1 
     UNTIL names (sub: 1) = SPACE
       MOVE names (sub: 1) TO last-name (sub2:)
     END-PERFORM
Assumptions made:
1. The variable 'names' contains first and last names only.
2. Each of the names does not contain embedded spaces.

I did not compile and test this code. You should have fun doing so.[pc2]

With a little modification, you could parse your array from right to left, stripping trailing spaces before extracting the last name.

Dimandja
 
Dimandja should have you on the right track. Just a couple of minor comments:

1. Dimandja uses reference modification rather than an array to handle the problem. I prefer his approach over the array-based approach, but . . . if the requirements say you must use an array, then . . . you must. Your definition of the array looks pretty much OK; I'd add an INDEXED BY clause to assign an index rather than use a subscript, but that's just personal preference.

2. In Dimandja's example, you'll need to figure out how to deal with sub2. I'd leave off the last perform altogether in favor of MOVE NAMES(SUB:) to LAST-NAME, but that uses reference modification! (It also presupposes no honorifics or other titles following the last name.)

3. Also, you should allow for the case where there are no spaces in the NAME field (very long last name, perhaps? or one of those hyphenated things that gets long). In an academic exercise, it may not be necessary, but in the real world you probably need to allow for it. Also, what about leading spaces? Must they be allowed for?

Good luck.

Glenn
Brainbench MVP for COBOL II
 
Thanks guys I made the changes accroding to my specs and the help you all gave me. My program works now [2thumbsup]
Now I hope I get a 100 for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top