cancel
Showing results for 
Search instead for 
Did you mean: 

problems with loop in sap script

luiz_bernardo
Discoverer
0 Kudos

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

moshenaveh
Community Manager
Community Manager
0 Kudos

Welcome to the SAP Community. Thank you for visiting us to get answers to your questions.

Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.

First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Second, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html, as that will help you when submitting questions to the community.

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

Now for some specific suggestions on how you might improve your question:

* Outline what steps you took to find answers (and why they weren't helpful) -- so members don't make suggestions that you've already tried.

* Share screenshots of what you've seen/done (if possible), as images always helps our members better understand your problem.

Should you wish, you can revise your question by selecting Actions, then Edit.

The more details you provide (in questions tagged correctly), the more likely it is that members will be able to respond.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

View Entire Topic
juliborzsei
Explorer
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?