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

What is the correct approach to pass address of variable?


IBM Mainframe Forums -> CICS
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Mon Aug 03, 2009 1:27 pm
Reply with quote

Hi All,

My requirement is to pass data of WK-VAR1 from Program A to Program B by passing an address.

WK-VAR1 is defined as below in program A

01 WK-VAR1.
02 WK-FIELD1 PIC X (86).
02 WK-FIELD2 PIC X (172000).
02 WK-VAR1-ADDRESS POINTER.

PROCEDURE DIVISION

SET WK-VAR1-ADDRESS TO ADDRESS OF WK-VAR1 .

EXEC CICS
LINK
PROGRAM (PROGRAM-B)
COMMAREA (WK-VAR1)
LENGTH (LENGTH OF WK-VAR1)
RESP (WK-RESP)
END-EXEC.



PRogram B

Working storage section

01 WK-HEADER.
02 WK-ACT-DATA PIC X (172086).
02 WK-ACT-ADDRESS POINTER.


Linkage section

01 DFHCOMMAREA.
02 LK-DATA PIC X (172086).
02 LK-VAR1-ADDRESS POINTER.

PROCEDURE DIVISION

SET WK-ACT-ADDRESS TO ADDRESS OF LK-VAR1-ADDRESS.

Now can i say whatever data was in WK-VAR1 of program A is in WK-HEADER of program B.

Is this the correct approach to pass huge data from one program to another program by passing an address? If not what is the best approach?



Regards
Bijal
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: Mon Aug 03, 2009 4:38 pm
Reply with quote

No, this is not the correct approach. From the CICS Language Reference manual, LINK command syntax, error conditions:
Quote:
LENGERR
RESP2 values:

11
The COMMAREA length is less than 0 or greater than 32767.
If you merely passed a pointer to the address, that's only 4 bytes -- but passing the whole 172,086 bytes won't work.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Aug 03, 2009 4:52 pm
Reply with quote

Also, the LINK must be LOCAL (within the same region), if you plan to pass an ADDRESS.

You CANNOT pass an ADDRESS via a remote LINK (DPL) and expect the address in the remote region to point to the same data.

You run the risk of corrupting whatever data is at this same address in the remote region and cause all sorts of problems.

So, don't do this....

Bill
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Mon Aug 03, 2009 6:17 pm
Reply with quote

Hi Robert & Bill

Can you please tell me the correct approach to do this?

Regards
Bijal
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Aug 03, 2009 7:14 pm
Reply with quote

In the LINKED-TO program, specify -

Code:

LINKAGE SECTION.
01  DFHCOMMAREA.
    03  CA-POINTER POINTER.

01  LK-DATA-REC.
    03  LK-DATA-LGTH PIC S9(08) COMP.
    03  LK-DATA PIC X(16777211).

SET ADDRESS OF LK-DATA-REC TO CA-POINTER.

When you pass a length associated with your data, you now have the ability to have a variable-length parameter. So, the binary-fullword (LK-DATA-LGTH) will contain the maximum-length that can be addressed in LK-DATA. LK-DATA-LGTH is populated in the LINKING program.

Note that 16777215 is the maximum length of an 01 level, so this is the reason for the PIC X(16777211).

You'll have to change the LINKING program's WS to allow for a data-lgth followed by the actual data. Note that the picture clause of the actual data does not need to be 16777211. It should be the maximum amount of data that the LINKED-TO program can address.

LINKAGE SECTION definitions don't take up any space/memory until addressability is established.

Note that IBM has always discouraged the passing of addresses for as long as I can recall. But, it's up to you to use this or not.

HTH....

Bill
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: Mon Aug 03, 2009 7:27 pm
Reply with quote

From the CICS Programming Guide manual (link at the top of the page):
Quote:
3.6.2.2 Unsafe techniques

The programming techniques in the unsafe category are:

* The use of long-life shared storage:

o The common work area (CWA)

o GETMAIN SHARED storage

o Storage obtained by a LOAD PROGRAM HOLD

* The use of task-lifetime local storage shared by synchronized tasks

It is possible for one task to pass the address of some task-lifetime storage to another task.

It may be safe for the receiving task to use the passed address, provided the owning task does not terminate. It is possible, but ill-advised, to use a CICS task-synchronization technique to allow the receiving task to prevent the sending task from terminating (or freeing the storage in some other way) before the receiver has finished with the address. However, such designs are not robust because there is a danger of the sending task being purged by some outside agency.

See "Sharing task-lifetime storage" in topic 3.6.4.4 for more details.
IBM considers what you are wanting to do to be inherently unsafe. I would strongly recommend a long round of discussion with your peers and management before implementing anything that IBM considers unsafe.
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Tue Aug 04, 2009 3:09 pm
Reply with quote

Bill O'Boyle wrote:
In the LINKED-TO program, specify -

[code]
LINKAGE SECTION.
01 DFHCOMMAREA.
03 CA-POINTER POINTER.

01 LK-DATA-REC.
03 LK-DATA-LGTH PIC S9(08) COMP.
03 LK-DATA PIC X(16777211).




How the variables will be defined in Program A?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Aug 04, 2009 3:46 pm
Reply with quote

Example -

Code:

01  WK-VAR-REC.
    03  WK-VAR-LGTH PIC S9(08) COMP.
    03  WK-VAR.
        05  WK-FIELD1 PIC X(86).
        05  WK-FIELD2 PIC X(172000).
01  WK-VAR-MISC.
    03  WK-VAR-POINTER POINTER.

MOVE LENGTH OF WK-VAR TO WK-VAR-LGTH.
SET WK-VAR-POINTER TO ADDRESS OF WK-VAR-REC.

At this point, you would issue the LINK to program "B" using WK-VAR-POINTER as the four-byte commarea.

But remember, IBM discourages passing addresses.

Your mileage may vary.... icon_wink.gif

Bill
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Tue Aug 04, 2009 4:17 pm
Reply with quote

Thanks for the information Bill.

I need to call Program-B as below

EXEC CICS LINK
PROGRAM(PROGRAM-B)
COMMAREA(WK-VAR-MISC)
LENGTH(WK-VAR-LENGTH)
RESP(RESP-CD)
END-EXEC.

In this way i will pass address to Program B, right?

Regards
Bijal
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Aug 04, 2009 4:54 pm
Reply with quote

NO, the COMMAREA is WK-VAR-POINTER and the LENGTH is LENGTH OF WK-VAR-POINTER, which is 4.

If you don't supply a LENGTH, the translator will automatically use LENGTH OF WK-VAR-POINTER.

Remember, you are passing the ADDRESS OF WK-VAR-REC, which can be found in WK-VAR-POINTER, as the COMMAREA to Program "B".

If for some reason, Program "B" becomes REMOTE, then this method will not work and you will crash and burn.
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 -> CICS

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Routing command Address SDSF to other... TSO/ISPF 2
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts How to pass the PARM value to my targ... COBOL Programming 8
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top