1

I am trying to reset password for sap user using BAPI_USER_CHANGE, but it is giving error as

password is not input field type

I am posting my code below. Here getRandomString() is user-defined function. I have copied this code from internet and I am completely unaware about this function.

    public static void resetSAPPwd()
    {
      //String newPassword = getRandomString();
        String newPassword ="mypwd";       
        String userId="myid";
    try{
        
          JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
          System.out.println("getRepositoryUser for resetSAPPwd : "+destination.getRepositoryUser());
          JCoFunction bapiUserChange = destination.getRepository().getFunction("BAPI_USER_CHANGE");
          
          System.out.println("1 check fn:  ");
             
         if(bapiUserChange != null){
              JCoParameterList userChangeInput = bapiUserChange.getImportParameterList();
             
                System.out.println("JCoParameterList object userChangeInput ............. :"+userChangeInput);    
               
                    JCoStructure sPassword = userChangeInput.getStructure("PASSWORD");
                    JCoStructure sPasswordx = userChangeInput.getStructure("PASSWORDX");
                    
                    sPassword.setValue(newPassword, "BAPIPWD");
                    System.out.println("0");
                    sPasswordx.setValue('X', "BAPIPWD");
                    System.out.println("1");
                    userChangeInput.setValue(userId, "USERNAME");
                    //userChangeInput.setValue(sPassword, "PASSWORD"); 
                    //userChangeInput.setValue(sPasswordx,"PASSWORDX");
                    System.out.println("2");
                    bapiUserChange.execute(destination);
                    
               System.out.println("Reset Pwd Done.......... ");
   
          }
    }catch(Exception e){
        System.out.println(e.getMessage());
    }

}

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
MNW
  • 79
  • 2
  • 7

0 Answers0