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!

Move trialing sign to leading sign?

Status
Not open for further replies.

wolves

Programmer
Jan 26, 2001
130
US
Easy for most I assume, but not for me.

Want to move this : 12456.56-

to this:

-12456.56.


Tried moving pic s9(5)v99 to pic 999,999.99


Thanks in advance.
 
Post your code please. (and Compiler vendor/version used).
The simple WS definition along with the move/displays will do.

And by the way. 999,999.99 will NOT show the sign as it is not defined.


It works with me.... if done well

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Code:
*----------------------------------
*       INFILE RECORD LAYOUT                           
*---------------------------------
 01  WS-INFILE-RECORD.
    05  WS-IN-PART1      PIC X(69).
    05  WS-IN-PART2      PIC 999999V99.


*-----------------------------------------------------------
*       OUTFILE RECORD LAYOUT                                  
*-----------------------------------
 01  WS-OUTFILE-RECORD.
    05  WS-OUT-PART1   PIC X(69).
    05  WS-OUT-PART2   PIC ---,---,---,---.99.
*------------------------------



 MOVE WS-IN-PART1    TO  WS-OUT-PART1
 MOVE WS-IN-PART2    TO  WS-OUT-PART2

 WRITE  OUTREC  FROM  WS-OUTFILE-RECORD



That is it. Just moving in to out, no editing of data at all.

Thanks.
 
Tried something new with no luck


Code:
*----------------------------------------------------------------*
*       INFILE RECORD LAYOUT                                     *
*----------------------------------------------------------------*
 01  WS-INFILE-RECORD.
    05  WS-IN-PART1              PIC X(79).
    05  WS-IN-PART2      PIC S9(13)V99 SIGN TRAILING SEPARATE.

*----------------------------------------------------------------*
*       OUTFILE RECORD LAYOUT                                    *
*----------------------------------------------------------------*
 01  WS-OUTFILE-RECORD.
    05  WS-OUT-PART1             PIC X(79).
    05  WS-OUT-PART2             PIC -9(13)V99.
*----------------------------------------------------------------*
 
Here's the error from my last try.

Code:
An operation was attempted on data defined with a separate sign.  The
value in the sign position was not a plus (+) or a minus (-).

The error might have been caused by a REDEFINES clause involving the
sign position or a group move involving the sign position, or the
position was never initialized.
 
The following is the output the program below , using an RM/COBOL compiler

V3= -1234.56== V4= -1,234.56==
V3= 1234.56== V4= 1,234.56==
V5=-00000123456==
V6=+00000123456==
V7=00000123456-==
V8=00000123456+==
Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  testing.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 v1 pic S9(9)V99 VALUE -1234.56.
       01 v2 pic  9(9)V99 VALUE  1234.56.
       01 v3 pic -(10).99.
       01 v4 pic ----,---,---.--.
       01 v5 pic S9(9)V99 VALUE -1234.56 SIGN LEADING SEPARATE.
       01 v6 pic S9(9)V99 VALUE  1234.56 SIGN LEADING SEPARATE.
       01 v7 pic S9(9)V99 VALUE -1234.56 SIGN TRAILING SEPARATE.
       01 v8 pic S9(9)V99 VALUE  1234.56 SIGN TRAILING SEPARATE.
       PROCEDURE       DIVISION.
       M1.  MOVE V1 TO v3 V4.
           DISPLAY "V3=" V3 "== V4=" V4 "==".
           MOVE V2 TO v3 V4.
           DISPLAY "V3=" V3 "== V4=" V4 "==".
           DISPLAY "V5=" V5 "==".
           DISPLAY "V6=" V6 "==".
           DISPLAY "V7=" V7 "==".
           DISPLAY "V8=" V8 "==".
           accept v1.

As for your code.

1- Make sure you initialize the variables before populating them.
e.g.
initialize WS-OUTFILE-RECORD or
move spaces to WS-OUT-PART1
move zeros to WS-OUT-PART2

should be done at the very start of the program.

Also you don't say where the error occurs. It is possible it is on the "write" and on this case the error is related to the way your FD is defined, and you have not shown us that.


Also by looking at your original post again, the value 12456.56- is not created by a "PIC S99999V99 SIGN TRAILING SEPARATE", but by a PIC 99999.99-
Note that the last is a numeric edited variable.



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Isn't the underlying question exactly HOW the input field is formatted? Is it sign trailing separate (or not)? Is it actually signed or not?

If you can show us the HEX value of some of the input fields, we might be able to figure this out

"Wolves" still hasn't told us the compiler and operating system - which might help us with the other parts of the problem.

Bill Klein
 
I apologize, I did forget to post this information.
I am using a COBOL 85 mainframe compiler on a S/390 using OS390.

Here is the hex value of the input file:

Code:
181,666.18-
FFF6FFF4FF6

181,666.18
FFF6FFF4FF

The first entry happens to be one the problem chids, the second entry is OK since it is a positive.

 
fredericofonseca:
I don't understand how the sign trailing amount will be converted according to your program? Should I not be moving v8 also?
 
Then the input field should be defined as

999,999.99-

If you defined as PIC X(11) I think the following will also work well.

01 in pic x(11)
01 out pic ----,---.99.

move in(1:11) to out if the value is negative, and
move in(1:10) to out otherwise





Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Here is what I have:

Code:
01  WS-INFILE-RECORD.
 05  WS-IN-PART1              PIC X(80).
 05  WS-IN-PART2       PIC 999,999.99-.

 *-------------------------------------------------------*
 *       OUTFILE RECORD             *
 *-------------------------------------------------------*
 01  WS-OUTFILE-RECORD.
 05  WS-OUT-PART1             PIC X(80).
 05  WS-OUT-PART2             PIC ----,---.99.




IF WS-IN-PART2 < 0
   MOVE WS-IN-PART2(1:11) TO WS-OUT-PART2
ELSE
   MOVE WS-IN-PART2(1:10) TO WS-OUT-PART2


And here is the error:

Code:
IDC0002I IDCAMS PROCESSING COMPLETE. MAXIMUM CONDITION CODE WAS 0
BEGIN FAMR0013
JAY
       661.
       661.
     661.00
JAY
    34,214.
    34,214.
CEE3207S The system detected a data exception (System Completion Code=0C7).
         From compile unit FAMR0011 at entry point FAMR0011 at compile unit offs MR0011 at compile unit offset +0000063A at address 0A600BFA.
<> LEAID ENTERED (LEVEL 07/09/2002 AT 11.37)
<> LEAID ABENDAID DD ALLOCATED BY #XAMAKDD DYNALLOC RC =00000
<> LEAID PROCESSING COMPLETE.


*******************************************
    *            Analysis of Error            *
    *******************************************
 
 
    A Data Exception was caused by data referenced at displacement 09C from
    the start of TGT BLW cell 00 (X'0').  The field contains
    X'F3F46BF2F1F4'.  Refer to the data division map in the program listing
    to locate the field name.
 
    The field causing the exception is located in a temporary work field in
    the DSA.  The actual field in error is in Working-Storage of program





 A Data Exception is caused when a computational-3 field has
    an invalid digit (not 0-9), or its last byte contains an invalid
    sign (not A, B, C, D, E, or F).


Here are the first 2 entries of the input file:

Code:
         200406                   661.95
444444444FFFFFF4444444444444444444FFF4FF
0000000002004060000000000000000000661B95
 ---------------------------------------
         200403                34,214.40
444444444FFFFFF4444444444444444FF6FFF4FF

 
Ah!!.

Now we have more info.
The program is failing because some of the positions you are trying to move have spaces on them.

And I said to define the field as PIC X if doing the reference modification bit.

try
01 WS-INFILE-RECORD.
05 WS-IN-PART1 PIC X(80).
05 WS-IN-PART2 PIC X(11).

*-------------------------------------------------------*
* OUTFILE RECORD *
*-------------------------------------------------------*
01 WS-OUTFILE-RECORD.
05 WS-OUT-PART1 PIC X(80).
05 WS-OUT-PART2 PIC ----,---.99.



INSPECT WS-IN-PART2(1:10) REPLACING ALL " " BY "0" (e.g. replace spaces by zeros)
IF WS-IN-PART2(11:1) = "-"
MOVE WS-IN-PART2(1:11) TO WS-OUT-PART2
ELSE
MOVE WS-IN-PART2(1:10) TO WS-OUT-PART2
END-IF


Not sure if it will work, as I don't have that access to that compiler.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Same error, unfortunately. I guess because of how I have the input defined maybe.
 
If your compiler supports the NUMVAL-C the following should work.
Code:
IDENTIFICATION DIVISION.                                         
PROGRAM-ID. DEMO.                                                
DATA DIVISION.                                                   
WORKING-STORAGE SECTION.                                         
01  WS-IN-PART2       PIC X(11).                                 
01  REDEFINES WS-IN-PART2.                                       
    10 WS-IN-PART3    PIC X(10).                                 
    10                PIC X(1).                                  
 01  WS-OUT-PART-N    PIC S9(8)V99.                              
 01  WS-OUT-PART2     PIC ----,---.99.                           
PROCEDURE DIVISION.                                              
MAIN1.                                                           
    MOVE " 34,214.40-" TO WS-IN-PART2                            
    DISPLAY "==" WS-IN-PART2 "==".                               
    COMPUTE WS-OUT-PART-N =  FUNCTION NUMVAL-C(WS-IN-PART2)      
    MOVE WS-OUT-PART-N TO WS-OUT-PART2.                          
    DISPLAY "==" WS-OUT-PART2 "==".

If not then search these forums and you will find one example of numeric field manipulation that will work on every compiler.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Thanks for all the help.
Will get to trying that idea and do some more searching. Will post when I get something to work.
You have been more than helpful.

 
Wolves,
You're getting a data exception because you're comparing a numeric edited field with a numeric literal.

IF WS-IN-PART2 < 0

WS-IN-PART2 contains a comma, period, and hyphen. Those are not numeric characters. Thus the data exception.

Instead, why not check WS-IN-PART2(11:1) = '-' to see if it is negative.

But why do you even need to check for negative? COBOL has a de-editing feature that will take a numeric edited field and put it back into its numeric value. You could then move that field to the output to get the desired result.


03 WS-IN-PART2 PIC 999,999.99-.
03 WS-OUT-PART2 PIC ----,---.99.
03 WORK-FIELD PIC S9(06)V99.


MOVE WS-IN-PART2 TO WORK-FIELD.
MOVE WORK-FIELD TO WS-OUT-PART2.



 
If you are using a currently supported COBOL on z/OS (or OS/390), then the following code should work.

Code:
01  WS-INFILE-RECORD.
 05  WS-IN-PART1              PIC X(80).
 05  WS-IN-PART2       PIC X(11).

 *-------------------------------------------------------*
 *       OUTFILE RECORD             *
 *-------------------------------------------------------*
 01  WS-OUTFILE-RECORD.
 05  WS-OUT-PART1             PIC X(80).
 05  WS-OUT-PART2             PIC ----,---.99.
      ...
Compute WS-Out-Part2 = Function NumVal (WS-IN-Part2)

Bill Klein
 
Bill,

I tried that specific format on a LE compiler (AS400) and it failed.

Error is basically saying that the "," (comma) is invalid as a parameter to the numval function.

In order for it to work I had to define the destination field as a non edited numeric (see example above).



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Something is wrong then (or maybe COBOL on OS/400 is intermediate not high-level). You *should* be able to use a numeric-edited field as the receiving field for a COMPUTE statement in an '85 Standard High-level compiler.

Bill Klein
 
This works on Tandem NonStop:
Code:
 IDENTIFICATION DIVISION.
 PROGRAM-ID. test1.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 05  WS-IN-PART2       PIC X(11) VALUE "123".
 05  WS-OUT-PART2             PIC ----,---.99.

 PROCEDURE DIVISION.
 0000-start.
     Compute WS-Out-Part2 = Function NumVal (WS-IN-Part2)
     DISPLAY WS-Out-Part2
     MOVE Function NumVal (WS-IN-Part2) TO WS-Out-Part2
     DISPLAY WS-Out-Part2
     STOP RUN.
The odd thing though is the results:
123.00
-6.12
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top