IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

XML numeric parse transformation problem


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Fri Mar 02, 2012 2:12 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Mar 02, 2012 2:20 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Mar 02, 2012 2:27 pm
Reply with quote

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
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Fri Mar 02, 2012 2:45 pm
Reply with quote

HI, enric,
content of ELEMENT-VALUE-NUM shows below:
Code:
Content characters: {123456789007}   
ELEMENT-VALUE-NUM :  .12345678E 12   
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Fri Mar 02, 2012 2:49 pm
Reply with quote

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
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Fri Mar 02, 2012 2:52 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Mar 02, 2012 2:52 pm
Reply with quote

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
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Fri Mar 02, 2012 3:32 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Mar 02, 2012 4:23 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Mar 02, 2012 5:01 pm
Reply with quote

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
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Fri Mar 02, 2012 10:32 pm
Reply with quote

Maybe I am missing something, but why are you using floating point? Does <PDAC> contain a floating point value?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Convert HEX to Numeric DB2 3
No new posts z/vm installation problem All Other Mainframe Topics 0
Search our Forums:

Back to Top