Skip to Content

Script to tell if document has an attachment in SAP

I would like to write a script to check if our MIRO and FB60 documents have an attachment.  I would prefer a system report, but our IT group has not been able to provide this.  I have reverted to writing a script that pulls up each invoice, opens up the attachment list window and then checks to see if there is an attachment.  My script is not great because if there is no attachment, I don't know how to cleanly determine this.  Right now I try to select the first attachment.

session.FindById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"

If there is no attachment, I get an error message.  In Excel I set up the error handler to jump to a part of the macro that records "no attachment", if there isn't an error message I record "has attachment".

Is there a cleaner way to do this?

Also, I'm checking thousands of these documents and if there is a warning message at the bottom of a window when I pull up the document with FBV3 (document deleted etc) then my macro falls over.  Any ideas on how to handle messages in a general way?

Thanks,

Tyler

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Oct 03, 2014 at 04:55 PM

    I use this technique to see if something exists or not to get ahead of it actually failing when you try to reference an object id that did show up as expected.

      This example is looking to see if a new window popped up with the serial nbr grid entry in it.  Not just any new window (that would be just wnd[1]), but specifically down to a field I expect to see on it, so I know it's not some other window I haven't seen before.

    Set SAPobj = SAPSession.FindById("wnd[1]/usr/tblSAPLIPW1TC_SERIAL_NUMBERS/ctxtRIPW0-SERNR[0,0]", False)

        If SAPobj Is Nothing Then

          MsgBox ("Serial Nbr provided but part is not serialized.  Order was not created. Skipping record")

          Exit Function

        Else

           'do good things

        End If

    I use this technique to check for warning messages and press enter to acknowledge

    I know there is a way to check if the type of message is a warning vs hard stop error and I considered just checking for that but it's handy to know what kind of warnings I have already accounted for so I still code it to look at the specific text.

      'check for not a working day warning and press Enter key to acknowledge

      If InStr(GetSAPStatus(), "not a working day") > 1 Then

        SAPSession.FindById("wnd[0]").SendVKey 0

      End If


    GetSAPStatus is a custom function:

    Function GetSAPStatus()

      On Error Resume Next

        GetSAPStatus = ""

        GetSAPStatus = SAPSession.ActiveWindow.FindByName("sbar", "GuiStatusbar").Text

      On Error GoTo 0

    End Function

    Add comment
    10|10000 characters needed characters exceeded

    • Thanks Chad.  I'm trying to implement your code, but the SAP script I recorded doesn't give me an object that I can address.  It shows as the following:

      ' this bit opens up the attachment list window

      session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"

      session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"

      ' this is what happens when I click on the first attachment

      session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").currentCellColumn = "BITM_DESCR"

      session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"

      I tried to use session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").Rows(0) as the object, but it isn't working.  (Object doesn't support this property or method).  Can you see what I'm doing wrong?  Ideally I would like to see if there is an attachment, or even better, read how many items are attached.

      Is there a way within SAP to see what objects are in each window and what methods and properties are associated with each object?

      Thanks,

      Tyler