Skip to Content
Personal Insights

 SAP GUI Scripting – BOM Creation

 SAP GUI Scripting – BOM Creation

SAP have “Script Recording and Playback” which allows us to record the desired transaction for creating master data or updating the information. This blog explains all about the issues what is faced while creating the BOM using Scripting Recording.

First there is no such content available for BOM Creation using the Scripting Recording and Playing Back. I thought that this content needs to be created and make available to know BOM creation in Scripting Recording.

  • There was numerous attempt I made to record “Single Header BOM creation” (Explained in a) Single Header Material – BOM Creation). I am unable meet with excel logic to repeatedly do the same job. Initially I have tried with executing the CS01 and placing 21 Components but I am unable to succeeded in this. Then I have tried to search in SAP SCN Help and found one discussion that for placing each items there need to be used New Items. So I have tried with the idea given by the person, I am unable succeed in my first attempt but then able succeed in second  So I am presenting below content where CS01 Input screen will get Header details and followed by While Loop will place component item continuously until the component is empty. So the attempt succeeded.
  • Next attempt made with Multiple header material BOM creation. Initially I start with little knowledge of Excel Macro for placing the header material and component material with two for loops. I am found struck with the programs. Then I have taken one week for thinking a logic for placing the multiple header for BOM Creation. Finally I end up with making logic of using If loop inside of the while loop that will compare previous cell of header material with the existing cell of header material.
  • Here is the logic for BOM Creation – More than one BOM. The above excel sheet will check each row. The header material in above screenshot will be checked. If existing cell of header material are same as previous header material the component will be placed in BOM. And if not the Scripting will execute CS01 and place the header material and first component line item. After that BOM component will be placed in BOM screen. This excel automation got succeeded. And you find the content in portion  “More than one Header BOM Creation” (Explained in B Portion)

 

  1. Single Header Material – BOM Creation

Script from SAP(Modified):

objSess.FindById(“wnd[0]/tbar[0]/okcd”).Text = “cs01”

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]/usr/ctxtRC29N-MATNR”).Text = material

objSess.FindById(“wnd[0]/usr/ctxtRC29N-WERKS”).Text = plant

objSess.FindById(“wnd[0]/usr/ctxtRC29N-STLAN”).Text = bomusage

objSess.FindById(“wnd[0]/usr/ctxtRC29N-DATUV”).Text = Date01

objSess.FindById(“wnd[0]/usr/ctxtRC29N-DATUV”).SetFocus

objSess.FindById(“wnd[0]/usr/ctxtRC29N-DATUV”).caretPosition = 10

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]”).sendVKey 0

 

While Cells(12 + i, 1).Value <> “”

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-POSNR[0,0]”).Text = Cells(12 + i, 1).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-POSTP[1,0]”).Text = Cells(12 + i, 2).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-IDNRK[2,0]”).Text = Cells(12 + i, 3).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).Text = Cells(12 + i, 4).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).SetFocus

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).caretPosition = 1

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT”).VerticalScrollbar.Position = i + 1

    i = i + 1

Wend

Required Excel format to maintain for uploading using Scripting:

  1. More than one Header BOM Creation:

 

Script from SAP(Modified):

While Cells(12 + i, 1).Value <> “”

    If Cells(12 + i, 1) <> Cells(11 + i, 1) Then

objSess.FindById(“wnd[0]/tbar[0]/btn[11]”).press

objSess.FindById(“wnd[0]/tbar[0]/okcd”).Text = “cs01”

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]/usr/ctxtRC29N-MATNR”).Text = Cells(12 + i, 1).Value

objSess.FindById(“wnd[0]/usr/ctxtRC29N-WERKS”).Text = Cells(12 + i, 2).Value

objSess.FindById(“wnd[0]/usr/ctxtRC29N-STLAN”).Text = Cells(12 + i, 3).Value

objSess.FindById(“wnd[0]/usr/ctxtRC29N-DATUV”).Text = Cells(12 + i, 4).Value

objSess.FindById(“wnd[0]/usr/ctxtRC29N-DATUV”).SetFocus

objSess.FindById(“wnd[0]/usr/ctxtRC29N-DATUV”).caretPosition = 10

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-POSNR[0,0]”).Text = Cells(12 + i, 5).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-POSTP[1,0]”).Text = Cells(12 + i, 6).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-IDNRK[2,0]”).Text = Cells(12 + i, 7).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).Text = Cells(12 + i, 8).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).SetFocus

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).caretPosition = 1

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT”).VerticalScrollbar.Position = i + 1

 Else

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-POSNR[0,0]”).Text = Cells(12 + i, 5).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-POSTP[1,0]”).Text = Cells(12 + i, 6).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-IDNRK[2,0]”).Text = Cells(12 + i, 7).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).Text = Cells(12 + i, 8).Value

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).SetFocus

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-MENGE[4,0]”).caretPosition = 1

objSess.FindById(“wnd[0]”).sendVKey 0

objSess.FindById(“wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT”).VerticalScrollbar.Position = i + 1

    End If

    i = i + 1

Wend

Required Excel format to maintain for uploading using Scripting:

To conclude, this blog will be useful for who is struggling to create BOM using SAP GUI SCRIPTING and the content can be useful for who is known about SAP GUI SCRIPTING and tried to create BOM.

By

Mahendran Paramasivan, SAP Consultant

 

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.