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
 

 

Generating sequence numbers in COBOL

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

New User


Joined: 28 Sep 2005
Posts: 7

PostPosted: Tue Jan 23, 2007 10:12 am    Post subject: Generating sequence numbers in COBOL
Reply with quote

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
View user's profile Send private message

prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Tue Jan 23, 2007 3:12 pm    Post subject:
Reply with quote

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 icon_biggrin.gif

Cheer's,
Thamilzan.
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Tue Jan 23, 2007 3:42 pm    Post subject: Re: Generating sequence numbers in COBOL
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Jan 23, 2007 4:01 pm    Post subject: Re: Generating sequence numbers in COBOL
Reply with quote

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
View user's profile Send private message
shaikmf

New User


Joined: 06 May 2005
Posts: 3
Location: Hyderabad

PostPosted: Tue Jan 23, 2007 7:21 pm    Post subject: Good sol.
Reply with quote

Aji,

Good solution.
Back to top
View user's profile Send private message
sandeep1dimri

New User


Joined: 30 Oct 2006
Posts: 76

PostPosted: Tue Jan 23, 2007 7:32 pm    Post subject:
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Jan 23, 2007 7:43 pm    Post subject:
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Jan 23, 2007 7:46 pm    Post subject: Re: Generating sequence numbers in COBOL
Reply with quote

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
View user's profile Send private message
sandeep1dimri

New User


Joined: 30 Oct 2006
Posts: 76

PostPosted: Wed Jan 24, 2007 10:54 am    Post subject:
Reply with quote

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
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 95
Location: India

PostPosted: Wed Jan 24, 2007 4:24 pm    Post subject: Re: Generating sequence numbers in COBOL
Reply with quote

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
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Wed Jan 24, 2007 4:37 pm    Post subject:
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed Jan 24, 2007 4:41 pm    Post subject:
Reply with quote

Aji,
Your code would be much more readable if you wrapped it with "code". That will retain the indent spaces.
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Wed Jan 24, 2007 4:47 pm    Post subject:
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed Jan 24, 2007 4:51 pm    Post subject:
Reply with quote

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
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 XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm


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