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

How to pass an array to external procedure in PLI.


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
angshu

New User


Joined: 09 Nov 2010
Posts: 4
Location: Pune

PostPosted: Wed Nov 10, 2010 12:22 am
Reply with quote

How can I pass an array to external procedure. I have coded the following but getting element value as blank in the external procedure.

In main procedure
------------------------
DCL EXT_PROC EXTERNAL ENTRY((3000) CHAR(7));
- - - - - - -
DCL ARRAY(3000) CHAR(7) INIT((3000)(7) ' ');
- - - - - - -
ARRAY(INDEX) = VALUE;
- - - - - - -
CALL EXT_PROC(ARRAY);

In external proedure
-------------------------
EXT_PROC: PROC(ARRAY);
- - - - - - -
DCL ARRAY(3000) CHAR(7);
- - - - - - -
PUT SKIP LIST(ARRAY(INDEX));

This gives blank value for ARRAY(INDEX).
Can anybody help to get me right code.If there is already some tread available please give me the path.
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: Wed Nov 10, 2010 12:30 am
Reply with quote

How do you set the value of INDEX in the calling program and subprogram?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Nov 10, 2010 12:47 am
Reply with quote

Main program:
Code:
FOO: PROC OPTIONS (MAIN) REORDER;                         
                                                           
DCL ARRY (3000)                    CHAR (7);               
                                                           
DCL 1 MY_DESCRIP                   UNAL,                   
      2  ARRY_LEN                  FIXED BIN (32) UNSIGNED,
      2  ELEMENT_LEN               FIXED BIN (32) UNSIGNED,
      2  ARRY_ADDR                 POINTER;               
                                                           
DCL D_PTR                          POINTER;               
                                                           
DCL BAR                            ENTRY (POINTER);       
                                                           
DCL ADDR                           BUILTIN;               
                                                           
ARRY (42)   = 'NOTARY';                                   
ARRY (666)  = 'SOJAC';                                     
ARRY_LEN    = 3000;                                       
ELEMENT_LEN = 7;                                           
ARRY_ADDR   = ADDR(ARRY);                                 
D_PTR       = ADDR(MY_DESCRIP);                           
CALL BAR(D_PTR);                                           
                                                           
END FOO;                                                   

External subroutine:
Code:
 BAR: PROC (D_PTR) REORDER;                                 
                                                           
 DCL D_PTR                          POINTER,               
     I                              FIXED BIN (31);         
                                                           
 DCL 1 MY_DESCRIP                   UNAL BASED(D_PTR),     
       2  ARRY_LEN                  FIXED BIN (32) UNSIGNED,
       2  ELEMENT_LEN               FIXED BIN (32) UNSIGNED,
       2  ARRY_ADDR                 POINTER;               
                                                           
 DCL ARRY (ARRY_LEN)                CHAR (ELEMENT_LEN)     
                                    BASED (ARRY_ADDR);     
                                                           
 DO I = 42, 666, 1024;                                     
   PUT SKIP EDIT ('ELEMENT IS = [', ARRY(I), ']') (A, A, A);
 END;                                                       
                                                           
 END BAR;                                                   

Output:
Code:
ELEMENT IS = [NOTARY ]
ELEMENT IS = [SOJAC  ]
ELEMENT IS = [       ]

Other solutions are possible.
Back to top
View user's profile Send private message
angshu

New User


Joined: 09 Nov 2010
Posts: 4
Location: Pune

PostPosted: Wed Nov 10, 2010 12:56 am
Reply with quote

Actually ARRAY is populated in DO WHILE loop & I incremented the by 1 after each iteration of the loop. Some thing like this,-

In main program
--------------------
DCL INDEX BIN FIXED(31) INIT(1);

DO WHILE(condition)

ARRAY(INDEX) = VALUE;

END;

The ARRAY size I have taken maximum 3000. There may be less than 3000 VALUE. In that case other elements will be blank.

In external procedure
-------------------------
DCL INDEX BIN FIXED(31) INIT(1);

DO WHILE(INDEX <= 3000 & ARRAY(INDEX) != ' ')

Processing with the ARRAY;
INDEX = INDEX+1;

END;
Back to top
View user's profile Send private message
angshu

New User


Joined: 09 Nov 2010
Posts: 4
Location: Pune

PostPosted: Wed Nov 10, 2010 2:12 pm
Reply with quote

Thanks Akatsukami for your post my I'm getting value now.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Thu Nov 11, 2010 3:55 am
Reply with quote

angshu wrote:
How can I pass an array to external procedure. I have coded the following but getting element value as blank in the external procedure.

In main procedure
------------------------
DCL EXT_PROC EXTERNAL ENTRY((3000) CHAR(7));
- - - - - - -
DCL ARRAY(3000) CHAR(7) INIT((3000)(7) ' ');
- - - - - - -
ARRAY(INDEX) = VALUE;
- - - - - - -
CALL EXT_PROC(ARRAY);

In external proedure
-------------------------
EXT_PROC: PROC(ARRAY);
- - - - - - -
DCL ARRAY(3000) CHAR(7);
- - - - - - -
PUT SKIP LIST(ARRAY(INDEX));

This gives blank value for ARRAY(INDEX).
Can anybody help to get me right code.If there is already some tread available please give me the path.


Wij runderen, wij glunderen....

Code:
/* Main */
dcl array (3000) char (7);
dcl ext entry /* if you really insist */ ((3000) char(7));

call ext(array);


Code:
/* External */
ext: proc(array);
dcl array(*) char(*);

end ext;


And processing is much better done as:

Code:
do i = lbound(array, 1) to hbound(array, 1) while(array(i) ^= '');
.
.
.
end;


And for what it's worth, the compiler has no trouble with PL/I written in lowercase, humans have far more trouble reading ALL-UPPERCASE...
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: Thu Nov 11, 2010 4:52 am
Reply with quote

Prino,

If the OP knew beforehand the exact number of array-entries, couldn't he use CONTROLLED storage and load up all the necessary entries, instead of wasting resources, by picking a HBOUND like 3000, when he/she may only need (for example) 1200?

Haven't code PL/I in decades, so maybe this is a red herring?

Bill
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Thu Nov 11, 2010 5:13 am
Reply with quote

Bill O'Boyle wrote:
If the OP knew beforehand the exact number of array-entries, couldn't he use CONTROLLED storage and load up all the necessary entries, instead of wasting resources, by picking a HBOUND like 3000, when he/she may only need (for example) 1200?

Haven't code PL/I in decades, so maybe this is a red herring?


Of course you can use controlled, but given that we're dealing with just 21,000 bytes in this case, why bother.

What's essential in the "EXT" routine is the use of asterisks in the declare of the array (both for the dimension as well as the length of the elements) and using LBOUND and HBOUND, as these will allow "EXT" to be used even if the bounds of the array, or the length of its elements, change.
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 -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
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
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Invoke stored procedure via batch JCL. DB2 2
Search our Forums:

Back to Top