0

My script is loading data in SAP GUI Recipe screen (transaction code C202) from Excel data.

In one of the Recipe screens, values are to be entered based on column "Phase" value from Excel. I need to update 2nd "Std Value" and 3rd "Std Value" for each particular "phase" from the Excel sheet.

SAP C202

Excel

Can you please help me with this ? I need to switch between rows to modify each phase

For i = 1 To LastRow

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nC202"
session.findById("wnd[0]").sendVKey 0

Plant = shControlPanel.Range("A" & CurrentRow).Value
RecipeGroup = shControlPanel.Range("B" & CurrentRow).Value
Recipe = shControlPanel.Range("C" & CurrentRow).Value
ECR = shControlPanel.Range("D" & CurrentRow).Value
Phase = shControlPanel.Range("E" & CurrentRow).Value
Value2 = shControlPanel.Range("F" & CurrentRow).Value
Value3 = shControlPanel.Range("G" & CurrentRow).Value


session.findById("wnd[0]/usr/ctxtRC271-PLNNR").Text = RecipeGroup
session.findById("wnd[0]/usr/txtRC271-PLNAL").Text = Recipe
session.findById("wnd[0]/usr/ctxtRC27M-WERKS").Text = Plant
session.findById("wnd[0]/usr/ctxtRC271-AENNR").Text = ECR
session.findById("wnd[0]/usr/ctxtRC271-STTAG").Text = "04.09.2020"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0

    j = 1
    PhaseToChange = session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VORNR[0," & j & "]").Text
    Resorce = session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/ctxtPLPOD-ARBPL[4," & j & "]").Text
    Do While Resorce <> ""
    
    PhaseToChange = session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VORNR[0," & j & "]").Text
    Resorce = session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/ctxtPLPOD-ARBPL[4," & j & "]").Text
    
        If Phase = PhaseToChange Then

            session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VGW02[18," & j & "]").Text = Value2
            session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VGW03[21," & j & "]").Text = Value3
            session.findById("wnd[0]").sendVKey 0
            j = j + 1
        Else
            j = j + 1
        End If

CurrentRow = CurrentRow + 1
Phase = shControlPanel.Range("E" & CurrentRow).Value
Value2 = shControlPanel.Range("F" & CurrentRow).Value
Value3 = shControlPanel.Range("G" & CurrentRow).Value

Loop

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

On Error Resume Next
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press

shControlPanel.Range("H" & CurrentRow).Value = "Recipe " & Recipe & " has been changed"

CurrentRow = CurrentRow + 1
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Pawel
  • 1
  • 1
  • I edited the text to clarify the question, please revert back if needed or improve it. Anyway, the question is currently unclear, could you show the SAP GUI screen in which you want to add the values and describe precisely the logic to implement. – Sandra Rossi Sep 04 '20 at 15:30
  • Many thanks for this :) I have added a screen from SAP and Transaction C202. – Pawel Sep 04 '20 at 15:36
  • Added loop - based on what I have found in stack archives :) – Pawel Sep 04 '20 at 16:52
  • Could you clarify if the lines already exist in `C202` with given "phases" ("Operation" in the screen) and your code has to update the columns "2nd Std Value" and "3rd Std Value"? If so, I guess you want to identify the Excel row which has the same "phase", and you want to know how to loop at Excel rows? – Sandra Rossi Sep 04 '20 at 16:58
  • Yes - the "Operation" from SAP C202 screen = Phase from the Excel – Pawel Sep 04 '20 at 17:02
  • Does this answer your question? [Iterating through populated rows](https://stackoverflow.com/questions/24377197/iterating-through-populated-rows) – Sandra Rossi Sep 04 '20 at 17:06
  • And yes I need to switch between the rows from Excel and increase somehow "Phase" from script to switch from 0012 to 0013 and then put to the 2nd Std Value value from Excel ie 0,001 - for 3rd Std Value from also 0,001 then change phase to 0014 and repeat till Resource in loop will be "empty"... – Pawel Sep 04 '20 at 17:11
  • I have modify the VBA and add CurrentRow + 1 to "Phase" , "Value2" , "Value3" and now it seems that is working properly :) – Pawel Sep 04 '20 at 17:26
  • Iterating through populated rows - is OK - but I need to earlier exit from the loop. When I add "+1" to the "CurrentRow", and reach to the "Phase" 0016, the "Resorce" still have a value... – Pawel Sep 04 '20 at 17:58
  • This question has already been asked too. – Sandra Rossi Sep 04 '20 at 18:00

1 Answers1

0

I do not have access to transaction C202. But from my point of view I try to smooth things over ...

LastRow = ActiveCell.SpecialCells(xlLastCell).Row

For i = 1 To LastRow

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nC202"
session.findById("wnd[0]").sendVKey 0

Plant = shControlPanel.Range("A" & i).Value
RecipeGroup = shControlPanel.Range("B" & i).Value
Recipe = shControlPanel.Range("C" & i).Value
ECR = shControlPanel.Range("D" & i).Value
Phase = shControlPanel.Range("E" & i).Value
Value2 = shControlPanel.Range("F" & i).Value
Value3 = shControlPanel.Range("G" & i).Value


session.findById("wnd[0]/usr/ctxtRC271-PLNNR").Text = RecipeGroup
session.findById("wnd[0]/usr/txtRC271-PLNAL").Text = Recipe
session.findById("wnd[0]/usr/ctxtRC27M-WERKS").Text = Plant
session.findById("wnd[0]/usr/ctxtRC271-AENNR").Text = ECR
session.findById("wnd[0]/usr/ctxtRC271-STTAG").Text = "04.09.2020"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0

j = 1

Do  

PhaseToChange = session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VORNR[0," & j & "]").Text
Resorce = session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/ctxtPLPOD-ARBPL[4," & j & "]").Text
    If Resorce = "" then exit do
    If Phase = PhaseToChange Then

        session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VGW02[18," & j & "]").Text = Value2
        session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401/txtPLPOD-VGW03[21," & j & "]").Text = Value3
        session.findById("wnd[0]").sendVKey 0
  
        shControlPanel.Range("H" & i).Value = "Recipe " & Recipe & " has been changed"
     End If
     j = j + 1
          
Loop

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

On Error Resume Next
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
On error goto 0

next i

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9
  • Thank you ScriptMan! I have to change such part to: ```Plant = shControlPanel.Range("A" & CurrentRow).Value RecipeGroup = shControlPanel.Range("B" & CurrentRow).Value Recipe = shControlPanel.Range("C" & CurrentRow).Value ECR = shControlPanel.Range("D" & CurrentRow).Value Phase = shControlPanel.Range("E" & CurrentRow).Value Value2 = shControlPanel.Range("F" & CurrentRow).Value Value3 = shControlPanel.Range("G" & CurrentRow).Value``` then script start to work properly. Many thanks for reply and help me with this "simple" topic... – Pawel Sep 10 '20 at 07:24