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:
01 excel-contents PIC X(13).
01 excel-contents-num redefines excel-contents PIC S9(12).
01 W-CELL-VALUE PIC S9(12).
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?
RE: Excel field needs re-formatting when extracted by COBOL. Any cure?
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