Skip to main content

Hi!

My program is writing to an XML-file.

1. A numeric field with two decimals, f1, is declared pic 9(5)v99. 

When writing 42.00 to f1 the result on xml file is <f1>42</f1>. I want both decimal 00 to be on the xml file.
When a decimals is for instance 10 the output for decimals is 1 and if it is 01 the output is 01 . So it is always when the last decimal is 0 they disappear from output. 

When declaring f1 pic 9(5).99 is the result <f1>00042.00</f1>. The decimals is ok now but I do not want the leading zeroes.

When declaring f1 pic z(4)9.99 is the result <f1>   42.00</f1>. Now are leading zeroes and decimals ok. But I do not want leading spaces.

How can I have a result like <f1>42.00</f1>?

It should be max 5 numbers before the decimal point and two after. It should be numeric.

Regards

Christina


#netexpress
#COBOL
#XML

Hi!

My program is writing to an XML-file.

1. A numeric field with two decimals, f1, is declared pic 9(5)v99. 

When writing 42.00 to f1 the result on xml file is <f1>42</f1>. I want both decimal 00 to be on the xml file.
When a decimals is for instance 10 the output for decimals is 1 and if it is 01 the output is 01 . So it is always when the last decimal is 0 they disappear from output. 

When declaring f1 pic 9(5).99 is the result <f1>00042.00</f1>. The decimals is ok now but I do not want the leading zeroes.

When declaring f1 pic z(4)9.99 is the result <f1>   42.00</f1>. Now are leading zeroes and decimals ok. But I do not want leading spaces.

How can I have a result like <f1>42.00</f1>?

It should be max 5 numbers before the decimal point and two after. It should be numeric.

Regards

Christina


#netexpress
#COBOL
#XML

The only way that I can seem to achieve the results that you are looking for is to use a pic x(8) field as your definition for f1 and move an alpanumeric representation of the number to it.

You should probably open up a support incident with customer care so that we can create a bug report for this as it should be possible to do what you want.

A kind of clunky workaround is shown below:

      $set preprocess(prexml) warn endp                     
          select xml-stream assign "out.xml"                
                  organization  is xml                      
                  document-type is "group"                  
                  file status is xml-bookdb-status.         
       xd xml-stream.                                       
       01  xmls-group   identified by "group".              
           05  f1 pic x(8)                      
               identified by "myNumber".                    
           05  f2 pic x(10)                        
               identified by "elementAlpha".                
       working-storage section.                             
       01 xml-bookdb-status  pic s9(9) comp.
       01 my-num-field       pic z(5).99.
       01 my-char-field      pic x(8) redefines my-num-field.
       01 sub-1              pic 9(2).
       procedure division.                                  
            move 42 to my-num-field
        *> In Visual COBOL you can use the statement below to trim spaces
        *>  move function trim(my-char-field) to xmls-Number *> In VC
        *> In NX you can use something like the following
            perform varying sub-1 from 1 by 1 until sub-1 >
               length of my-char-field
               if my-char-field(sub-1:1) not = " "
                  exit perform
               end-if
           end-perform
           if sub-1 not > length of my-char-field
              move my-char-field(sub-1:) to my-char-field
           end-if
           move my-char-field to f1
           
           move "Alpha" to f2
           open output xml-stream                          
           write xmls-group                                
           close xml-stream                                
           stop run.              


The only way that I can seem to achieve the results that you are looking for is to use a pic x(8) field as your definition for f1 and move an alpanumeric representation of the number to it.

You should probably open up a support incident with customer care so that we can create a bug report for this as it should be possible to do what you want.

A kind of clunky workaround is shown below:

      $set preprocess(prexml) warn endp                     
          select xml-stream assign "out.xml"                
                  organization  is xml                      
                  document-type is "group"                  
                  file status is xml-bookdb-status.         
       xd xml-stream.                                       
       01  xmls-group   identified by "group".              
           05  f1 pic x(8)                      
               identified by "myNumber".                    
           05  f2 pic x(10)                        
               identified by "elementAlpha".                
       working-storage section.                             
       01 xml-bookdb-status  pic s9(9) comp.
       01 my-num-field       pic z(5).99.
       01 my-char-field      pic x(8) redefines my-num-field.
       01 sub-1              pic 9(2).
       procedure division.                                  
            move 42 to my-num-field
        *> In Visual COBOL you can use the statement below to trim spaces
        *>  move function trim(my-char-field) to xmls-Number *> In VC
        *> In NX you can use something like the following
            perform varying sub-1 from 1 by 1 until sub-1 >
               length of my-char-field
               if my-char-field(sub-1:1) not = " "
                  exit perform
               end-if
           end-perform
           if sub-1 not > length of my-char-field
              move my-char-field(sub-1:) to my-char-field
           end-if
           move my-char-field to f1
           
           move "Alpha" to f2
           open output xml-stream                          
           write xmls-group                                
           close xml-stream                                
           stop run.              

Hi!

Thank you for anwsering.

At the moment I use Net Express and I´ve solved it yesterday by changing the declaration to pic x. Then I moved the data to a one character bigger field, moving the numbers but not the decimals one step to the left and then placing '.' in the right spot. After that I did a loop for finding place number for first character <> '0'. Then I used that number to move  the disired numbers (and .'')  to the xml field .

Regards

Christina K