cancel
Showing results for 
Search instead for 
Did you mean: 

Bapi_Document_Checkoutview2 woes

Former Member
0 Kudos

I'm writing a call to retrieve a document (PDF, XLS, DOC, TXT....pretty much any file) from a document management system hooked up to our SAP system. Based on some old DCOM Connector code, I was told the bapi to use is the one in the subject line above.

To call this BAPI, i follow these steps in C#:

1. Connect to SAP

2. Call Bapi_Document_Getactversion to get the correct version number stored in SAP of the document i'm looking for.

3. Call Bapi_Document_Getdetail2 to get the details of the file i'm looking for.

4. Call Bapi_Document_Checkoutview2 by sending all the relevant information including where to retrieve the file to on my local workstation.

Steps 1, 2 and 3 all work. Step 4 either fails with no messages (by looking at the BAPIRET2 return table) if i have my connection property set to SAPGui = 1 or 2. If i don't specify the SAPGui property of the connection, i get the following error returned in BAPIRET2:

"RFC partner does not allow to start any program"

Has anyone used Bapi_Document_Checkoutview2 successfully (or even Bapi_Document_Checkoutview or Bapi_Document_Checkoutviewx)? I can post some code if needed. I've been stumped on this for 2 days now.

Any help appreciated.

Thanks!

H

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi.

I'am getting the error: File C:\_TEST01.xls cannot be created

What can I do about this error.

0 Kudos

Hi, I've tried declaring in both the webform1.aspx and the SapProxy1.vb forms. Also the saphttp & sapftp files are in both WINNT and WINNT/system32 folders.

There dont appear to be any apparent errors and the build is ok so I assume it is getting the Librfc32.dll ok.

Returncode shows a value of 0 after it is executed. It is under result(0) BAPIRET2 that I get the RFC partner error.

Thanks again.

Former Member
0 Kudos

Hi,

The only reason I could see is that it is not able to pick or invoke the rfcallowstartprgram function, the return code to this call will be zero even if it is not able to make a call successfully invoke this function. Just check whether you have the RFC SDK installed on the system where you are running your .NET code and chekc for the file "saprfc.h" . it should be there in C:\Program Files\SAP\FrontEnd\SAPgui\rfcsdk\include

Directory could be C or D depends where you SAP GUI Frontend is installed.

Former Member
0 Kudos

Hi,

I am also stuck with this error "RFC Partner does not allow to start any program". I am using BAPI_DOCUMENT_CHECKIN2 to check in a document to one of the archive server. This BAPI is getting called from VB. Going through the previous replies of this thread, I can see that I need to code the RFCallowstartprogram function, Can anyone guide me what will be it's equivalent VB code for this function and from where to download the 2 exe

SAPFTP.exe and SAPHTTP.exe.

0 Kudos

Hi,

I'm also trying to get this working in ASP.NET solution but getting the "RFC Partner does not allow to start any program" error as well. I'm new to .NET and BAPIs so any detailed help would be appreciated.

Thanks

Former Member
0 Kudos

Hi,

I got my BAPI working and now I am able to attach and archive a document from my VB code. I did everything correct only issue was the call to LIBRFC32 DLL to get the hold of program RfcAllowStartProgram.

The VB code to call this function before the CHECKIN bapi is

Private Const RAccess As String = " "

Private Declare Function RfcAllowStartProgram Lib "librfc32" (ByVal RAccess As String) As Integer

Call this just before the call to BAPI Checkin or Checkout is made.

ReturnCode = RfcAllowStartProgram("sapftp;saphttp")

Now call the CHECK IN BAPI from Vb code, In ABAP the CHECKIN BAPI is something liek this

CALL FUNCTION 'CVAPI_DOC_CHECKIN'

EXPORTING

PF_DOKAR = LV_DOKAR

PF_DOKNR = LV_DOC_NUMBER

PF_DOKVR = LV_DOC_VERSION

PF_DOKTL = LV_DOC_PART

PS_API_CONTROL = LIT_API_CONTROL

IMPORTING

PSX_MESSAGE = LIT_PSX_MESSAGE_1

TABLES

PT_FILES_X = LIT_PT_FILES.

You have to make sure that sapftp.exe and saphttp.exe are there in the directory C:\WINDOWS\SYSTEM32

Thats it and it will work

0 Kudos

Hi, Thanks for the code Sunil.

Unfortunately I still can't get it to work. As I said I’m new to .NET. I’ve tried your code in a couple of places:

Before the call to SapProxy11.Bapi_Document_Checkoutview2 in my webform1.aspx

Dim Returncode

Returncode = RfcAllowStartProgram("sapftp;saphttp")

SapProxy11.Bapi_Document_Checkoutview2("", "", "", DocFile, SapProxy11.DocumentNumber, SapProxy11.DocumentPart, SapProxy11.DocumentType, SapProxy11.DocumentVersion, "X", "X", "1", "", "", Ret, DocCompTab, DocFilesTab, DocStructTab)

and also before results = SAPInvoke(“Bapi_Documentment_Checkoutview2 etc in SapProxy1.vb pages.

Dim results As Object()

Dim Returncode

Returncode = RfcAllowStartProgram("sapftp;saphttp")

results = SAPInvoke("Bapi_Document_Checkoutview2", New Object() { _

Docbomchangenumber, Docbomrevisionlevel, Docbomvalidfrom, Documentfile, Documentnumber, Documentpart, Documenttype, Documentversion, Getcomponents, Getheader, Getstructure, Hostname, Originalpath, Components, Documentfiles, Documentstructure})

Return0 = CType(results(0), BAPIRET2)

Components = CType(results(1), BAPI_DOC_COMPTable)

Documentfiles = CType(results(2), BAPI_DOC_FILES2Table)

Documentstructure = CType(results(3), BAPI_DOC_STRUCTURETable)

Hope this all makes sense.

Former Member
0 Kudos

Hi,

You have not mentioned about declaring the RfcAllowStartProgram, you have to declare this function before it gets called. This function is there in SAPRFC.h file and which is a part of LIBRFC32, so as you see below the code in VB, it declares the RfcAllowStartProgram function. Also make sure that you saphttp.exe and sapftp.exe are there in C:\windows\System32 folder.

Private Const RAccess As String = " "

Private Declare Function RfcAllowStartProgram Lib "librfc32" (ByVal RAccess As String) As Integer

Former Member
0 Kudos

Hi Hithesh,

Thank you very much for your reply. I'll briefly explain what Business Connector (BC) is. BC is a SAP software which enables integration between sap and other technologies. BC uses Internet as the communication medium for other technologies and RFC for SAP.

What we are trying to do is execute this bapi from BC means through internet. Since BC is a java based product, execution of RfcAllowStartProgram should be through Java or C code embeded in Java code. We have C header file which has following declarations:

.

.

#define RfcAllowStartProgram RfcAllowStartProgramU

.

.

RFC_RC SAP_API RfcAllowStartProgram(

rfc_char_t * pname_list /* @parm zero terminated string.

  • This is a list of programs which can

  • be started by the RFC library by the

  • RFC partner if required. A program

  • name can have max. 512 B. They must

  • be separated by ;.

  • NULL: any program is allowed.

*/

);

.

.

We don’t have C expertise here. I have two questions which will help us to solve the problem.

1. How to execute RfcAllowStartProgram using C or Java? If this function can be called using Java what libraries should be included.

2. Should this function be called each time you want to execute Bapi_Document_Checkoutview2?

Any help would be appreciated very much.

Thanks in advance.

Former Member
0 Kudos

> 1. How to execute RfcAllowStartProgram using C or

> Java? If this function can be called using Java what

> libraries should be included.

This i'm unsure about.

> 2. Should this function be called each time you want

> to execute Bapi_Document_Checkoutview2?

I make the PInvoke call for every call in C# via the .NET Connector.

H

Former Member
0 Kudos

Hi Ramesh,

I have got the same problem you have had: I try to call the Bapi_Document_Checkoutview2 via BC and get the same error like you. Have you found a solution for that problem.

I'll really appreciate it if you can give me a hint.

Thanks

Bengt

former_member187506
Contributor
0 Kudos

Try this

JCO.setMiddlewareProperty("jco.middleware.allow_start_of_programs",

"ftp;sapftp;sapftpa;sapkprotp;http;saphttp;saphttpa");

Former Member
0 Kudos

After nearly a week, I think I have finally figured this problem out and i can now download files from SAP. Here's the lessons learned:

  • The stock Bapi_Document_Checkoutview2 does not download the file. I had to use Bapi_Document_Checkoutviewx. Now i'm almost certain these are stock BAPIs from SAP as my company does not allow the ones out of the box to be changed in any way. I found these SAP notes in OSS that might help regarding the problem with Bapi_Document_Checkoutview2: #445696, #352693 and #434878. I have not done any of the changes as suggested by these notes so i don't know if they would fix this bapi. As i said, i'm using Bapi_Document_Checkoutviewx and the file gets downloaded to the client. I need to still check if it's affecting the record in SAP in any adverse way. But i'm doubting for now.

  • The file SAPFTP.exe needs to reside in your /bin directory of your app. Hiri mentions in this thread it needs to go in your win\system32, but the app's /bin directory is neater (keeping things self-contained).

  • The PInvoke call to RfcAllowStartProgram has to be made else you'll get the nasty "can't start program error". Again thanks Hiri. Also there is as OSS note on this...i don't have the number off-hand.

I'll post my code as soon as i clean it up.

H

Former Member
0 Kudos

Hello Hithesh,

I am trying to do a similar thing using Business Connecctor, and I am getting the error

"RFC partner does not allow to start any program"

What was the solution for this problem?

Regards,

Samir.

Former Member
0 Kudos

I'm not too sure about the Business Connector. Are you using this from C#/VB.NET?

Anyway, from the .NET connector, that "RFC" error can be resolved by pinvoking to the librfc32.dll

Declared like so at class level (C#):

[DllImport("librfc32.dll")]

public static extern int RfcAllowStartProgram(long lpApplicationName);

From my method before the call to bapi:

RfcAllowStartProgram(0);

I have librfc32.dll residing in my /bin directory of my app.

Hope that helps.

H

Former Member
0 Kudos

Hitesh,

This should take care of the problem.

**code

[DllImport("librfc32.dll")]

public static extern int RfcAllowStartProgram(long lpApplicationName);

Make sure that librfc32.dll file is in the windows system folder (machine running the APP)

*end code**

I have a question related to the app. Are you using Treeview control to display the documents? I have developed a similar app using Treeview control. It works, but I am not very happy it and looking for ideas to change the application.

Thanks,

Hiri

Former Member
0 Kudos

Ok, this looks promising. Hiri, what do i pass for the paramater lpApplicationName? Will this be the process ID of the application the code is running under?

My app is rather simple for now. It's an ASP.NET app. My first goal is to just get the file to download properly via HTTP. I need to create a way for users to create links directly to the documents stored in SAP so that it can be integrated into a CAD system (I work for an engineering company that stores CAD drawings and other literature in SAP's doc management system).

I might consider making a more robust front-end later.

Is it possible for you to post the code you used? If i ever get this working, i'll post my code here too.

Thanks!

H

Former Member
0 Kudos

You don't need to pass anything to lpApplicationName. By default it is initial(0).

I forgot to mention, you got to use this in your sub that performs the check out.

RfcAllowStartProgram(0);

The app is pretty big, I am not sure if I can post the entire project here. Here's the part that does the download. I tried my best to make the code readble

****Begin code ****

private void document_checkout()

{

string[] DocArray = ViewDoc.Split(new Char[] {'%'});

doknr = DocArray[0];

doctype = DocArray[1];

docpart = DocArray[2];

docver = DocArray[3];

string targetpath = @"c:\temp\" ;

int index = Convert.ToInt16(DocArray[4]) ;

string docfile;

//Call header class again

proxy.Connection =

SAP.Connector.SAPLoginProvider.GetSAPConnection(this);

try

{

proxy.Z_Bapi_Document_Getdetail2(doknr,doctype,ref

longtexts,ref objecttable,docpart,docver,"X",

out data,out docdata,out bapiret,ref docfilestable);

}

catch(Exception ex)

{

}

string novalue = string.Empty ;

BAPI_DOC_COMPTable compTable = new BAPI_DOC_COMPTable();

BAPI_DOC_STRUCTURETable docstructTable = new BAPI_DOC_STRUCTURETable();

BAPI_DOC_FILES2Table docfilestable1 = new BAPI_DOC_FILES2Table();

proxy.Connection = SAP.Connector.SAPLoginProvider.GetSAPConnection(this);

try

{

RfcAllowStartProgram(0);

proxy.Z_Bapi_Document_Checkoutview3(novalue,novalue,novalue,docfiles,doknr,docpart,doctype,docver,novalue,novalue,novalue,novalue,targetpath,out bapiret,ref compTable, ref docfilestable1,ref docstructTable);

docfile = docfilestable[index].Docfile ;

if ( docfile != null )

{

string path = targetpath + docfile ;

System.IO.FileInfo file = new System.IO.FileInfo(path);

if (file.Exists)

{

// set appropriate headers

Response.Clear();

Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

Response.AddHeader("Content-Length", file.Length.ToString());

Response.ContentType = "application/none";

Response.WriteFile(file.FullName);

Response.End();

}

}

}

// TODO:Remember to copy sapftp.exe and

//saphttp.exe to PATH or c:\windows\system32

// TODO:Remember to copy librfc32.dll to

// c:\windows\system32

// TODO:Remember to register regsvr32 obout_ASPTreeView_XP.dll using the command

//regsvr32 "c:\ANYWHERE\obout_ASPTreeView_XP.dll"

catch(Exception ex)

{

}//end catch

}//End document_checkout

****End code

Former Member
0 Kudos

Hiri,

Thanks for the code. I'm getting further but still have issues. One thing i 've noticed is that you are using Z_Bapi_*. I'm assuming these are custom Bapis? Was there a reason you using those instead of the standard ones (Bapi_Document_Getdetail2 and Bapi_Document_Checkoutview2)?

Anyway, i'm using the stock ones. When calling Bapi_Document_Checkoutview2, i'm sending in the correct file to get plus the local path to place the file in. Everytime i call it though, the outbound BAPI_DOC_FILES2Table is always empty. The document does exist in SAP and I can view it when searching for it from CV03N.

Any other thoughts?

Thanks

H

Former Member
0 Kudos

One more thing, the return table (BAPIRET2) from the call to Bapi_Document_Checkoutview2 comes back with message:

"Win32 error 2: The system cannot find the file spe"

I kid you not. The message is truncated. Looks like the max size is set to 50. <gripe>I hate the field limitations in SAP in general...everything is either truncated or abbreviated in a sucky way....me = coming from a non-SAP environment</gripe>

Anyway, that tells me it's a client error but surely the outbound BAPI_DOC_FILES2Table should contain something. It's always empty.

H

Former Member
0 Kudos

Could you post your code ? Also,check the path of the local file that you are passing to the BAPI.

The reason I had to create a Z_BAPI was, SAP wouldn't handle the document number conversion when called from outside of SAP. We have external numbering(alpha numeric) and Z_BAPI had a routine to convert it to internal SAP number format and then call the standard SAP bapi. I could have done this conversion outside SAP, but then it's so easy in SAP ....me = coming from SAP environment - lol

Former Member
0 Kudos

Here's the code....hope it comes through fine. Right now i'm running this on a win forms C# app...on a click of a button.

<codeSnip>

// Connection settings for SAP

SAP.Connector.Destination dest = new SAP.Connector.Destination();

dest.Username = "myUID";

dest.Password = "myPWD";

dest.Client = 5;

dest.Language = "en";

dest.AppServerHost = "tdb5";

dest.SystemNumber = 1;

SAP.Connector.SAPConnection sapConn = new SAP.Connector.SAPConnection(dest);

// Hard coded values of a single document that exists in SAP...it's a PDF doc.

string docNumber = "NDR60403001";

string docPart = "000";

string docType = "NDR";

string docVersion = "00";

// Some declares...

BAPI_DOC_DRAW2 docData = null;

BAPIRET2 ret = null;

BAPI_CHARACTERISTIC_VALUESTable characteristics = new BAPI_CHARACTERISTIC_VALUESTable();

BAPI_CLASS_ALLOCATIONTable classAllocs = new BAPI_CLASS_ALLOCATIONTable();

BAPI_DOC_COMPTable components = new BAPI_DOC_COMPTable();

BAPI_DOC_DRATTable docDescrips = new BAPI_DOC_DRATTable();

BAPI_DOC_FILES2Table docFiles = new BAPI_DOC_FILES2Table();

BAPI_DOC_STRUCTURETable docStruct = new BAPI_DOC_STRUCTURETable();

BAPI_DOC_TEXTTable longTexts = new BAPI_DOC_TEXTTable();

BAPI_DOC_DRADTable objectLinks = new BAPI_DOC_DRADTable();

BAPI_DOC_DRAPTable status = new BAPI_DOC_DRAPTable();

BAPI_DOC_STRUCTURETable whereUsed = new BAPI_DOC_STRUCTURETable();

BAPI_DOC_DRAW2Table drawTable = new BAPI_DOC_DRAW2Table();

BAPI_DOC_APPLICATIONSTable appTable = new BAPI_DOC_APPLICATIONSTable();

SAPDocProxy proxy = new SAPDocProxy();

proxy.Connection = sapConn;

try

{

proxy.Connection.Open();

string actualVersion = "";

// Note...i know there's only 1 version for this doc now. I don't need to call this.

proxy.Bapi_Document_Getactversion("", docNumber, docPart, docType, docVersion, "", out actualVersion, out ret);

if(!(actualVersion == string.Empty))

{

docVersion = actualVersion;

}

// get detail of doc

proxy.Bapi_Document_Getdetail2(docNumber, docPart, docType, docVersion, "", "", "", "", "", "", "", "", out docData,

out ret, ref characteristics, ref classAllocs, ref components, ref docDescrips, ref docFiles,

ref docStruct, ref longTexts, ref objectLinks, ref status, ref whereUsed);

if(!(docFiles.Count == 1))

{

MessageBox.Show("No file found!");

return;

}

// i'm hard coding the file name to write to for now

docFiles[0].Docfile = @"C:\temp\abc.pdf";

// the outbound file will come here

BAPI_DOC_FILES2Table docFilesOut = new BAPI_DOC_FILES2Table();

// needed for outbound call as per Hiri (SAP Forums)

RfcAllowStartProgram(0);

// get the file from SAP. THIS IS THE CALL THAT FAILS.

proxy.Bapi_Document_Checkoutview2("", "", "", docFiles[0], docNumber, docPart, docType, docVersion, "", "", "", "", "", out ret, ref components, ref docFilesOut, ref whereUsed);

// !!!

// At this point docFilesOut is an empty collection and ret has a message about that Win32 error 2.

// !!!

}

finally

{

proxy.Connection.Close();

}

MessageBox.Show("Done!");

</codeSnip>

Former Member
0 Kudos

ok - couple things I noticed.

1) // i'm hard coding the file name to write to for now

docFiles[0].Docfile = @"C:\temp\abc.pdf";

I am not sure why you need this. I take it abc.pdf is your file being checked out of the document(NDR60403001). You don't need to pass any value to docFiles. It's an export parameter(table) from BAPI.

2)can you try passing a X to getheader parameter in the call

proxy.Bapi_Document_Checkoutview2("", "", "", docFiles[0], docNumber, docPart, docType, docVersion, "", "", "", "", "", out ret, ref components, ref docFilesOut, ref whereUsed);

3)Have you copied files SAPFTP.exe and SAPHTTP.exe files to your c:\windows\system32(or to the machine that is running this app) folder?

4)Have you tried running this BAPI in sap with the same parameters? does it download the file to your c:\temp folder?

5)One last thing - as this is a win forms, you can set the abap debug property = true on SAP destination control and this will enable you to debug inside SAP - if the machine running this APP has SAP gui installed.

OK - it was more than a couple things

Hiri

Former Member
0 Kudos

Hiri....i'm getting further...check inline below.

> ok - couple things I noticed.

> 1) // i'm hard coding the file name to write to for

> now

> docFiles[0].Docfile = @"C:\temp\abc.pdf";

> I am not sure why you need this. I take it abc.pdf is

> your file being checked out of the

> document(NDR60403001). You don't need to pass any

> value to docFiles. It's an export parameter(table)

> from BAPI.

Well, isn't it inbound for this BAPI? I'm guessing it uses that table to determine which file to get out. I'm changing that docfile property as what's stored in SAP is not really the file name but the entire path with the file name of the user that uploaded it. So it could be "c:\documents and settings\userA\docs\aaa.pdf".

> 3)Have you copied files SAPFTP.exe and SAPHTTP.exe

> files to your c:\windows\system32(or to the machine

> that is running this app) folder?

I did so now. What do these files do?

> 2)can you try passing a X to getheader parameter in

> the call

> proxy.Bapi_Document_Checkoutview2("", "", "",

> docFiles[0], docNumber, docPart, docType, docVersion,

> "", "", "", "", "", out ret, ref components, ref

> docFilesOut, ref whereUsed);

Before copying those exe files, adding the X made no difference. After doing so, the return table with the X added comes back with this error:

"No temprorary current directory for your frontend available"

<sapSmack>The quality is beginning to show with these error messages. </sapSmack>. But this looks promising. Where do i set the temporary directory? I don't see anything to pass to the BAPI for this.

If i leave out the X, no error messages comes back.....but no file gets downloaded too :(. No file comes back with the X too.

> 4)Have you tried running this BAPI in sap with the

> same parameters? does it download the file to your

> c:\temp folder?

>

> 5)One last thing - as this is a win forms, you can

> set the abap debug property = true on SAP destination

> control and this will enable you to debug inside SAP

> - if the machine running this APP has SAP gui

> installed.

I tried running with the ABAP debug on....but was not too familiar on checking values as i was stepping through the code. I'm gonna try again.

I have tried running the BAPI from the SAP GUI before....but that was before the SAP*.exe files being copied to the win directory. Gonna try again.

Thanks for the great help! I'm getting close to cracking this....

H

Former Member
0 Kudos

Just some more info.

The old DCOM connector code I have used to call AdviseGuiSink. I could not find the equivalent for this in the .NET Connector. My understanding is is that this caused a GUI session behind the scenes (off topic, but ain't this ugly?). This led me to believe that the "SAPGui" property of the connection might be the equivalent in .NET....but i can't confirm this. One of you SAP guys?

Reading from another post on this forum the setting for SAPGui is "1 means SAPGUI visible, 2 means that SAPGUI is hidden after RFC call".

Also this caused my "RFC partner does not allow to start any program" problem to disappear.

Former Member
0 Kudos

Hi,

Yes, setting SAPGUI=1/2 allows SAPGUI to be started whenever the called function module needs it. Please note that a SAP user of type Dialog (instead of CPIC, Batch etc) is required when this option is set. Also make sure that your application is not running within ASP.NET/IIS.

Regards,

Guangwei

Former Member
0 Kudos

Oops. Yes, my app is a ASP.NET app. I guess i'll scratch the idea of setting SAPGUI.