Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

VBA call to BAPI_CTRACDOCUMENT_CREATE

Former Member
0 Likes
783

Hey All,

Working on a task to call BAPI_CTRADOCUMENT_CREATE from VBA in an Excel spread sheet and am experiencing some problems getting one of the Import parameters.

Here is an excerpt of the code:

' Create instance of BAPI module

Set oCrDocFunc = obFunctions.Add("BAPI_CTRACDOCUMENT_CREATE")

' Create structures for BAPI

Dim I_TEST As Object

Dim I_DocHdr As Object

Dim I_DocNbr As Object

Dim I_Return As Object

' Get structures from BAPI

Set I_TEST = oCrDocFunc.Exports.Item("TESTRUN")

Set I_DocHdr = oCrDocFunc.Exports("DOCUMENTHEADER")

Set I_DocNbr = oCrDocFunc.Imports.Item("DOCUMENTNUMBER")

Set I_Return = oCrDocFunc.tables.Item("RETURN")

            • end of excerpt

I am using the debugger to step through the program. When the debugger gets to the <b>Set I_DocHdr</b> code the WATCH window shows Error 0 after execution.

Looking at the BAPI there are 2 import parameters; TESTRUN and DOCUMENTHEADER.

TESTRUN is set to be like BAPICTRACAUX-TESTRUN (field)

DOCUMENTHEADER is set to be like BAPIDFKKKO (structure)

Seems to work just fine until it gets to the Set command for the DOCUMENTHEADER.

Can anyone tell me what I am doing wrong?

Thanks,

Bill

Hey All,

Working on a task to call BAPI_CTRADOCUMENT_CREATE from VBA in an Excel spread sheet and am experiencing some problems getting one of the Import parameters.

Here is an excerpt of the code:

' Create instance of BAPI module

Set oCrDocFunc = obFunctions.Add("BAPI_CTRACDOCUMENT_CREATE")

' Create structures for BAPI

Dim I_TEST As Object

Dim I_DocHdr As Object

Dim I_DocNbr As Object

Dim I_Return As Object

' Get structures from BAPI

Set I_TEST = oCrDocFunc.Exports.Item("TESTRUN")

Set I_DocHdr = oCrDocFunc.Exports("DOCUMENTHEADER")

Set I_DocNbr = oCrDocFunc.Imports.Item("DOCUMENTNUMBER")

Set I_Return = oCrDocFunc.tables.Item("RETURN")

            • end of excerpt

I am using the debugger to step through the program. When the debugger gets to the <b>Set I_DocHdr</b> code the WATCH window shows Error 0 after execution.

Looking at the BAPI there are 2 import parameters; TESTRUN and DOCUMENTHEADER.

TESTRUN is set to be like BAPICTRACAUX-TESTRUN (field)

DOCUMENTHEADER is set to be like BAPIDFKKKO (structure)

Seems to work just fine until it gets to the Set command for the DOCUMENTHEADER.

Can anyone tell me what I am doing wrong?

Thanks,

Bill

3 REPLIES 3
Read only

Former Member
0 Likes
676

Bill,

Add "Item" sub-object to your SET statement.

Before:

Set I_DocHdr = oCrDocFunc.Exports("DOCUMENTHEADER")

After:

Set I_DocHdr = oCrDocFunc.Exports.Item("DOCUMENTHEADER")

Read only

0 Likes
676

Sorry, this did not help. DOCUMENTHEADER is a structure and changing the setting to:

Set I_DocHdr = oCrDocFunc.Exports.Item("DOCUMENTHEADER")

Still returns an <b></b>ERROR 0<b></b>

Bill

Read only

0 Likes
676

Hi,

Could you please share your solution on this as I am stuck on this since a week.

Many Thanks in advance.

Regards,

Neal