View previous topic :: View next topic
|
Author |
Message |
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
ESSPRABHU
New User
Joined: 11 Oct 2005 Posts: 22
|
|
|
|
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 |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi Dick,
That's very small and effective solution.... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
varying i from 1 by 1 until i > 26999 in combination with DIVIDE REMAINDER is also an option |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
same way as in your/ESSPRABHU post : ws-letter(i+1) or ALPH-VAR(I+1:1) |
|
Back to top |
|
|
|