# Cobol 4 - The trouble with computing TEXT positive and negat

Author Message
ivke.stojic

New User

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

 Posted: Mon Dec 20, 2021 4:23 pm 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 " " DELIMITED SIZE NAZIV(PCP:DUZ) DELIMITED SIZE "" DELIMITED SIZE INTO SLXMLDBF WRITE SLXMLDBF The above code will write in the file 234.32 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
ivke.stojic

New User

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

 Posted: Mon Dec 20, 2021 5:16 pm 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 " " DELIMITED SIZE br11 DELIMITED SIZE "" DELIMITED SIZE INTO SLXMLDBF. WRITE SLXMLDBF. MOVE "23.43" TO txtbr2. MOVE SPACE TO SLXMLDBF. STRING " " DELIMITED SIZE br22 DELIMITED SIZE "" DELIMITED SIZE INTO SLXMLDBF. WRITE SLXMLDBF. COMPUTE br2 = br2 + br1. MOVE SPACE TO SLXMLDBF. STRING " " DELIMITED SIZE br22 DELIMITED SIZE "" DELIMITED SIZE INTO SLXMLDBF. WRITE SLXMLDBF. The above code will give the output -123.32 23.43 The program is crashing because of this line COMPUTE br2 = br2 + br1.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Cobol prog to put an indicator on the... JCL & VSAM 1 COBOL Ascending and descending sort n... COBOL Programming 5 COBOL program logic for comparisipn o... COBOL Programming 2 REXX to send an email in Mainframe wi... CLIST & REXX 3 COBOL - create and write to output fi... COBOL Programming 0
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us