cancel
Showing results for 
Search instead for 
Did you mean: 

RFC callback server not available

0 Kudos

Hello community,

I´m using SAP .NET connector in MS Visual Studio 2012 C#.

From my C# program I try to download a document from SAP to C:\temp\ using function module "BAPI_DOCUMENT_CHECKOUTVIEW2".

When the FM is called I receive the error "RFC callback server not available" in C#.

Does anyone have an idea why this error occurs?

How can I fix this problem?

Thank you very much for your help!

Best regards,

Veit Gaudich

Accepted Solutions (1)

Accepted Solutions (1)

former_member197445
Contributor
0 Kudos

Apparently that function module has had issue being called remotely in the past.  Try following with SCMS_DOC_READ.

  DATA: lt_files2          TYPE STANDARD TABLE OF bapi_doc_files2,

        ls_files2          TYPE bapi_doc_files2,

        ls_return          TYPE bapiret2,

        lt_bin             TYPE STANDARD TABLE OF sdokcntbin,

        lt_inf             TYPE STANDARD TABLE OF scms_acinf,

        ls_inf             TYPE scms_acinf.

  CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'

    EXPORTING

      documenttype    = documenttype

      documentnumber  = documentnumber

      documentpart    = documentpart

      documentversion = documentversion

      getdocfiles     = 'X'

    IMPORTING

      return          = ls_return

    TABLES

      documentfiles   = lt_files2.

  CALL FUNCTION 'SCMS_DOC_READ'

    EXPORTING

      stor_cat    = 'ZCR01'

      doc_id      = ls_files2-file_id

    TABLES

      access_info = lt_inf

      content_bin = lt_bin.

  READ TABLE lt_inf INTO ls_inf INDEX 1.

  IF sy-subrc NE 0.

   

  ENDIF.

  " Convert XData to Xstring

  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

    EXPORTING

      input_length = ls_inf-comp_size

    IMPORTING

      buffer       = contentx

    TABLES

      binary_tab   = lt_bin

    EXCEPTIONS

      failed       = 1

      OTHERS       = 2.

  IF sy-subrc NE 0.

   

  ENDIF.

  filename = ls_inf-comp_id.

0 Kudos

Hi Case,

thank you very much.

The problem is, that I want to save the document in SAP to C:\temp\ and this is not working.

I tried cl_gui_frontend_services=>gui_download after your code, but I´m getting the error 21 = CONTROL_FLUSH_ERROR, when I´m starting it from C#.

I´ll try to put the binary data to C# now and save the document to file there.

Regards,

Veit

former_member197445
Contributor
0 Kudos

You will not be able to use an SAP rfc call to save the file locally.  You can save the Binary XString to a file (from SCMS_BINARY_TO_XSTRING) using C#.  One thing I need to know to help is if you're writing a web application or a Windows application?  And also, is the document a PDF or other formats?

former_member197445
Contributor
0 Kudos

The reason I ask about the PDF is that if you're writing a web application, it's sometimes easier to present the PDF in the browser and let the user save it (or not) themselves.

0 Kudos

I´m writing a Windows C# application and yes, you´re right. Next thing I will try is to save the binary to a file using C#.

I want to save the binary data as a PDF file.

Thanks again for your help!

0 Kudos

OK, I got it! For all of you, who have the same problem.

In SAP .NET Connector 3.x it´s not possible to save documents on the local PC.

What I did is using Case Ahr´s code to get the document and save it as XSTRING.

This XSTRING goes out to C# and here the document is saved as PDF file using this C# code:

byte[] E_BUFFER = function.GetByteArray("E_BUFFER");

if (E_BUFFER != null)

{

  foreach (artEtikettResult etres2 in result)

  {

    FileStream fs = new FileStream(@"C:\temp\" + etres2.Docfile, FileMode.Create);

    BinaryWriter w = new BinaryWriter(fs);

    w.Write(E_BUFFER);

    w.Close();

    fs.Close();

  }

}

Thank you Case for your support on that!

Former Member
0 Kudos

Hi,

Can you tell me how to download an internal table to an xstring. I want to download this internal table as an excel document in local PC through RFC.

Answers (2)

Answers (2)

0 Kudos

OK guys,

as some people where asking me how I finally made it, here´s the code.

If it´s useful for you, please give me some points...

Regards,

Veit

1. Button Click Event in C#

private void btnShowLabel_Click(object sender, EventArgs e)

        {

            artBAPIRET2 bapiret2 = null;

            ListView.SelectedListViewItemCollection selitems1 = lstvwLabel.SelectedItems;

            if (selitems1 != null)

            {

                ListViewItem item1 = selitems1[0];

                if (item1 != null)

                {

                    artEtikettResult etres1 = (artEtikettResult)item1.Tag;

                    if (etres1 != null)

                    {

                        List<artEtikettResult> l1 = _sap.Z_ARTIS_VG_SHOW_ETIKETT_NET(_WZV.Materialnummer, out bapiret2, etres1.EtikettMatNr);

                        if (l1 != null)

                        {

                            artEtikettResult etres2 = l1.First();

                            if (etres2 != null)

                            {

                                ProcessStartInfo startInfo = new ProcessStartInfo(etres2.Docfile);

                                //startInfo.WindowStyle = ProcessWindowStyle.Minimized;

                                //startInfo.Arguments = ;

                                Process.Start(startInfo);

                            }

                        }

                    }

                }

            }

        }

2. C# Call of FM in SAP:

    public List<artEtikettResult> Z_ARTIS_VG_SHOW_ETIKETT_NET(string sMaterialnummer, out artBAPIRET2 bapiret2, string sEtikettnummer = "")
    {
        List<artEtikettResult> result = new List<artEtikettResult>();

        string matnr1 = GetMaterialnummer18stellig(sMaterialnummer);
        if (matnr1 != "")
        {
            IRfcFunction function = destination.Repository.CreateFunction("Z_ARTIS_VG_SHOW_ETIKETT_NET");

            function.SetValue("I_MATNR", matnr1);

            if (sEtikettnummer != "")
            {
                string etikettnr1 = GetMaterialnummer18stellig(sEtikettnummer);
                if (etikettnr1 != "")
                {
                    function.SetValue("I_IDNRK", sEtikettnummer);
                }
            }

            function.Invoke(destination);

            IRfcStructure E_RETURN = function.GetStructure("E_RETURN");
            if (E_RETURN != null)
            {
                artBAPIRET2 ret2 = new artBAPIRET2();
                ret2.TYPE = E_RETURN.GetString("TYPE");
                ret2.ID = E_RETURN.GetString("ID");
                ret2.NUMBER = E_RETURN.GetString("NUMBER");
                ret2.MESSAGE = E_RETURN.GetString("MESSAGE");
                ret2.LOG_NO = E_RETURN.GetString("LOG_NO");
                ret2.MESSAGE_V1 = E_RETURN.GetString("MESSAGE_V1");
                ret2.MESSAGE_V2 = E_RETURN.GetString("MESSAGE_V2");
                ret2.MESSAGE_V3 = E_RETURN.GetString("MESSAGE_V3");
                ret2.MESSAGE_V4 = E_RETURN.GetString("MESSAGE_V4");
                ret2.PARAMETER = E_RETURN.GetString("PARAMETER");
                ret2.ROW = E_RETURN.GetString("ROW");
                ret2.FIELD = E_RETURN.GetString("FIELD");
                ret2.SYSTEM = E_RETURN.GetString("SYSTEM");

                bapiret2 = ret2;

                if (ret2.TYPE != "E")
                {
                    IRfcTable T_DOC = function.GetTable("T_DOC");
                    if (T_DOC != null)
                    {
                        foreach (IRfcStructure row in T_DOC)
                        {
                            artEtikettResult etres1 = new artEtikettResult();
                            etres1.Docfile = row.GetString("DOCFILE");
                            string docnr1 = row.GetString("DOCNR");
                            etres1.DokumentNr = GetEtikettnummerWthoutNull(docnr1);
                            string idnrk1 = row.GetString("IDNRK");
                            etres1.EtikettMatNr = GetEtikettnummerWthoutNull(idnrk1);
                            etres1.Return = ret2;

                            result.Add(etres1);
                        }

                    }
                }

                // E_BUFFER ist in SAP ein XSTRING, was eine Array von Byte in C# entspricht
                byte[] E_BUFFER = function.GetByteArray("E_BUFFER");
                if (E_BUFFER != null)
                {
                    foreach (artEtikettResult etres2 in result)
                    {
                        FileStream fs = new FileStream(etres2.Docfile, FileMode.Create);

                        // Create the writer for data.

                        BinaryWriter w = new BinaryWriter(fs);

                        // Write data to Test.data.

                        w.Write(E_BUFFER);

                        w.Close();

                        fs.Close();
                    }
                }

                return result;
            }
        }
        bapiret2 = null;
        return null;
    }

3. FM in SAP

FUNCTION z_artis_vg_show_etikett_net.

*"----------------------------------------------------------------------

*"*"Lokale Schnittstelle:

*"  IMPORTING

*"     VALUE(I_MATNR) TYPE  MATNR

*"     VALUE(I_IDNRK) TYPE  IDNRK OPTIONAL

*"  EXPORTING

*"     VALUE(E_RETURN) TYPE  BAPIRET2

*"     VALUE(E_BUFFER) TYPE  XSTRING

*"  TABLES

*"      T_DOC STRUCTURE  ZARTIS_DOC

*"  EXCEPTIONS

*"      NO_STUE_BER

*"      NO_STUE_WRK

*"      NO_KLAH_BKL

*"      NO_ALLOCATION

*"      SET_AENNR

*"      CHANGE_NR_NOT_EXIST

*"      DATE_IN_PAST

*"      ERROR_CLASS

*"      ERROR_DATE_RESTRICTION

*"      ERROR_STATUS

*"      ALT_NOT_FOUND

*"      CALL_INVALID

*"      MATERIAL_NOT_FOUND

*"      MISSING_AUTHORIZATION

*"      NO_BOM_FOUND

*"      NO_PLANT_DATA

*"      NO_SUITABLE_BOM_FOUND

*"      CONVERSION_ERROR

*"      E_KLASSIFIZIERUNG

*"      E_BAPI_DOCUMENT_GETOBJECTDOCS

*"      E_BAPI_DOCUMENT_CHECKOUTVIEW2

*"      NO_FILE_FOUND

*"      E_NO_ACTIVE_DOC_VERSION

*"      NO_DRAW_BGR

*"----------------------------------------------------------------------

  DATA: itab_stb TYPE TABLE OF stpox,

        wa_stb TYPE stpox,

        str_topmat TYPE cstmat,

        l_dstdt TYPE csdata-xfeld,

        itab_matcat TYPE TABLE OF cscmat,

        matnr1 TYPE matnr.

  DATA: wa_objid TYPE api_ob_key,

        itab_objid TYPE TABLE OF api_ob_key,

        wa_alloc TYPE api_kssk,

        itab_alloc TYPE TABLE OF api_kssk.

  DATA: l_error_statu,

        obj1 TYPE kssk-objek,

        obtab1 TYPE tclt-obtab.

  DATA: ls_doclist TYPE bapi_doc_keys,

        lt_doclist TYPE TABLE OF bapi_doc_keys,

        objectkey TYPE bapi_doc_drad-objectkey.

  DATA: wa_documentfile TYPE  bapi_doc_files2,

        itab_documentstructure TYPE TABLE OF bapi_doc_structure,

        wa_documentfiles TYPE bapi_doc_files2,

        itab_documentfiles TYPE TABLE OF bapi_doc_files2,

        itab_components TYPE TABLE OF bapi_doc_comp.

  DATA: doc_found TYPE c,

        do_exit TYPE c,

        t_str_agrs TYPE TABLE OF str_agrs,

        wa_str_agrs TYPE str_agrs.

  DATA: error TYPE string.

  DATA: ls_doc TYPE zartis_doc.

  DATA: lt_documentfiles  TYPE TABLE OF bapi_doc_files2,

        ls_documentfile    TYPE bapi_doc_files2,

        lt_access_info  TYPE TABLE OF scms_acinf,

        ls_access_info  TYPE scms_acinf,

        lt_content_bin  TYPE TABLE OF sdokcntbin,

        lv_contentx TYPE xstring,

        lv_filename TYPE sdok_filnm,

        lv_filename_s TYPE string.

  DATA: ls_ret_getdetail2 TYPE bapiret2,

        ls_ret_getactversion  TYPE  bapiret2,

        ls_ret_getobjectdocs TYPE bapiret2.

  doc_found = space.

  error = space.

  do_exit = space.

* Authority-Check für Stücklisten

  AUTHORITY-CHECK OBJECT 'C_STUE_BER'

           ID 'STLTY' FIELD 'M'

           ID 'STLAN' FIELD '1'

           ID 'ACTVT' FIELD '03'

           ID 'BEGRU' DUMMY.

  IF sy-subrc = 0.

    AUTHORITY-CHECK OBJECT 'C_STUE_WRK'

             ID 'ACTVT' FIELD '03'

             ID 'CSWRK' FIELD '0001'.

    IF sy-subrc = 0.

      AUTHORITY-CHECK OBJECT 'C_KLAH_BKL'

                         ID 'ACTVT' FIELD '03'

                         ID 'BGRKL' DUMMY.

      IF sy-subrc = 0.

        AUTHORITY-CHECK OBJECT 'C_DRAW_BGR'

                 ID 'BEGRU' FIELD 'WRB'.

        IF sy-subrc = 0.

*         Stückliste zum Material holen

          CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

            EXPORTING

              capid                 = 'PP01'

              datuv                 = sy-datum

              mbwls                 = 'X'

              mktls                 = 'X'

              mehrs                 = 'X'

              mtnrv                 = i_matnr

              sanfr                 = '1'

              stlan                 = '1'

              werks                 = '0001'

            IMPORTING

              topmat                = str_topmat

              dstst                 = l_dstdt

            TABLES

              stb                   = itab_stb

              matcat                = itab_matcat

            EXCEPTIONS

              alt_not_found         = 1

              call_invalid          = 2

              material_not_found    = 3

              missing_authorization = 4

              no_bom_found          = 5

              no_plant_data         = 6

              no_suitable_bom_found = 7

              conversion_error      = 8

              OTHERS                = 9.

          IF sy-subrc <> 0.

            CASE sy-subrc.

              WHEN 1.

                RAISE alt_not_found.

              WHEN 2.

                RAISE call_invalid.

              WHEN 3.

                RAISE material_not_found.

              WHEN 4.

                RAISE missing_authorization.

              WHEN 5.

                RAISE no_bom_found.

              WHEN 6.

                RAISE no_plant_data.

              WHEN 7.

                RAISE no_suitable_bom_found.

              WHEN 8.

                RAISE conversion_error.

            ENDCASE.

            RETURN.

          ENDIF.

          SORT itab_stb BY stufe.

          CLEAR: ls_doc, t_doc.

          REFRESH: t_doc.

*           Etiketten in Stückliste suchen

          LOOP AT itab_stb INTO wa_stb.

            IF do_exit = space.

              CLEAR: wa_objid, itab_objid.

              REFRESH: itab_objid.

              wa_objid-field = 'MATNR'.

              wa_objid-value = wa_stb-idnrk.

              APPEND wa_objid TO itab_objid.

              CLEAR: itab_alloc.

              REFRESH: itab_alloc.

              obj1 = wa_stb-idnrk.

              obtab1 = 'MARA'.

*               anhand der Klassifizierung prüfen, ob das Material auch ein Etikett ist

              CALL FUNCTION 'CLAP_DDB_GET_CLASSIFICATION'

                EXPORTING

                  object                 = obj1

                  obtab                  = obtab1

                  spras                  = sy-langu

                IMPORTING

                  error_statu            = l_error_statu

                TABLES

                  allocations            = itab_alloc

                EXCEPTIONS

                  no_allocation          = 1

                  set_aennr              = 2

                  change_nr_not_exist    = 3

                  date_in_past           = 4

                  error_class            = 5

                  error_date_restriction = 6

                  error_status           = 7

                  OTHERS                 = 8.

              IF sy-subrc = 0.

                LOOP AT itab_alloc INTO wa_alloc.

                  IF wa_alloc-klart = '200' AND wa_alloc-class = 'PRODUKTETIKETT_206'.

                    IF do_exit = space.

                      objectkey = wa_stb-idnrk.

*                       Verknüpfte Dokumente zum Material holen

                      CALL FUNCTION 'BAPI_DOCUMENT_GETOBJECTDOCS'

                        EXPORTING

                          objecttype          = 'MARA'

                          objectkey           = objectkey

                          currentversionsonly = 'X'

                          date                = sy-datum

                        IMPORTING

                          return              = ls_ret_getobjectdocs

                        TABLES

                          documentlist        = lt_doclist.

                      IF sy-subrc = 0 AND

                         ls_ret_getobjectdocs-type NE 'E'.

                        LOOP AT lt_doclist INTO ls_doclist.

                          IF do_exit = space.

*                             aktive Version des Dokuments holen

                            CALL FUNCTION 'BAPI_DOCUMENT_GETACTVERSION'

                              EXPORTING

                                documenttype   = ls_doclist-documenttype

                                documentnumber = ls_doclist-documentnumber

                                documentpart   = ls_doclist-documentpart

                                date           = sy-datum

                                releaseonly    = 'X'

                              IMPORTING

                                return         = ls_ret_getactversion

                                actualversion  = ls_doclist-documentversion.

                            IF sy-subrc = 0 AND

                               ls_ret_getactversion-type NE 'E' AND

                               NOT ls_doclist-documentversion IS INITIAL.

*                               Details zum Dokument holen

                              CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'

                                EXPORTING

                                  documenttype    = ls_doclist-documenttype

                                  documentnumber  = ls_doclist-documentnumber

                                  documentpart    = ls_doclist-documentpart

                                  documentversion = ls_doclist-documentversion

                                  getdocfiles     = 'X'

                                IMPORTING

                                  return          = ls_ret_getdetail2

                                TABLES

                                  documentfiles   = lt_documentfiles.

                              IF sy-subrc = 0 AND

                                 ls_ret_getdetail2-type NE 'E'.

                                LOOP AT lt_documentfiles INTO ls_documentfile.

                                  ls_doc-docfile         = ls_documentfile-docfile.

                                  ls_doc-docnr           = ls_doclist-documentnumber.

                                  ls_doc-idnrk           = wa_stb-idnrk.

                                  ls_doc-storagecategory = ls_documentfile-storagecategory.

                                  ls_doc-file_id         = ls_documentfile-file_id.

                                  APPEND ls_doc TO t_doc.

                                  doc_found = 'X'.

                                  error = space.

                                ENDLOOP.

                              ELSE.

                                error = 'BAPI_DOCUMENT_GETDETAIL2'.

                                do_exit = 'X'.

                                EXIT.

                              ENDIF.

                            ELSE.

                              error = 'E_NO_ACTIVE_DOC_VERSION'.

                            ENDIF.

                          ELSE.

                            error = space.

                            EXIT.

                          ENDIF.

                        ENDLOOP.

                      ELSE.

                        error = 'E_BAPI_DOCUMENT_GETOBJECTDOCS'.

                      ENDIF.

                    ELSE.

                      error = space.

                      EXIT.

                    ENDIF.

                  ELSE.

                    error = 'E_KLASSIFIZIERUNG'.

                  ENDIF.

                ENDLOOP.

              ELSE.

                CASE sy-subrc.

                  WHEN 1.

                    error = 'NO_ALLOCATION'.

                  WHEN 2.

                    error = 'SET_AENNR'.

                  WHEN 3.

                    error = 'CHANGE_NR_NOT_EXIST'.

                  WHEN 4.

                    error = 'DATE_IN_PAST'.

                  WHEN 5.

                    error = 'ERROR_CLASS'.

                  WHEN 6.

                    error = 'ERROR_DATE_RESTRICTION'.

                  WHEN 7.

                    error = 'ERROR_STATUS'.

                ENDCASE.

              ENDIF.

            ENDIF.

          ENDLOOP.

          IF doc_found IS INITIAL.

            IF error = 'NO_ALLOCATION'.

              RAISE no_allocation.

            ENDIF.

            IF error = 'E_KLASSIFIZIERUNG'.

              RAISE e_klassifizierung.

            ENDIF.

            IF error = 'E_BAPI_DOCUMENT_GETOBJECTDOCS'.

              e_return = ls_ret_getobjectdocs.

            ENDIF.

            IF error = 'E_NO_ACTIVE_DOC_VERSION'.

              e_return = ls_ret_getactversion.

            ENDIF.

            IF error = 'BAPI_DOCUMENT_GETDETAIL2'.

              e_return = ls_ret_getdetail2.

            ENDIF.

            IF  error = 'SET_AENNR'.

              RAISE set_aennr.

            ENDIF.

            IF  error = 'CHANGE_NR_NOT_EXIST'.

              RAISE change_nr_not_exist.

            ENDIF.

            IF  error = 'DATE_IN_PAST'.

              RAISE date_in_past.

            ENDIF.

            IF  error = 'ERROR_CLASS'.

              RAISE error_class.

            ENDIF.

            IF  error = 'ERROR_DATE_RESTRICTION'.

              RAISE error_date_restriction.

            ENDIF.

            IF  error = 'ERROR_STATUS'.

              RAISE error_status.

            ENDIF.

          ENDIF.

*       wenn ein Dokument vorgegeben wurde, dann

*       den Byte-Stream diese Dokument laden

*       und zurückgeben

          IF i_idnrk IS NOT INITIAL.

            READ TABLE t_doc INTO ls_doc WITH KEY idnrk = i_idnrk.

            CALL FUNCTION 'SCMS_DOC_READ'

              EXPORTING

                stor_cat    = ls_doc-storagecategory

                doc_id      = ls_doc-file_id

              TABLES

                access_info = lt_access_info

                content_bin = lt_content_bin.

            IF sy-subrc = 0.

              READ TABLE lt_access_info INTO ls_access_info INDEX 1.

              IF sy-subrc = 0.

                " Convert XData to Xstring

                CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

                  EXPORTING

                    input_length = ls_access_info-comp_size

                  IMPORTING

                    buffer       = e_buffer

                  TABLES

                    binary_tab   = lt_content_bin

                  EXCEPTIONS

                    failed       = 1

                    OTHERS       = 2.

                IF sy-subrc = 0.

                  doc_found = 'X'.

                  error = space.

                ENDIF.

              ENDIF.

            ENDIF.

          ENDIF.

        ELSE.

          IF sy-subrc = 4.

            RAISE no_draw_bgr.

          ENDIF.

        ENDIF.

      ELSE.

        IF sy-subrc = 4.

          RAISE no_klah_bkl.

        ENDIF.

      ENDIF.

    ELSE.

      IF sy-subrc = 4.

        RAISE no_stue_wrk.

      ENDIF.

    ENDIF.

  ELSE.

    IF sy-subrc = 4.

      RAISE no_stue_ber.

    ENDIF.

  ENDIF.

ENDFUNCTION.

former_member197445
Contributor
0 Kudos

Let's see your code.  It's probably in the way you are saving to disk.

0 Kudos

Hi Case,

I have a Z_xxx function module, which is called from C# and here´s the call of BAPI_DOCUMENT_CHECKOUTVIEW2 in this FM:

CALL FUNCTION 'BAPI_DOCUMENT_CHECKOUTVIEW2'

                                  EXPORTING

                                   documenttype              = wa_doclist-documenttype

                                   documentnumber            = wa_doclist-documentnumber

                                   documentpart              = wa_doclist-documentpart

                                   documentversion           = wa_doclist-documentversion

                                   documentfile              = wa_documentfile

                                   getstructure              = '0'

                                   getcomponents             = 'X'

                                   originalpath              = 'c:\temp\'

                                   hostname                  = 'DEFAULT'

                                   getheader                 = 'X'

*                                DOCBOMCHANGENUMBER        =

*                                DOCBOMVALIDFROM           =

*                                DOCBOMREVISIONLEVEL       =

*                                PF_HTTP_DEST              = ' '

*                                PF_FTP_DEST               = ' '

                                 IMPORTING

                                   return                    = ret2

                                 TABLES

                                   documentstructure         = itab_documentstructure

                                   documentfiles             = itab_documentfiles

                                   components                = itab_components.

Regards,

Veit