cancel
Showing results for 
Search instead for 
Did you mean: 

JCO input Parameter Structures : BAPI_USER_CHANGE

Former Member
0 Kudos

Hi Experts,

I have a JCO connection calling bapi (BAPI_USER_CHANGE) to reset user's password.

I am passing USERNAME, PASSWORD and PASSWORDX. However I am getting an error when password PASSWORD:

"Cannot convert a value of '5qtzsRMVRn' from type java.lang.String to STRUCTURE at field PASSWORD"

I may have to get structure first, but when what to I assign it to?


String newPassword = getRandomString();
    
    try{
		JCO.Function bapiUserChange = repository.getFunctionTemplate("BAPI_USER_CHANGE").getFunction();
		if(bapiUserChange != null){
			JCO.ParameterList userChangeInput = bapiUserChange.getImportParameterList();
			
			JCO.Structure sPassword = userChangeInput.getStructure("PASSWORD");
			
			//sPassword.setValue(newPassword, ????) //what do I assign it to?
			
			userChangeInput.setValue(userId, "USERNAME");
			userChangeInput.setValue(newPassword, "PASSWORD");  // this gives an error
			userChangeInput.setValue("X","PASSWORDX"); //I know "X" is true, this will give an error too I believe
			
			mConnection.execute(bapiUserChange);
			
			//send E-mail
			boolean emailSent = sendEmail(userId, newPassword, "XXX200");
			msgMgr.reportSuccess("Password Reset Done");	
			
			if(mConnection != null){
				mConnection.disconnect();
			}
					
		}
    }catch(Exception e){
    	msgMgr.reportException("Could not change password " + e.getMessage(),true);
    }

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Solved.


String newPassword = getRandomString();
    
    try{
		JCO.Function bapiUserChange = repository.getFunctionTemplate("BAPI_USER_CHANGE").getFunction();
		if(bapiUserChange != null){
			JCO.ParameterList userChangeInput = bapiUserChange.getImportParameterList();
			
			JCO.Structure sPassword = userChangeInput.getStructure("PASSWORD");
			JCO.Structure sPasswordx = userChangeInput.getStructure("PASSWORDX");
			
			sPassword.setValue(newPassword, "BAPIPWD");
			sPasswordx.setValue('X', "BAPIPWD");
			
			userChangeInput.setValue(userId, "USERNAME");
			userChangeInput.setValue(sPassword, "PASSWORD"); 
			userChangeInput.setValue(sPasswordx,"PASSWORDX");
			
			mConnection.execute(bapiUserChange);
			
			//send E-mail
			boolean emailSent = sendEmail(userId, newPassword, client);
			msgMgr.reportSuccess("Password Reset Done");	
			
			disconnectJCO();
					
		}
    }catch(Exception e){
    	msgMgr.reportException("Could not change password " + e.getMessage(),true);
    }finally{
		disconnectJCO();
    }

Former Member
0 Kudos

Hi Rahim,

               I am using SAPJco3.x api for reset password by using java client.Should it work with above code by changing classes according to latest Api.Following Code for SAPJCo3.x

public static void resetSAPPwd()

        {

      String userId="myid";

        String newPassword ="mypwd";

      try{

      JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);

      JCoContext.begin(destination);

      

              JCoFunction bapiUserChange = destination.getRepository().getFunctionTemplate("BAPI_USER_CHANGE").getFunction();

             

              if(bapiUserChange != null){

                   JCoParameterList userChangeInput = bapiUserChange.getImportParameterList();

               

                   JCoStructure sPassword = userChangeInput.getStructure("PASSWORD");

                   JCoStructure sPasswordx = userChangeInput.getStructure("PASSWORDX");

                         

                

                   sPassword.setValue("BAPIPWD",newPassword);

                   sPasswordx.setValue("BAPIPWD",'X');

                  

                    userChangeInput.setValue("USERNAME",userId);

                    userChangeInput.setValue("PASSWORD",sPassword);

                    userChangeInput.setValue("PASSWORDX",sPasswordx);

                   

                     bapiUserChange.execute(destination);

                 

                   System.out.println("SAP Pasw0rd reset done :");

              }

        }catch(Exception e){

         e.getStackTrace();

      System.out.println(e.getMessage());

          

        }

  }