Cobol soll eine S9(10)V99 Zahl Ausgeben?

Ich möchte einen Wert negativ oder Positiv im SYSOUT ausgeben.

BSP:

In diesen Beispiel wollte ich einfach nur versuchen eine Negative Zahl auszugeben, aber leider klappt das nicht wie ich es mir vorgestellt habe:

SYSOUT

Wie bekomme ich es hin das der Wert als Negativ oder Positiv ausgegeben wird mit dezimal Zahlen?

z.B. -10.13 oder +10.13

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
DaaanielTV
1 year ago

To output an S9(10)V99 number in the COBOL program as a positive or negative value with decimal places, you can take the following steps:

  1. Define a variable with the PIC code S9(10)V99 to keep the number.
  2. Fill the variable with the desired value, whereby the sign is adjusted accordingly.
  3. Use the “MOVE” and “EDITED” commands along with a suitable image instruction to output the value in the desired format in the SYSOUT.

Below you will find a code section that demonstrates this:

IDENTIFICATION DIVISION. PROGRAM-ID. MYPROGRAM. DATA DIVISION. WORKING-STORAGE SECTION. 01 MY-NUMBER PIC S9(10)V99. 01 MY-STRING PIC X(12). PROCEDURE DIVISION. BEGIN. MOVE -10.13 TO MY-NUMBER. IF MY-NUMBER < 0 MOVE '-' TO MY-STRING(1:1) ELSE MOVE '+' TO MY-STRING(1:1) END-IF. MOVE MY-NUMBER TO MY-STRING(2:). MOVE MY-STRING TO SYSOUT. STOP RUN.

In this example, the number -10,13 is assigned to the variable MY-NUMBER. Then it is checked whether the number is negative, and the corresponding sign (+ or -) is assigned to the variable MY-STRING. The number MY-NUMBER is then converted to MY-STRING with the image instruction 'Z9.99' and output together with the sign in the SYSOUT. The output should be "+10.13".

Please note that the exact code may vary depending on the requirements of your program.