Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

XML numeric parse transformation problem

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: XML numeric parse transformation problem
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Fri Mar 02, 2012 2:20 pm    Post subject: Reply to: XML numeric transformation problem...HELP!!!
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Fri Mar 02, 2012 2:27 pm    Post subject: Reply to: XML numeric transformation problem...HELP!!!
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    Post subject:
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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Fri Mar 02, 2012 2:52 pm    Post subject: Reply to: XML numeric transformation problem...HELP!!!
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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Fri Mar 02, 2012 5:01 pm    Post subject: Reply to: XML numeric transformation problem...HELP!!!
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: 641
Location: Whitby, ON, Canada

PostPosted: Fri Mar 02, 2012 10:32 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts DB2 Streaming Batch Processing Problem Manshadi DB2 4 Sat Sep 24, 2016 12:14 pm
No new posts Problem with GETMAIN command amitc23 CICS 6 Thu Sep 01, 2016 1:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us