Skip to Content

Sapscript to check if a field contains something.

Hello,

I have a Excel/SAPscript macro that closes WBS elements in CJ20N. This macro will fail upon trying to close a WBS that is already closed, because the close alternative is faded and unavailable in the menus. Therefore I want the macro to check the WBS element system status field if it contains the "CLSD" status before setting the status.

I have tried this which does not work, the .Contains("CLSD")-part, I have also tried .Text.Contains("CLSD"), .Text = "CLSD", and no one of those are working. If it finds CLSD in this field in the code, it should move on to "Redanstangdhoppaover" in my code (this skips the actual setting of the status).

If session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3999/tabsTABCJWB/tabpGRND/ssubSUBSCR1:SAPLCJWB:1210/subSTATUS:SAPLCJWB:0700/txtCNJ_STAT-STTXT_INT").Contains("CLSD") Then GoTo Redanstangdhoppaover

What else is there left to try?

Thanks, Mattias

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 19, 2011 at 04:11 PM

    Hello Mattias,

    try this:

    Dim oName
    Set oName = session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3999/tabsTABCJWB/tabpGRND/ssubSUBSCR1:SAPLCJWB:1210/subSTATUS:SAPLCJWB:0700/txtCNJ_STAT-STTXT_INT")
    If InStr(oName.text, "CLSD", 1) > 0 Then
      MsgBox "Found"
    Else
      MsgBox "Not found"
    End If

    Hope it helps.

    Cheers

    Stefan

    Add comment
    10|10000 characters needed characters exceeded

    • Hi and thanks for the answer.

      Got it to work with this edit:

      Dim oName
      Set oName = session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3999/tabsTABCJWB/tabpGRND/ssubSUBSCR1:SAPLCJWB:1210/subSTATUS:SAPLCJWB:0700/txtCNJ_STAT-STTXT_INT")
      If InStr(oName.Text, "CLSD") > 0 Then session.findById("wnd[0]/tbar[0]/btn[3]").press
      GoTo Redanstangdhoppaover

      Thanks again :]

      Mattias