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

Dynamic load a csect


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 202
Location: Toronto, ON, Canada

PostPosted: Thu Aug 13, 2015 11:57 pm
Reply with quote

CICS has a command to load a csect into memory and set a pointer
Code:
EXEC CICS
LOAD PROGRAM('mypgm')
SET(ADDRESS OF WS-MYPGM-PTR)
END-EXEC.

How can I do something similar in a COBOL program running in batch? I checked the Language Environment manual but could not find a utility for this.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Aug 14, 2015 12:02 am
Reply with quote

Code:
CALL <variable-name>
where variable-name is the program name you want to call. It doesn't work exactly the same (you cannot set a pointer for it, for example). The load module indicated in <variable-name> must be available via STEPLIB (etc.) when the program executes, but does not need to be included in the linkage edit / bind of the calling program.
Back to top
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 202
Location: Toronto, ON, Canada

PostPosted: Fri Aug 14, 2015 12:09 am
Reply with quote

Sorry forgot to mention - it is not an executable csect. It is an assembler csect which has just data. After the load a LINKAGE variable is set to point to the csect. The program can then do a SEARCH ALL on the variable to find a data item.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Aug 14, 2015 12:40 am
Reply with quote

Code:
       01  W-LOAD-POINTER                      USAGE PROCEDURE-POINTER.
       01  FILLER REDEFINES W-LOAD-POINTER.
           05 W-ADDRESS-OF-LOAD                USAGE POINTER.


           SET W-LOAD-POINTER           TO ENTRY
                                            "yourcsectname"
[or]
                                            identifier-containing-csect-name
           SET ADDRESS OF L-SEARCH-TABLE
                                        TO W-ADDRESS-OF-LOAD


This will load the CSECT (assuming in your search chain, of course) and put the address of the entry-point into W-LOAD-POINTER. Which you then REDEFINES as an ordinary POINTER, and use it as you would an ordinary POINTER.

What you are short of is the length of the table to be searched (from that) so include it in the CSECT (or know what was loaded in there). Your table in the LINKAGE SECTION should use an ODO.

Alternatively, a hard-coded table and recompile when the length changes.
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Fri Aug 14, 2015 12:42 am
Reply with quote

This is how I have done a batch program loading the same assemble table as I would in CICS.

Code:
ASSEMBLE TABLE

WSSSRYNU AMODE 31
WSSSRYNU RMODE ANY
WSSSRYNU CSECT
SRYCOUNT DC    A(SRYLNGTH/08)
SRYENTRY DC    CL08'xxxxxxx1'         
         DC    CL08'xxxxxxx2 '       
         DC    CL08'xxxxxxx3 '   
         DC    CL08'@@@@@@@@'         END OF TABLE
SRYLNGTH EQU   *-SRYENTRY
         END   

COBOL BATCH CODE TO ACCESS ABOVE TABLE

01  WS-TBL1-STRG.
    05  WS-TBL1-NAME           PIC X(08)  VALUE 'WSSSRYNU'.
    05  WS-TBL1-ADDR           USAGE  PROCEDURE-POINTER.
    05  FILLER  REDEFINES  WS-TBL1-ADDR.
        10  WS-TBL1-DATA       USAGE  POINTER.
        10  FILLER                    PIC X(04).

    05  WS-TBL1-IDX              PIC 9(08)  VALUE ZEROES.

    05  WS-TBL1-VERIFIED      PIC X(01)  VALUE ' '.
        88  WS-TBL1-LOADED                    VALUE 'L'.
        88  WS-TBL1-FAILED                     VALUE 'F'.

    05 WS-ACCESS-VERIFY      PIC X(01) VALUE ' '.
       88 WS-ACCESS-MATCH                  VALUE 'M'.
       88 WS-ACCESS-ERROR                  VALUE 'E'.




LINKAGE SECTION.

01 PCT-SRYN-TABLE.
  05 PCT-SRYN-COUNT             PIC 9(04) VALUE ZEROES.
  05 PCT-SRYN-ENTRY             OCCURS 0 TO 60 TIMES
                                DEPENDING ON PCT-SRYN-COUNT.
    10 PCT-SRYN-ACCESS          PIC X(08) VALUE SPACES.


PROCEDURE DIVISION

SET WS-TBL1-ADDR  TO  NULLS
SET WS-TBL1-ADDR  TO  ENTRY  WS-TBL1-NAME

IF WS-TBL1-ADDR  =  NULLS
    DISPLAY '********************************************'
    DISPLAY '* PROGRAM xxxxxxxx: '
    DISPLAY '* 909 - TABLE NOT LOADED:'  WS-TBL1-NAME
    DISPLAY '********************************************'
    MOVE '909'            TO LIT-ABEND-CODE
    PERFORM 9999-ABEND
ELSE
    SET WS-TBL1-LOADED                    TO  TRUE
    SET ADDRESS OF PCT-SRYN-TABLE  TO  WS-TBL1-DATA
END-IF


IF WS-TBL1-LOADED
  PERFORM VARYING WS-TBL1-IDX  FROM 1 BY 1
    UNTIL WS-ACCESS-MATCH OR WS-ACCESS-ERROR

    IF PCT-SRYN-ACCESS (WS-TBL1-IDX) = '@@@@@@@@'
      SET WS-ACCESS-ERROR TO TRUE
    END-IF

    IF WS-xxxx-USER = PCT-SRYN-ACCESS (WS-TBL1-IDX)
      SET WS-ACCESS-MATCH TO TRUE
    END-IF
  END-PERFORM
END-IF
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Aug 14, 2015 12:52 am
Reply with quote

That's a more detailed example of it. I missed pasting the PIC X(4) in the REDEFINES.

PROCEDURE-POINTERs are funny things, which have an address, then another four bytes.

A FUNCTION-POINTER is similar, but only four bytes long. One way to make use of a function in C/C++, for instance.

We covered this last time the PROCEDURE-POINTER came up. I don't think your error code is ever going to execute. Unless you have a Language Environment abend handler, and you have no code for that. So you'll get an S806, or an S706, or an Sx06 depending on how busted the CSECT is.

If you have the handler, you don't need the NULLS processing.
Back to top
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 202
Location: Toronto, ON, Canada

PostPosted: Fri Aug 14, 2015 1:13 am
Reply with quote

Excellent icon_biggrin.gif That worked. Thank you
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts How to load to DB2 with column level ... DB2 6
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts REASON 00D70014 in load utility DB2 6
No new posts JCL Dynamic System Symbols JCL & VSAM 3
Search our Forums:

Back to Top