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

About Linked Lists in Cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 2:36 am
Reply with quote

Hello everyone,

first I've got to ask for your forgiveness. I've just startet with Cobol and I come from Java, C++ and C# (oop). So also I have some problems with variable - and programmingstructur.

Now that I have figurt out the base rules of programming Cobol I would like to code a linked list. Unfortunately there are only some Cobol code snippets in the www. But to understand the whole code I need a complete implementation of a linked list.

So I know its overcharged for you, but I would like to ask you for it. It would help me a lot.

Thanks f?r your supporting.

with Greetings from germany

Rene
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu May 10, 2007 3:07 am
Reply with quote

Hello and welcome to the forums icon_smile.gif

If you'll provide some detail about what you want, we will probably be able to offer suggestions.

What kind of linked-list are you looking for? The 2 types i've worked with are bi-directional and forward-only.

What kind of requirement are you working on? If you show some sample data and how you want it linked and how you want to process it after it is linked, we'll be happy to help.
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 11:41 am
Reply with quote

Hi,

thank you for your fast help.

I have some problems with variable constructions. For example in C you make a struct an creating intances of a variable. How can I make the same in Cobol? Of course Cobol doesnt know any kinds of variable instances, so how can I realize a simple linked list ... (forewarded linked list)?

greetings

Rene
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu May 10, 2007 1:50 pm
Reply with quote

Dynamic allocation in COBOL, like malloc or new in C?
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 2:50 pm
Reply with quote

I don't know it exactly. I have to use ANSI Cobol85 so if there is a posibility to use dynamic allocatet memory i want to try it. Otherwise I have to use declarated variables.

For example, I want to code a forwarded linked list with 4 members?

How das this look? (I just mean declaration of variables and building up the list - no functions like Insert or delete)

Thank you

greetings

Rene
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 3:01 pm
Reply with quote

sry ... bad english ... declareted means declared .... *arg*
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu May 10, 2007 3:22 pm
Reply with quote

I have known about COBOL LE function CEEGTST that "gets heaps of storage" and CEEFRST that "frees the storage". I never used it, but you can search more on them.
Array implementation for linklist will be much easier i guess..
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 3:24 pm
Reply with quote

So how would an array implementation work ?? ...
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu May 10, 2007 4:31 pm
Reply with quote

Are you aware of OCCURS and OCCURS DEPENDING ON in COBOL?
It should work like C implementation..

You define a structure with OCCURS..
01 index-var pic 9.
01 linklist.
05 cobol-struct occurs 5 times.
10 indiactor-var 9(01).
10 var1 x(05).
10 var2 x(05).
10 var3 9(05).

And you can control the linklist operations INSERT, DELETE using indiactor-var and index-var.
Indiacator-var should identify next valid occurence number and index-var can be used to access a particualr node.
This is vary crude picture which came to my mind at this time, there can be more efficient method too.. Need to here from you now.. icon_smile.gif
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 4:47 pm
Reply with quote

Thank you for your support, but this isnt exactly what I am looking for. I would like to use pointers to create a linked list ... C or C++ style.

bye

Rene
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Thu May 10, 2007 6:41 pm
Reply with quote

ReneBeck,

Below I have pasted an example that my buddy sent me. I think he snagged it off the internet. I forget where it come from. I remember testing it and finding a bug so hopefully the version below includes my fix. I think it does but beware.

Note that the version below uses embedded sub-programs but this is not necessary. The version below uses CEEGTST to dynamically allocate memory and is probably closer to what you are looking for. Not that CEEGTST can be issued from within CICS or batch.

As well, beware if you intend to do this from within a CICS transaction. The memory allocated by CEEGTST will not persist until task termination, as would be the case with CICS GETMAIN. Storage acquired by CEEGTST will be release automatically when the run unit collapses - or of course when you explicitly release it yourself.


000001*MODULE/FILE NAME: LINKLST
000002***************************************************
000003** **
000004** DEMONSTRATION FOR LINKED LIST HANDLING **
000005** **
000006***************************************************
000007 IDENTIFICATION DIVISION.
000008 PROGRAM-ID. RH3B89.
000009 DATA DIVISION.
000010 WORKING-STORAGE SECTION.
000011 01 RET-CDE PIC 9(3).
000012 01 HEAD-OF-LIST POINTER.
000013 LINKAGE SECTION.
000014 01 LINK GLOBAL.
000015 02 DATA-PART PIC 9(4).
000016 02 NEXT-PTR POINTER.
000017 PROCEDURE DIVISION.

000018 CALL "BULDLST" USING HEAD-OF-LIST,
000019 RET-CDE
000020 IF RET-CDE = ZERO THEN
000021 CALL "SHOWLST" USING HEAD-OF-LIST
000022 CALL "FREELST" USING HEAD-OF-LIST
000023 IF HEAD-OF-LIST = NULL THEN
000024 DISPLAY "LIST HAS BEEN FREED."
000025 END-IF
000026 END-IF
000027 GOBACK
000028 .
000029


IDENTIFICATION DIVISION.
PROGRAM-ID BULDLST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 9(4).
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING HEAD-OF-LIST, RET-CDE.
MAINLINE SECTION.
CALL "MEMALOC" USING BY REFERENCE HEAD-OF-LIST,
BY CONTENT LENGTH OF LINK,
BY REFERENCE RET-CDE
IF RET-CDE = ZERO THEN
SET ADDRESS OF LINK TO HEAD-OF-LIST
PERFORM VARYING I FROM 1 BY 1
UNTIL I > 4
OR RET-CDE > ZERO
MOVE I TO DATA-PART OF LINK
CALL "MEMALOC" USING BY REFERENCE NEXT-PTR OF LINK,
BY CONTENT LENGTH OF LINK,
BY REFERENCE RET-CDE
IF RET-CDE = ZERO THEN
SET ADDRESS OF LINK TO NEXT-PTR OF LINK
END-IF
END-PERFORM
IF RET-CDE = ZERO THEN
MOVE I TO DATA-PART OF LINK
SET NEXT-PTR OF LINK TO NULL
END-IF
END-IF
GOBACK
.
END PROGRAM BULDLST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID SHOWLST.
DATA DIVISION.
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
PROCEDURE DIVISION USING HEAD-OF-LIST.
MAINLINE SECTION.
SET ADDRESS OF LINK TO HEAD-OF-LIST
PERFORM UNTIL ADDRESS OF LINK = NULL
DISPLAY DATA-PART
SET ADDRESS OF LINK TO NEXT-PTR OF LINK
END-PERFORM
GOBACK
.
END PROGRAM SHOWLST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID FREELST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NXT-PTR POINTER.
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
PROCEDURE DIVISION USING HEAD-OF-LIST.
MAINLINE SECTION.
PERFORM UNTIL HEAD-OF-LIST = NULL
SET ADDRESS OF LINK TO HEAD-OF-LIST
SET NXT-PTR TO NEXT-PTR OF LINK
CALL "MEMFREE" USING HEAD-OF-LIST
SET HEAD-OF-LIST TO NXT-PTR
END-PERFORM
GOBACK
.
END PROGRAM FREELST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID MEMALOC COMMON PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEAPID PIC S9(9) BINARY.
01 FC.
02 CONDITION-TOKEN-VALUE.
COPY CEEIGZCT.
03 CASE-1-CONDITION-ID.
04 SEVERITY PIC S9(4) BINARY.
04 MSG-NO PIC S9(4) BINARY.
03 CASE-2-CONDITION-ID
REDEFINES CASE-1-CONDITION-ID.
04 CLASS-CODE PIC S9(4) BINARY.
04 CAUSE-CODE PIC S9(4) BINARY.
03 CASE-SEV-CTL PIC X.
03 FACILITY-ID PIC XXX.
02 I-S-INFO PIC S9(9) BINARY.
LINKAGE SECTION.
01 PTR-TO-MEM POINTER.
01 NBR-OF-BYTES PIC S9(9) BINARY.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING PTR-TO-MEM, NBR-OF-BYTES, RET-CDE.
MOVE 0 TO HEAPID
CALL "CEEGTST" USING HEAPID,
NBR-OF-BYTES,
PTR-TO-MEM,
FC
IF CEE000 OF FC THEN
MOVE ZERO TO RET-CDE
ELSE
DISPLAY "CEEGTST FAILED WITH: " MSG-NO OF FC
MOVE 1 TO RET-CDE
SET PTR-TO-MEM TO NULL
END-IF
GOBACK.
END PROGRAM MEMALOC.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID MEMFREE COMMON PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEAPID PIC S9(9) BINARY.
01 FC.
02 CONDITION-TOKEN-VALUE.
COPY CEEIGZCT.
03 CASE-1-CONDITION-ID.
04 SEVERITY PIC S9(4) BINARY.
04 MSG-NO PIC S9(4) BINARY.
03 CASE-2-CONDITION-ID
REDEFINES CASE-1-CONDITION-ID.
04 CLASS-CODE PIC S9(4) BINARY.
04 CAUSE-CODE PIC S9(4) BINARY.
03 CASE-SEV-CTL PIC X.
03 FACILITY-ID PIC XXX.
02 I-S-INFO PIC S9(9) BINARY.
LINKAGE SECTION.
01 PTR-TO-MEM POINTER.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING PTR-TO-MEM, RET-CDE.
MOVE 0 TO HEAPID
CALL "CEEFRST" USING PTR-TO-MEM,
FC
IF CEE000 OF FC THEN
MOVE ZERO TO RET-CDE
ELSE
DISPLAY "CEEFRST FAILED WITH: " MSG-NO OF FC
MOVE 1 TO RET-CDE
END-IF
GOBACK.
END PROGRAM MEMFREE.
END PROGRAM RH3B89.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu May 10, 2007 6:58 pm
Reply with quote

Have you looked at CEEGTST in LE as per may previous post?
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu May 10, 2007 7:01 pm
Reply with quote

OK, TG Murphy has given you a program.
Thanks TG icon_biggrin.gif
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 7:07 pm
Reply with quote

Thank you! ... This comes quit close to what Im looking fot! ...
Back to top
View user's profile Send private message
ReneBeck

New User


Joined: 09 May 2007
Posts: 8
Location: Germany

PostPosted: Thu May 10, 2007 7:10 pm
Reply with quote

fot = for ...
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu May 10, 2007 9:23 pm
Reply with quote

Hello Rene,

Quote:
fot = for ...


I hate it when the keyboard does that icon_smile.gif Always seem to notice it after clicking "submit". . .

Looks like you've got what you need to progress.

We're here when there are new "opportunities" with COBOL, JCL, etc icon_smile.gif
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Fri May 11, 2007 8:52 pm
Reply with quote

Sorry... Correction needed.

I wrote:

Not that CEEGTST can be issued from within CICS or batch.

I really meant....

Note that ....
Back to top
View user's profile Send private message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 18

PostPosted: Tue May 15, 2007 5:34 pm
Reply with quote

Hello Rene,

I would like to request you to have a look on the following link:

home.swbell.net/mck9/cobol/tech/struct.html

Please explore to the "Linked list" link in that page. It may give you some helpful information.

Some days before i was trying to develope an OOPS cobol program. But could not complete. In the above given link you can get usage of POINTER in COBOL.

Regards,
Amiya.

ReneBeck wrote:
Thank you! ... This comes quit close to what Im looking fot! ...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top