View Full Version : Sub-Procedures with Arrays
05-21-2002, 06:09 AM
Bill - I believe the following will work: Hdftactgrp(*no) H debug DProcess pr D * value DArray s 3s 0 dim(12) inz /free callp Process(%addr(Array)); dump; *inlr = *on; /end-free P Process b DProcess pi DPtr * value DIx s 3u 0 /free for Ix = 1 to 12; Array(Ix) = Ix * 2; endfor; /end-free P Process e Bill
05-21-2002, 10:58 AM
Bill; Thanks, I'll give it a try. Bill
05-21-2002, 11:21 AM
Check the attached program. It has a procedure that takes an array as a parameter and returns an array as a result.
05-22-2002, 04:44 PM
What problems are you having? Is it not compiling, or are you getting the wrong results?
05-23-2002, 12:28 PM
It wasn't compiling. I finally got my head out of my derrier and put the array in a data structure. The problem was with a G/L Budget file that had to be exported to a UNIX based RMS/COBOL system. The 12 monthly buckets in the same record as 12 YTD buckets that had to be accumulative. The original criteria was to not calculate YTD amounts past the current qtr. Then it changed to zeroing out YTD figures if an account(store) closed. Now back to calculating complete year. Since there are three programs that produce records for this file and they all needed to do the same YTD calcs and I forgot one of them on one of the changes I decided to just send the monthly array to the sub-proc and get teh the YTD back. What I did was D month_ds DS d month_ary 7 0 dim(12) d ytd_ds ds d ytd_ary 9 0 dim(12) <center> eval ytd_ds = calc_ytd(month_ds) </center> Sub-proc /if not defined(have_budytd) /define have_budytd d budytd pr 108 d budcur 84 /eof /else p budytd b d budytd pi 108 d budcur 84 d Idx s 2 0 d ytd_ds ds d ytd_ary 9s 0 dim(12) inz d cur_ds ds d cur_ary 7s 0 dim(12) inz <center> eval cur_ds = budcur </center><center> eval idx = 1 </center><center> eval ytd_ary = 0 </center><center> eval ytd_ary(1) = cur_ary(1) </center> <center> dou idx = 12 </center><center> eval idx = idx + 1 </center><center> eval ytd_ary(idx) = ytd_ary(idx - 1) + </center><center> cur_ary(idx) </center><center> enddo </center> <center> return ytd_ds </center>p budytd e /endif This worked fine. I appreciate the help and the responses. Bill
02-20-2003, 03:36 PM
The code that I am trying to setup is below. I am defining a datastructure based on 12 fields in an externally defined file and then trying to overlay them with an array. My problem is that I can't seem to get this pass the editor. I know its something simple, just please point me in the right direction and I will be most appreciative. Barbara Edens firstname.lastname@example.org
02-20-2003, 03:36 PM
I am trying to write a Sub-Proc that will take a 12 place numeric array manipulate it and return a 12 place numeric array with calculated results based on the input array. My problem is that I can't seem to get it to work. I have done other SP's with data structures passed back, but never arrays. Help! TIA Bill Barnes
02-21-2003, 08:08 AM
>D Unitds DS >D Per1_Unit > etc >D Per12_Unit >D UnitArray like(Per1_Unit) Dim(12) Overlay(Untd) You have to code the DS name on the overlay keyword for this to work. Since that won't fit on the same line any more, move one of the keywords to the next line. D UnitArray like(Per1_Unit) Dim(12) D Overlay(Unitds)
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.