piersharding / RSAP

SAP NW RFC connector for R
21 stars 16 forks source link

SNC_LIB and SNC_LIB_64 library path variable #3

Closed SaJaToGu closed 6 years ago

SaJaToGu commented 6 years ago

I have a problem within a shiny app to distinguish between 64 and 32 bit SNC libraries. If a SNC_LIB_64 lib path variable exists, those should be used to load the SNC library instead of SNC_LIB. Other vice it comes to an error and a dump of the R-Session. Please see the following issues posted by me on stackoverflow. : https://stackoverflow.com/questions/48081706/sys-setenvsnc-lib-lib-path-64-fails/48084667#48084667

Full coding:

' Open Connection to BW (Business Warehouse)

'

' @param user with sap user and password

' @param password with sap password

' @param SAP to pass warnings and errors

'

' @return con with BW connection

' @export

'

OpenConnection2BW <- function(user = NULL, password = NULL, SAP = NULL, SNC = NULL) { require(RSAP) require(shiny)

# browser()
if (is.null(user) || user == "") {
  user <- Sys.getenv("USER")
  if (is.null(user) || user == "") {
    user <- Sys.getenv("USERNAME")
  }
  user <- toupper(user)
}
if (isTruthy(SNC)) {
  # check SNC_LIB path from environment variables
  # 32 or 64 bit?
  # if 64 bit lib path is set, set the default lib path variable
  # SNC_LIB to it
  lib_path_64 <- Sys.getenv("SNC_LIB_64")
  if (lib_path_64 != "") {
    browser()
    Sys.setenv("SNC_LIB" = lib_path_64)
  }
  SAP$con <- tryCatch({
    RSAPConnect(
      ashost = "ms-dcb73.glpoly.net",
      sysnr = "30",
      client = "200",
      user = user,
      lang = "EN",
      SNC_QOP = "9",
      SNC_SSO = "1",
      SNC_PARTNERNAME = "p:CN=B73, OU=SNCAuthCert, O=Covestro"
    )
  },
  error = function(errorCondition) {
    # cat("in err handler")
    # message(errorCondition)
    SAP$error <-
      paste(SAP$warning, errorCondition)
  },
  warning = function(warningCondition) {
    # cat("in warn handler")
    # message(warningCondition)
    SAP$warning <- warningCondition
  })
} else { # SNC == FALSE
  SAP$con <- tryCatch({
    RSAPConnect(
      ashost = "ms-dcb73.glpoly.net",
      sysnr = "30",
      client = "200",
      user = user,
      passwd = password,
      lang = "EN"
    )
  },
  error = function(errorCondition) {
    # cat("in err handler")
    # message(errorCondition)
    SAP$error <-
      paste(SAP$warning, errorCondition)
  },
  warning = function(warningCondition) {
    # cat("in warn handler")
    # message(warningCondition)
    SAP$warning <- warningCondition
  })
}
return(SAP)

}

SaJaToGu commented 6 years ago

I passed the SNC_LIB path by the parameter SNC_LIB now:

' Open Connection to BW (Business Warehouse)

'

' @param user with sap user and password

' @param password with sap password

' @param SAP to pass warnings and errors

'

' @return con with BW connection

' @export

'

OpenConnection2BW <- function(user = NULL, password = NULL, SAP = NULL, SNC = NULL) { require(RSAP) require(shiny)

# browser()
if (is.null(user) || user == "") {
  user <- Sys.getenv("USER")
  if (is.null(user) || user == "") {
    user <- Sys.getenv("USERNAME")
  }
  user <- toupper(user)
}
if (isTruthy(SNC)) {
  # check SNC_LIB path from environment variables
  # 32 or 64 bit?
  # if 64 bit lib path is set, set the default lib path variable
  # SNC_LIB to it
  snc_lib_path_64 <- Sys.getenv("SNC_LIB_64")
  if (lib_path_64 != "") {
    # browser()
    snc_lib_path = snc_lib_path_64
  } else {
    snc_lib_path = Sys.getenv("SNC_LIB")
  }
  SAP$con <- tryCatch({
    RSAPConnect(
      ashost = "ms-dcb73.glpoly.net",
      sysnr = "30",
      client = "200",
      user = user,
      lang = "EN",
      SNC_QOP = "9",
      SNC_SSO = "1",
      SNC_LIB = snc_lib_path,
      SNC_PARTNERNAME = "p:CN=B73, OU=SNCAuthCert, O=Covestro"
    )
  },
  error = function(errorCondition) {
    # cat("in err handler")
    # message(errorCondition)
    SAP$error <-
      paste(SAP$warning, errorCondition)
  },
  warning = function(warningCondition) {
    # cat("in warn handler")
    # message(warningCondition)
    SAP$warning <- warningCondition
  })
} else { # SNC == FALSE
  SAP$con <- tryCatch({
    RSAPConnect(
      ashost = "ms-dcb73.glpoly.net",
      sysnr = "30",
      client = "200",
      user = user,
      passwd = password,
      lang = "EN"
    )
  },
  error = function(errorCondition) {
    # cat("in err handler")
    # message(errorCondition)
    SAP$error <-
      paste(SAP$warning, errorCondition)
  },
  warning = function(warningCondition) {
    # cat("in warn handler")
    # message(warningCondition)
    SAP$warning <- warningCondition
  })
}
return(SAP)

}