cancel
Showing results for 
Search instead for 
Did you mean: 

problems with loop in sap script

luiz_bernardo
Discoverer
0 Kudos
339

I made a script with a loop to carry out several items from a file, but the transaction has a limit of 10 items, and the files 15 or more, I need help so that the script understands that it needs to scroll down when it has no empty lines

    For Each cel In rng
    
        If IsEmpty(cel.Value) Then
        Exit For
        End If
        
        
        Session.findById("wnd[0]").sendVKey 4
        Session.findById("wnd[1]/usr/tabsG_SELONETABSTRIP/tabpTAB001/ssubSUBSCR_PRESEL:SAPLSDH4:0220/sub:SAPLSDH4:0220/txtG_SELFLD_TAB-LOW[0,24]").Text = cel.Value
        Session.findById("wnd[1]/usr/tabsG_SELONETABSTRIP/tabpTAB001/ssubSUBSCR_PRESEL:SAPLSDH4:0220/sub:SAPLSDH4:0220/txtG_SELFLD_TAB-LOW[0,24]").caretPosition = 19
        Session.findById("wnd[1]").sendVKey 0
        cel.Offset(0, 1) = Session.findById("wnd[1]/usr/lbl[49,3]").Text
        Session.findById("wnd[1]/usr/lbl[49,3]").caretPosition = 5
        Session.findById("wnd[1]").sendVKey 2
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/tblSAPLCOMKTCTRL_3010/txtRESBD-MENGE[4," & CInt(contador) & "]").Text = Cells(contador2, 7).Value
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/tblSAPLCOMKTCTRL_3010/ctxtRESBD-POSTP[6," & CInt(contador) & "]").Text = "n"
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/tblSAPLCOMKTCTRL_3010/ctxtRESBD-POSTP[6," & CInt(contador) & "]").SetFocus
        Session.findById("wnd[0]").sendVKey 0
        If Session.ActiveWindow.Name = "wnd[1]" Then
            Session.findById("wnd[1]/tbar[0]/btn[0]").press
        End If
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/tblSAPLCOMKTCTRL_3010").getAbsoluteRow(contador).Selected = True
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/tblSAPLCOMKTCTRL_3010/txtRESBD-POSNR[0," & CInt(contador) & "]").SetFocus
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/btnBTN_EINK").press
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1300/tabsTS_1300/tabpEINK/ssubSUB_KMP_DETAIL:SAPLCOMD:3170/txtRESBD-GPREIS").Text = ThisWorkbook.Worksheets("Planilha1").Cells(contador2, 9).Value
                If Session.ActiveWindow.Name = "wnd[1]" Then
            Session.findById("wnd[1]/tbar[0]/btn[3]").press
        End If
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1300/tabsTS_1300/tabpEINK/ssubSUB_KMP_DETAIL:SAPLCOMD:3170/ctxtRESBD-LIFNR").Text = Cells(2, 13).Value
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1300/tabsTS_1300/tabpEINK/ssubSUB_KMP_DETAIL:SAPLCOMD:3170/txtRESBD-AFNAM").Text = Cells(1, 13).Value
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1300/tabsTS_1300/tabpEINK/ssubSUB_KMP_DETAIL:SAPLCOMD:3170/txtRESBD-BEDNR").Text = "2"
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1300/tabsTS_1300/tabpEINK/ssubSUB_KMP_DETAIL:SAPLCOMD:3170/ctxtRESBD-LIFNR").SetFocus
        Session.findById("wnd[0]").sendVKey 0
        Session.findById("wnd[0]").sendVKey 0
        Session.findById("wnd[0]").sendVKey 0
        Session.findById("wnd[0]/tbar[0]/btn[3]").press
        If Session.ActiveWindow.Name = "wnd[1]" Then
            Session.findById("wnd[1]/tbar[0]/btn[3]").press
        End If
        Session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1200/subSUB_AVO_KOMP:SAPLCOIH:1206/tabsTS_1206/tabpKPVG/ssubSUB_AVO_OVERVIEW:SAPLCOMK:3010/tblSAPLCOMKTCTRL_3010").getAbsoluteRow(contador).Selected = False
        Session.findById("wnd[0]").sendVKey 4
        Session.findById("wnd[0]").sendVKey 0
        
        
        contador = contador + 1
        contador2 = contador2 + 1


        
    Next cel

Accepted Solutions (0)

Answers (2)

Answers (2)

juliborzsei
Associate
Associate
0 Kudos

Hi Luiz!

I have just double checked your question with our team and they confirmed that this request is not related to the ESL twig based language we use in SAP Emarsys for creating dynamic personalized content in marketing campaigns. Maybe you can specify in which product are you looking to use this and tag the question accordingly?

juliborzsei
Associate
Associate
0 Kudos

HI Luiz! Can you please explain a bit more what you would like to achieve with ESL? It's not entirely clear for me now.

Thank you,

Juli

luiz_bernardo
Discoverer
0 Kudos

my work orders usually have more than 15 items, however this transaction can only do 10 at a time, how can I tell the script that when I do 10 items it has to scroll down to show more lines?