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
 
How to pass an array to external procedure in PLI.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
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    Post subject: How to pass an array to external procedure in PLI.
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Wed Nov 10, 2010 12:30 am    Post subject:
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: 1775
Location: Bloomington, IL

PostPosted: Wed Nov 10, 2010 12:47 am    Post subject:
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    Post subject: Reply to: How to pass an array to external procedure in PLI.
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    Post subject: Reply to: How to pass an array to external procedure in PLI.
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: 1049
Location: Oostende, Belgium

PostPosted: Thu Nov 11, 2010 3:55 am    Post subject: Re: How to pass an array to external procedure in PLI.
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Thu Nov 11, 2010 4:52 am    Post subject: Reply to: How to pass an array to external procedure in PLI.
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: 1049
Location: Oostende, Belgium

PostPosted: Thu Nov 11, 2010 5:13 am    Post subject: Re: Reply to: How to pass an array to external procedure in
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    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Calling procedure with multiple entri... steve-myers PL/I & Assembler 5 Fri Jan 27, 2017 3:33 pm
No new posts Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts JES2 JEC: Use UNIX Pipes to Pass Data... Virendra Shambharkar JCL & VSAM 21 Tue Dec 20, 2016 6:55 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm

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