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
 

 

Incrementation of Alphanumeric value.

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

New User


Joined: 16 Oct 2006
Posts: 80
Location: chennai

PostPosted: Tue Jun 22, 2010 9:21 am    Post subject: Incrementation of Alphanumeric value.
Reply with quote

Hi,

I have one requirement that how to increment the value by using COBOL program. Example:

i have a value like 'A0001' with PIC X(5). Need to increase this value from A0001 --> A0002,A0003,A0004 up to A9999 and then next increase by B0000,B0001,B0002 up to B9999 and this sequence will continue up to Z9999 and then stop.

A0001
A0002
.
.
.
A9999
B0000
B0001
B0002
.
.
.
B9999
C0000
C0001
.
.
.
C9999
.
.
.
Z0000
Z0001
.
.
.
Z9999

please help me anybody to write a code in COBOL. i am using Enterprise COBOL.

Thanks,
Nath.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Jun 22, 2010 12:41 pm    Post subject:
Reply with quote

normally I would say,
'what have you accomplished'.

Today you get a freebie; you only have to debug it.

Code:

05  ws-var   pic x(05) value 'A0000'
05  redef
     redefines
     ws-var.
     10  first-char pic x(01).
     10  last-four  pic 9(04).

05  alphabet   pic x(26) value 'ABCDEFGHIHKLMNOPQRSTUVWXYZ'.
05  ws-tab
      redefines
      alphabet.
      10  ws-letter occurs 26 times
                          indexed by alpha-idx
                          pic x(01).
.....


PERFORM VARYING alpha-idx
               FROM 1
                   BY 1
              UNTIL alpha-idx > 26
    move ws-letter(alpha-idx) to first-char
    PERFORM VARYING LAST-FOUR
                         FROM 0
                          BY   1
                    UNTIL LAST-FOUR = 9999
        WITH TEST AFTER
    END-PERFORM
END-PERFORM
Back to top
View user's profile Send private message
ESSPRABHU

New User


Joined: 11 Oct 2005
Posts: 22

PostPosted: Tue Jun 22, 2010 3:24 pm    Post subject: Reply to: Incrementation of Alphanumeric value.
Reply with quote

Guha,

Try this. It's a pseudo code. You have to develop it.

01 ALPH-VAR PIC X(26) VALUE 'ABc............XYZ'.

01 GROUP-VAR PIC X(5).
05 ALPH PIC X(1).
05 NUMB-VAR PIC 9(4).

PERFORM PARA-1 VARYING I 0 BY 1 UNITL I>26
VARYING J 1 BY 1 UNTIL J>9999


PARA-1.

MOVE ALPH-VAR(I+1:1) TO ALPH
MOVE J TO NUMB-VAR

END.
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Tue Jun 22, 2010 5:59 pm    Post subject:
Reply with quote

Hi Dick,
That's very small and effective solution....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Jun 22, 2010 6:11 pm    Post subject:
Reply with quote

Ketan,
I provided mine to exhibit the BEFORE/AFTER TEST clause

although,
ESSPRABHU's solution also works
as well as showing the ability to utilize a 'double' VARYING

with a slight correction
PERFORM PARA-1 VARYING I FROM 0 BY 1 UNITL I>25
AFTER VARYING J FROM 1 BY 1 UNTIL J>9999
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Jun 22, 2010 7:20 pm    Post subject:
Reply with quote

varying i from 1 by 1 until i > 26999 in combination with DIVIDE REMAINDER is also an option
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Tue Jun 22, 2010 8:43 pm    Post subject:
Reply with quote

a correction to my last post:

instead of
AFTER VARYING J FROM 1 BY 1 UNTIL J>9999

SB:
AFTER VARYING J FROM 0 BY 1 UNTIL J>9999


GuyC,

ok, I will bite. could you explain you post, please.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Jun 23, 2010 4:55 pm    Post subject:
Reply with quote

Code:
perform varying X from 1 by 1 until X > 26999
    divide X by 10000 giving I remainder J
...
end-perform

is identical to
Code:
PERFORM VARYING I FROM 1 BY 1 UNTIL I>26
AFTER VARYING J FROM 0 BY 1 UNTIL J>9999
   compute X = I * 10000 + J
   ...
END-PERFORM

This could be useful when you also need / start from a normal sequence number.
for example : TablePartnr = 3096 => VSAM = **.C096
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Jun 23, 2010 5:03 pm    Post subject:
Reply with quote

thx for the explanation,
but I continue to be a dummy,
and don't understand where do you derive the alpha A thru Z for the first character.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jun 28, 2010 2:16 pm    Post subject:
Reply with quote

same way as in your/ESSPRABHU post : ws-letter(i+1) or ALPH-VAR(I+1:1)
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
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts alphanumeric sequence generation sivaprasad.gadhi COBOL Programming 6 Wed Mar 30, 2016 3:03 am
No new posts alphanumeric sequence generation sivaprasad.gadhi DFSORT/ICETOOL 8 Mon Mar 21, 2016 1:09 am
No new posts To determine the range on a Alphanume... Prasanth Kumar COBOL Programming 3 Mon Feb 15, 2016 9:35 am


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