View previous topic :: View next topic
|
Author |
Message |
lakshmi_p01
New User
Joined: 28 Sep 2005 Posts: 7
|
|
|
|
I have a field which is numeric and of 3 character length. This field is getting generated automatically now. This take value from 0 to 999. So the file can have only 1000 options now. We want to have more number of options for this field so that file can take more number of records. We are converting this field to alphanumeric which is again of 3 characters. It can take from A - Z and 0 - 9 but no special characters. In mainframes since data stores in EBCDIC format A to Z comes before 0 to 9.
So the file can have AAA, AAB,.....,AA0, AA1,.....AA9, ABA,.... ZZZ,000,....999. How to generate this sequence in COBOL?
Kindly help me out.
Thanks in advance for the help.
Regards,
Lakshmi |
|
Back to top |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
Hi Lakshmi,
Its a very intresting piece of requirement but got to use lot of logic, Will tell a logic but i am not sure whether it is possible with cobol, U said that u are begining the series with AAA which is PIC X(3), if u split this variable u would be getting three individual elements, all these individual values would be having a unique ASCII value say for examle 63 for A (Not Sure??), u can increment this value to get the next alphabet i.e.. B (63+1), and once the last character reaches Z there should be a checking crtiteria which would give the next value as 0 (AAZ to AA0) you should also be knowing the ASCII value of number's to code this logic and if u get the end of series like AA9 then the program should consider the second byte from left and increment its ASCII value to make it as ABA then the series would follow till AB9 till 999, I have not tried to use the ASCII register to code COBOL program's but i know that it can be done in C language , If you could find some way to code this logic in COBOL please let us know
Cheer's,
Thamilzan. |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Please check this one.
working-storage section.
01 a pic x(3) value "AAA".
01 b pic x value spaces.
01 c pic x value spaces.
01 d pic x value spaces.
01 m.
02 n occurs 3 times.
03 ws-temp pic x.
01 i pic 99 value 0.
procedure division.
p1.
move a to m.
display m.
p2.
move ws-temp(3) to b.
if b not = 9
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A"
move b to ws-temp(3)
else
move ws-temp(2) to c
inspect c converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A"
move c to ws-temp(2)
move "A" to ws-temp(3).
if ws-temp(2) = 9 and ws-temp(3) = 9
display m
move ws-temp(1) to d
inspect d converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A"
move d to ws-temp(1)
move "A" to ws-temp(2) ws-temp(3).
display m.
go to p2.
Aji Cherian |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
lakshmi_p01 wrote: |
How to generate this sequence in COBOL? |
Thank you, this one will keep me thinking all day, I'll be back if I come up with anything elegant. |
|
Back to top |
|
|
shaikmf
New User
Joined: 06 May 2005 Posts: 3 Location: Hyderabad
|
|
|
|
Aji,
Good solution. |
|
Back to top |
|
|
sandeep1dimri
New User
Joined: 30 Oct 2006 Posts: 76
|
|
|
|
Hi
Check this pseudo code
Array 1 : ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
ARRAY 2 : ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
ARRAY 3 : ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
NESTED PERFORM
perform 36 times (i.e on ARRAY1)-- COUNT-1
PERFORM 36 TIMES ON ARRAY 2---- cOUNT2
PERFORM 36 TIMES ON ARRAY 3 --- COUNT3
STRING ARRAY1(COUNT1)
ARRAY1(COUNT2)
ARRAY1(COUNT3) IN WS-SEQ
dISPAY WS-SEQ
END-PERFORM
END-PERFORM
END-PERFORM
SO WE ARE ONLY LEFT WITH COUNTING 1 TO 999
thats just a addition
Please let me know if u stuck while implementation.
Sandeep |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
sandeep1dimri wrote: |
Array 1 : ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
ARRAY 2 : ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
ARRAY 3 : ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
NESTED PERFORM
Code: |
perform 36 times (i.e on ARRAY1)-- COUNT-1
PERFORM 36 TIMES ON ARRAY 2---- cOUNT2
PERFORM 36 TIMES ON ARRAY 3 --- COUNT3
STRING ARRAY1(COUNT1)
ARRAY1(COUNT2)
ARRAY1(COUNT3) IN WS-SEQ
dISPAY WS-SEQ
END-PERFORM
END-PERFORM
END-PERFORM |
SO WE ARE ONLY LEFT WITH COUNTING 1 TO 999 |
You only need one array.
How would you handle a situation where you have the prior sequence number and need to generate the next one? Like given "D8K", how would you generate "D8L"? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
lakshmi_p01 wrote: |
I have a field which is numeric and of 3 character length. This field is getting generated automatically now. This take value from 0 to 999. So the file can have only 1000 options now. We want to have more number of options for this field so that file can take more number of records. We are converting this field to alphanumeric which is again of 3 characters. It can take from A - Z and 0 - 9 but no special characters. In mainframes since data stores in EBCDIC format A to Z comes before 0 to 9.
So the file can have AAA, AAB,.....,AA0, AA1,.....AA9, ABA,.... ZZZ,000,....999. |
If the sequence already exists, wouldn't you want 001...999, 99A...99Z, 9A0...9AZ and so on? |
|
Back to top |
|
|
sandeep1dimri
New User
Joined: 30 Oct 2006 Posts: 76
|
|
|
|
Hi William
yeah we can do with the one array that though came to me while i left the day!!!
How would you handle a situation where you have the prior sequence number and need to generate the next one? Like given "D8K", how would you generate "D8L"?
hi i think it will also come up for ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
and third qualifier will just proceed with K then L then ------ upto 9
so it will generate all
Please let me know if it still have logical problem
sandeep |
|
Back to top |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
Aji wrote: |
Please check this one.
working-storage section.
01 a pic x(3) value "AAA".
01 b pic x value spaces.
01 c pic x value spaces.
01 d pic x value spaces.
01 m.
02 n occurs 3 times.
03 ws-temp pic x.
01 i pic 99 value 0.
procedure division.
p1.
move a to m.
display m.
p2.
move ws-temp(3) to b.
if b not = 9
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A"
move b to ws-temp(3)
else
move ws-temp(2) to c
inspect c converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A"
move c to ws-temp(2)
move "A" to ws-temp(3).
if ws-temp(2) = 9 and ws-temp(3) = 9
display m
move ws-temp(1) to d
inspect d converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A"
move d to ws-temp(1)
move "A" to ws-temp(2) ws-temp(3).
display m.
go to p2.
Aji Cherian |
Would you please explain me what does the below statment do exactly.
INSPECT B CONVERTING
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" TO
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A" |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
I have made some changes in the previous code. But it functions like the earlier one.
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A".
In the above case if the value of b is "A" after 'inspect' b becomes "B"
Similarly if b is "Z" after 'inspect' b becomes "0".
working-storage section.
01 a pic x(3) value "AAA".
01 b pic x value spaces.
01 m.
02 n occurs 3 times.
03 ws-temp pic x.
procedure division.
p1.
move a to m.
display m.
perform p2 thru p-exit.
stop run.
p2.
move ws-temp(3) to b.
if b not = 9
perform c-para
move b to ws-temp(3)
else
move ws-temp(2) to b
perform c-para
move b to ws-temp(2)
move "A" to ws-temp(3)
end-if.
if ws-temp(2) = 9 and ws-temp(3) = 9
display m
if m = 999
go to p-exit
end-if
move ws-temp(1) to b
perform c-para
move b to ws-temp(1)
move "A" to ws-temp(2) ws-temp(3)
end-if.
display m.
go to p2.
c-para.
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A".
p-exit.
exit.
Aji Cherian |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Aji,
Your code would be much more readable if you wrapped it with "code". That will retain the indent spaces. |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Thanks for the suggestion William.
Aji Cherian
Code: |
working-storage section.
01 a pic x(3) value "AAA".
01 b pic x value spaces.
01 m.
02 n occurs 3 times.
03 ws-temp pic x.
procedure division.
p1.
move a to m.
display m.
perform p2 thru p-exit.
stop run.
p2.
move ws-temp(3) to b.
if b not = 9
perform c-para
move b to ws-temp(3)
else
move ws-temp(2) to b
perform c-para
move b to ws-temp(2)
move "A" to ws-temp(3)
end-if.
if ws-temp(2) = 9 and ws-temp(3) = 9
display m
if m = 999
go to p-exit
end-if
move ws-temp(1) to b
perform c-para
move b to ws-temp(1)
move "A" to ws-temp(2) ws-temp(3)
end-if.
display m.
go to p2.
c-para.
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A".
p-exit.
exit.
|
|
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Aji wrote: |
I have made some changes in the previous code. But it functions like the earlier one.
Code: |
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A". |
In the above case if the value of b is "A" after 'inspect' b becomes "B"
Similarly if b is "Z" after 'inspect' b becomes "0".
Code: |
working-storage section.
01 a pic x(3) value "AAA".
01 b pic x value spaces.
01 m.
02 n occurs 3 times.
03 ws-temp pic x.
procedure division.
p1.
move a to m.
display m.
perform p2 thru p-exit.
stop run.
p2.
move ws-temp(3) to b.
if b not = 9
perform c-para
move b to ws-temp(3)
else
move ws-temp(2) to b
perform c-para
move b to ws-temp(2)
move "A" to ws-temp(3)
end-if.
if ws-temp(2) = 9 and ws-temp(3) = 9
display m
if m = 999
go to p-exit
end-if
move ws-temp(1) to b
perform c-para
move b to ws-temp(1)
move "A" to ws-temp(2) ws-temp(3)
end-if.
display m.
go to p2.
c-para.
inspect b converting
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" to
"BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789A".
p-exit.
exit. |
Aji Cherian |
|
|
Back to top |
|
|
|