Search code examples
arraysibm-midrangerpgle

How to fix "dont get a clear Array after a Programm Call"


I have written a Programm to encode some Strings. I write a 2nd Programm to call this encode-Tool. Here i create a Array (A_FELDER) and fill it with some Text. In the following Point 1 you can see my encode-Tool. In Point 2 you cann see the declaration from my Array and the FOR-LOOP. And in Point 3 the call to the encode-Tool.

Before i call the Tool, my Array have three Data sets. When the encode-Tool run successfully my Array (A_FELDER) is empty.

I tried to change *INLR = *ON; to return. But i get the same result. Also i create a second Array and write back the data in this array. Same result, empty Array.

I change my encode-Tool to a Program out after the Parameters. My Array (A_FELDER) have the three Data sets. So my guess: The java Call clear some Storage and my Array cant find his space.

Point 1

D Verschl         S               O   Class(*Java:'eirich.verschl.Verschl')
D $input          S           1024a                                        
D $output         S           1024a     

D new_Verschl     PR              O   EXTPROC(*JAVA:                  
D                                             'eirich.verschl.Verschl'
D                                             :*CONSTRUCTOR)           

D encrypt         PR              O   EXTPROC(*JAVA:                    
D                                             'eirich.verschl.Verschl': 
D                                             'encrypt')                
D                                     CLASS  (*JAVA:'java.lang.String') 
D  arg0                           O   CLASS  (*JAVA:'java.lang.String') 

C     *entry        plist                                     
C                   parm                    $input            
C                   parm                    $output           

/Free
//Generate new Object named Verschl              
Verschl     = new_Verschl();                   

//Trim and create Java String from input Parm    
fldjString  = makestring(%trimr($input));      

// ENCRYPT java String                           
fldjString2 = encrypt(Verschl:fldjString);     

//Convert jString in Alpha                       
fldBty      = cvtToBytes(fldjString2);         

//return value for call pgm                      
$output     = fldBty;

Point 2

D*                                            
D A_FELDER        S            256A   DIM(20) 
D* 

C                   EVAL      A_FELDER(1) = KOFIRM     
C                   EVAL      A_FELDER(2) = HEAUNR     
C                   EVAL      A_FELDER(3) = KOAUNR 
C*
C                   FOR       COUNT = 1 TO %ELEM(A_FELDER)     
C*                                                             
C                   IF        A_FELDER(COUNT) <> *BLANKS       
C*                                                             
C                   EVAL      I_UNVERSCHL_J = A_FELDER(COUNT)  
C                   EXSR      DATAENCRYPT                      
C                   EVAL      A_FELDER(COUNT) = I_VERSCHL      
C*                                                             
C                   ENDIF                                      
C*                                                             
C                   ENDFOR     

Point 3

C     DATAENCRYPT   BEGSR                                    
C*                                                           
C                   EVAL      $INPUT_JAVA  = I_UNVERSCHL_J   
C                   EVAL      $OUTPUT_JAVA = ''              
C*                                                           
C                   CALL(E)   'WD20001JR'                    
C                   PARM                    $INPUT_JAVA      
C                   PARM                    $OUTPUT_JAVA     
C*                                                           
C                   EVAL      I_VERSCHL    = $OUTPUT_JAVA  
C*                                                           
C                   ENDSR 

So i want to Crypt my Strings and than write back in this Array (A_FELDER). But after the Programm Call i have an empty Array. The other Fields are not empty. Save the AS400 Array variables different than normal variables?

Its so hard for me to describe this Problem, therefore im so sorry for my bad English.


Solution

  • Do you have a prototype for WD20001JR and D specs for $INPUT_JAVA and $OUTPUT_JAVA? Since the parameters are passed by reference, you might be overwriting your array fields unintentionally if the sizes of these fields do not match the sizes expected by the called program WD20001JR.