How do I make a tab delimited export file using Cobol?

How do I make a tab delimited export file using Cobol.  We have a program written by our previous programmer that gives me exactly what we want, but it is space delimited.  It exports several files and all I want to do is replace the single space FILLER with the tab character.   I haven't worked in Cobol for a long time so be specific!  (OK--dumb it down works too.)  

 DATA DIVISION.
  FILE SECTION.
  FD  OUTPUT-FILE                                  
      LABEL RECORDS ARE OMITTED.
  01  OUTPUT-RECORD.                                
      03  FIELD-1                  PIC X(34).        
      03  FILLER                   PIC X(1).        
      03  FIELD-2                  PIC 9(4).        
      03  FILLER                   PIC X(1).        
      03  FIELD-3                  PIC X(30).        
      03  FILLER                   PIC X(1).        
      03  FIELD-4                  PIC X(02).        
   
annetjeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
tliottaCommented:
annetje:

Since no one's picked this up yet...

Without knowing the platform/compiler, it's hard to be certain of some details. Under an i5/OS compiler, you have a bit of difficulty because OUTPUT-RECORD has its fields defined directly beneath the FD entry for the file. The FD entry effectively described the file's I/O buffer rather than a separate WORKING-STORAGE memory area.

This means that simple changes such as adding VALUE clauses to the FILLER items isn't very useful. Each new record image in the buffer will reinitialize the area and overlay the VALUEs.

Ideally, the record image would be built in a WORKING-STORAGE 01-level item. That record image would be populated with your data and the FILLERs could have a fixed VALUE. Then you'd use a WRITE ... FROM to output the records.

By doing the work outside of the buffer you'd take advantage of what the compiler can do to help you, at the cost of a tiny bit of extra coding for data definitions plus a slightly indirect I/O.

Whenever possible, I try to avoid doing actual data manipulation in any buffer area. I always want to isolate anything that I do from what some underlying DBMS or operating system might do for buffering, double-buffering or what have you.

In short, I'd move your 01-level OUTPUT-RECORD to under WORKING-STORAGE. I'd add VALUE '[tab]' to each appropriate FILLER, using whatever the [tab] character is one your platform, possibly a hex value. I'd create a new 01-level item under the FD perhaps named FD-OUTPUT-RECORD. And I'd change my WRITE to be WRITE FD-OUTPUT-RECORD FROM OUTPUT-RECORD.

I'd also take care _not_ to clear the entire 01-level OUTPUT-RECORD but instead only reinitialize the individual 03-level field. Reinitializing the 01-level would wipe out my VALUEs.

At least, that's how I'd do it given what appears to be your starting point. Technically, I probably wouldn't do it this way at all. I'd probably be using STRING to bring all of the elements together, and perhaps a variety of other technique changes.

But that's beyond the scope of your question...

Tom
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
rlpjrCommented:
You can get a tab delimited output file by using the Hex 09 value for your tab character.  In your Output-Record replace the filler by a variable name such as TAB-1.  See sample Output-Record below.  
   01  OUTPUT-RECORD.                                
      03  FIELD-1                  PIC X(34).        
      03  TAB-1                     PIC X(1).        
      03  FIELD-2                  PIC 9(4).        
      03  TAB-2                     PIC X(1).        
      03  FIELD-3                  PIC X(30).        
      03  TAB-3                     PIC X(1).        
      03  FIELD-4                  PIC X(02).    
In your procedure division simply move the hex value 09 (zero nine) to the Tab-1, Tab-2, Tab-3 fields, like below.

MOVE X09 TO TAB-1.
MOVE X09 TO TAB-2.
MOVE X09 TO TAB-3.

The X in front of the 09 field indicates to COBOL that the value is a hex value.  Be sure to enclose the 09 in double quotes.

This should give you a tab delimited file.
0
 
rlpjrCommented:
The above comment at 2:25 shoud have the " character where the little boxes are.  copied and pasted the answer from a word document and the " character was repalced by the little boxes.  Sorry for any confusion.

0
 
plenahanCommented:
01  HEX-09-CREATE.
    02  FILLER        VALUE +09          PIC S9(02) COMP.
01  HEX-09X REDEFINES HEX-09-CREATE.
    02  HEX-09                           PIC X(01).
    02  FILLERXX                         PIC X(01).

Put the above code in Working Storage, then in the Procedure Division simply
                  MOVE HEX-09                  TO SOME-FIELD.

You can change the name to TAB if you wish and it works the same.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.