midrange.com code scratchpad
Name:
return value from Java method truncated in RPG program
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
02/27/2015 03:44:49 am
IP:
Logged
Description:
The RPG program calls Java method checkInvRPG, which retrieves inventory information from SAP and returns the quantity available for inventory items.
If no error, it simply returns the quantity available as a string value such as '275'. If an error occurrs, the java program concatenates the quantity with a "|" followed by the error message. The output would appear as "0|This is an error message up to 80 characters long.......".
Code:
  1. ------------------------------------------------------------------------------
  2. Output from RPG program when using valid item number:
  3.  
  4. 275
  5.  
  6. ------------------------------------------------------------------------------
  7. Output from RPG program with invalid item branch (returned value from Java method is truncated):
  8.  
  9. 0|Plant 972 is not configured   
  10.  
  11. ------------------------------------------------------------------------------
  12. Output from Eclipse Java console when using valid item number:
  13.  
  14. 275
  15.  
  16. ------------------------------------------------------------------------------
  17. Output from Eclipse Java console when using an invalid branch (shows complete message):
  18.  
  19. SAP_Inv_RPG_Z8CCx
  20. 0|Plant 972 is not configured in SAP ECC constant table
  21.  
  22. ====================================================
  23. ====================================================
  24.  
  25.  
  26. RPG prototypes:
  27.  
  28. D mthcheckInvRPG...                                                     
  29. D                 PR                                                    
  30. D                                     extproc( *JAVA                    
  31. D                                            : 'com.jde.SAP.SAP_Inv_RPG'
  32. d                                            : 'checkInvRPG'            
  33. d                                            )                          
  34. d                                     like(jstring)                     
  35. d                                     static                            
  36. d APItoCall                           like(jstring)                     
  37. d Destination                         like(jstring)                     
  38. d Hostname                            like(jstring)                     
  39. d Sysnbr                              like(jstring)                     
  40. d Clientno                            like(jstring)                     
  41. d LangID                              like(jstring)                     
  42. d UserID                              like(jstring)                     
  43. d Password                            like(jstring)                     
  44. d Branch                              like(jstring)                     
  45. d ItemNbr                             like(jstring)                     
  46. d UOM                                 like(jstring)                     
  47. d DebugFlag                           like(jstring)                     
  48.  
  49. d cvtToBytes      PR            30A   EXTPROC(*JAVA:              
  50. d                                             'java.lang.String': 
  51. d                                             'getBytes')         
  52. d                                     Varying                     
  53.  
  54. [...]
  55.  
  56. d $ReturnedValue  s            200A        
  57. d VC0001...                             
  58. d                 s            198A     
  59.  
  60. // All fields ending with underscore ('_') character are defined as:
  61.  
  62. d Returnval_...                                                   
  63. d                 s               o   Class(*JAVA:'java.lang.String')   
  64.  
  65. [...]
  66.  
  67. Returnval_  = 
  68. mthcheckInvZ8CCx( APItoCall_         
  69.                              : Destination_   
  70.                              : Host_          
  71.                              : SysNbr_        
  72.                              : ClientNo_      
  73.                              : LangID_        
  74.                              : UserID_        
  75.                              : Pwd_           
  76.                              : Branch_        
  77.                              : ItemNbr_      
  78.                              : UOM_           
  79.                              : DebugFlag_         
  80.                              );                   
  81.                                                   
  82. $ReturnedValue = cvtToBytes( ReturnVal_ );        
  83.  
  84. // VC0001 is defined as 198 long, printed on report ending in position 198
  85.  
  86. VC0001 = $ReturnedValue;                          
  87. Except Detail2;                                   
  88.  
  89. ============================================================
  90. ============================================================
  91.  
  92. Java code:
  93.  
  94. package com.jde.SAP;
  95.  
  96. import com.sap.conn.jco.JCoException;
  97.  
  98. public class SAP_Inv_RPG_Z8CCx {
  99.     /**
  100.      * Retrieve Item from SAP
  101.      * @return
  102.      */
  103.  
  104.     public static String checkInvZ8CC( String APItocall 
  105.             , String destname
  106.             , String hostname
  107.             , String sysnbr
  108.             , String clientno
  109.             , String langid
  110.             , String UserID
  111.             , String Pwd
  112.             , String Plant
  113.             , String ItemNbr
  114.             , String UoM
  115.             , String debugflag
  116.             ) 
  117.     {
  118.         String returnVal;
  119.         String message;
  120.         returnVal = null;
  121.  
  122.         SAP_Inventory Inv = new SAP_Inventory();
  123.  
  124.         returnVal = Inv.SAP_Login( destname
  125.                 , UserID
  126.                 , Pwd
  127.                 , hostname
  128.                 , sysnbr
  129.                 , clientno
  130.                 , langid                            
  131.                 ).trim();        
  132.  
  133.         try {    
  134.         returnVal = Inv.Z_8CC_MATERIAL_AVAIL( destname
  135.                     , Plant
  136.                     , ItemNbr
  137.                     , UoM
  138.                     , debugflag
  139.                     );            
  140.         } catch (JCoException e) {
  141.             // TODO Auto-generated catch block
  142.             //e.printStackTrace();
  143.             message = " Method (SAP_Inv_RPG_Z8CC): System Unavailable";
  144.             return message ;
  145.         }    
  146.  
  147.         if (returnVal == null) {
  148.             returnVal = " ";
  149.         }
  150.         System.out.println("SAP_Inv_RPG_Z8CCx" + "\n");
  151.         System.out.println(returnVal + "\n");
  152.         
  153.         Inv = null;
  154.         return returnVal ;
  155.     }
  156. }
  157.  
  158.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css