0

I am writing a program in COBOL that reads data from table and dumps it into a CSV file. My work definitions columns are defined as (for instance) FACILITYCODE. Below is the detail of of column:

Working Storage : WS-FACILITYCODE PIC X(04) VALUE "XYZ".

Program Definition: MOVE WS-FACILITYCODE TO ABI-FACILITYCODE.

When my program is written, the CSV header comes out as "Facilitycode." I want to change that to "FACILITY_CODE"

Code used to create the CSV PERFORM 800-WRITECSV-XYZINV.

A comparable exmaple in SQL world would be 'AS'.

Any suggestions please.

Thank you!

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
Shaji
  • 741
  • 2
  • 9
  • 23
  • A table means something in COBOL. Is that the sense you are using it in? Or do you mean a DB table? How are you creating the CSV? You'll have to show how you are creating the CSV. – Bill Woodger May 05 '14 at 15:50
  • Thank you @BillWoodger. In this case, lets say, I am writing a constant to a CSV file. My working store column name is something; but I want my CSV column name to be something else. I am also querying data from a SQL database and I am having a hard time customizing the CSV column headers based on my specifications. – Shaji May 05 '14 at 16:07
  • Can you edit (link under your question) the actual code you are using to create the CSV into your question please. – Bill Woodger May 05 '14 at 16:11
  • OK, thanks. Perhaps I was unclear. Somewhere in your program is some code to format the header of the CSV, and format the CSV itself. Knowing whether it was something packaged-up by Micro Focus, or a home-grown routine at your site, or whether it relies on all the coding being in your program, would give us some insight as to how to answer your question. So, please show the code. – Bill Woodger May 05 '14 at 22:19
  • What does 800-WRITECSV-XYZINV do ??? how / where is the CSV header written – Bruce Martin May 06 '14 at 02:53

1 Answers1

2

As everybody says, we need to know what PERFORM 800-WRITECSV-XYZINV. does...

but I have worked in a similar solution for write CSV files

  *...
  *acces to you table and it fills the variables WS-A WS-B and WS-C

  *build heather
   STRING "A"  ","
          "B"  "," 
          "C"         DELIMITED BY SIZE
      INTO WS-LINE
   END-STRING

  * write header
   WRITE FILE  FROM WS-LINE
   ...

Then for each file from the table, you can:

   INITIALIZE WS-LINE

  *build line whit the values
   STRING WS-A  ","
          WS-B  "," 
          WS-C         DELIMITED BY "SIZE" <-- it will print all spaces that each variable have 
      INTO WS-LINE
   END-STRING

  * write line
   WRITE FILE  FROM WS-LINE
   ...
brasofilo
  • 25,496
  • 15
  • 91
  • 179
Sarabadu
  • 587
  • 2
  • 18