Monday 7 November 2016

SAP CBTA - Posibility of storing output parameter in TDC - Transferring output parameter across CBTA script

There is no option to store CBTA script out put parameter in TDC(Test Data Container) though we can display it in results.

If our requirement is passing one script output parameter as input parameter for other script then make composite script by pulling both 2 CBTA scripts together

 Once we have exported output parameter value from one CBTA script(details highlighted in above screenshot) we can import that parameter in other CBTA script (details highlighted in below screenshot)


If we are expecting to pass parameter across composite script then we only have option to write custom code to export parameter and later create another custom code to import that parameter.

Below are few sample custom component codes to use it.

'====================================================================
''Function to update column value in excel file
'====================================================================
Public Function uf_XLS_UpdateColumnValue(sExcelPath, sSheetName,sSearchCriteria , sField, sValue)

  Dim objExcel
Dim objWorkbook
Dim sColumnName
Dim iKeywordRow
Dim iFeildColumn
Dim arrSearchCriteria

arrSearchCriteria = Split(sSearchCriteria,"=")
sKeywordField = arrSearchCriteria(0)
sKeyword = arrSearchCriteria(1)
     
    Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Open(Trim(sExcelPath))
objExcel.Sheets(Trim(sSheetName)).Select

iColumnNumber = objExcel.Cells.Find(Trim(sKeywordField)).Column
sColumnName = uf_XLS_ConvertColNoToColName(iColumnNumber)

iKeywordRow = objExcel.Range(sColumnName & ":" & sColumnName).Find(Trim(sKeyword)).Row
If sField = "" Then
iFieldColumn = objExcel.Cells.Find(Trim(sKeyword)).Column + 1
Else
iFieldColumn = objExcel.Cells.Find(Trim(sField)).Column
End If
objExcel.Cells(iKeywordRow, iFieldColumn) = sValue
objExcel.ActiveWorkbook.Save

If Err.Number <> 0 Then rc = micFail Else rc = micPass
    objWorkbook.close
objExcel.Application.Quit
    Set objWorkbook = Nothing
Set objExcel=Nothing

uf_XLS_UpdateColumnValue = rc
End Function

'====================================================================
''Function to retrieve column value from excel file
'====================================================================
Public Function uf_XLS_GetSpecificColumnValue(sExcelPath, sSheetName,sSearchCriteria , sField)
  Dim objExcel
Dim objWorkbook
Dim sColumnName
Dim iKeywordRow
Dim iFeildColumn
Dim sValue
Dim arrSearchCriteria

arrSearchCriteria = Split(sSearchCriteria,"=")
sKeywordField = arrSearchCriteria(0)
sKeyword = arrSearchCriteria(1)
 
    Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Open(Trim(sExcelPath))
objExcel.Sheets(Trim(sSheetName)).Select

iColumnNumber = objExcel.Cells.Find(Trim(sKeywordField)).Column
sColumnName = uf_XLS_ConvertColNoToColName(iColumnNumber)

iKeywordRow = objExcel.Range(sColumnName & ":" & sColumnName).Find(Trim(sKeyword)).Row
If sField = "" Then
iFeildColumn = objExcel.Cells.Find(Trim(sKeyword)).Column + 1
Else
iFeildColumn = objExcel.Cells.Find(Trim(sField)).Column
End If
sValue = Trim(objExcel.Cells(iKeywordRow, iFeildColumn))

objWorkbook.close
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel=Nothing

uf_XLS_GetSpecificColumnValue = sValue
End Function

'====================================================================
''Function to write value in text file
'====================================================================
Public Function uf_FS_WriteTextFile(sFilePath,sData)
   Const ForAppending=8
'Objects for Text File
Dim objTextFile, objSetTextFile
' Create A test file object
Set objTextFile = CreateObject("Scripting.FileSystemObject")
' Open it in Append Mode
Set objSetTextFile = objTextFile.OpenTextFile(sFilePath,ForAppending,True)
'Write the data into the file
objSetTextFile.WriteLine  sData
'Close the file
objSetTextFile.Close

If Err.Number <> 0 Then rc = micFail Else rc = micPass
uf_FS_WriteTextFile = rc
End Function
'===================================================================
''Function to read value from text file
'===================================================================
Public Function uf_FS_ReadTextFile(sPath)
Const ForReading=1
'Objects for Text File
Dim objTextFile, objSetTextFile
' Create A test file object
Set objTextFile = CreateObject("Scripting.FileSystemObject")
' Open it in Read Mode
Set objSetTextFile = objTextFile.OpenTextFile(sPath,ForReading,True)
'Read the data into the file
strFileData= objSetTextFile.ReadAll
'Close the file
objSetTextFile.Close
uf_FS_ReadTextFile = strFileData
End Function
'==================================================================