cancel
Showing results for 
Search instead for 
Did you mean: 

Sap script vba excel compare field

Former Member
0 Kudos

Hello,

I am new and doesn't know much about scripting.

But can anyone help me with a script that i can use to compare a field from sap and excel.

And if both fields are the same it must enter some data at sap

Example.

Excel

00069114_P 

SAP (MM02 MRP 1 and button MRP AREA)

00069114_P

0069114_P the same value

then it must select the field at sap.

Sorry for mine bad english.

Greetings Raoul

Accepted Solutions (0)

Answers (1)

Answers (1)

holger_khn
Contributor
0 Kudos

Hello.

May you can perform a script recording from call Transaction MM02 until you touch all fields which should in scope and should compared.

Cause in some Environments not all Options are enabled like in your Environment. (E.g. we have not button MRP area enbaled in our System for Transaction MM02).

With a script recording we should be able to suggest some way how you can achieve your requirements.

Best regards,

Holger

Former Member
0 Kudos

Hello Hoger,

Thank you for your reply.

This is mine script so far.

Session.findById("wnd[0]").maximize

Session.findById("wnd[0]/tbar[0]/okcd").Text = "/nmm02"

Session.findById("wnd[0]").sendVKey 0

Session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = A

Session.findById("wnd[1]/tbar[0]/btn[19]").press

Session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").getAbsoluteRow(11).Selected = True

Session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,11]").SetFocus

Session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,11]").caretPosition = 0

Session.findById("wnd[1]/tbar[0]/btn[0]").press

Session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").Text = B

Session.findById("wnd[1]/tbar[0]/btn[0]").press

Session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP12/ssubTABFRA1:SAPLMGMM:2000/subSUB5:SAPLMGD1:2480/btnMARC_DIBER_PUSH").press

Session.findById("wnd[1]/usr/tblSAPLMD_MGD1TC_LOOPBERID").getAbsoluteRow(4).Selected = True


Session.findById("wnd[1]/usr/tblSAPLMD_MGD1TC_LOOPBERID/ctxtSMDMA-BERID[0,4]").SetFocus ' <--- button MRP AREA

Session.findById("wnd[1]/usr/tblSAPLMD_MGD1TC_LOOPBERID/ctxtSMDMA-BERID[0,4]").caretPosition = 0 ' <---- MRP selectie with excel needed


Session.findById("wnd[1]/usr/btnPB02").press

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP01/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0030/ctxtMDMA-DISGR").Text = C

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP01/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0030/ctxtMDMA-DISMM").Text = D

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP01/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0030/ctxtMDMA-DISPO").Text = E

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP01/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0030/ctxtMDMA-DISLS").Text = F

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP01/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0030/ctxtMDMA-DISLS").SetFocus

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP01/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0030/ctxtMDMA-DISLS").caretPosition = 2

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP02").Select

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP02/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0040/chkMDMA-PLIFZX").Selected = True

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP02/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0040/ctxtMDMA-SOBSL").Text = G

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP02/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0040/txtMDMA-PLIFZ").Text = H

Session.findById("wnd[2]/usr/tabsTABSTRIP1/tabpSP02/ssubTABFRA1:SAPLMD_MGD1:0005/subSUB1:SAPLMD_MGD1:0040/chkMDMA-PLIFZX").SetFocus

Session.findById("wnd[2]/tbar[0]/btn[7]").press

Session.findById("wnd[1]/tbar[0]/btn[7]").press

Session.findById("wnd[2]/tbar[0]/btn[0]").press

Session.findById("wnd[0]/tbar[0]/btn[11]").press

Session.findById("wnd[0]").sendVKey 0

Session.findById("wnd[0]/tbar[0]/btn[3]").press

holger_khn
Contributor
0 Kudos

Hello.

I suggest you make a FOR-NEXT VBA Loop over all lines in your Excel WB sheet. Fill required variables with fields from line.

A second Loop (e.g. DO UNTIL) for the MRP-area value. There I suggest to record a scroll of existing MRP-lines as it is easier to take everytime top line for compare than dynamic move.

If MRP-area field value = Excel field value your update Action can initate.

If MRP-area value not exist or Loop runs into empty field next line from FOR-NEXT Loop should called.

Hope this give you some ideas.

Best regards

Holger