Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to display as 'seventythreethousand fourthirtyfour'

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ksivapradeep

New User


Joined: 30 Jul 2004
Posts: 95

PostPosted: Sat Sep 25, 2004 11:01 pm    Post subject: How to display as 'seventythreethousand fourthirtyfour'
Reply with quote

hi all,

i have the data in a variable like this

01 a pic 9(5) value 73434.

they sked me that how to display it as 'seventythreethousand fourthirtyfour' in the out put

is there anylogic please help me

regards,
siva pradeep
Back to top
View user's profile Send private message

harinadh

New User


Joined: 01 Sep 2004
Posts: 18

PostPosted: Mon Sep 27, 2004 11:40 am    Post subject: convert number to string`
Reply with quote

Hi,

I can give u program changing number to string. But, it is not optimum.
You can use Reference Modification in some places.

IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
ENVIRONMENT DIVISION.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 TEMP PIC 9(2).
01 TEMP1 PIC 9(3).
01 NUMB PIC 9(5) VALUE 12345.
01 ONE-ARRAY.
05 ONE PIC X(5) OCCURS 9 TIMES.
01 TWO-ARRAY.
05 TWO PIC X(9) OCCURS 10 TIMES.
01 THREE-ARRAY.
05 THREE PIC X(7) OCCURS 9 TIMES.

PROCEDURE DIVISION.

MAIN-PARA.

MOVE "ONE" TO ONE(1).
MOVE "TWO" TO ONE(2).
MOVE "THREE" TO ONE(3).
MOVE "FOUR" TO ONE(4).
MOVE "FIVE" TO ONE(5).
MOVE "SIX" TO ONE(6).
MOVE "SEVEN" TO ONE(7).
MOVE "EIGHT" TO ONE(8).
MOVE "NINE" TO ONE(9).

MOVE "ELEVEN" TO TWO(1).
MOVE "TWELVE" TO TWO(2).
MOVE "THIRTEEN" TO TWO(3).
MOVE "FOURTEEN" TO TWO(4).
MOVE "FIFTEEN" TO TWO(5).
MOVE "SIXTEEN" TO TWO(6).
MOVE "SEVENTEEN" TO TWO(7).
MOVE "EIGHTEEN" TO TWO(8).
MOVE "NINETEEN" TO TWO(9).

MOVE "TEN" TO THREE(1).
MOVE "TWENTY" TO THREE(2).
MOVE "THIRTY" TO THREE(3).
MOVE "FOURTY" TO THREE(4).
MOVE "FIFTY" TO THREE(5).
MOVE "SIXTY" TO THREE(6).
MOVE "SEVENTY" TO THREE(7).
MOVE "EIGHTY" TO THREE(8).
MOVE "NINETY" TO THREE(9).

DIVIDE NUMB BY 1000 GIVING TEMP REMAINDER TEMP1.
SUBTRACT 10 FROM TEMP GIVING TEMP.
DISPLAY TWO (TEMP) "Thousands".
DIVIDE TEMP1 BY 100 GIVING TEMP REMAINDER TEMP1.
DISPLAY ONE (TEMP) "Hundreds".
DIVIDE TEMP1 BY 10 GIVING TEMP REMAINDER TEMP1.
DISPLAY THREE (TEMP).
DISPLAY ONE(TEMP1).
STOP RUN.
You can read value also to NUMB.......

Thanks
hari
Back to top
View user's profile Send private message
sandip_datta

Active User


Joined: 02 Dec 2003
Posts: 151
Location: Tokyo, Japan

PostPosted: Mon Sep 27, 2004 2:19 pm    Post subject:
Reply with quote

How will it work if NUMB is 100 or 1000?
I think it can not be done progamattically or if can be done will be very very complex. Sometime people ask questions to check how flexcible you are to say "I CAN'T DO IT".

Regards,
Sandip.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Sep 27, 2004 11:02 pm    Post subject:
Reply with quote

I won't write the code for you but here's some logic you might consider:

Build 2 tables; one for 1-19 (one-nineteen); one for 10-90 (ten-ninety).
Use the digits in the number as a subscript into the tables.
Use ref/mod to extract the subscripts.
Define a field for each numeric catagory, i.e. thousands, hundreds, and tens/units and init them to spaces.
Move the table values into the numeric catagory fields.

The logic to move the table vals to the num cat fields will contain checks to decide to use the 1-19 tbl or a combo of both 1-19 and 10-90, i.e., if > 19, use both tbls, else use 1-19.

Remember, before using the tables, check for zero subscript and move an appropriate value to the num cat field.

The mainline logic to set up the string will look something like this:
Code:

move 1 to ptr
if thousand >  spaces
   string      thousand   delim by space
              'thousand'  delim by size
    into       output     pointer ptr
   end-string
end-if
if hundred >   spaces
   string      hundred    delim by space
     into      output     pointer ptr
   end-string
end-if
if tens-unit > spaces
   string      tens-unit  delim by space
      into     output     pointer ptr
   end-string
end-if

Remember, you have to check for special (usually zero and teens) circumstances and code exception routines for them. For example:

35506 is said thirtyfivethousandfiveZEROsix.
15621 is said FIFTEENthousandsixtwentyone
Back to top
View user's profile Send private message
balajiofcrrcoe

New User


Joined: 07 Jul 2005
Posts: 41
Location: chennai

PostPosted: Wed Feb 01, 2006 7:48 pm    Post subject: Re: some logic(asked in TCS)
Reply with quote

Hi,
I tried like this, it seems working

IDENTIFICATION DIVISION.
PROGRAM-ID. NUMTEL.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*********** INPUT FILE(write the five digit number in this file) *****************************

SELECT IN-FILE ASSIGN TO FILEIN
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-FILEIN.
*********** FILE TO SPELL THE NUMBER(FILE-SPL),maintain a file with first two digits from 00 to ***99(this field shld be primary key) and the corresponding number spell in desc(another field)**
*****
SELECT FILE-SPL ASSIGN TO FILESPL
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS PRIM-KEY
FILE STATUS IS WS-FILESPL.
DATA DIVISION.
FILE SECTION.
FD IN-FILE.

01 INREC.
05 X PIC 9(05).

FD FILE-SPL.
01 FILEREC.
05 PRIM-KEY PIC 9(02).
05 NUM-SPL PIC X(25).
WORKING-STORAGE SECTION.
01 OUTREC.
05 Y PIC 9(05).
05 DESC PIC X(50).

77 EOF-INFILE PIC 9(01) VALUE ZERO.
01 FILE-STAT.
05 WS-FILEIN PIC X(02).
05 WS-FILESPL PIC X(02).
77 DESCA PIC X(25) VALUE SPACES.
77 DESCB PIC X(25) VALUE SPACES.
77 DESCC PIC X(25) VALUE SPACES.
01 NUMDIV.
05 A PIC 9(02).
05 B PIC 9(01).
05 C PIC 9(02).
PROCEDURE DIVISION.
0000-MAIN.
PERFORM OPEN-FILES.
PERFORM READ-WRITE.
PERFORM CLOSE-FILES.
PERFORM STOP-RUN.
STOP-RUN SECTION.
STOP RUN.
CLOSE-FILES SECTION.
CLOSE IN-FILE
OUT-FILE
FILE-SPL.
OPEN-FILES.
OPEN INPUT IN-FILE.
IF WS-FILEIN = 00
NEXT SENTENCE
ELSE
DISPLAY 'ERROR IN FILE OPEN' WS-FILEIN
PERFORM STOP-RUN
END-IF.
OPEN INPUT FILE-SPL.
IF WS-FILESPL = 00
NEXT SENTENCE
ELSE
DISPLAY 'ERROR IN FILE OPEN' WS-FILESPL
PERFORM STOP-RUN
END-IF

READ-WRITE SECTION.
READ IN-FILE AT END MOVE 1 TO EOF-INFILE.
PERFORM NUM-CONV UNTIL EOF-INFILE = 1.

NUM-CONV SECTION.
***use reference modification to extract the thousands,hundreds and **tens
MOVE X(1:2) TO A.
MOVE X(3:1) TO B.
MOVE X(4:2) TO C.
DISPLAY A
DISPLAY B
DISPLAY C
MOVE ZEROS TO PRIM-KEY.
MOVE LOW-VALUES TO NUM-SPL.

****read for the number spell in the vsam file maintained
MOVE A TO PRIM-KEY.
READ FILE-SPL INVALID KEY PERFORM INVALID-KEY.
MOVE NUM-SPL TO DESCA.
MOVE ZEROS TO PRIM-KEY.
MOVE LOW-VALUES TO NUM-SPL.
MOVE B TO PRIM-KEY.
READ FILE-SPL INVALID KEY PERFORM INVALID-KEY.
MOVE NUM-SPL TO DESCB.
MOVE ZEROS TO PRIM-KEY.
MOVE LOW-VALUES TO NUM-SPL.
MOVE C TO PRIM-KEY.
READ FILE-SPL INVALID KEY PERFORM INVALID-KEY.
MOVE NUM-SPL TO DESCC.


*** validate for thousands ,hundreds and tens and accordingly use the *** the string stmt
IF A >0
STRING DESCA SPACE 'THOUSAND' SPACE
DESCB SPACE 'HUNDRED' SPACE
DESCC DELIMITED BY SPACE
INTO DESC
END-IF.
IF (A = 0 AND B > 0)
STRING DESCB SPACE 'HUNDRED' SPACE
DESCC DELIMITED BY SPACE
INTO DESC
END-IF.
IF (A = 0 AND B = 0 AND C > 0)
MOVE DESCC TO DESC
END-IF.
IF (A = 0 AND B = 0 AND C = 0)
MOVE 'ZERO' TO DESC
END-IF.


DISPLAY 'THE SPELL IS' DESC
MOVE X TO Y.
DISPLAY OUTREC.
READ IN-FILE AT END MOVE 1 TO EOF-INFILE.
INVALID-KEY SECTION.
DISPLAY 'NO RECORD EXIST WITH THE KEY'.

-------------------------------------------------------------------
o/p

12301TWELVETHOUSANDTHREEHUNDREDONE
00122ONEHUNDREDTWENTYTWO
00000ZERO



Please feel free for any further clarificarions.




regards,
naga samba siva rao
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Thu Feb 02, 2006 9:26 am    Post subject: Re: some logic(asked in TCS)
Reply with quote

balajiofcrrcoe wrote:
Hi,
I tried like this, it seems working

IDENTIFICATION DIVISION.
PROGRAM-ID. NUMTEL.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*********** INPUT FILE(write the five digit number in this file) *****************************

SELECT IN-FILE ASSIGN TO FILEIN
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-FILEIN.
*********** FILE TO SPELL THE NUMBER(FILE-SPL),maintain a file with first two digits from 00 to ***99(this field shld be primary key) and the corresponding number spell in desc(another field)**
*****
SELECT FILE-SPL ASSIGN TO FILESPL
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS PRIM-KEY
FILE STATUS IS WS-FILESPL.
DATA DIVISION.
FILE SECTION.
FD IN-FILE.

01 INREC.
05 X PIC 9(05).

FD FILE-SPL.
01 FILEREC.
05 PRIM-KEY PIC 9(02).
05 NUM-SPL PIC X(25).
WORKING-STORAGE SECTION.
01 OUTREC.
05 Y PIC 9(05).
05 DESC PIC X(50).

77 EOF-INFILE PIC 9(01) VALUE ZERO.
01 FILE-STAT.
05 WS-FILEIN PIC X(02).
05 WS-FILESPL PIC X(02).
77 DESCA PIC X(25) VALUE SPACES.
77 DESCB PIC X(25) VALUE SPACES.
77 DESCC PIC X(25) VALUE SPACES.
01 NUMDIV.
05 A PIC 9(02).
05 B PIC 9(01).
05 C PIC 9(02).
PROCEDURE DIVISION.
0000-MAIN.
PERFORM OPEN-FILES.
PERFORM READ-WRITE.
PERFORM CLOSE-FILES.
PERFORM STOP-RUN.
STOP-RUN SECTION.
STOP RUN.
CLOSE-FILES SECTION.
CLOSE IN-FILE
OUT-FILE
FILE-SPL.
OPEN-FILES.
OPEN INPUT IN-FILE.
IF WS-FILEIN = 00
NEXT SENTENCE
ELSE
DISPLAY 'ERROR IN FILE OPEN' WS-FILEIN
PERFORM STOP-RUN
END-IF.
OPEN INPUT FILE-SPL.
IF WS-FILESPL = 00
NEXT SENTENCE
ELSE
DISPLAY 'ERROR IN FILE OPEN' WS-FILESPL
PERFORM STOP-RUN
END-IF

READ-WRITE SECTION.
READ IN-FILE AT END MOVE 1 TO EOF-INFILE.
PERFORM NUM-CONV UNTIL EOF-INFILE = 1.

NUM-CONV SECTION.
***use reference modification to extract the thousands,hundreds and **tens
MOVE X(1:2) TO A.
MOVE X(3:1) TO B.
MOVE X(4:2) TO C.
DISPLAY A
DISPLAY B
DISPLAY C
MOVE ZEROS TO PRIM-KEY.
MOVE LOW-VALUES TO NUM-SPL.

****read for the number spell in the vsam file maintained
MOVE A TO PRIM-KEY.
READ FILE-SPL INVALID KEY PERFORM INVALID-KEY.
MOVE NUM-SPL TO DESCA.
MOVE ZEROS TO PRIM-KEY.
MOVE LOW-VALUES TO NUM-SPL.
MOVE B TO PRIM-KEY.
READ FILE-SPL INVALID KEY PERFORM INVALID-KEY.
MOVE NUM-SPL TO DESCB.
MOVE ZEROS TO PRIM-KEY.
MOVE LOW-VALUES TO NUM-SPL.
MOVE C TO PRIM-KEY.
READ FILE-SPL INVALID KEY PERFORM INVALID-KEY.
MOVE NUM-SPL TO DESCC.


*** validate for thousands ,hundreds and tens and accordingly use the *** the string stmt
IF A >0
STRING DESCA SPACE 'THOUSAND' SPACE
DESCB SPACE 'HUNDRED' SPACE
DESCC DELIMITED BY SPACE
INTO DESC
END-IF.
IF (A = 0 AND B > 0)
STRING DESCB SPACE 'HUNDRED' SPACE
DESCC DELIMITED BY SPACE
INTO DESC
END-IF.
IF (A = 0 AND B = 0 AND C > 0)
MOVE DESCC TO DESC
END-IF.
IF (A = 0 AND B = 0 AND C = 0)
MOVE 'ZERO' TO DESC
END-IF.


DISPLAY 'THE SPELL IS' DESC
MOVE X TO Y.
DISPLAY OUTREC.
READ IN-FILE AT END MOVE 1 TO EOF-INFILE.
INVALID-KEY SECTION.
DISPLAY 'NO RECORD EXIST WITH THE KEY'.

-------------------------------------------------------------------
o/p

12301TWELVETHOUSANDTHREEHUNDREDONE
00122ONEHUNDREDTWENTYTWO
00000ZERO



Please feel free for any further clarificarions.




regards,
naga samba siva rao



hai naga samba siva rao,

ive a clarification required.

how do we get the equivalent alphabetic name of the prime key. i.e; how do we get the string TWELVE for the first two characters 12.

am i right in analysis that these values are available in the identifier NUM-SPL of the FILE-SPL.

moreover, i need one more clarification. suppose that my in-file has only one record in it. after the first READ, will the EOF condition be set or its only after the second attempt to READ the EOF will be set?

please clarify me on these.


kind regards,

gowtham
Back to top
View user's profile Send private message
balajiofcrrcoe

New User


Joined: 07 Jul 2005
Posts: 41
Location: chennai

PostPosted: Fri Feb 03, 2006 12:43 am    Post subject: Re: How to display as 'seventythreethousand fourthirtyfour'
Reply with quote

Hi gowtham,

Your analysis is correct

i am maintaining a file FILE-SPL which has the records from 00 to 99
PRIM-KEY is the primary key and NUM-SPL is the corresponding spell
for the number,and in my second read only the eof is set


please feel free for further clarifications


Regards,
Naga samba siva rao
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Display ZEDLMSG without Pressing F1 &... anandgbe CLIST & REXX 8 Thu Dec 15, 2016 4:20 pm
No new posts How to display value of an exit param... lind sh CICS 2 Sun Oct 09, 2016 12:28 pm
This topic is locked: you cannot edit posts or make replies. DSList (3.4) cannot display Chinese c... jacobdng TSO/ISPF 4 Wed Oct 05, 2016 2:51 pm
This topic is locked: you cannot edit posts or make replies. Get and display content of an address... lind sh CICS 1 Mon Aug 08, 2016 9:18 am
No new posts How to display data in separate lines... salilnigam1970 DFSORT/ICETOOL 2 Tue Jan 26, 2016 9:49 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us