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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with embedded signs

Status
Not open for further replies.

NewToForum

Programmer
Aug 11, 2008
2
IN
We are trying to create a file and one of the fields needs to have an embedded sign in the last position.We would be writing the file in ASCII and before transmitting the file out to a vendor converting it to EBCDIC.
Example:
01 amount-1 pic s9(16)v99.
01 amount-2 pic s9(13).
01 receiving-field pic s9(13).
Doing calculations with amount-1 throughout program. Then amount-1 is moved to amount-2. And amount-2 is moved to receiving-field of outgoing file. Last position of receiving field must be an embedded sign (contain a character...is this standard?) EX: a positive 3 in the last position should show as a C. Any suggestions on how the fields should be set up?
 
Please try

01 receiving-field pic s9(13) sign is trailing.


The SIGN clause specifies the location and format of an item's operational sign.

General Format

[ SIGN IS ] {LEADING } [ SEPARATE CHARACTER ]
{TRAILING}

Syntax Rules

1. The SIGN clause may appear only in a numeric data description entry whose PICTURE string contains the "S" symbol, or on a group item that contains such an entry.

2. The item must have USAGE DISPLAY.

General Rules

1. If the SIGN clause is omitted for a data item, then the operational sign is incorporated into the final digit of the data item. The "S" symbol does not occupy any space in the data item in this case.

2. If the SIGN clause is specified, but without the SEPARATE CHARACTER phrase, then the sign is incorporated into the first or last digit of the data item as specified.

3. If the SEPARATE CHARACTER phrase is specified in the SIGN clause, then the "S" symbol represents a separate character position and it adds one to the size of the data item. This character is located as the first or last character of the data item as specified in the clause. The sign is represented with a "+" or "-" character as appropriate. The zero value may have either sign.

4. If the SIGN phrase is specified for a group item, then it applies to each subordinate elementary numeric data item. A SIGN phrase specified for an elementary data item takes precedence over a SIGN phrase specified for one of its group items. If more than one group item has a SIGN phrase specified for it in a hierarchy, the lowest level one takes precedence.

Dixi
 
More Info.

With the above definition all value of +3 would be stored in the receiving-field as x'303030303030303030303030C3' in ASCII. (-3 would be x'303030303030303030303030D3' in ASCII). In EBCDIC it would be x'F0F0F0F0F0F0F0F0F0F0F0F0C3' resp. x'F0F0...F0D3'.

As you mentioned above positive 3 should give a 'C' in last position I think this referres to the EBCDIC code where 'C' is represented as x'C3'.

In general you should prefer to give the sign as a separate character (byte) for transferring data between different systems. Otherwise you have to take care of how the data is converted from ASCII to EBCDIC and vice versa.

Dixi
 
I work on a PC in Realia COBOL and have to supply data on a tape to a bureau. I have the same problem. My COBOL ASCII signed characters don't match their COBOL EBCDIC signed characters when doing the data translation. The easiest solution is this:

Define your receiving field like this:

05 RECEIVING-FIELD PIC 9(13). *no sign
05 REDEFINES RECEIVING-FIELD.
10 PIC X(12).
10 SIGN-POS PIC X.

In the PROCEDURE DIVISION:

MOVE AMOUNT-1 TO RECEIVING-FIELD.
IF AMOUNT-1 IS NEGATIVE
INSPECT SIGN-POS CONVERTING '0123456789' TO '}JKLMNOPQR'
ELSE
INSPECT SIGN-POS CONVERTING '0123456789' TO '{ABCDEFGHI'
END-IF.

If the amount needs to be rounded you can use a COMPUTE in place of the MOVE.

I've been getting tapes accepted using this code for years.

Betty Scherber
BrainBench MVP for COBOL II
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top