Search code examples
javaibm-midrangerpg

Call RPG Program from JAVA


I want to call a RPG program from JAVA, the RPG program receive this parameters:

0013.00       * Entry parameters                             
0013.10      C           *ENTRY    PLIST                     
0013.20      C                     PARM           P0RTN   7  
0013.30      C           P1ATCD    PARM           WP0001  1  
0013.40      C           P2AMCD    PARM           WP0002  7  
0013.50      C           P3ARCD    PARM           WP0003  70 
0013.60      C           P4BGCD    PARM           WP0004  6  
0013.70      C           P5EFDX    PARM           WP0005  80 
0013.80      C           P6V9VA    PARM P6V9VA    WP0006 132 

and this is the Data Structure in RPG:

0010.70       * Parameter declarations                            
0010.80      IP1PARM      DS                                      
0010.90       * I : MAP Company ID                                
0011.00      I                                        1   1 P1ATCD
0011.10      IP2PARM      DS                                      
0011.20       * I : MAP Product ID                                
0011.30      I                                        1   7 P2AMCD
0011.40      IP3PARM      DS                                      
0011.50       * I : MAP Person/Company ID                         
0011.60      I                                    P   1   40P3ARCD
0011.70      IP4PARM      DS                                      
0011.80       * I : MAP Fund ID                                   
0011.90      I                                        1   6 P4BGCD
0012.00      IP5PARM      DS                                      
0012.10       * I : MAP Wk Evaluation Date                        
0012.20      I                                    P   1   50P5EFDX
0012.30      IP6PARM      DS                                      
0012.40       * B : MAP Capital Total                             
0012.50      I                                    P   1   72P6V9VA
0012.60      I            DS                                      

This is my code in JAVA to call the program:

ProgramParameter[] parameterList = new ProgramParameter[6];
// First parameter is to input a name.
AS400Text nametext = new AS400Text(1);
parameterList[0] = new ProgramParameter(nametext.toBytes("F"));
parameterList[0].setParameterType(ProgramParameter.PASS_BY_VALUE);
nametext = new AS400Text(7);
parameterList[1] = new ProgramParameter(nametext.toBytes("XXX"));
parameterList[1].setParameterType(ProgramParameter.PASS_BY_VALUE);
AS400ZonedDecimal  person = new AS400ZonedDecimal(4,0);
//AS400Text person= new AS400Text(4);
parameterList[2] = new ProgramParameter(person.toBytes(452));
parameterList[2].setParameterType(ProgramParameter.PASS_BY_VALUE);
nametext = new AS400Text(6);
parameterList[3] = new ProgramParameter(nametext.toBytes("XXXXXX"));
AS400PackedDecimal evaluationDate = new AS400PackedDecimal(8, 0);
parameterList[4] = new ProgramParameter(evaluationDate.toBytes(20150715));
//parameter is to get the answer, up to 50 bytes long.
parameterList[5] = new ProgramParameter(50);

But, when I run the program, I get a message from AS400, this is the text:

Message ID . . . . . . :   RPG0907       Severity . . . . . . . :   99         
Message type . . . . . :   Inquiry                                             
Date sent  . . . . . . :   20/11/15      Time sent  . . . . . . :   19:38:27   

Message . . . . :   PROGRAM 1350 decimal-data error in field (C G S D F).      
Cause . . . . . :   The RPG program PROGRAM in library LIBRARY found a        
decimal-data error at statement 1350. One field did not contain valid        
numeric data.  The digit and/or sign is not valid.                           
Recovery  . . . :   Enter C to cancel, G to continue processing at *GETIN, S   
to obtain a system dump, or D to obtain an RPG formatted dump.               
Possible choices for replying to message . . . . . . . . . . . . . . . :       
D -- Obtain RPG formatted dump.                                              
S -- Obtain system dump.                                                     
G -- Continue processing at *GETIN.                                          
C -- Cancel.                                                                 
                                                                   More... 
Type reply below, then press Enter.                                            
Reply  . . . .      

I was trying to change data type from variable person (in JAVA), i tried with AS400Bin2, AS400Bin4, AS400Bin8, AS400Floa4, AS400Float8, AS400DecFloat, AS400PackedDecimal and AS400ZonedDecimal, but no one works, i get the same error when I run the class.

Thanks a lot for you help.


Solution

  • The problem is at statement 13.50, P3ARCD PARM WP0003 70.

    The RPG parameter list contains 7 entries, but you are only account for 6 in your Java code. I think your parameters are "shifted up" seven bytes. Try passing seven leading spaces to account for P0RTN.