Highlighted
Contributor.
Contributor.
480 views

Excel field needs re-formatting when extracted by COBOL. Any cure?

We're now successfully using Visual COBOL to read data from Excel, which is a victory.  But we've got a problem. 

Here's relevant program code:

          working-storage section.

          01 excel-contents PIC X(13).
          01 excel-contents-num redefines excel-contents PIC S9(12).

          01 W-CELL-VALUE   PIC S9(12).

          procedure division.

          invoke Cell "getValue" returning excel-contents.

          MOVE excel-contents-num TO W-CELL-VALUE.

The problem:  example -- the Excel cell contains the 15

W-CELL-VALUE should be "000000000015"

instead, we're getting       "15          "

We could fix this with some kind of character-handling, but before we try that, is there something simple that we're overlooking?

Tags (2)
0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Excel field needs re-formatting when extracted by COBOL. Any cure?

It sounds as if the cell is defined as text or general instead of numeric within the spreadsheet. Is this correct?
You are returning it into a pic x field so it is alphanumeric in your program. The best way to convert it to an actual numeric would be to use something like:

move function numval(excel-contents) to w-cell-value
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.