SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
siva_8489
Calcite | Level 5

How to run Java code using SAS (WPS) without JCL

 

Am try to call the java application using mainframe SAS 9.1 (WPS).  Its a simple hello world program in which Java application will return some value/outfile. I need to read the same via SAS and comparing the result with existing values.

 

But when i try to execute it hits an error :
ERROR: Could not find JREOPTIONS entry for "-Dwps.jre.libjvm="

Since this is a mainframe sas , as posted in other blogs i am not able to set  the class path .

On the other hand we are able to access java via JCL through a proc but i need the same via sas .

My code :

 /*options jreoptions =(-Djava.class.path= */                          
 /*jreoptions =(-Djava.class.path=                                     
  "/u/siva/BatchJava/lib/apps/helloWorld.jar") ; */                  
 proc options option=jreoptions;                                       
 run;                                                                  
 /*%INCLUDE 'SYSS.P.COZEEE.PARMLIB(COZCFGD)'; */                       
                                                                       
 proc javainfo; run;                                                   
 endsas;                                                               
                                                                       
 %macro init_classpath_update;                                         
     DATA _null_;                                                      
         LENGTH  path_separator $ 2                                    
                 orig_classpath $ 500;                                 
                 path_separator = '/';                                 
         DECLARE JavaObj f("java.io.File", "");                        
         f.getStaticStringField("pathSeparator", path_separator);      
         orig_classpath = STRIP(SYSGET("CLASSPATH"));                 

        IF _ERROR_ = 1 OR LENGTH(orig_classpath) = 0 THEN DO;          
            PUT "NOTE: Ignore any messages from the next statement(s)";
            orig_classpath = "";                                       
        END;                                                           
        CALL SYMPUTX('CP_orig_classpath',                              
                      STRIP(orig_classpath), 'GLOBAL');                
        CALL SYMPUTX('CP_path_separator',                              
                      COMPRESS(path_separator), 'GLOBAL');             
    RUN;                                                               
%mend;                                                                 
%macro add_to_classpath(cp_addition);                                  
    DATA _null_;                                                       
        LENGTH  current_classpath $ 500                                
                new_classpath $ 500;                                   
        current_classpath = STRIP(SYSGET("CLASSPATH"));                
        IF _ERROR_ = 1 OR LENGTH(current_classpath) = 0 THEN DO;       
        PUT "NOTE: Ignore any messages from the nearby statement(s)";  
            new_classpath = "&cp_addition";                            
        END;                                                          

         ELSE DO;                                                        
             new_classpath = COMPRESS(current_classpath) ||              
                             "&CP_path_separator" || "&cp_addition";     
         END;                                                            
         CALL SYMPUTX('CP_new_classpath', STRIP(new_classpath),'GLOBAL');
     RUN;                                                                
     %PUT NOTE: Setting Java classpath to &CP_new_classpath;             
     OPTIONS SET=CLASSPATH "&CP_new_classpath";                          
 %mend;                                                                  
 %macro reset_classpath;                                                 
     %PUT NOTE: Setting Java classpath back to its                       
     original state: &CP_orig_classpath;                                 
     OPTIONS SET=CLASSPATH "&CP_orig_classpath";                         
 %mend;                                                                  
                                                                         
                                                                         
 %init_classpath_update;                                                 
 %add_to_classpath(/u/siva/BatchJava/lib/apps/helloWorld.jar);         
                                                                        

                                                       
 data _null_;                                           
 /* -- set length of variable to capture message ; */   
 length message $ 200 ;                                 
 /** -- initiate java object ; */                       
 declare javaobj jobj ("helloWorld");                   
 /* -- get message and clean up ; */                    
 jobj.callStringMethod('getMessage', message);          
 jobj.delete();                                         
 put message = ;                                        
 run;                                                   
 %reset_classpath;                                     

 

 

Reference Link: http://www2.sas.com/proceedings/sugi30/241-30.pdf

 

Could some one help me out here .

 

Thanks ~

1 REPLY 1
ChrisHemedinger
Community Manager

If you're using WPS, the "JavaObj plumbing" is likely to be different than what SAS supports.  You might need to work with WPS support to find the answer to this question in your environment.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 952 views
  • 0 likes
  • 2 in conversation