Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

signed values

Status
Not open for further replies.

jimlee

Programmer
Jan 27, 2001
213
GB
hi,
I have a project in which i need to provide test a test data file contatining various fields for validation.

one of these fields is to contain a customer balance which will be either positive or negative.

how do i create the data field in the test file without actually typing in the + or - ?

i know how the data is stored and can create the relevant clause in the program to accept data from the keyboard but haven't had to do it this way yet, i'm sure it is very simple, your help will be appreciated.

kind regards jimlee
 
Hi JL,

You didn't mention your environment or what you coded to represent the data.
In a mainframe system the sign is represented by an over-punch, e.g.:

with a pic s9.

+1 is A (X'C1')
+2 B X'C2'
-1 J X'D1'
-2 K X'D2'

I don't know what the ASCII equivs would be, but you can whip up a Q&D pgm to display or file them.

Regards, Jack.
 
Jack, jimlee,

what is also important is the picture, off course.
I'll give a few examples for a mainframe environment, where EBCDIC is used (all without SIGN LEADING).

As Jack already mentioned, for a zoned numeric field, each figure is in fact the character represention of that figure. In EBCDIC coding, '0' - '9' are coded as X'F0' - X'F9'. When the field is signed, however, the rightmost character is changed into either X'C#' for positive or X'D#' for negative, where # is the figure in that position.
When displayed, that will show a character rather then a figure.

In a packed decimal (COMP-3) field, every nibble contains one position, exept for the least significant nibble of the rightmost byte. If the least significant figure of a number is #, the rightmost byte contains either X'#C' for positive or X'#D' for negative.

Hope this helps,
regards,
Ronald.
 
hi, thax to jack and ronald for your quick responses,
i;m using microfocus2 personal cobol on my pc. so i don't suppose it would be the same for this as it is for mainframes? the file created is in pure ascii format.
regards jimlee
 
Hi JL,

Someone out there should know the hex equiv of a pos n and neg n. If not see below.
If your environment is PC, do what I suggested; write a pgm, e.g.:

05 disp-nbr pic s99.

move +0 to disp-nbr
perform 100-write-nbrs 10 times
move spaces to fd-nbr-rec
write fd-nbr-rec
move -9 to disp-nbr
perform 100-write-nbrs 10 times
.
100-write-nbrs.
write fd-nbr-rec from disp-nbr
add +1 to disp-nbr
.

Use an editor to look at the file in hex.
This will give you a file w/the bit configs of all digits +/- 0-9, then use them to construct your test file. If your editor dooesn't allow you to enter hex values, you can find the "printable" equiv in any ascii values table. They're usually provided as an appendix in a COBOL manual.

Hope this helps, Jack.

Regards, Jack.
 
hi, jack
cheers, i'll give it a go, much appreciated

regards, jimlee
 
cool! got it sorted,
just incase it might help anyone else, this is how i did it in the end,

IDENTIFICATION DIVISION.
PROGRAM-ID. GET-NEG-VALUES.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TEST-FILE ASSIGN TO "TEST.DAT"
ORGANIZATION LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD TEST-FILE.
01 TEST-REC.
05 TEST-FIELD PIC S999.


WORKING-STORAGE SECTION.
01 W-SUB PIC S999.


PROCEDURE DIVISION.
MAIN.
*create a file of negative values
OPEN OUTPUT TEST-FILE
PERFORM VARYING W-SUB FROM 0 BY -1 UNTIL
W-SUB < -105
WRITE TEST-REC FROM W-SUB
END-PERFORM

*display file values with corresponding neg numbers
CLOSE TEST-FILE
OPEN INPUT TEST-FILE
PERFORM VARYING W-SUB FROM 0 BY -1 UNTIL
W-SUB < -105
READ TEST-FILE
DISPLAY W-SUB &quot; - &quot; TEST-REC
END-PERFORM
CLOSE TEST-FILE
STOP RUN.

this works with MICROFOCUS2 compiler in windows.

cheers again for your help. jimlee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top