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

Cobol Routines

Status
Not open for further replies.

jmanj

Programmer
May 20, 2003
298
US
I could not imagine I'm back doing Cobol stuff(after 20 yrs) and here I am doing just that! I used to do Cobol with IBM and Tandem mainframes but this time I have to do it in Micro Focus version for unix. Being rusty and does'nt have any book for reference I'm at a dilemna for new Cobol functionality.

Does anybody have a routine to parse out a string field? This should remove any special character in a field? i.,e. removing
special characters from ZIP codes or PHONE numbers....I could not even remember how to use an array(or is there one?).

Thanks for any help.

 
K5TM,

Thanks for the links. That really jogs my memory. I was hoping
that INSPECT is still in use but UNSTRING is quite new to me.
The substring fuction (n:n) is also a new thing which I can fully use.

Thanks for the help.
 
INSPECT is still available and can do many of the functions you requested quite well. It can be used to set up the pointers for referece modification, the COBOL term for substrings, although it is not really the same as substrings as COBOL does not have "strings".

Reference modification actually dynamically defines an alphameric field relative to the beginning of the referenced field with an optional explicitly specified length. The field is treated as a group level. The relative beginning position can be zero or negative. It can result in addressing errors if one is careless.

There are several books available that describe the current COBOL standards. Perhaps someone else on this forum can point you to specific ones.

There are also some evolving new functions that may be included in the next standards release. There are pointers in this forum to the current draft version of the new standards.

Micro Focus supports several extensions to the current and draft standards as well.
 
I think it is better to store telephone numbers as text and then redefine it into three fields. i.e. area code, prefix, number. Some cases you may need an extension number as well. However you store the fields it is better to store them the same way every time and check for obvious errors. Obviously it is hard to fix other peoples mistakes, but you can at least make it harder to enter phone numbers incorrectly in the future. If you build a form or some kind of fields to enter the phone number make 3 fields so it shows the editing on the form and the users will understand what goes where.

Example:
( [_ _ _] ) [_ _ _]-[_ _ _ _]

That makes it easier to check and easier for the user to understand. It is a lot better than just enter a phone number any what you want in a 10 or 15 character field.

If you do not like my post feel free to point out your opinion or my errors.
 
Thanks for all your reply. At meantime because of your generosity I was able to come up a quick way of parsing out unnecessary characters from a field. Here's what I did just for
a starter. The routine will remove any characters rather than numerics.

my WS:
01 AMG-STRING-ROUTINE.
02 AMG-INP-LENGTH PIC 9(3) VALUE ZEROES.
02 AMG-OUT-LENGTH PIC 9(3) VALUE ZEROES.
02 AMG-INPUT-DATA PIC X(100) VALUE SPACES.
02 AMG-STRING-DATA PIC X(100) VALUE SPACES.
02 AMGPT1 PIC 9(3) VALUE ZEROES.
02 AMGPT2 PIC 9(3) VALUE ZEROES.
02 AMG-VALID-NUM PIC X(1) VALUE SPACES.
88 AMG-VALID-NUMBERS VALUE "0","1","2","3","4",
"5","6","7","8","9".


Here's the procedure.

INITIALIZE AMG-STRING-ROUTINE
MOVE 15 TO AMG-INP-LENGTH
MOVE 14 TO AMG-OUT-LENGTH
MOVE PEM-HM-PHONE-NBR TO AMG-INPUT-DATA
PERFORM 1041-STRING-ROUTINE
THRU 1041-ROUTINE-END
MOVE AMG-STRING-DATA(1:14) TO AMG-HM-PHONE-NBR.

Here's that routine:
*****************************************************************
* Routine to remove non-numeric characters in a field. *
* Resulting output is all numeric. *
*****************************************************************
1041-STRING-ROUTINE.
*****************************************************************
MOVE 0 TO AMGPT1.
MOVE 0 TO AMGPT2.

1041-ROUTINE-START.

ADD 1 TO AMGPT1.

IF (AMGPT1 > AMG-INP-LENGTH)
OR (AMGPT2 > AMG-OUT-LENGTH)
GO TO 1041-ROUTINE-END.

MOVE INPUT-DATA(AMGPT1:1) TO AMG-VALID-NUM.

IF (NOT AMG-VALID-NUMBERS)
GO TO 1041-ROUTINE-START.

ADD 1 TO AMGPT2.

IF (AMGPT2 > AMG-OUT-LENGTH)
GO TO 1041-ROUTINE-END.

MOVE AMG-INPUT-DATA(AMGPT1:1) TO AMG-STRING-DATA(AMGPT2:1).
GO TO 1041-ROUTINE-START.

1041-ROUTINE-END.


NOTE: I know there is a better way doing of this (by looping)
but this is my first attempt and it works. The next
routine I'm going to built is for all characters.

Thanks everyone.
 
oops!

The field INPUT-DATA should have been AMG-INPUT-DATA. My typo.

everything went fine after compilation. All ZIP, SSN, Phones were converted into all numerics as what the client wants.
 
jmanj,

You might want also to consider the normalization technique demonstrated by my post in the following thread:thread209-907971 (4th post). This technique might be useful as you continue to create functions.



Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top