IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Cobol 4 - The trouble with computing TEXT positive and negat


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ivke.stojic

New User


Joined: 20 Dec 2021
Posts: 2
Location: Србија

PostPosted: Mon Dec 20, 2021 4:23 pm
Reply with quote

I have trouble computing two numbers where one can be a negative number. All numbers are kept as text.

What is happening...

All the values are kept as text in the field of type PIC X(...) VALUES SPACES.

I have a procedure that will find the start of the value. For example:

_ _ _ _ _ 2 3 4 . 32
_ _ _ _ _ - 19. 32 (can be also negative number)

( underscores are representing spaces)

Adding, subtracting, multiplying, dividing everything works fine with a positive number. IF I got a negative number the program will break.

MOVE "_ _ _ _ 2 3 4 . 3 2" TO NAZIV
PERFORM SEC-LEN
SEC-LEN will give me two informations 1) whare are the first number position from left - PCP
2) what is the length of the number - DUZ

For the above example, PCP is 5 and DUZ is 6 (five numbers + dot)

MOVE SPACE TO SLXMLDBF
STRING " <AMOUNT>" DELIMITED SIZE
NAZIV(PCP:DUZ) DELIMITED SIZE
"</AMOUNT>" DELIMITED SIZE INTO SLXMLDBF
WRITE SLXMLDBF

The above code will write in the file <AMOUNT>234.32</AMOUNT>

01 NUM-1 PIC 9(13) VALUE 0.
MOVE NAZIV(PCP:DUZ) TO NUM-1.
COMPUTE NUM-1 = NUM-1 + 10.

If I try to move string "-23.32" tp S9 variable and do some addition the program will crash

I tried to work with S9(...) type of fields for the calculation of positive and negative numbers but without results. All operation on two positive numbers works fine. The problem comming when I get a negative number (tried with S9 type of filed

Redefining text field also didn't work for me.

My question is ... If there is a negative number written as text, how can I put it in the S9 variable and then use it for additions with another positive/negative number converted also from text?


I really hope that somebody can help me to overcome this problem!

Regards,
Ivan
Back to top
View user's profile Send private message
ivke.stojic

New User


Joined: 20 Dec 2021
Posts: 2
Location: Србија

PostPosted: Mon Dec 20, 2021 5:16 pm
Reply with quote

Here is the full example:

01 br1 pic s9(5)v99.
01 br11 pic -9(5).99.
01 txtbr1 REDEFINES br11 PIC X(8).


01 br2 pic s9(5)v99.
01 br22 pic -9(5).99.
01 txtbr2 REDEFINES br22 PIC X(8).


move "-123.32" to txtbr1.

MOVE SPACE TO SLXMLDBF.
STRING " <AMOUNT_1>" DELIMITED SIZE
br11 DELIMITED SIZE
"</AMOUNT_1>" DELIMITED SIZE INTO SLXMLDBF.
WRITE SLXMLDBF.

MOVE "23.43" TO txtbr2.

MOVE SPACE TO SLXMLDBF.
STRING " <AMOUNT_2>" DELIMITED SIZE
br22 DELIMITED SIZE
"</AMOUNT_2>" DELIMITED SIZE INTO SLXMLDBF.
WRITE SLXMLDBF.

COMPUTE br2 = br2 + br1.

MOVE SPACE TO SLXMLDBF.
STRING " <AMOUNT_3>" DELIMITED SIZE
br22 DELIMITED SIZE
"</AMOUNT_3>" DELIMITED SIZE INTO SLXMLDBF.
WRITE SLXMLDBF.

The above code will give the output
<AMOUNT_1>-123.32 </AMOUNT_1>
<AMOUNT_2>23.43 </AMOUNT_2>


The program is crashing because of this line
COMPUTE br2 = br2 + br1.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top