![]() |
Convert Digits to a Text String SimoTXTN - The COBOL Source Code http://www.simotime.com |
| When technology complements business | Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
This document provides information about the SimoTXTN routine that converts a numeric value (or digits) to a text string of words. Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com
The SimoTXTN routine (or callable program) will convert the digits in a text string to words in a new text string. For example, the numeric value of 000123 will be converted to a text string of "One-hundred-twenty-three"
The following will expand a single byte into eight bytes of 0's or 1's based on the bit settings within the one byte field.
move 'DECIMAL2' to TXN-PASS-REQUEST
move '000000001898' to TXN-PASS-DIGITS-R
move '-' to TXN-PASS-TXT-DELIMITER
move 'Dollars ' to TXN-PASS-TXT-SUFFIX
move '$' to TXN-PASS-NUM-SYMBOL
call 'SIMOTXTN' using TXN-PASS-AREA
move TXN-PASS-TXT to MESSAGE-TEXT
In the preceding example the contents of TXN-PASS-TXT will be "Eighteen-and-98/100-Dollars " upon return from the call to SIMOTXTN.
A copy file is provided to define the pass area to be used when calling SimoBITS. The following statement is required in the WORKING STORAGE section of the calling program.
COPY PASSTXTN.
The following is the COBOL Source Code.
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOTXTN.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2010 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any non-commercial purpose and without fee is hereby *
* granted, provided the SimoTime copyright notice appear on all *
* copies of the software. The SimoTime name or Logo may not be *
* used in any advertising or publicity pertaining to the use *
* of the software without the written permission of SimoTime *
* Enterprises. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Enterprises. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Enterprises. *
* *
* SimoTime Enterprises makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any express or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Enterprises shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Enterprises *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
* *
*****************************************************************
*
*****************************************************************
* Source Member: SIMOTXTN.CBL
* Copy Files: PASSTXTN.CPY
*****************************************************************
*
* SIMOTXTN - A called routine for digit to text conversions.
*
* CALLING PROTOCOL
* ----------------
* Use standard COBOL calling procedures.
*
* DESCRIPTION
* -----------
* This program will do Digits to Text conversions.
*
****************************************************************
*
* MAINTENANCE
* -----------
* 1989/02/27 Simmons, Created program.
* 1989/02/27 Simmons, no changes to date
*
*****************************************************************
*
DATA DIVISION.
WORKING-STORAGE SECTION.
*
*****************************************************************
* Data-structure for Title and Copyright...
*****************************************************************
01 SIM-TITLE.
05 T1 pic X(11) value '* SIMOTXTN '.
05 T2 pic X(34) value 'Convert Digits to a Text String '.
05 T3 pic X(10) value ' v06.03.03'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* SIMOTXTN '.
05 C2 pic X(20) value 'Copyright 1987-2009 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
05 C4 pic X(20) value ' All Rights Reserved'.
01 FIRST-TIME pic X value 'Y'.
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* SIMOTXTN '.
05 MESSAGE-TEXT pic X(68).
01 WORK-DIGITS-A.
05 WORK-DIGITS-A1 pic X(3).
05 WORK-DIGITS-A2 pic X(3).
05 WORK-DIGITS-A3 pic X(3).
05 WORK-DIGITS-A4 pic X(3).
01 WORK-DIGITS-N redefines WORK-DIGITS-A
pic 9(12).
01 WORK-DECIMAL-2A.
05 WORK-DECIMAL-N1 pic 9(10).
05 WORK-DECIMAL-N2 pic 9(2).
01 TEXT-FOR-CENTS.
05 filler pic X(4) value 'and-'.
05 TEXT-CENT-AMOUNT pic 9(2) value 0.
05 filler pic X(5) value '/100-'.
01 TEXT-FOR-CENTS-A1 redefines TEXT-FOR-CENTS
pic X(11).
01 WORK-01 pic X.
01 WORK-03 pic X(3).
01 WORK-10 pic X(10).
01 I-X1 pic 9(3) value 0.
01 I-X2 pic 9(3) value 0.
01 DIGITS-FLAG pic X value 'N'.
01 EDIT-WORD-0 pic X(17) value '$@@@,@@@,@@@,@@@ '.
01 EDIT-WORD-2 pic X(17) value '$@,@@@,@@@,@@@.@@'.
*****************************************************************
LINKAGE SECTION.
COPY PASSTXTN.
*****************************************************************
PROCEDURE DIVISION using TXN-PASS-AREA.
if FIRST-TIME not = 'N'
perform Z-POST-COPYRIGHT
move 'N' to FIRST-TIME
end-if
initialize TXN-PASS-RESULT
initialize TXN-PASS-TXT-LENGTH
move SPACES to TXN-PASS-TXT
move SPACES to WORK-DIGITS-A
move TXN-PASS-NUM-SYMBOL to EDIT-WORD-0(1:1)
move TXN-PASS-NUM-SYMBOL to EDIT-WORD-2(1:1)
perform EDIT-TXN-PASS-DIGITS
evaluate TXN-PASS-REQUEST
when 'DECIMAL0' perform CREATE-TEXT-FOR-ZERO-DECIMALS
when 'DECIMAL2' perform CREATE-TEXT-FOR-TWO-DECIMALS
when OTHER perform Z-POST-INVALID-REQUEST
end-evaluate
add TXN-PASS-RESULT to ZERO giving RETURN-CODE
GOBACK.
*****************************************************************
CREATE-TEXT-FOR-TWO-DECIMALS.
*
* Validate the input string contains all digits...
*
perform VALIDATE-DIGITS-OR-ABEND
move TXN-PASS-NUM-RIGHT-ADJUST to WORK-DECIMAL-2A
add WORK-DECIMAL-N1 to ZERO giving WORK-DIGITS-N
add WORK-DECIMAL-N2 to ZERO giving TEXT-CENT-AMOUNT
perform CREATE-TEXT-02
perform CREATE-LEFT-EDIT-2
exit.
CREATE-LEFT-EDIT-0.
move TXN-PASS-NUM-RIGHT-ADJUST
to TXN-PASS-NUM-LEFT-EDITED
exit.
CREATE-LEFT-EDIT-2.
move EDIT-WORD-2 to TXN-PASS-NUM-LEFT-EDITED
move TXN-PASS-NUM-SYMBOL to TXN-PASS-NUM-LEFT-EDITED(1:1)
add 12 to ZERO giving I-X1
add 17 to ZERO giving I-X2
move TXN-PASS-NUM-RIGHT-ADJUST to WORK-DIGITS-A
perform until I-X1 = 0
or I-X2 = 1
if TXN-PASS-NUM-LEFT-EDITED(I-X2:1) = '@'
move WORK-DIGITS-A(I-X1:1)
to TXN-PASS-NUM-LEFT-EDITED(I-X2:1)
subtract 1 from I-X1
subtract 1 from I-X2
else
subtract 1 from I-X2
end-if
end-perform
move 'N' to DIGITS-FLAG
add 1 to ZERO giving I-X1
perform until DIGITS-FLAG = 'Y'
if TXN-PASS-NUM-LEFT-EDITED(I-X1:1) = '0'
or TXN-PASS-NUM-LEFT-EDITED(I-X1:1) =
EDIT-WORD-2(I-X1:1)
add 1 to I-X1
else
move 'Y' to DIGITS-FLAG
end-if
if I-X1 > 13
move 'Y' to DIGITS-FLAG
end-if
end-perform
if I-X1 > 1
subtract 1 from I-X1
perform until I-X1 < 2
add 2 to ZERO giving I-X2
perform 15 times
move TXN-PASS-NUM-LEFT-EDITED(I-X2 + 1:1)
to TXN-PASS-NUM-LEFT-EDITED(I-X2:1)
add 1 to I-X2
end-perform
subtract 1 from I-X1
move SPACE to TXN-PASS-NUM-LEFT-EDITED(17:1)
end-perform
end-if
exit.
*****************************************************************
CREATE-TEXT-FOR-ZERO-DECIMALS.
*
* Validate the input string contains all digits...
*
perform VALIDATE-DIGITS-OR-ABEND
add TXN-PASS-NUM-RIGHT-ADJUST to ZERO giving WORK-DIGITS-N
perform CREATE-TEXT-02
perform CREATE-LEFT-EDIT-0
exit.
*****************************************************************
CREATE-TEXT-02.
*
* Process a Zero value...
if TXN-PASS-NUM-RIGHT-ADJUST = 0
if TXN-PASS-REQUEST = 'DECIMAL2'
if TXN-PASS-TXT-SUFFIX = SPACES
move 'Zero-and-00/100' to TXN-PASS-TXT
perform CREATE-TEXT-CALCULATE-LENGTH
else
move 'Zero-and-00/100-' to TXN-PASS-TXT
inspect TXN-PASS-TXT
replacing FIRST ' '
by TXN-PASS-TXT-SUFFIX
perform CREATE-TEXT-CALCULATE-LENGTH
end-if
else
move 'Zero' to TXN-PASS-TXT
add 4 to ZERO giving TXN-PASS-TXT-LENGTH
end-if
move SPACES to TXN-PASS-NUM-LEFT-EDITED
move '$0.00***' to TXN-PASS-NUM-LEFT-EDITED(1:8)
GOBACK
end-if
*
* Process when two-decimal positions and the value to the
* left of the decimal position is zero...
if WORK-DIGITS-N = 0
move 'Zero-' to TXN-PASS-TXT
end-if
*
* Process the first group of three digits...
if WORK-DIGITS-A1 not = '000'
move WORK-DIGITS-A1 to WORK-03
perform CREATE-TEXT-THREE-DIGIT-GROUP
inspect TXN-PASS-TXT
replacing FIRST ' ' by 'Billion-'
end-if
*
* Process the second group of three digits...
if WORK-DIGITS-A2 not = '000'
move WORK-DIGITS-A2 to WORK-03
perform CREATE-TEXT-THREE-DIGIT-GROUP
inspect TXN-PASS-TXT
replacing FIRST ' ' by 'Million-'
end-if
*
* Process the third group of three digits...
if WORK-DIGITS-A3 not = '000'
move WORK-DIGITS-A3 to WORK-03
perform CREATE-TEXT-THREE-DIGIT-GROUP
inspect TXN-PASS-TXT
replacing FIRST ' ' by 'Thousand-'
end-if
*
* Process the fourth group of three digits...
if WORK-DIGITS-A4 not = '000'
move WORK-DIGITS-A4 to WORK-03
perform CREATE-TEXT-THREE-DIGIT-GROUP
end-if
*
* Add suffix info for two decimal positions...
if TXN-PASS-REQUEST = 'DECIMAL2'
inspect TXN-PASS-TXT
replacing FIRST ' ' by TEXT-FOR-CENTS-A1
end-if
*
* Add suffix to text string...
inspect TXN-PASS-TXT
replacing FIRST ' ' by TXN-PASS-TXT-SUFFIX
*
* Remove trailing hyphen...
inspect TXN-PASS-TXT replacing FIRST '- ' by ' '
*
* Calculate the length of the text within the text string...
perform CREATE-TEXT-CALCULATE-LENGTH
*
* Replace word delimiter with user defined character...
if TXN-PASS-TXT-DELIMITER not = '-'
inspect TXN-PASS-TXT
replacing all '-' by TXN-PASS-TXT-DELIMITER
end-if
exit.
*****************************************************************
CREATE-TEXT-CALCULATE-LENGTH.
add 1 to ZERO giving TXN-PASS-TXT-LENGTH
perform until TXN-PASS-TXT-LENGTH = 150
or TXN-PASS-TXT(TXN-PASS-TXT-LENGTH:1) = SPACE
add 1 to TXN-PASS-TXT-LENGTH
end-perform
subtract 1 from TXN-PASS-TXT-LENGTH
exit.
*****************************************************************
CREATE-TEXT-THREE-DIGIT-GROUP.
move SPACES to WORK-10
move WORK-03(1:1) to WORK-01
perform CREATE-TEXT-ONE-THRU-NINE
if WORK-10 not = SPACES
inspect TXN-PASS-TXT
replacing FIRST ' ' by WORK-10
inspect TXN-PASS-TXT
replacing FIRST ' ' by 'Hundred-'
end-if
if WORK-03(2:1) = '1'
perform CREATE-TEXT-FOR-TEEN
else
perform CREATE-TEXT-FOR-NON-TEEN
end-if
exit.
*****************************************************************
CREATE-TEXT-FOR-TEEN.
move SPACES to WORK-10
evaluate WORK-03(3:1)
when '0' move 'Ten- ' to WORK-10
when '1' move 'Eleven- ' to WORK-10
when '2' move 'Twelve- ' to WORK-10
when '3' move 'Thirteen- ' to WORK-10
when '4' move 'Fourteen- ' to WORK-10
when '5' move 'Fifteen- ' to WORK-10
when '6' move 'Sixteen- ' to WORK-10
when '7' move 'Seventeen-' to WORK-10
when '8' move 'Eighteen- ' to WORK-10
when '9' move 'Nineteen- ' to WORK-10
end-evaluate
if WORK-10 not = SPACES
inspect TXN-PASS-TXT
replacing FIRST ' ' by WORK-10
end-if
exit.
*****************************************************************
CREATE-TEXT-FOR-NON-TEEN.
move SPACES to WORK-10
evaluate WORK-03(2:1)
when '2' move 'Twenty- ' to WORK-10
when '3' move 'Thirty- ' to WORK-10
when '4' move 'Forty- ' to WORK-10
when '5' move 'Fifty- ' to WORK-10
when '6' move 'Sixty- ' to WORK-10
when '7' move 'Seventy- ' to WORK-10
when '8' move 'Eighty- ' to WORK-10
when '9' move 'Ninety- ' to WORK-10
end-evaluate
if WORK-10 not = SPACES
inspect TXN-PASS-TXT
replacing FIRST ' ' by WORK-10
end-if
move SPACES to WORK-10
move WORK-03(3:1) to WORK-01
perform CREATE-TEXT-ONE-THRU-NINE
if WORK-10 not = SPACES
inspect TXN-PASS-TXT
replacing FIRST ' ' by WORK-10
end-if
exit.
*****************************************************************
CREATE-TEXT-ONE-THRU-NINE.
evaluate WORK-01
when '1' move 'One- ' to WORK-10
when '2' move 'Two- ' to WORK-10
when '3' move 'Three- ' to WORK-10
when '4' move 'Four- ' to WORK-10
when '5' move 'Five- ' to WORK-10
when '6' move 'Six- ' to WORK-10
when '7' move 'Seven- ' to WORK-10
when '8' move 'Eight- ' to WORK-10
when '9' move 'Nine- ' to WORK-10
end-evaluate
exit.
*****************************************************************
* Scan the input digets and create right-adjusted, numeric...
*****************************************************************
EDIT-TXN-PASS-DIGITS.
add 1 to ZERO giving I-X1
add 1 to ZERO giving I-X2
move SPACES to WORK-DIGITS-A
perform until I-X1 > 12
if TXN-PASS-DIGITS-R(I-X1:1) = ','
or TXN-PASS-DIGITS-R(I-X1:1) = '.'
add 1 to I-X1
else
move TXN-PASS-DIGITS-R(I-X1:1) to WORK-DIGITS-A(I-X2:1)
add 1 to I-X1
add 1 to I-X2
end-if
end-perform
if WORK-DIGITS-A(12:1) = SPACE
perform until WORK-DIGITS-A(12:1) not = SPACE
add 11 to ZERO giving I-X1
add 12 to ZERO giving I-X2
perform 11 times
move WORK-DIGITS-A(I-X1:1)
to WORK-DIGITS-A(I-X2:1)
subtract 1 from I-X1
subtract 1 from I-X2
end-perform
move '0' to WORK-DIGITS-A(1:1)
end-perform
end-if
move WORK-DIGITS-A to TXN-PASS-NUM-RIGHT-ADJUST
exit.
*****************************************************************
* Validate that input string is all digits, if not ABEND...
*****************************************************************
VALIDATE-DIGITS-OR-ABEND.
add 1 to ZERO giving I-X1
perform 12 times
if TXN-PASS-NUM-RIGHT-ADJUST(I-X1:1) > 0
and TXN-PASS-NUM-RIGHT-ADJUST(I-X1:1) < 9
or TXN-PASS-NUM-RIGHT-ADJUST(I-X1:1) = 0
or TXN-PASS-NUM-RIGHT-ADJUST(I-X1:1) = 9
add 1 to I-X1
else
perform Z-POST-NOT-ALL-DIGITS
end-if
end-perform
exit.
*****************************************************************
* The following Z-Routines perform administrative tasks
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
exit.
*****************************************************************
Z-POST-INVALID-REQUEST.
move 'INVALID REQUEST - ' to MESSAGE-TEXT
move TXN-PASS-REQUEST to MESSAGE-TEXT(19:8)
perform Z-POST-MESSAGE
add 16 to ZERO giving TXN-PASS-RESULT
exit.
*****************************************************************
Z-POST-MESSAGE.
display MESSAGE-BUFFER upon console
move SPACES to MESSAGE-TEXT
exit.
*****************************************************************
Z-POST-NOT-ALL-DIGITS.
move 'Not all DIGITS - ' to MESSAGE-TEXT
move TXN-PASS-DIGITS-R to MESSAGE-TEXT(18:12)
perform Z-POST-MESSAGE
add 16 to ZERO giving TXN-PASS-RESULT
move SPACES to TXN-PASS-TXT
move 'ERROR, VOID this item...' to TXN-PASS-TXT
GOBACK.
*****************************************************************
* This program is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
The purpose of this document is to provide a COBOL Source member for viewing.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
You may view an example of a COBOL program that uses SimoTXTN at http://www.simotime.com/cbltxn01.htm.
You may view the complete list of SimoTime callable Modules or Driver Programs at http://www.simotime.com/simomods.htm.
The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPScan also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |