View previous topic :: View next topic
|
Author |
Message |
angshu
New User
Joined: 09 Nov 2010 Posts: 4 Location: Pune
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
How do you set the value of INDEX in the calling program and subprogram? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
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 |
|
|
angshu
New User
Joined: 09 Nov 2010 Posts: 4 Location: Pune
|
|
|
|
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 |
|
|
angshu
New User
Joined: 09 Nov 2010 Posts: 4 Location: Pune
|
|
|
|
Thanks Akatsukami for your post my I'm getting value now. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
|