anilmalhotra
New Member
- Joined
- Sep 1, 2015
- Messages
- 1
I am an SAP developer with little knowledge of VBA. I am creating an VBA to post data to SAP using a BAPI. The coding is working fine & I am able to post data into SAP. My problem is I have several rows in my excel, I have to loop the rows one by one & upload data in SAP, after each upload i need to clear the contents, I am unaware of what syntax needs to be used to clear the data of the object variable. Below is the code snippet..
I am using the code <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">"Set POITEMS = NOTHING"</code> but again when I set the object, the previous data is not cleared & duplicate enteries are created in SAP
Thanks in Advance!! Regards, Anil Malhotra
Code:
[/FONT]Set objbapicontrol = CreateObject("SAP.Functions")Set objbapi = objbapicontrol.Add("BAPI_PO_CREATE1")
Set poheader = objbapi.exports.Item("POHEADER")
Set poitems = objbapi.tables.Item("POITEM")
For Each row In [POHEAD].Rows '##PO Header
If row.Columns(row.ListObject.ListColumns("SAP_PO_NUM").Index).Value = "" Then
ponum = (row.Columns(row.ListObject.ListColumns("PONumber").Index).Value)
poheader.Value("COMP_CODE") = (row.Columns(row.ListObject.ListColumns("COCD").Index).Value)
i = "00001"
n = 1
'###Loop Detail
For Each rowd In [PODET].Rows '##PO Detail
If (rowd.Columns(rowd.ListObject.ListColumns("PONumber").Index).Value) = ponum Then
poitem = (rowd.Columns(rowd.ListObject.ListColumns("Itemnumber").Index).Value)
poitems.Rows.Add
poitemsx.Rows.Add
poitems.Value(n, "PO_ITEM") = i
poitems.Value(n, "MATERIAL") = Material
Next '##PO Detail
returnfunc = objbapi.call
ponumber = objbapi.imports("EXPPURCHASEORDER")
Set retmess = objbapi.tables.Item("RETURN")
Set poitems = Nothing
next[FONT=Helvetica Neue]
I am using the code <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">"Set POITEMS = NOTHING"</code> but again when I set the object, the previous data is not cleared & duplicate enteries are created in SAP
Thanks in Advance!! Regards, Anil Malhotra