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
 

 

Increment count using alphanumeric

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

New User


Joined: 27 Jul 2006
Posts: 1

PostPosted: Thu Jul 27, 2006 7:50 pm    Post subject: Increment count using alphanumeric
Reply with quote

Hi guys im new in cobol and i tried to check if it is possible to use the alphanumeric in counting.

like:

00
01
02
...
...
...
09
0A
0B
0C
...
...
..
0Y
0Z
10
11
..
...
...
19
1A
..


if this is possible, canyou help me how to achieve it?
Back to top
View user's profile Send private message

DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Jul 28, 2006 4:22 am    Post subject: Re: Increment count using alphanumeric
Reply with quote

This is possible, but not easy, and I cannot think of any rational reason for doing this except just for an exercise.

It cannot be accomplished with a simple ?ADD 1 TO WS-COUNTER?

See below that the stored hex value for a display ?0? (zero) is x?F0? decimal 240, ?9? is x?F9? decimal 249, then ?A? is x?C1? decimal 193, and so on. As you can see, 9 (dec 249) + 1 does not = ?A? (dec 193)
Code:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
FFFFFFFFFFCCCCCCCCCDDDDDDDDDEEEEEEEE
012345678912345678912345678923456789


However, exercises can be fun.

Try this code:

Code:

WORKING-STORAGE SECTION.                                       
                                                               
01 WS-AFPHANUMERICS.                                           
   02 ALPHA-SET                  PIC X(36)  VALUE               
      '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.                   
                                                               
01 WS-VARIABLES.                                               
   02 WS-COUNTER                 PIC 9(9)   COMP-3             
                                            VALUE 0.           
   02 WS-WORK-COUNTER            PIC 9(9)   COMP-3             
                                            VALUE 0.           
   02 WS-ALPHA-COUNTER           PIC X(10).                     
   02 WS-ZERO                    PIC X(10)  VALUE '         0'.
   02 WS-REM                     PIC 9(2)   COMP-3.             
   02 WS-SUB                     PIC S9(3)  COMP-3.             
   02 WS-LEN                     PIC S9(3)  COMP-3.             

PROCEDURE DIVISION.                                     
                                                         
PROGRAM-START.                                           
                                                         
    PERFORM                                             
      VARYING WS-COUNTER FROM 0 BY 1                     
      UNTIL WS-COUNTER > 100                             
        PERFORM DISPLAY-ALPHA THRU DISPLAY-EXIT         
    END-PERFORM.                                         
                                                         
    MOVE 352765992     TO WS-COUNTER.                   
    PERFORM DISPLAY-ALPHA THRU DISPLAY-EXIT.             
                                                         
    GOBACK.                                             
                                                         
DISPLAY-ALPHA.                                                     
                                                                   
    MOVE WS-COUNTER TO WS-WORK-COUNTER.                           
    MOVE WS-ZERO TO WS-ALPHA-COUNTER.                             
                                                                   
    PERFORM                                                       
      VARYING WS-SUB FROM LENGTH OF WS-ALPHA-COUNTER BY -1         
      UNTIL WS-SUB < 1                                             
      OR WS-WORK-COUNTER = 0                                       
        DIVIDE WS-WORK-COUNTER BY 36 GIVING WS-WORK-COUNTER       
                                  REMAINDER WS-REM                 
        MOVE ALPHA-SET(WS-REM + 1:1)                               
                             TO WS-ALPHA-COUNTER(WS-SUB:1)         
    END-PERFORM.                                                   
                                                                   
    DISPLAY 'WS-COUNTER > : ' WS-COUNTER                           
            ' ALPHA-COUNTER > : ' WS-ALPHA-COUNTER.               
                                                                   
DISPLAY-EXIT.                                                     
    EXIT.


Results are:

Code:

WS-COUNTER > : 000000000 ALPHA-COUNTER > :          0
WS-COUNTER > : 000000001 ALPHA-COUNTER > :          1
WS-COUNTER > : 000000002 ALPHA-COUNTER > :          2
WS-COUNTER > : 000000003 ALPHA-COUNTER > :          3
WS-COUNTER > : 000000004 ALPHA-COUNTER > :          4
WS-COUNTER > : 000000005 ALPHA-COUNTER > :          5
WS-COUNTER > : 000000006 ALPHA-COUNTER > :          6
WS-COUNTER > : 000000007 ALPHA-COUNTER > :          7
WS-COUNTER > : 000000008 ALPHA-COUNTER > :          8
WS-COUNTER > : 000000009 ALPHA-COUNTER > :          9
WS-COUNTER > : 000000010 ALPHA-COUNTER > :          A
WS-COUNTER > : 000000011 ALPHA-COUNTER > :          B
WS-COUNTER > : 000000012 ALPHA-COUNTER > :          C
WS-COUNTER > : 000000013 ALPHA-COUNTER > :          D
WS-COUNTER > : 000000014 ALPHA-COUNTER > :          E
WS-COUNTER > : 000000015 ALPHA-COUNTER > :          F
:
WS-COUNTER > : 000000034 ALPHA-COUNTER > :          Y
WS-COUNTER > : 000000035 ALPHA-COUNTER > :          Z
WS-COUNTER > : 000000036 ALPHA-COUNTER > :         10
WS-COUNTER > : 000000037 ALPHA-COUNTER > :         11
WS-COUNTER > : 000000038 ALPHA-COUNTER > :         12
WS-COUNTER > : 000000039 ALPHA-COUNTER > :         13
WS-COUNTER > : 000000040 ALPHA-COUNTER > :         14
WS-COUNTER > : 000000041 ALPHA-COUNTER > :         15
WS-COUNTER > : 000000042 ALPHA-COUNTER > :         16
WS-COUNTER > : 000000043 ALPHA-COUNTER > :         17
WS-COUNTER > : 000000044 ALPHA-COUNTER > :         18
WS-COUNTER > : 000000045 ALPHA-COUNTER > :         19
WS-COUNTER > : 000000046 ALPHA-COUNTER > :         1A
WS-COUNTER > : 000000047 ALPHA-COUNTER > :         1B
WS-COUNTER > : 000000048 ALPHA-COUNTER > :         1C
:
WS-COUNTER > : 000000069 ALPHA-COUNTER > :         1X
WS-COUNTER > : 000000070 ALPHA-COUNTER > :         1Y
WS-COUNTER > : 000000071 ALPHA-COUNTER > :         1Z
WS-COUNTER > : 000000072 ALPHA-COUNTER > :         20
WS-COUNTER > : 000000073 ALPHA-COUNTER > :         21
WS-COUNTER > : 000000074 ALPHA-COUNTER > :         22
:
WS-COUNTER > : 000000099 ALPHA-COUNTER > :         2R
WS-COUNTER > : 000000100 ALPHA-COUNTER > :         2S
WS-COUNTER > : 352765992 ALPHA-COUNTER > :     5U0ZZC


Dave
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Jul 28, 2006 7:19 pm    Post subject: Re: Increment count using alphanumeric
Reply with quote

Dave you rock man...
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 Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Display FTP Session Count within TSO Yolanda Harvey TSO/ISPF 3 Fri Mar 10, 2017 10:31 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm


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