help reading negative values in data file - test code and test data 
Author Message
 help reading negative values in data file - test code and test data

A post a little while ago (a few lines away in the newgroup listing), I
requested some help in getting a MicroFocus COBOL porgram to read negative
values in a data file into the program without creating a run time error of
an illegal character.  Per suggestion of Jerry P, I have reposted with a
brief testing program, and the data used in the test run.  Note I included
both positive and negative data entries.  The last digit in the negative
fields have the ASCII listed character to indicate a negative value.

Again, I would appreciate help in determining what I need to modify such
thatnegative field can be stored on disk and read properly by the program.
Some code spacing is lost in this post.  My real code alignment does meet
COBOL specs.

Again, thanks for all assistence.
****************************************************************************
**************
       Identification Division.
       Program-id.    negate.
       Author.        david.
      *
      *    to verify data storage of negative values
      *
      *
       environment division.
       configuration section.
       source-computer.     mine.
       object-computer.     mine.
       input-output section.
       file-control.
           select negative-file
               assign to "a:\negated.dat"
               organization is line sequential.
           select print-file
               assign to "prn".

       data division.
       file section.

       fd  negative-file
           record contains 17 characters
           data record is negative-record.

       01  negative-record.
           11  positive-value-1   pic  S999 sign is trailing.
           11  positive-value-2   pic S9999 sign is trailing.
           11  negative-value-1   pic  S999 sign is trailing.
           11  negative-value-2   pic S9999 sign is trailing.
           11  positive-value-3   pic  S999 sign is trailing.

       fd  print-file
           record contains 80 characters
           data record is print-line.

       01  print-line   pic x(80).

       working-storage section.

       77  quit-key      pic x  value space.

       01  display-line.
           11  filler           pic x(16) value '    positive'.
           11  positive-value-1-out  pic   999CR  value 0.
           11  filler           pic x(16) value '    positive'.
           11  positive-value-2-out  pic  9999CR  value 0.
           11  filler           pic x(16) value '    negative'.
           11  negative-value-1-out  pic   999CR  value 0.
           11  filler           pic x(16) value '    negative'.
           11  negative-value-2-out  pic  9999CR  value 0.
           11  filler           pic x(16) value '    positive'.
           11  positive-value-3-out  pic   999CR  value 0.

       procedure division.

       control-routine.
           open input negative-file
                output print-file.

           read negative-file
               at end move 'Q' to quit-key.
           perform loop-routine
               until quit-key = 'Q'.
           close negative-file print-file.
           stop run.

       loop-routine.
           move spaces to print-line.
           move positive-value-1 to positive-value-1-out.
           move positive-value-2 to positive-value-2-out.
           move negative-value-1 to negative-value-1-out.
           move negative-value-2 to negative-value-2-out.
           move positive-value-3 to positive-value-3-out.
           move display-line to print-line.
           write print-line after advancing 1 line.
           read negative-file
               at end move 'Q' to quit-key.
****************************************************************************
*****************
following is the test data file:

111111111Q111Q111
222222222R222R222
333333333S333S333
555555555U555U555
000000000Z000Z000



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data
I had a similar problem with Acu-Cobol a few months ago and had to read it
in as a string and wrote a small piece of code to convert a string to a
number.

If you want I can try and dig up the little piece of code.

Regards,

Ray Smith


Quote:
> A post a little while ago (a few lines away in the newgroup listing), I
> requested some help in getting a MicroFocus COBOL porgram to read negative
> values in a data file into the program without creating a run time error
of
> an illegal character.  Per suggestion of Jerry P, I have reposted with a
> brief testing program, and the data used in the test run.  Note I included
> both positive and negative data entries.  The last digit in the negative
> fields have the ASCII listed character to indicate a negative value.

> Again, I would appreciate help in determining what I need to modify such
> thatnegative field can be stored on disk and read properly by the program.
> Some code spacing is lost in this post.  My real code alignment does meet
> COBOL specs.

> Again, thanks for all assistence.

****************************************************************************

- Show quoted text -

Quote:
> **************
>        Identification Division.
>        Program-id.    negate.
>        Author.        david.
>       *
>       *    to verify data storage of negative values
>       *
>       *
>        environment division.
>        configuration section.
>        source-computer.     mine.
>        object-computer.     mine.
>        input-output section.
>        file-control.
>            select negative-file
>                assign to "a:\negated.dat"
>                organization is line sequential.
>            select print-file
>                assign to "prn".

>        data division.
>        file section.

>        fd  negative-file
>            record contains 17 characters
>            data record is negative-record.

>        01  negative-record.
>            11  positive-value-1   pic  S999 sign is trailing.
>            11  positive-value-2   pic S9999 sign is trailing.
>            11  negative-value-1   pic  S999 sign is trailing.
>            11  negative-value-2   pic S9999 sign is trailing.
>            11  positive-value-3   pic  S999 sign is trailing.

>        fd  print-file
>            record contains 80 characters
>            data record is print-line.

>        01  print-line   pic x(80).

>        working-storage section.

>        77  quit-key      pic x  value space.

>        01  display-line.
>            11  filler           pic x(16) value '    positive'.
>            11  positive-value-1-out  pic   999CR  value 0.
>            11  filler           pic x(16) value '    positive'.
>            11  positive-value-2-out  pic  9999CR  value 0.
>            11  filler           pic x(16) value '    negative'.
>            11  negative-value-1-out  pic   999CR  value 0.
>            11  filler           pic x(16) value '    negative'.
>            11  negative-value-2-out  pic  9999CR  value 0.
>            11  filler           pic x(16) value '    positive'.
>            11  positive-value-3-out  pic   999CR  value 0.

>        procedure division.

>        control-routine.
>            open input negative-file
>                 output print-file.

>            read negative-file
>                at end move 'Q' to quit-key.
>            perform loop-routine
>                until quit-key = 'Q'.
>            close negative-file print-file.
>            stop run.

>        loop-routine.
>            move spaces to print-line.
>            move positive-value-1 to positive-value-1-out.
>            move positive-value-2 to positive-value-2-out.
>            move negative-value-1 to negative-value-1-out.
>            move negative-value-2 to negative-value-2-out.
>            move positive-value-3 to positive-value-3-out.
>            move display-line to print-line.
>            write print-line after advancing 1 line.
>            read negative-file
>                at end move 'Q' to quit-key.

****************************************************************************

- Show quoted text -

Quote:
> *****************
> following is the test data file:

> 111111111Q111Q111
> 222222222R222R222
> 333333333S333S333
> 555555555U555U555
> 000000000Z000Z000



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data
Assuming that you actually have the correct values for negative signs (which
I haven't checked in an ASCII conversion table - I assume that you know they
ARE different between ASCII and EBCDIC),

What are your Micro Focus compiler directives for:
   CHARSET
      and
   SIGN

Either of these could be forcing part (or all) of your system into EBCDIC
when you are assuming that it is processing in ASCII.

P.S. If all else fails, run with the runtime switch -F - which will force off
ALL (well most) numeric checks - and you won't get any 163 errors - even if
you expect them.

--
Bill Klein
    wmklein <at> ix dot netcom dot com

Quote:
> A post a little while ago (a few lines away in the newgroup listing), I
> requested some help in getting a MicroFocus COBOL porgram to read negative
> values in a data file into the program without creating a run time error of
> an illegal character.  Per suggestion of Jerry P, I have reposted with a
> brief testing program, and the data used in the test run.  Note I included
> both positive and negative data entries.  The last digit in the negative
> fields have the ASCII listed character to indicate a negative value.

> Again, I would appreciate help in determining what I need to modify such
> thatnegative field can be stored on disk and read properly by the program.
> Some code spacing is lost in this post.  My real code alignment does meet
> COBOL specs.

> Again, thanks for all assistence.

****************************************************************************
Quote:
> **************
>        Identification Division.
>        Program-id.    negate.
>        Author.        david.
>       *
>       *    to verify data storage of negative values
>       *
>       *
>        environment division.
>        configuration section.
>        source-computer.     mine.
>        object-computer.     mine.
>        input-output section.
>        file-control.
>            select negative-file
>                assign to "a:\negated.dat"
>                organization is line sequential.
>            select print-file
>                assign to "prn".

>        data division.
>        file section.

>        fd  negative-file
>            record contains 17 characters
>            data record is negative-record.

>        01  negative-record.
>            11  positive-value-1   pic  S999 sign is trailing.
>            11  positive-value-2   pic S9999 sign is trailing.
>            11  negative-value-1   pic  S999 sign is trailing.
>            11  negative-value-2   pic S9999 sign is trailing.
>            11  positive-value-3   pic  S999 sign is trailing.

>        fd  print-file
>            record contains 80 characters
>            data record is print-line.

>        01  print-line   pic x(80).

>        working-storage section.

>        77  quit-key      pic x  value space.

>        01  display-line.
>            11  filler           pic x(16) value '    positive'.
>            11  positive-value-1-out  pic   999CR  value 0.
>            11  filler           pic x(16) value '    positive'.
>            11  positive-value-2-out  pic  9999CR  value 0.
>            11  filler           pic x(16) value '    negative'.
>            11  negative-value-1-out  pic   999CR  value 0.
>            11  filler           pic x(16) value '    negative'.
>            11  negative-value-2-out  pic  9999CR  value 0.
>            11  filler           pic x(16) value '    positive'.
>            11  positive-value-3-out  pic   999CR  value 0.

>        procedure division.

>        control-routine.
>            open input negative-file
>                 output print-file.

>            read negative-file
>                at end move 'Q' to quit-key.
>            perform loop-routine
>                until quit-key = 'Q'.
>            close negative-file print-file.
>            stop run.

>        loop-routine.
>            move spaces to print-line.
>            move positive-value-1 to positive-value-1-out.
>            move positive-value-2 to positive-value-2-out.
>            move negative-value-1 to negative-value-1-out.
>            move negative-value-2 to negative-value-2-out.
>            move positive-value-3 to positive-value-3-out.
>            move display-line to print-line.
>            write print-line after advancing 1 line.
>            read negative-file
>                at end move 'Q' to quit-key.

****************************************************************************

- Show quoted text -

Quote:
> *****************
> following is the test data file:

> 111111111Q111Q111
> 222222222R222R222
> 333333333S333S333
> 555555555U555U555
> 000000000Z000Z000



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data


Hi:

You will never be able to write totally-dependable programs
if you neglect to check the file-status after EVERY I-O
operation. You should also detect an empty file.

Thanks

TOny Dilworth

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data
Try using READ INTO.... as I think that will do a group move and
bypass any numeric checks at the time of the READ, waiting for you to try
arithmetic on the field. You can then do an IS NUMERIC... and find out on
which field(s)
the read is failing.

One other thing: you may wish to download my free text and graphics tutorial
on COBOL data types from http://www.flexus.com/softwaredownload.html, get
file COBDATA.ZIP.

--
Michael Mattias
Tal Systems
Racine WI USA


Quote:
>        file section.

>        fd  negative-file
>            record contains 17 characters
>            data record is negative-record.

>        01  negative-record.
>            11  positive-value-1   pic  S999 sign is trailing.
>            11  positive-value-2   pic S9999 sign is trailing.
>            11  negative-value-1   pic  S999 sign is trailing.
>            11  negative-value-2   pic S9999 sign is trailing.
>            11  positive-value-3   pic  S999 sign is trailing.

>            read negative-file
>                at end move 'Q' to quit-key.
>            perform loop-routine
>                until quit-key = 'Q'.
>            close negative-file print-file.
>            stop run.

> *****************
> following is the test data file:

> 111111111Q111Q111
> 222222222R222R222
> 333333333S333S333
> 555555555U555U555
> 000000000Z000Z000



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data

Quote:

>following is the test data file:

>111111111Q111Q111
>222222222R222R222
>333333333S333S333
>555555555U555U555
>000000000Z000Z000

I question the validity of the overstrike/signed negative values.
ASCII numbers range from x'30' thru x'39' for un-signed.
My understanding of the positive/negative sign is that 'c' and 'd'
are used as the respective high order digit of the least significant
digit.  This being the case, signed positive values would be x'c0'
thru x'c9' and negative values would be x'd0' thru x'd9'.
By the ASCII map that I have, the signed values do not fall within
the printable character range.
My first thought would be to create a test program to move positive
or negative numbers into a W-S area, and display a redefine of the
same area with PIC X(...) to validate the range of 1+ thru 9+ and
1- thru 9-.


Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data

Quote:

>You will never be able to write totally-dependable programs
>if you neglect to check the file-status after EVERY I-O
>operation. You should also detect an empty file.

Let's make that "Sometimes".  Having discovered "optional" with '85
COBOL I found I could eliminate most of my "35" status checks.  Most
times I opened input, if I got a 35 Open Output, Close, Open I-O.  Now
I just make it Select Optional File-name assign to foo, Open I-O
File-name.  No need to check for a 35 anymore  - it can't happen!

If a file MUST exist, obviously you need to check for a 35 -- that's
why I said "Sometimes".



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data

Quote:
>You will never be able to write totally-dependable programs
>if you neglect to check the file-status after EVERY I-O
>operation. You should also detect an empty file.

Dependable to do what?  If your open fails, the read or write will abort
the program.  That may be just what you want.  At least that is better
than aborting with an open of a VSAM file with a return of 97.  Our
purchased package calls a COBOL program which does an open and checks
for a "00" return code.  They overlooked that a "97" is fine.  Their
programs check to see if the called program returned a "7" (failure).
By ignoring this check, we can wait for an abort when we try to read
that file - but the read will work fine if the VSAM return code was
"97".

Determine what you want to happen for various I-O errors.  Test for the
conditions where you want to make specific actions (EOF, not-found), and
if what you want to happen will happen anyway (abort), let it.



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data
I used this going from EBCDIC to ANSII.  Our file that came with our
textbook were in EBCDIC, and we got Microfocus compiler using ASCII.  Had to
come to this newsgroup for help, none in the literature.

Hope this helps - if it does, thank the regular posters here, they're who
helped me.

* Convert EBCDIC embedded negative to ANSII
           INSPECT IR-GROUP-AMOUNT CONVERTING "}JKLMNOPQR"
               TO "pqrstuvwxy"

Pat



Mon, 23 Sep 2002 03:00:00 GMT  
 help reading negative values in data file - test code and test data
On Thu, 06 Apr 2000 05:15:46 GMT, in comp.lang.cobol, "David Cole"

Quote:

>A post a little while ago (a few lines away in the newgroup listing), I
>requested some help in getting a MicroFocus COBOL porgram to read negative
>values in a data file into the program without creating a run time error of
>an illegal character.  Per suggestion of Jerry P, I have reposted with a
>brief testing program, and the data used in the test run.  Note I included
>both positive and negative data entries.  The last digit in the negative
>fields have the ASCII listed character to indicate a negative value.

>Again, I would appreciate help in determining what I need to modify such
>thatnegative field can be stored on disk and read properly by the program.
>Some code spacing is lost in this post.  My real code alignment does meet
>COBOL specs.

>Again, thanks for all assistence.
>****************************************************************************
>**************
>       Identification Division.
>       Program-id.    negate.
>       Author.        david.
>      *
>      *    to verify data storage of negative values
>      *
>      *
>       environment division.
>       configuration section.
>       source-computer.     mine.
>       object-computer.     mine.
>       input-output section.
>       file-control.
>           select negative-file
>               assign to "a:\negated.dat"
>               organization is line sequential.
>           select print-file
>               assign to "prn"

My compiler needs
                organization is line sequential.
at this place

- Show quoted text -

Quote:
>               .
>       data division.
>       file section.

>       fd  negative-file
>           record contains 17 characters
>           data record is negative-record.

>       01  negative-record.
>           11  positive-value-1   pic  S999 sign is trailing.
>           11  positive-value-2   pic S9999 sign is trailing.
>           11  negative-value-1   pic  S999 sign is trailing.
>           11  negative-value-2   pic S9999 sign is trailing.
>           11  positive-value-3   pic  S999 sign is trailing.

>       fd  print-file
>           record contains 80 characters

make the 107 (or more)
Quote:
>           data record is print-line.

>       01  print-line   pic x(80).

change this to           PIC X(107).
Quote:

>       working-storage section.

>       77  quit-key      pic x  value space.

>       01  display-line.
>           11  filler           pic x(16) value '    positive'.
>           11  positive-value-1-out  pic   999CR  value 0.

This leads to a compiler error on my system.  The correct picture would be  a string.

Quote:
>           11  filler           pic x(16) value '    positive'.
>           11  positive-value-2-out  pic  9999CR  value 0.
same as above
>           11  filler           pic x(16) value '    negative'.
>           11  negative-value-1-out  pic   999CR  value 0.
same as above
>           11  filler           pic x(16) value '    negative'.
>           11  negative-value-2-out  pic  9999CR  value 0.
same as above
>           11  filler           pic x(16) value '    positive'.
>           11  positive-value-3-out  pic   999CR  value 0.
same as above

The display line is quite a bit larger than the print-line, that is
truncation will occurr.............................................

- Show quoted text -

Quote:
>       procedure division.                                      

>       control-routine.                                          
>           open input negative-file
>                output print-file.

>           read negative-file
>               at end move 'Q' to quit-key.
>           perform loop-routine
>               until quit-key = 'Q'.
>           close negative-file print-file.                        
>           stop run.                                              

>       loop-routine.                                              
>           move spaces to print-line.                            
>           move positive-value-1 to positive-value-1-out.          
>           move positive-value-2 to positive-value-2-out.        
>           move negative-value-1 to negative-value-1-out.          
>           move negative-value-2 to negative-value-2-out.        
>           move positive-value-3 to positive-value-3-out.        
>           move display-line to print-line.                      

........... here <-------------------------------------------------!
Quote:
>           write print-line after advancing 1 line.
>           read negative-file
>               at end move 'Q' to quit-key.
>****************************************************************************
>*****************
>following is the test data file:

>111111111Q111Q111
>222222222R222R222
>333333333S333S333
>555555555U555U555
>000000000Z000Z000

Making changes as indicated I get the following results

positive  111   positive   1111   negative   111CR   negative    1111CR    positive    111
positive  222   positive   2222   negative   222CR   negative    2222CR    positive    222
positive  333   positive   3333   negative   333CR   negative    3333CR    positive    333
positive  555   positive   5555   negative   555CR   negative    5555CR    positive    555
positive  000   positive   0000   negative   00:CR   negative    000:CR    positive    000

(Some spaces have been removed from the above line to make them fit into my newsreader
window without wrapping)

I used the IBM Visual Age COBOL Compiler for Win/NT.  When I write signed negative
numbers, the system provides LOWER CASE character digits (p to z) instead of the upper
case digits you are using.  I don't know anything about COBOL on AS/400, but might the
compiler be case sensitive in that area?  Try

a)  lower cased signed digits
b)  fixing the program as indicated

With kind regards
Volker Bandke

     With kind Regards            |\      _,,,---,,_
                            ZZZzz /,`.-'`'    -.  ;-;;,
     Volker Bandke               |,4-  ) )-,_. ,\ (  `'-'
      (BSP GmbH)                '---''(_/--'  `-'\_)

         LOGO: A kiddie's replica of a Rolls Royce. Comes with a real engine and a working horn.



Tue, 24 Sep 2002 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Thank you - re:help reading negative values in data file

2. Help with reading of negative numbers in data file

3. Read VFP data files into Clipper data files

4. Unit testing data; What to test

5. Tcl Test Script Data – Database Advice (Test Automation Improvements)

6. Can I read previous test data into Labview?

7. Tested routine for simulting external read of ascii data (for omission detection)

8. Reading a data file from a very remote data

9. How to create a data file to read values

10. datamodeller test data file

11. CR/LF input in a data file to read into an MS Fortran code

12. Negative Numbers in Test File

 

 
Powered by phpBB® Forum Software