11-26-2014 4:47 PM
Hi, I have the following Problem:
I want the upload some Files to SAP dms System.
First of all i implement the functionmodule "BAPI_DOCUMENT_CREATE2" in my .net Programm.
Then i tested tue Applikation... and the RFC call creates an correct document Info set in erp. I can have a look on it, with CV03N.
Now i wanted to implement the fileupload.
So i filled the Table DOCUMENTFILES ANd copied the sapftp.exe in my Program Exekution Directory.
If i now call my .net Program, it crashes with the exception "callback not supported".
What is my Problem?
I cant Figure it out.... Thanks for the help.
My Code:
Imports SAP.Middleware.Connector
Imports System.IO
Public Class frmMain
Public Sub New()
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
RfcDestinationManager.RegisterDestinationConfiguration(New MyBackendConfig)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'SAP TRANSACTIONS:
'CV01N - Create Document
'CV02N - Change Document
'CV04N - Find Document
'CV03N - Display document
System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
#If DEBUG Then
txtPfad.Text = "C:\Users\bkoch\Desktop\20141126153403.pdf"
#End If
' Get a destination object from the destination manager
Dim SapRfcDest As RfcDestination = RfcDestinationManager.GetDestination("DEV")
Try
' Create connection to the RFC repository
Dim SapRfcRepo As RfcRepository = SapRfcDest.Repository
' BAPI functionmodules
Dim documentCreateBapi As IRfcFunction = SapRfcRepo.CreateFunction("BAPI_DOCUMENT_CREATE2")
Dim bapiRollback As IRfcFunction = SapRfcRepo.CreateFunction("BAPI_TRANSACTION_ROLLBACK")
Dim bapiCommit As IRfcFunction = SapRfcRepo.CreateFunction("BAPI_TRANSACTION_COMMIT")
' Structures
Dim documentData As IRfcStructure = documentCreateBapi.GetStructure("DOCUMENTDATA")
Dim bapireturn As IRfcStructure = documentCreateBapi.GetStructure("RETURN")
Dim documentFiles As IRfcTable = documentCreateBapi.GetTable("DOCUMENTFILES")
' Fill fields
documentCreateBapi.SetValue("HOSTNAME", My.Computer.Name)
documentCreateBapi.SetValue("PF_FTP_DEST", "SAPFTP")
' Fill Fields for only one document
documentData.SetValue("DOCUMENTTYPE", "ZOQ")
documentData.SetValue("DOCUMENTNUMBER", "TEST DOCUMENT 01")
documentData.SetValue("DOCUMENTVERSION", "00")
documentData.SetValue("DOCUMENTPART", "000")
documentData.SetValue("VALIDFROMDATE", System.DateTime.Now)
documentData.SetValue("REVLEVEL", "00")
documentData.SetValue("DESCRIPTION", "Test Document 01 Created via NCo3")
documentData.SetValue("USERNAME", SapRfcDest.User.ToUpper)
documentData.SetValue("AUTHORITYGROUP", "BVV")
' Fill documentFiles Table
documentFiles.Append()
documentFiles.SetValue("WSAPPLICATION", SetExtensionToSapExtension(Path.GetExtension(txtPfad.Text)))
'documentFiles.SetValue("DOCPATH", (Path.GetDirectoryName(txtPfad.Text) & "\").ToUpper)
documentFiles.SetValue("DOCFILE", txtPfad.Text) '(Path.GetFileName(txtPfad.Text)).ToUpper)
documentFiles.SetValue("LANGUAGE", "DE")
documentFiles.SetValue("DESCRIPTION", "Test Document 01 Created via NCo3")
documentFiles.SetValue("CHECKEDIN", "X")
documentFiles.SetValue("STORAGECATEGORY", "ZBVV_LOGI")
documentFiles.SetValue("CREATED_BY", SapRfcDest.User.ToUpper)
RfcSessionManager.BeginContext(SapRfcDest)
documentCreateBapi.Invoke(SapRfcDest)
Dim DOCUMENTTYPE As String = documentCreateBapi.GetValue("DOCUMENTTYPE").ToString()
Dim DOCUMENTNUMBER As String = documentCreateBapi.GetValue("DOCUMENTNUMBER").ToString()
Dim DOCUMENTPART As String = documentCreateBapi.GetValue("DOCUMENTPART").ToString()
Dim DOCUMENTVERSION As String = documentCreateBapi.GetValue("DOCUMENTVERSION").ToString()
Select Case bapireturn.GetValue("TYPE").ToString
Case "A"
MessageBox.Show(bapireturn.GetValue("MESSAGE").ToString, bapireturn.GetValue("TYPE").ToString, MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
bapiRollback.Invoke(SapRfcDest)
Case "E"
MessageBox.Show(bapireturn.GetValue("MESSAGE").ToString, bapireturn.GetValue("TYPE").ToString, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
bapiRollback.Invoke(SapRfcDest)
Case "W"
If bapireturn.GetValue("MESSAGE").ToString <> String.Empty Then MessageBox.Show(bapireturn.GetValue("MESSAGE").ToString, bapireturn.GetValue("TYPE").ToString, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
MessageBox.Show(String.Format("Datei: '{0}', Type: '{1}', Part: '{2}', Version: '{3}' angelegt!", DOCUMENTNUMBER, DOCUMENTTYPE, DOCUMENTPART, DOCUMENTVERSION))
bapiCommit.Invoke(SapRfcDest)
Case Else
If bapireturn.GetValue("MESSAGE").ToString <> String.Empty Then MessageBox.Show(bapireturn.GetValue("MESSAGE").ToString, bapireturn.GetValue("TYPE").ToString, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
MessageBox.Show(String.Format("Datei: '{0}', Type: '{1}', Part: '{2}', Version: '{3}' angelegt!", DOCUMENTNUMBER, DOCUMENTTYPE, DOCUMENTPART, DOCUMENTVERSION))
bapiCommit.Invoke(SapRfcDest)
End Select
RfcSessionManager.EndContext(SapRfcDest)
Catch ex As RfcCommunicationException
MessageBox.Show(ex.Message, "RfcCommunicationException")
Catch ex As RfcLogonException
MessageBox.Show(ex.Message, "RfcLogonException")
Catch ex As RfcAbapRuntimeException
MessageBox.Show(ex.Message, "RfcAbapRuntimeException")
Catch ex As RfcAbapBaseException
MessageBox.Show(ex.Message, "RfcAbapBaseException")
Catch ex As Exception
MessageBox.Show(ex.Message, "Exception")
Finally
System.Windows.Forms.Cursor.Current = Cursors.Default
End Try
End Sub
Private Sub btnPfad_Click(sender As Object, e As EventArgs) Handles btnPfad.Click
Using _ofd As New OpenFileDialog
_ofd.Multiselect = False
If _ofd.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
txtPfad.Text = _ofd.FileName
Else
txtPfad.Text = String.Empty
End If
End Using
End Sub
Private Function SetExtensionToSapExtension(ByVal extension As String) As String
If extension.Contains(".") Then
Return extension.Substring(1, extension.Length - 1).ToUpper
Else
Return extension.ToUpper
End If
End Function
End Class
11-26-2014 8:45 PM
...if i use the Parameter:
parms.Add(RfcConfigParameters.UseSAPGui, "1")
in BackendConfiguration Class; the upload will work.
But in productive Environment there is not SAP GUI installed.
11-27-2014 1:08 PM
So i find out, in sap 504692 (https://websmp230.sap-ag.de/sap(bD1kZSZjPTAwMQ==)/bc/bsp/sno/ui_entry/entry.htm?param=69765F6D6F6465...that i have to use functionmodule "CVAPI_DOC_CHANGE"...
Now i can switch parms.Add(RfcConfigParameters.UseSAPGui, "1") to parms.Add(RfcConfigParameters.UseSAPGui, "0"), so no SAP GUI is used.
But i get an error: "Error while checking in or laydown of XXX (my documents path)" or something similar.
11-27-2014 2:29 PM
There is no practical way.. i will build my own functionmodule with xstring...
CASE CLOSED
12-04-2014 10:07 AM
Here is my solution with an own reomte fm with Import xstring:
FUNCTION zklo_ws_setdocument. *"---------------------------------------------------------------------- *"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(DOCUMENTTYPE) TYPE BAPI_DOC_AUX-DOCTYPE *" VALUE(DOCUMENTNUMBER) TYPE BAPI_DOC_AUX-DOCNUMBER *" VALUE(DOCUMENTPART) TYPE BAPI_DOC_AUX-DOCPART *" VALUE(DOCUMENTVERSION) TYPE BAPI_DOC_AUX-DOCVERSION *" VALUE(BIN_FILE) TYPE XSTRING *" VALUE(FILENAME) TYPE DRAW-FILEP *" EXPORTING *" VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2 *" VALUE(NEW_DOCUMENTTYPE) TYPE BAPI_DOC_AUX-DOCTYPE *" VALUE(NEW_DOCUMENTNUMBER) TYPE BAPI_DOC_AUX-DOCNUMBER *" VALUE(NEW_DOCUMENTPART) TYPE BAPI_DOC_AUX-DOCPART *" VALUE(NEW_DOCUMENTVERSION) TYPE BAPI_DOC_AUX-DOCVERSION *"---------------------------------------------------------------------- TYPES: BEGIN OF zst_ts_raw_line, line(2550) TYPE x, END OF zst_ts_raw_line. DATA: ls_message TYPE messages, ls_drao TYPE drao, lt_drao TYPE TABLE OF drao, ls_return TYPE bapiret2, ls_document TYPE bapi_doc_draw2, lv_size TYPE i, lt_bindata TYPE STANDARD TABLE OF zst_ts_raw_line, ls_bindata LIKE LINE OF lt_bindata, lt_files TYPE cvapi_tbl_doc_files, ls_files TYPE cvapi_doc_file, ls_api_ctrl TYPE cvapi_api_control, ls_draw TYPE draw, lt_drat TYPE TABLE OF dms_db_drat, ls_drat TYPE dms_db_drat. "ByteArray in Tabelle konvertieren CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = bin_file IMPORTING output_length = lv_size TABLES binary_tab = lt_bindata. LOOP AT lt_bindata INTO ls_bindata. CLEAR ls_drao. ls_drao-orblk = ls_bindata-line. ls_drao-orln = lv_size. ls_drao-dokar = documenttype. ls_drao-doknr = documentnumber. ls_drao-dokvr = documentversion. ls_drao-doktl = documentpart. ls_drao-appnr = '1'. APPEND ls_drao TO lt_drao. ENDLOOP. "Dokumentenart automatisch ermitteln. CALL FUNCTION 'CV120_DOC_GET_APPL' EXPORTING pf_file = filename IMPORTING pfx_dappl = ls_files-dappl. IF ls_files-dappl EQ 'PD1'. "SAP Customizing ist hier krum... ls_files-dappl = 'PDF'. ENDIF. "Datei in Tabelle anhängen... ls_files-appnr = '1'. ls_files-filename = filename. ls_files-updateflag = 'I'. ls_files-langu = sy-langu. ls_files-storage_cat = 'DMS_C1_ST'. "Muss u.U. angepasst werden... ls_files-description = filename. ls_files-checked_in = 'X'. ls_files-active_version = 'X'. APPEND ls_files TO lt_files. "Allgemeine Einstellungen ls_api_ctrl = 'CV01N'. "Kopfdaten aufbereiten ls_draw-dokar = documenttype. ls_draw-doknr = documentnumber. ls_draw-doktl = documentpart. ls_draw-dokvr = documentversion. ls_draw-filep = ls_files-filename. ls_draw-dappl = ls_files-dappl. ls_draw-begru = 'BVV'. "Muss u.U. angepasst werden... "Weitere Tabellen aufbereiten ls_drat-dokar = ls_draw-dokar. ls_drat-doknr = ls_draw-doknr. ls_drat-dokvr = ls_draw-dokvr. ls_drat-doktl = ls_draw-doktl. ls_drat-langu = sy-langu. ls_drat-dktxt = ls_files-filename. APPEND ls_drat TO lt_drat. "Prüfen ob Dokument bereits vorhanden.. CALL FUNCTION 'CVAPI_DOC_GETDETAIL' EXPORTING pf_dokar = ls_draw-dokar pf_doknr = ls_draw-doknr pf_dokvr = ls_draw-dokvr pf_doktl = ls_draw-doktl EXCEPTIONS not_found = 1 no_auth = 2 error = 3 OTHERS = 4. IF sy-subrc EQ 1. "not found CALL FUNCTION 'CVAPI_DOC_CREATE' EXPORTING ps_draw = ls_draw * PF_STATUSLOG = ' ' * PF_REVLEVEL = ps_api_control = ls_api_ctrl pf_ftp_dest = 'SAPFTP' pf_http_dest = 'SAPHTTP' pf_hostname = 'DEFAULT' pf_content_provide = 'TBL' "Als interne Tabelle IMPORTING psx_message = ls_message pfx_dokar = new_documenttype pfx_doknr = new_documentnumber pfx_dokvr = new_documentversion pfx_doktl = new_documentpart TABLES * PT_DRAD_X = pt_drat_x = lt_drat pt_files_x = lt_files * PT_COMP_X = pt_content = lt_drao * DOCUMENTDESCRIPTIONS = . ELSEIF sy-subrc EQ 0. "found CALL FUNCTION 'CVAPI_DOC_CHECKIN' EXPORTING pf_dokar = ls_draw-dokar pf_doknr = ls_draw-doknr pf_dokvr = ls_draw-dokvr pf_doktl = ls_draw-doktl * PS_DOC_STATUS = pf_ftp_dest = 'SAPFTP' pf_http_dest = 'SAPHTTP' pf_hostname = 'DEFAULT' ps_api_control = ls_api_ctrl * PF_REPLACE = ' ' pf_content_provide = 'TBL' "Als interne Tabelle IMPORTING psx_message = ls_message TABLES pt_files_x = lt_files * PT_COMP_X = pt_content = lt_drao. ELSE. "error return-type = 'E'. return-message = 'Fehler beim suchen des Dokuments.'. ENDIF. IF ls_message-msg_type CA 'EA'. return-type = ls_message-msg_type. return-message = ls_message-msg_txt. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. COMMIT WORK. ENDIF. ENDFUNCTION.