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!

PIC Clause confusion 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have to write a COBOL program for my college course and am stuck on a PIC clause. I have to list employee numbers (xxx-xx-xxxx) with hyphens, but have no idea how to write the PIC clause.

Help/advice is appreciated!
 
Hi,

Why don't you just break down the number into parts?

01 EMPLOYEE-NUMBER PIC 9(9).
01 FILLER1 REDEFINES EMPLOYEE-NUMBER.
03 EMPLOYEE-NUMBER-1 PIC X(3).
03 EMPLOYEE-NUMBER-2 PIC XX.
03 EMPLOYEE-NUMBER-3 PIC X(4).
01 EMPLOYEE-NUMBER-EDITED.
03 EM-NR-ED-1 PIC X(3).
03 FILLER-2 PIC X VALUE '-'.
03 EM-NR-ED-2 PIC XX.
03 FILLER-3 PIC X VALUE '-'.
03 EM-NR-ED-3 PIC X(4).
...
MOVE EMPLOYEE-NUMBER-1 TO EM-NR-ED-1.
MOVE EMPLOYEE-NUMBER-2 TO EM-NR-ED-2.
MOVE EMPLOYEE-NUMBER-3 TO EM-NR-ED-3.

This works always in a fast way.

Other constructions with picture xxx/xx/xxxx and inspect .. replacing '/' by '-' is always much slower.

But there are also many other methods to do this but the original approach is efficient.

I hope this helps.
 
Just for the sake of argument, here's an alternative:

if it's just displaying or listing you wanna do, you can use reference modification (provided the COBOL you use supports that; it really should, though !):

01 EMPLOYEE-NUMBER PIC 9(9).
01 EMPLOYEE-NUM-DISP PIC X(11).

...

STRING EMPLOYEE-NUMBER (1 : 3)
'-'
EMPLOYEE-NUMBER (4 : 2)
'-'
EMPLOYEE-NUMBER (6 : 4)
DELIMITED BY SIZE
INTO EMPLOYEE-NUM-DISP.

Employee-num-disp now holds your edited employee-number to work with.
STRING is standard COBOL and also works pretty fast.

Good luck !
 
Hi,
Here is another way
01 emp-number pic 9(9).
01 emp-mask pic 999b999b999 ('b' means a blank)
move emp-number to emp-mask
inspect emp-mask replacing all space by "-".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top