View previous topic :: View next topic
|
Author |
Message |
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
I have a XML file which contains below segment:
Quote: |
<PDAC>123456789007</PDAC> |
I'm using COBOL to parse this XML file, and the above content is parsed by below code:
Code: |
Compute ELEMENT-VALUE-NUM
= function numval-c(XML-Text) |
ELEMENT-VALUE-NUM is declared as below:
Code: |
1 ELEMENT-VALUE-NUM USAGE IS COMP-1. |
after above process, ELEMENT-VALUE-NUM is moved to a BIGINT variable VALUE-BIGINT, which is declared like below:
Code: |
05 VALUE-BIGINT PIC S9(18) COMP. |
the move operation is :
Code: |
MOVE ELEMENT-VALUE-NUM TO VALUE-BIGINT
DISPLAY 'VALUE-BIGINT: ' VALUE-BIGINT |
but after successful execution of the program, and when I check the log, I found below result:
Code: |
Content characters: {123456789007}
End element tag: {PDAC}
VALUE-BIGINT: 000000123456782000 |
I cannot understand why value 123456789007 became 123456782000 after the program parse....
Would u please kindly provide me some hint or suggestions on this?? thanks. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
for the sake of completeness why did You not post also the result of a
Code: |
DISPLAY 'ELEMENT-VALUE-NUM: ' ELEMENT-VALUE-NUM |
? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Why do you think a COMPUTE is "parsing" anything?
What do you have for compiler option ARITH?
Why use NUMVAL-C instead of NUMVAL?
Have you tried any other possibilities instead of the COMPUTE using NUMVAL for getting the number?
EDIT: And why a COMP-1 not COMP-2, which has greater precision? |
|
Back to top |
|
|
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
HI, enric,
content of ELEMENT-VALUE-NUM shows below:
Code: |
Content characters: {123456789007}
ELEMENT-VALUE-NUM : .12345678E 12 |
|
|
Back to top |
|
|
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
hi, Bill,
compile option is ARITH(EXTEND);
I tried to use NUMVAL to transform string into numeric data, and the result shows the same. nothing improved.
I do not have any other idea to transform a string into numeric data except using NUMVAL or NUMVAL-C, would u please suggest? |
|
Back to top |
|
|
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
hi, all,
I tried to declare with COMP-2 instead of COMP-1,
and the result shows OK.
Thanks for your suggestion!!! |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
From your most recent display output, you still haven't tried COMP-2.
What is XML-TEXT defined as?
There would be the usual suspects for an alternative to NUMVAL (NUMVAL-C allows currency symbols to be in the string, which you don't need). Subscripting, indexing, reference-modification, occurs depending on. Even UNSTRING might suit, depending on the answer to the question. |
|
Back to top |
|
|
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
hi, Bill,
thanks to your suggestion, I declared that varaible to COMP-2, and the program worked fine.
XML-TEXT is COBOL reserved word, we don't need to declare it.
From COBOL programming guide, I also cannot see the declaration of it, but I supposed it should be declared as VARCHAR type. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
from programming ref:
Quote: |
XML-TEXT is an elementary data item of category alphanumeric of the length of the contained XML document fragment. The length of XML-TEXT can vary from 0 through 134,180,862 bytes. |
varchar is not a COBOL term, it is a db2 term. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Thanks dbz.
dejunzhu, something along the lines of this might do you as a replacement, if you want to try it. W-VARIABLE-LENGTH is a variable-length field. In your case you have your value already, so ignore the first two MOVE's which are for testing.
Test the field for numeric. Do something useful if it is not (you should be testing for numeric before using NUMVAL anyway, else it will abend if not numeric).
Code: |
01 W-ALPHA-RIGHT-JUST PIC X(18) JUST RIGHT.
01 W-NUM REDEFINES W-ALPHA-RIGHT-JUST PIC 9(18).
|
Code: |
MOVE +12 TO W-DATA-LENGTH
MOVE "123456789007" TO W-VARIABLE-LENGTH
IF W-VARIABLE-LENGTH NUMERIC
MOVE W-VARIABLE-LENGTH TO W-ALPHA-RIGHT-JUST
INSPECT W-ALPHA REPLACING LEADING SPACE BY ZERO
DISPLAY ">" W-NUM "<"
END-IF
MOVE +18 TO W-DATA-LENGTH
MOVE "123456123456789007" TO W-VARIABLE-LENGTH
IF W-VARIABLE-LENGTH NUMERIC
MOVE W-VARIABLE-LENGTH TO W-ALPHA-RIGHT-JUST
INSPECT W-ALPHA REPLACING LEADING SPACE BY ZERO
DISPLAY ">" W-NUM "<"
END-IF
|
Output is
Code: |
>000000123456789007<
>123456123456789007<
|
Which you can then MOVE to your COMP field.
You are free, of course, to use a better data-name for W-NUM. |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
Maybe I am missing something, but why are you using floating point? Does <PDAC> contain a floating point value? |
|
Back to top |
|
|
|