IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Incrementation of Alphanumeric value.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Tue Jun 22, 2010 9:21 am
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: 6966
Location: porcelain throne

PostPosted: Tue Jun 22, 2010 12:41 pm
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
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
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: 6966
Location: porcelain throne

PostPosted: Tue Jun 22, 2010 6:11 pm
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
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: 6966
Location: porcelain throne

PostPosted: Tue Jun 22, 2010 8:43 pm
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
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: 6966
Location: porcelain throne

PostPosted: Wed Jun 23, 2010 5:03 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
No new posts Packed decimal to Alphanumeric COBOL Programming 2
No new posts Alphanumeric to Packed Decimal Conver... COBOL Programming 2
This topic is locked: you cannot edit posts or make replies. Can a alphanumeric data be moved to a... COBOL Programming 10
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... COBOL Programming 8
Search our Forums:

Back to Top