Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
POINTERS concepts in COBOL

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

Active User


Joined: 22 Aug 2005
Posts: 413
Location: Colarado, US

PostPosted: Tue Nov 22, 2005 8:26 pm    Post subject: POINTERS concepts in COBOL
Reply with quote

Hi folks,

Can anyone tell me whether COBOL supports POINTERS concepts. Please give me a clear explanation on how to achieve the same.
Back to top
View user's profile Send private message

priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Tue Nov 22, 2005 10:21 pm    Post subject:
Reply with quote

Yes, Cobol supports pointers as USAGE clause.

example:

01 A USAGE POINTER VALUE NULL.

01 B USAGE PONTER VALUE ADDRESS OF A.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Wed Nov 23, 2005 11:12 am    Post subject: Pointers in COBOL
Reply with quote

Hi frnd,
i too thought of asking this query. how is it possible in accepting and manipulating. can u give me one example plz. since in C v will b using like '&' to refer the address and '*' for the value so as like that in COBOL how can v access those pointer values in that. and Pointer array also.
Back to top
View user's profile Send private message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Tue Nov 29, 2005 8:38 pm    Post subject:
Reply with quote

Pointer declaration
The concept of pointer was introduced along with COBOL-II. We can declare a pointer variable in COBOL II using the following working storage declaration:

05 WS-POINTER-VAR USAGE IS POINTER.

This will declare WS-POINTER-VAR as a four-byte field with can store address of any data item.

Setting addressability
A pointer variable ponts to nothing until unless we set it to point to some group or elementary element of LINKAGE SECTION. Below is an example which show you how we can point to an group element using pointer.

Example:
LINKAGE SECTION.

01 NAME-STRUCTURE.
05 FIRST-NAME PIC X(15).
05 SECOND-NAME PIC X(15).

Now in procedure division using following statement to set the addressability:

SET WS-POINTER-VAR TO ADDRESS OF NAME-STRUCTURE.

Note: A pointer variable can point to only LINKAGE SECTION elements.

Dereferencing a Pointer Variable

Suppose we have a pointer variable with us, say WS-POINTER-1, which points to an object(memory) having structure same as NAME-STRUCTURE declared above. Now in order to use the object pointed by the pointer variable we have to first dereference this pointer variable. Which can be done as shown below:

SET ADDRESS OF NAME-STRUCTURE TO WS-POINTER-1.

Once this has been done we can use NAME-STRUCTURE as normal variable and we will be actually working on the object pointed by the pointer WS-POINTER-1.

NOTE: Pointers can be passed as parameter to sub-programs which can then dereference it and can work on the actual object pointed by the pointer.

Some more stuff

NULL is a special pointer which points to nothing. We can set a pointer variable to NULL.
For example:

SET WS-POINTER-1 TO NULL.

We can also compare a ponter variable with another pointer variable or with NULL.
For example:

IF WS-POINTER-VAR NOT = NULL THEN
IF WS-POINTER-VAR = WS-POINTER-1 THEN
-----------------------
------------------------
END-IF
END-IF.

I hope this stuff would clear the concept of pointers in COBOL to some extent to you.

Please feal free to ask more or to share your knowledge with me.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Wed Nov 30, 2005 11:23 am    Post subject: pointers in COBOL
Reply with quote

hi frnd,
thank u verymuch. let me try and inform u if i face any problem
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 413
Location: Colarado, US

PostPosted: Wed Nov 30, 2005 10:27 pm    Post subject: Re: Whether COBOL supports POINTERS concepts
Reply with quote

Hi All,

Thanks for your reply.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Wed Nov 30, 2005 10:33 pm    Post subject: Re: Whether COBOL supports POINTERS concepts
Reply with quote

I found this link for pointers in COBOL.

http://home.swbell.net/mck9/cobol/tech/cobolptr.html

Regards,

Priyesh.
Back to top
View user's profile Send private message
Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Thu Dec 01, 2005 10:37 am    Post subject:
Reply with quote

Hi Friends,

Good work done by you all.

Till now I thought Pointer concept is not there in COBOL.

Umesh & priyesh Thanks a lot for your detailed explanation and for the link.
Back to top
View user's profile Send private message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Thu Dec 01, 2005 11:21 am    Post subject:
Reply with quote

Thanks Hames and other members for these words of appreciation.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Dec 02, 2005 7:32 am    Post subject:
Reply with quote

Late again to the party icon_redface.gif , but here's something I wrote a while back that uses the pointer concept to access system cntl blks.
Code:

       CBL LIST,NOOFF
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    RUNINFO.
       AUTHOR.        JACK SLEIGHT.
       ENVIRONMENT DIVISION.
      ****************************************************************
      *  DISPLAYS THE FOLLOWING RUN INFO FOR THE CALLING PROGRAM:    *
      *                                                              *
      *       *   PGM/JOB/JOBSTEP/PROCSTEP NAMES                     *
      *       *   ENTRY/LOAD/END POINTS AND LENGTH OF PROGRAM        *
      *                                                              *
      *  FOR COBOL II PROGRAMS ALSO DISPLAYS 4 BYTES OF HEX INDICAT- *
      *  ORS SHOWING THE COMPILE OPTIONS SELECTED AT COMPILE TIME.   *
      ****************************************************************

       CONFIGURATION                   SECTION.
       SOURCE-COMPUTER. IBM-370.
       OBJECT-COMPUTER. IBM-370.
       DATA DIVISION.
       FILE SECTION.

      ****************************************************************
       WORKING-STORAGE                 SECTION.
      ****************************************************************

       01  WS-TCB-ADDR-01.
           10  WS-TCB-ADDR             POINTER.

       01  WS-CVT-ADDR-01.
           10  WS-CVT-ADDR             POINTER.

      ****************************************************************
       01  WS-DISPLAY-FIELDS.
      ****************************************************************
           10  WS-PN-DISPLAY           PIC X(008).
           10  WS-STEP-DISPLAY.
               20 WS-JSTP-NAME         PIC X(008) VALUE "NOT USED".
               20 FILLER               PIC X(001) VALUE "/".
               20 WS-PSTP-NAME         PIC X(008) VALUE "NOT USED".

           10  WS-CTYPE-DISPLAY        PIC X(002).
           10  WS-CREL-DISPLAY         PIC X(005).
           10  WS-CTIME-DISPLAY        PIC X(008).
           10  WS-OPTBYTE-DISPLAY      PIC X(008).

           10  WS-CDATE-DISPLAY        PIC X(012).
           10  REDEFINES WS-CDATE-DISPLAY.
           15  WS-CDATE-DISPLAY-RED.
               20 WS-VSMO-DAY-DISPLAY  PIC X(008).
               20 WS-VSYEAR-DISPLAY    PIC X(004).

           10  WS-EP-DISPLAY           PIC X(008).
           10  WS-LP-DISPLAY           PIC X(008).
           10  WS-FP-DISPLAY           PIC X(008).
           10  WS-LEN-DISPLAY          PIC X(008).

      ****************************************************************
       01  WS-WORK-FIELDS.
      ****************************************************************

           05  WS-ZERO                 PIC 9(009) VALUE 0     COMP.
           05  WS-WORK-FP              PIC 9(009)             COMP.

           05  WS-WORK-PACKED          PIC 9(009)             COMP-3.
           05  REDEFINES WS-WORK-PACKED.
           10  WS-WORK-X5.
               20  WS-WORK-X1          PIC X(001).
               20  WS-WORK-X3          PIC X(003).
           05  REDEFINES WS-WORK-PACKED.
           10  WS-WORK-BIN4            PIC 9(009)     COMP.

           05  WS-WORK-UNPACKED        PIC 9(009).
           05  REDEFINES WS-WORK-UNPACKED.
           10  WS-WORK-UNPACKED-8      PIC 9(008).
1     /
      ****************************************************************
       LINKAGE                         SECTION.
      ****************************************************************

       01  LK-TCB-ADDR                 POINTER.

      *--------------------------------------------------------------
      *===> T A S K   C O N T R O L   B L O C K
      *--------------------------------------------------------------
       01  LK-TCB.
           10  FILLER                  PIC X(012).
           10  LK-TIOT-ADDR            POINTER.
           10  FILLER                  PIC X(028).
           10  LK-LAST-CDE-ADDR        POINTER.

      *--------------------------------------------------------------
      *===>     T A S K   I/O   T A B L E
      *--------------------------------------------------------------
       01  LK-TIOT.
           10  LK-JOB-NAME             PIC X(008).
           10  LK-JSTP-NAME            PIC X(008).
           10 LK-PSTP-NAME             PIC X(008).

      *--------------------------------------------------------------
      *===> C O N T E N T S    D I R E C T O R Y    E N T R Y
      *--------------------------------------------------------------
       01  LK-CDE.
           10  LK-PREV-CDE-ADDR        POINTER.
           10  FILLER                  PIC X(004).
           10  LK-PGM-NAME             PIC X(008).
           10  LK-EP-ADDR              PIC X(004).
           10  LK-EXTENT-LST-ADDR      POINTER.

      *--------------------------------------------------------------
      *===>         E X T E N T    L I S T
      *--------------------------------------------------------------
       01  LK-EXTENT-LST.
           10  FILLER                  PIC X(009).
           10  LK-PGM-LEN              PIC X(003).
           10  LK-LP-ADDR              PIC X(004).
           10  REDEFINES  LK-LP-ADDR.
           15  LK-LP-ADDR-BIN          PIC 9(009) COMP.
           10  REDEFINES  LK-LP-ADDR.
           15  LK-LP-ADDR-PTR          POINTER.

      ****************************************************************
       01  LK-COMPILER-INFO.
      ****************************************************************
           05  LK-VSCOB-INFO.
               10 FILLER               PIC X(020).
               10 LK-TYPE-VS           PIC X(002).
                  88 LK-VSCOBOL                     VALUE "VS".
               10 FILLER               PIC X(001).
               10 LK-VSREL-NBR         PIC X(001).
               10 FILLER               PIC X(112).
               10 LK-VSTIME            PIC X(008).
               10 LK-VSMO-DAY          PIC X(008).
               10 LK-VSYEAR            PIC X(004).
           05  REDEFINES  LK-VSCOB-INFO.
           10  LK-COBII-INFO.
               20 FILLER               PIC X(014).
               20 LK-TYPE-II           PIC X(002).
               20 FILLER               PIC X(001).
               20 LK-IIREL-NBR         PIC X(006).
               20 LK-IIMON-DAY-YR      PIC X(009).
               20 LK-IITIME            PIC X(008).
               20 FILLER               PIC X(004).
               20 LK-IIOPT-BYTES       PIC X(004).
1     /

      ****************************************************************
       PROCEDURE DIVISION.
      ****************************************************************

       000-MAINLINE.

      *--------------------------------------------------------------
      *===>  ESTABLISH ADDRESSABILITY FOR TIOT
      *--------------------------------------------------------------

           MOVE            X"0000021C" TO  WS-TCB-ADDR-01
           SET  ADDRESS OF LK-TCB-ADDR TO  WS-TCB-ADDR
           SET  ADDRESS OF LK-TCB      TO  LK-TCB-ADDR
           SET  ADDRESS OF LK-TIOT     TO  LK-TIOT-ADDR

      *--------------------------------------------------------------
      *===>  SET UP STEP NAMES FOR DISPLAY
      *--------------------------------------------------------------

           IF LK-JSTP-NAME = SPACES
              AND
              LK-PSTP-NAME = SPACES
              GO TO 000-CONTINUE
           END-IF
           IF LK-PSTP-NAME = SPACES
              MOVE LK-JSTP-NAME TO WS-JSTP-NAME
           ELSE
              MOVE LK-PSTP-NAME TO WS-JSTP-NAME
              MOVE LK-JSTP-NAME TO WS-PSTP-NAME
           END-IF
           .
       000-CONTINUE.

      *--------------------------------------------------------------
      *===>  SET UP PGM NAME FOR DISPLAY
      *--------------------------------------------------------------

           SET ADDRESS OF LK-CDE TO LK-LAST-CDE-ADDR
           PERFORM WITH TEST BEFORE UNTIL LK-PREV-CDE-ADDR = NULLS
                   SET ADDRESS OF LK-CDE TO  LK-PREV-CDE-ADDR
           END-PERFORM
           MOVE LK-PGM-NAME TO WS-PN-DISPLAY

      *--------------------------------------------------------------
      *===>  SET UP ENTRY POINT ADDR FOR DISPLAY
      *--------------------------------------------------------------

           MOVE LK-EP-ADDR   TO  WS-WORK-X5
           PERFORM 100-CONVERT-HEX-DATA
           MOVE WS-WORK-UNPACKED-8 TO WS-EP-DISPLAY

      *--------------------------------------------------------------
      *===>  SET UP LOAD POINT ADDR FOR DISPLAY
      *--------------------------------------------------------------
           SET ADDRESS OF LK-EXTENT-LST TO LK-EXTENT-LST-ADDR
           MOVE LK-LP-ADDR   TO  WS-WORK-X5
           PERFORM 100-CONVERT-HEX-DATA
           MOVE WS-WORK-UNPACKED-8 TO WS-LP-DISPLAY

      *--------------------------------------------------------------
      *===>  SET UP PGM LENGTH FOR DISPLAY
      *--------------------------------------------------------------
           MOVE    X"00"     TO  WS-WORK-X1
           MOVE LK-PGM-LEN   TO  WS-WORK-X3
           PERFORM 100-CONVERT-HEX-DATA
           MOVE    WS-WORK-UNPACKED-8  TO  WS-LEN-DISPLAY

      *--------------------------------------------------------------
      *===>  SET UP PGM END POINT ADDR FOR DISPLAY
      *--------------------------------------------------------------
           COMPUTE
           WS-WORK-FP  =  LK-LP-ADDR-BIN + (WS-WORK-BIN4 - 1)
           MOVE WS-WORK-FP   TO  WS-WORK-X5
           PERFORM 100-CONVERT-HEX-DATA
           MOVE WS-WORK-UNPACKED-8 TO WS-FP-DISPLAY

      *--------------------------------------------------------------
      *===>  SET UP COMPILER INFORMATION FOR DISPLAY
      *--------------------------------------------------------------
           SET ADDRESS OF LK-COMPILER-INFO TO LK-LP-ADDR-PTR
           IF  LK-TYPE-VS = "VS"
               MOVE   SPACES        TO WS-CTYPE-DISPLAY
               MOVE LK-VSREL-NBR    TO WS-CREL-DISPLAY
               MOVE LK-VSTIME       TO WS-CTIME-DISPLAY
               MOVE LK-VSMO-DAY     TO WS-VSMO-DAY-DISPLAY
               MOVE LK-VSYEAR       TO WS-VSYEAR-DISPLAY
           ELSE

      *    IF  LK-TYPE-II = "C2"
               MOVE    "II"         TO WS-CTYPE-DISPLAY
               MOVE LK-IIREL-NBR    TO WS-CREL-DISPLAY
               MOVE LK-IITIME       TO WS-CTIME-DISPLAY
               MOVE LK-IIMON-DAY-YR TO WS-CDATE-DISPLAY
           END-IF

           DISPLAY " "
      *--------------------------------------------------------------
      *===>  DISPLAY ALL INFORMATION PREVIOUSLY SET UP
      *--------------------------------------------------------------
           DISPLAY "*****************************"
                   "**************************************************"
           DISPLAY " PROGRAM "                     WS-PN-DISPLAY
                   " RUN FROM JOB "                LK-JOB-NAME
                   " IN STEP/PROCSTEP ===> "       WS-STEP-DISPLAY
           DISPLAY " COMPILED UNDER VSCOBOL"       WS-CTYPE-DISPLAY
                                          " REL  " WS-CREL-DISPLAY
                                          " AT "   WS-CTIME-DISPLAY
                                          " ON "   WS-CDATE-DISPLAY
      *--------------------------------------------------------------
      *===>  DISPLAY COBOL II OPTION BITS
      *--------------------------------------------------------------
           IF NOT     LK-VSCOBOL DISPLAY  " "
              MOVE    LK-IIOPT-BYTES      TO  WS-WORK-X5
              PERFORM 100-CONVERT-HEX-DATA
              MOVE    WS-WORK-UNPACKED-8  TO  WS-OPTBYTE-DISPLAY
              DISPLAY " INDICATORS FOR COMPILER OPTIONS IN EFFECT ==> "
                                                   WS-OPTBYTE-DISPLAY
           END-IF
           DISPLAY " "
           DISPLAY "                  " "ENTRY POINT "  WS-EP-DISPLAY
           DISPLAY "                  " " LOAD POINT "  WS-LP-DISPLAY
           DISPLAY "                  " "  END POINT "  WS-FP-DISPLAY
           DISPLAY "                  " "     LENGTH "  WS-LEN-DISPLAY
           DISPLAY "*****************************"
                   "**************************************************"
           DISPLAY " "
      ****************************************************************
      *             USED TO FORCE A DUMP AT EOJ
      *--------------------------------------------------------------
      *    COMPUTE WS-WORK-BIN4 =  WS-WORK-BIN4 / WS-ZERO
      ****************************************************************
           GOBACK
           .
       100-CONVERT-HEX-DATA.
      *--------------------------------------------------------------
      *===>  CONVERTS HEX DATA FOR DISPLAY PURPOSES
      *      E.G. X"04FB" ====> X"F0F4C6C2" OR 04FB CHARACTER
      *--------------------------------------------------------------
           MOVE    WS-WORK-PACKED TO WS-WORK-UNPACKED
           INSPECT WS-WORK-UNPACKED CONVERTING
                   X"FAFBFCFDFEFF"  TO  "ABCDEF"
           .
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Fri Dec 02, 2005 10:20 am    Post subject: pointers in COBOL
Reply with quote

Hi frnd,

It's little big lengthy but worthy.. let us check out the coding and inform u if not clear. Thank u for ur coded reply.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Fri Oct 06, 2006 6:02 pm    Post subject:
Reply with quote

Hi,

Would u please tell me how we can access a variable using pointer.

LINKAGE SECTION.

01 NAME-STRUCTURE.
05 FIRST-NAME PIC X(15).
05 SECOND-NAME PIC X(15).

SET WS-POINTER-VAR TO ADDRESS OF NAME-STRUCTURE.

But how we can access NAME-STRUCTURE using WS-POINTER-VAR ?
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
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
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

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us