How to pick random rows from excel and paste it in SAP

Hi Team,

I have some 130 rows in excel but i need to copy first 4 rows from excel and paste it in SAP and again i have to copy next 4 rows from 5th row and again i have to copy next 4 rows frm wer it stopped…how do i achieve this

Assumption: Project is set to Windows Compatibility

Assign Actvitiy

SegmentTables | List(Of DataTable) =
dtDataVar.AsEnumerable.Chunk(4).Select(Function (x) x.CopyToDataTable).toList

We split the origin DataTable into a List of smaller DataTables

@bhanupriya.cb

Assign: currentIndex = 1

While currentIndex <= dt.Rows.Count
    Assign: rowsToCopy = dt.AsEnumerable().Skip(currentIndex - 1).Take(4).CopyToDataTable()
    // Assuming dt is your DataTable variable containing the Excel data
    
    // Copy the rows from 'rowsToCopy' and paste them into SAP
    
    // Update currentIndex for the next iteration
    Assign: currentIndex = currentIndex + 4
End While

Hi Thanks for ur reply, but i am getting the same list everytime even after 4th row is fetched, please find below FYR.

image

Hi Thanks for ur reply, sorry to ask u this, can u please brief it? like after splitting it hw do i paste it in SAP ?

in general you would loop over the List of segmented Datatables and work within each iteration with the four Data Rows

depends on how the information is to place into SAP. Feel free to elaborate more on this and share with us details on this part

@bhanupriya.cb

Sequence10.zip (2.2 KB)
I hope this helps you

Hi Thank you
this is working fine but while pasting into sap, it is also pasting column name even though i had removed add headers.

we would assume that you used a output DataTable or similar to create the content which you want to place within the SAP

Any Part results you can check with inspections e.g. immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

As an alternate flow check:

Assign Actvitiy
SegmentTables | List(Of DataTable) =
dtDataVar.AsEnumerable.Chunk(4).Select(Function (x) x.CopyToDataTable).toList

For each activity (not for each row activity) - Type Argument: DataTable
For each | tbl in SegmentTables

  • Do some preparing Work in SAP, if needed
  • Assign activity:
    strSAPString =
String.Join(Environment.Newline, tbl.AsEnumerable.Select(Function (x) x("Column0").toString.Trim))
  • place strSAPString into SAP or simulate with a log message
  • Do some post Work in SAP, if needed

Hi @bhanupriya.cb

  1. Store DataTable in Varibale DT
  2. Break you DT into 4 rows of DataTable
    ** ListDT is of List(Of DataTable) varibale

DT.AsEnumerable.Chunk(4).Select(Function (x) x.CopyToDataTable).ToList

  1. Use For Each Loop Activity
  2. Use Output Data Table Activity to convert into String with considering one Column

currentItem.DefaultView.ToTable(True,"Column0")

  1. Use Set To Clipboard Activity to copy 4 rows

Then you can simply paste in SAP

Hope it will helps you :slight_smile:
Cheers!!