/*@(#) cadrftst.c       20.5.3.1     SAP     %E */
/*--------------------------------------------------------------------*/
/*                                                                    */
/*  SAP AG Walldorf                                                   */
/*  SAP  Systeme, Anwendungen und Produkte in der Datenverarbeitung   */
/*                                                                    */
/*  (C) Copyright SAP AG 1995                                         */
/*                                                                    */
/*--------------------------------------------------------------------*/
/*  File: cadrftst.c                                                  */
/*--------------------------------------------------------------------*/
/*  program for testing the dialog rfc                                */
/*                                                                    */
/*  routines:                                                         */
/*  ---------                                                         */
/*                                                                    */
/*  rfc_error1()          writes error messages into dev_rfc file     */
/*  reconnect_to_sap()    Reconnect to SAP                            */
/*  display_mat_master()  Display Mat.Master via dialog rfc           */
/*  display_mat_master_via_api() Display Mat.Master via dia.rfc (API) */
/*  request_mat_master()  Request Mat.Master data via SAP CAD         */
/*                        function library                            */
/*--------------------------------------------------------------------*/
/*  3.0F                                                              */
/*  BINK097985 231096 get rid of compiler warnings                    */
/*  3.0E                                                              */
/*  BINK090600 120796 connect to SAP with function CadRfcOpen         */
/*  3.0A                                                              */
/*  BINK052794 020595 new                                             */
/*--------------------------------------------------------------------*/
/* Read this first!                                                   */
/* Before you can test this program, you must first do some           */
/* customization in the R/3 system                                    */
/*                                                                    */
/* 1. Go into the customizing of the Document Management System       */
/* 2. Select Generel Data                                             */
/* 3. Customize Data Carrier Type as described in the CAD dialog RFC  */
/*    documentation (IMPORTANT: enter a valid path name. Enter this   */
/*    path name in the local file cadrfc.ini for CadRfcTempDir        */
/* 4. Select Workstation Application                                  */
/*    Enter WS application TST                                        */
/*          Interface      X                                          */
/*          StartAut       X                                          */
/*          Sx             Space                                      */
/*          Description    test program for dialog rfc                */
/*          ArchId         A2                                         */
/*          File format    Space                                      */
/*          StartAut       X                                          */
/*    Save this entry, go back                                        */
/* 5. Select Workstation Application in network                       */
/*    Enter Ty             one of the defined Data Carrier Types      */
/*          App            TST                                        */
/*          A              2                                          */
/*          Application    <path>/cadrftst<.exe>                      */
/*    Save this entry, go back to the main menu level                 */
/* 6. Select Logistics->Central Functions->Engineering, then          */
/*    Extras->other frontend type. Select the correct frontend type   */
/*    (This is the data carrier type to which you linked the          */
/*    workstation application)                                        */
/* 7. Select Extras->Connect applicat.			              */
/*    You should now see an entry called "test program for dialog rfc"*/
/* 8. Select this entry to connect to the test program                */
/*							              */
/* As described in the CAD dialog RFC documentation the system now    */
/* tries to communicate with the local program cadrfc.<exe>.          */
/* This program must be found in the search path of the local         */
/* computer. Otherwise you may change the path on the SAP side        */
/* To do this:                                                        */
/* Select Tools->Administration->Network->RFC destinations            */
/* Select the entry named DIALOG_CAD_RFC                              */
/* You then can change the program path for the cadrfc program        */
/* Save the changes                                                   */
/*--------------------------------------------------------------------*/

#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>

/* RFC libraries                                                     */
#include "saprfc.h"
#include "sapitab.h"

/* Header file needed for call in display_mat_master_via_api()       */
#include "cadrfc.h"

/* Header file needed for call in request_mat_master()                */
#include "caddialg.h"

#if defined(SAPonWINDOWS) || defined(SAPonNT)
#include <windows.h>
int PASCAL WinMain (HANDLE, HANDLE, LPSTR, int);
#else
#include <Xm/BulletinB.h>
#include <Xm/PushB.h>
#include <Xm/Label.h>
#include <Xm/Text.h>

void button_okCB();
void button_exitCB();
Widget parent_shell = NULL;
Widget msgbox;
XmFontList newfontlist;
Widget bboard;
Widget text1;

#endif

/* used functions                                                    */
int reconnect_to_sap();
int connect_to_sap();
int display_mat_master();
int display_mat_master_via_api();
int request_mat_master();
void rfc_error1();
void DisplayMessage();
void DisplayText();

/* external used function from cadrfcxx.dll */
int  GetFileEntry          (char *, char *, char *, char *);


/* global variables needed in SAP CAD function library APIs           */
SAPHD          hd;
char           *sapmes;
char           *rcvstr;

/* global variables needed in RFC calls                               */
RFC_RC         CadRfcRc;
RFC_HANDLE     handle;


char messagex[400];
char ux_mess[4000];
int  rc=0;
char *argv_glob[2];

#if defined(SAPonWINDOWS) || defined(SAPonNT)
/*--------------------------------------------------------------------*/
/* int WinMain for MS-Windows and MS-WindowsNT                        */
/*--------------------------------------------------------------------*/
/* main starting routine of cadrftst                                  */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   hInstance        WinMain                               */
/*             hPrevInstance       "                                  */
/*             lpszCmdLine         "                                  */
/*             nCmdShow            "                                  */
/*             __argc           main and WinMain                      */
/*             __argv                 "                               */
/*   OUTPUT:   ----             -----                                 */
/*--------------------------------------------------------------------*/
/*   Return:   rc               exit code                             */
/*--------------------------------------------------------------------*/
int PASCAL WinMain (HANDLE  hInstance,
                    HANDLE  hPrevInstance,
                    LPSTR   lpszCmdLine,
                    int nCmdShow)
{
  extern char ** __argv;
  extern int  __argc;
  int  rc;

  if (__argc < 2) {
    DisplayMessage(2);
    return(2);
  }

/* if connect from external application to SAP (av. from 3.0C)       */
  if (strncmp(__argv[1], "/r3connect",10) == 0) {
    rc = connect_to_sap();
    if (rc == 0) DisplayMessage(1);
    else         return(rc);
  }
  else {

/* Check that there are 3 parameters when program is called via SAP or cadrfc  */
    if (__argc < 4) {
      DisplayMessage(2);
      return(2);
    }
    else {

/* call routine for reconnect to SAP                                  */
      rc = reconnect_to_sap(__argc, __argv);
      if (rc == 0) DisplayMessage(1);
      else         return(rc);
    }
  }

/* call routine for displaying mat.master via dialog RFC (direct RFC call) */
  rc = display_mat_master();
  if (rc == 0) DisplayMessage(3);
  else         return(rc);

/* call routine for displaying mat.master via dialog RFC (with API)   */
  rc = display_mat_master_via_api();
  if (rc == 0) DisplayMessage(4);
  else         return(rc);

/* call routine for retrieving mat.master infos with SAP CAD function library call  */
  rc = request_mat_master(__argv);
  if (rc == 0) DisplayMessage(5);
  else         return(rc);

/* Terminating RFC connection                                         */
  RfcClose(handle);

}
#else



/*--------------------------------------------------------------------*/
/* int main                                                           */
/*--------------------------------------------------------------------*/
/* main starting routine of cadrftst                                  */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   hInstance        WinMain                               */
/*             hPrevInstance       "                                  */
/*             lpszCmdLine         "                                  */
/*             nCmdShow            "                                  */
/*             __argc           main and WinMain                      */
/*             __argv                 "                               */
/*   OUTPUT:   ----             -----                                 */
/*--------------------------------------------------------------------*/
/*   Return:   rc               exit code                             */
/*--------------------------------------------------------------------*/
int main( int __argc, char ** __argv )
{

  XmString mess1;
  Arg args[20];
  int n;
  Widget label1;
  Widget button1;
  Widget button2;
  XtAppContext app_context;

  memset(ux_mess, 0, sizeof(ux_mess));

  parent_shell = XtAppInitialize (&app_context, "XMfonts", NULL, 0, &__argc, __argv, NULL, args, 0);

  n = 0;
  XtSetArg (args[n], XmNallowShellResize, True); n++;
  XtSetArg (args[n], XmNheight, 400); n++;
  XtSetArg (args[n], XmNwidth, 500); n++;
  bboard = XmCreateBulletinBoard(parent_shell, "bboard", args, n);
  XtManageChild(bboard);

  n = 0;
  XtSetArg(args[n], XmNlabelString, XmStringCreate("CAD dialog RFC test program",
           XmSTRING_DEFAULT_CHARSET)); n++;
  label1 = XmCreateLabel(bboard, "label1", args, n);
  XtManageChild(label1);

  n = 0;
  mess1 = XmStringCreateLtoR("OK", XmSTRING_DEFAULT_CHARSET);
  XtSetArg(args[n], XmNlabelString, mess1); n++;
  XtSetArg(args[n], XmNy, 330); n++;
  button1 = XmCreatePushButton(bboard, "button1", args, n);
  XtManageChild(button1);
  XtAddCallback(button1, XmNactivateCallback, button_okCB, NULL);

  n = 0;
  mess1 = XmStringCreateLtoR("Cancel", XmSTRING_DEFAULT_CHARSET);
  XtSetArg(args[n], XmNlabelString, mess1); n++;
  XtSetArg(args[n], XmNy, 330); n++;
  XtSetArg(args[n], XmNx, 80); n++;
  button2 = XmCreatePushButton(bboard, "button2", args, n);
  XtManageChild(button2);
  XtAddCallback(button2, XmNactivateCallback, button_exitCB, NULL);

  if (__argc < 2) {
    DisplayMessage(2);
    rc = 100;
    XtUnmanageChild(button1);
  }

/* if connect from external application to SAP (av. from 3.0C)       */
  if (strncmp(__argv[1], "/r3connect",10) == 0) {
    argv_glob[0] = __argv[0];
    rc = connect_to_sap();
    if (rc == 0) DisplayMessage(1);
    else         XtUnmanageChild(button1);
  }
  else {

/* Check that there are 3 parameters when program is called via SAP or cadrfc  */
    if (__argc < 4) {
      DisplayMessage(2);
      rc = 100;
      XtUnmanageChild(button1);
    }
    else {
      argv_glob[0] = __argv[0];

/* call routine for reconnect to SAP                                  */
      rc = reconnect_to_sap(__argc, __argv);
      if (rc == 0) DisplayMessage(1);
      else         XtUnmanageChild(button1);
    }
  }

  XtRealizeWidget(parent_shell);
  XtAppMainLoop(app_context);
  return(0);
}
#endif



/*--------------------------------------------------------------------*/
/* voide rfc_error1                                                   */
/*--------------------------------------------------------------------*/
/* RFC error handling. Write message in dev_rfc file                  */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   operation        RFC operation code                    */
/*   OUTPUT:   ----             -----                                 */
/*--------------------------------------------------------------------*/
/*   Return:   ----             -----                                 */
/*--------------------------------------------------------------------*/
void rfc_error1( char * operation )
{
  FILE *fp;
  RFC_ERROR_INFO error_info;
  char *envp;
  char finame[133];
  char dirsign;

  memset(finame, 0, sizeof(finame));

/* get CADRFC environment variable for logfile                        */
  envp=getenv("CADRFC");
  if (envp == NULL) {
    fp = fopen("./dev_rfc","a");

/* When impossible to access file in working dir -> use home dir      */
    if (fp == 0) {
      envp=getenv("HOME");
      if (envp == NULL) return;

      strcpy(finame,envp);
      dirsign = finame[strlen(finame)-1];
      if (dirsign != '/' && dirsign != '\\') strcat(finame,"/");

      strcat(finame,"dev_rfc");
      fp = fopen(finame , "a");
      if (fp  == NULL) return;
    }
  }
  else {

/* try environment variable                                          */
    strcpy(finame, envp);
    dirsign = finame[strlen(finame)-1];
    if (dirsign != '/' && dirsign != '\\') strcat(finame,"/");

    strcat(finame,"dev_rfc");
    fp = fopen(finame , "a");
    if (fp == NULL) return;
  }

  fprintf( fp, "\n%s in CADRFTST\n", operation );
  memset( &error_info, 0, sizeof( error_info ) );
  RfcLastError( &error_info );
  fprintf( fp, "Error info :\n" );
  fprintf( fp, "key        : %s\n", error_info.key );
  fprintf( fp, "status     : %s\n", error_info.status );
  fprintf( fp, "message    : %s\n", error_info.message );
  fprintf( fp, "internal   : %s\n\n", error_info.intstat );
  fclose(fp);
  return;
}



/*--------------------------------------------------------------------*/
/* int reconnect_to_sap                                               */
/*--------------------------------------------------------------------*/
/* Routine for reconnecting to SAP                                    */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   argc             argc                                  */
/*             argv             argv                                  */
/*   OUTPUT:   ----             -----                                 */
/*--------------------------------------------------------------------*/
/*   Return:   rc               return code                           */
/*--------------------------------------------------------------------*/
int reconnect_to_sap(int argc, char** argv) {
  int rc;
  char char_err_id[2];
  char *accept_argv[5];
  RFC_FUNCTIONNAME functionname;

  if (argc > 3) {
    accept_argv[0]=argv[0];
    accept_argv[1]=argv[1];
    accept_argv[2]=argv[2];
    accept_argv[3]=argv[3];
    accept_argv[4]=0;
  }
  memset(char_err_id,' ',sizeof(char_err_id));
  handle = RfcAccept( accept_argv );
  if( handle == RFC_HANDLE_NULL ) {
    DisplayMessage(6);
    return(6);
  }

  rc = RfcGetName( handle, functionname );
  if( rc != RFC_OK ) {
    DisplayMessage(7);
    return(7);
  }

  rc = RfcGetData( handle, NULL, NULL );
  if( rc != RFC_OK ) {
    DisplayMessage(8);
    return(8);
  }

/* if correct up to here, there had been a successul reconnect to SAP */
  return(0);
}



/*--------------------------------------------------------------------*/
/* int connect_to_sap                                                 */
/*--------------------------------------------------------------------*/
/* Routine for connecting to SAP (possible from 3.0C)                 */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             -----                                 */
/*   OUTPUT:   ----             -----                                 */
/*--------------------------------------------------------------------*/
/*   Return:   rc               return code                           */
/*--------------------------------------------------------------------*/
int connect_to_sap() {

  int retcod;

  /* connect to the SAP-System */
  /* get connect parameter from CADRFC.INI file */

  retcod = CadRfcOpen ( "", "", "", "", "", "", "", &handle);  /* BINK090600 120796 */
  if( retcod != 0 ) return(17);
  
/* if correct up to here, there had been a successul connect to SAP   */
  return(0);
}



/*--------------------------------------------------------------------*/
/* int display_mat_master                                             */
/*--------------------------------------------------------------------*/
/* Routine calls a dialog RFC for displaying a mat. master            */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             ----                                  */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   rc               return code                           */
/*--------------------------------------------------------------------*/
int display_mat_master() {
  RFC_PARAMETER exporting[8];
  RFC_TABLE     tables[8];
  char *        exception_ptr;
  RFC_PARAMETER importing[8];
  char          Material[18];
  char          FunctionCode[14];

/* the next two definitions are necassary to define the two table    */
/* structures which are used in the Mat.Master Display RFC           */
#ifndef SAP_ST_SAP_FIELD_DATA
#define SAP_ST_SAP_FIELD_DATA
  typedef struct
    {
    RFC_CHAR Fieldmulti[40];
    RFC_CHAR Fieldname[35];
    RFC_CHAR Fieldvalue[255];
    } SAP_FIELD_DATA;
#endif

#ifndef SAP_ST_CLASS_CHARACTERISTICS
#define SAP_ST_CLASS_CHARACTERISTICS
  typedef struct
    {
    RFC_CHAR Atnam[30];
    RFC_CHAR Atbez[30];
    RFC_CHAR Atwrt[30];
    RFC_CHAR Dinkb[3];
    RFC_CHAR Unit[6];
    } CLASS_CHARACTERISTICS;
#endif

  ITAB_H thSapFieldData = ITAB_NULL;
  ITAB_H thDmsCharac    = ITAB_NULL;

/* initialize table for SAP_FIELD_DATA                              */
  thSapFieldData = ItCreate ("SAP_FIELD_DATA", sizeof (SAP_FIELD_DATA), 0, 0);
  if (thSapFieldData == ITAB_NULL) {
    DisplayMessage(9);
    return(9);
  }

/* initialize table for Class-Characteristics                       */
  thDmsCharac = ItCreate ("CLASS_CHARACTERISTICS", sizeof (CLASS_CHARACTERISTICS), 0, 0);
  if (thDmsCharac == ITAB_NULL) {
    DisplayMessage(10);
    return(10);
  }

/* Fill in material master number which should be displayed         */
  memset(Material,' ', sizeof(Material));
  memcpy(Material,"EB01",4);

  memset(FunctionCode,' ', sizeof(FunctionCode));

  exporting[0].name = "MATERIAL";
  exporting[0].nlen = 8;
  exporting[0].addr = Material;
  exporting[0].leng = sizeof(Material);
  exporting[0].type = TYPC;
  exporting[1].name = NULL;
  importing[0].name = "FUNCTION_CODE";
  importing[0].nlen = 13;
  importing[0].addr = FunctionCode;
  importing[0].leng = sizeof(FunctionCode);
  importing[0].type = TYPC;
  importing[1].name = NULL;
  tables[0].name     = "SAP_FIELD_DATA";
  tables[0].nlen     = 14;
  tables[0].type     = TYPC;
  tables[0].ithandle = thSapFieldData;
  tables[0].leng     = sizeof(SAP_FIELD_DATA);
  tables[0].itmode   = RFC_ITMODE_BYREFERENCE;
  tables[1].name     = "DMS_CLASS_DATA";
  tables[1].nlen     = 14;
  tables[1].type     = TYPC;
  tables[1].ithandle = thDmsCharac;
  tables[1].leng     = sizeof(CLASS_CHARACTERISTICS);
  tables[1].itmode   = RFC_ITMODE_BYREFERENCE;
  tables[2].name     = NULL;

  CadRfcRc = RfcCallReceive( handle, "RFC_DISPLAY_MATERIAL_MASTER",
                             exporting, importing, tables,
                             &exception_ptr );
  if (CadRfcRc != RFC_OK) {
    DisplayMessage(11);
    return(11);
  }
  return(0);
}



/*--------------------------------------------------------------------*/
/* int display_mat_master_via_api                                     */
/*--------------------------------------------------------------------*/
/* Routine calls a dialog RFC for displaying a mat. master            */
/* Routine uses a call out of the CAD dialog rfc library              */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             ----                                  */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   rc               return code                           */
/*--------------------------------------------------------------------*/
int display_mat_master_via_api() {
  BICSK                 *MaterialHeaderData;
  CadRfcExportField     *pExportData;
  CadRfcImportField     *pImportData;
  DRAW_RFC              *pDocumentData;
  ITAB_H                *thSapFieldData = ITAB_NULL;
  ITAB_H                *thDmsCharac    = ITAB_NULL;
  int                   rc;

/* Intialize API Interface (must be done one time before the first api call) */
  rc = CadRfcAllocMemory(&pExportData, &pImportData,
                               &MaterialHeaderData, &pDocumentData);

  if (rc != (int) RFC_OK) {
    DisplayMessage(12);
    return(12);
  }

/* Give RFC handle to API lib                                       */
  rc = CadRfcSetHandle(&handle);

/* Fill in material master number which should be displayed         */
/* Call mat.master display API                                      */
  memcpy(pExportData->Material,"EB01",4);
  rc = CadRfcMatDisplay(pExportData, pImportData, &thSapFieldData, &thDmsCharac);
  if (rc != (int) RFC_OK) {
    DisplayMessage(13);
    return(13);
  }
  return(0);
}



/*--------------------------------------------------------------------*/
/* int request_mat_master                                             */
/*--------------------------------------------------------------------*/
/* Routine retrieves data from a mat. master record from SAP          */
/* This routine uses APIs out of the SAP CAD function library         */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             ----                                  */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   rc               return code                           */
/*--------------------------------------------------------------------*/
int request_mat_master(char** argv) {
  char        sendstr[100];

/* Give RFC handle to API lib                                      */
  CadRfcRc = CadRfcSetHandle(&handle);

/* Intialize SAP CAD function library                              */
/* (must be done one time before the first api call)               */
  hd = SapConncRfc(*argv,"DEMO",&rcvstr,&sapmes);
  if (hd.cpicrc != RFC_OK) {
    DisplayMessage(14);
    return(14);
  }

/* Mat.master request call                                         */
  strcpy(sendstr,"EB01              0001    X     ");
  hd = SapMatrq("MR",sendstr,&rcvstr,&sapmes);
  if (hd.cpicrc != RFC_OK) {
    DisplayMessage(15);
    return(15);
  }
  else {
    DisplayMessage(16);
    return(0);
  }
}



/*--------------------------------------------------------------------*/
/* void DisplayMessage                                                */
/*--------------------------------------------------------------------*/
/* Display window with message                                        */
/*                                                                    */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   code             Message-Code                          */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   ----             ----                                  */
/*--------------------------------------------------------------------*/
void DisplayMessage(int code) {
  char messagex[400];
  char header[40];

#if defined(SAPonWINDOWS) || defined(SAPonNT)
  HWND dummy_hwnd = 0;
#endif

  strcpy(header, "CAD dialog RFC");

  switch(code) {
    case 1:
      strcpy(messagex, "Reconnect to SAP o.k.\n");
      strcat(messagex, "Next step: Display material master using RFC call");
	  break;
    case 2:
      strcpy(messagex, "Usage: cadrftst /r3connect or cadrftst para1 para2 para3");
	  break;
    case 3:
      strcpy(messagex, "Next step: Display material master using Dialog RFC API");
	  break;
    case 4:
      strcpy(messagex, "Next step: Retrieving mat. master record using\n");
      strcat(messagex, "API call out of the  SAP CAD function library");
	  break;
    case 5:
      strcpy(messagex, "Now terminating program");
	  break;
    case 6:
      strcpy(messagex, "Rfc error by RfcAccept");
      rfc_error1(messagex);
	  break;
    case 7:
      strcpy(messagex, "Rfc error by RfcGetName");
      rfc_error1(messagex);
	  break;
    case 8:
      strcpy(messagex, "Rfc error by RfcGetData");
      rfc_error1(messagex);
	  break;
    case 9:
      strcpy(messagex, "Error by creating SAP_FIELD_DATA");
      rfc_error1(messagex);
	  break;
    case 10:
      strcpy(messagex, "Error by creating thDmsCharac");
      rfc_error1(messagex);
	  break;
    case 11:
      strcpy(messagex, "RFC error by RFC_DISPLAY_MATERIAL_MASTER");
      rfc_error1(messagex);
	  break;
    case 12:
      strcpy(messagex, "RFC error by CadRfcAllocMemory");
      rfc_error1(messagex);
	  break;
    case 13:
      strcpy(messagex, "RFC error by CadRfcMatDisplay");
      rfc_error1(messagex);
	  break;
    case 14:
      strcpy(messagex, "RFC error by SapConncRfc");
      rfc_error1(messagex);
	  break;
    case 15:
      strcpy(messagex, "RFC error by SapMatrq");
      rfc_error1(messagex);
	  break;
    case 16:
      strcpy(messagex,"Received data: ");
      strncat(messagex, rcvstr,(int) hd.datalen);
	  strcat(messagex, "\nReaceived message: ");
	  strncat(messagex, sapmes,hd.meslen);
	  strcpy(header, "CAD dialog RFC - SapMatrq");
	  break;
    case 17:
      strcpy(messagex, "Rfc error by RfcOpen");
      rfc_error1(messagex);
	  break;
    default:
      strcpy(messagex, "Unknown message");
	  break;
  }
#if defined(SAPonWINDOWS) || defined(SAPonNT)
  MessageBox((HWND) dummy_hwnd, (LPCSTR) messagex,
             (LPCSTR) header, MB_OK);
#else
  if ( (int) strlen(ux_mess) > 0) strcat(ux_mess,"\n");
  strcat(ux_mess,messagex);
  DisplayText(bboard);
  XtManageChild(text1);
#endif
}



#if !defined(SAPonWINDOWS) && !defined(SAPonNT)
/*--------------------------------------------------------------------*/
/* void button_exitCB                                                 */
/*--------------------------------------------------------------------*/
/*                                                                    */
/*                                                                    */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             ----                                  */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   ----             ----                                  */
/*--------------------------------------------------------------------*/
void button_exitCB(w, client_data, call_data)
Widget w;
caddr_t client_data;
caddr_t call_data;
{
  w = w;                    /* only for compilation purpose RM600 */
  client_data = client_data;
  call_data   = call_data;

  exit(0);
}



/*--------------------------------------------------------------------*/
/* void button_exitCB                                                 */
/*--------------------------------------------------------------------*/
/*                                                                    */
/*                                                                    */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             ----                                  */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   ----             ----                                  */
/*--------------------------------------------------------------------*/
void button_okCB(w, client_data, call_data)
Widget w;
caddr_t client_data;
caddr_t call_data;
{
  static int i=0;

  client_data = client_data;  /* only for compilation purpose RM600 */
  call_data   = call_data;

  if (rc != 0) XtUnmanageChild(w);

  i++;
  switch (i) {
    case 1:
      rc = display_mat_master();
      if (rc != 0) XtUnmanageChild(w);
      else DisplayMessage(3);
      break;
    case 2:
      rc = display_mat_master_via_api();
      if (rc != 0) XtUnmanageChild(w);
      else DisplayMessage(4);
      break;
    case 3:
      rc = request_mat_master(argv_glob);
      if (rc != 0) XtUnmanageChild(w);
      else DisplayMessage(5);
      break;
    case 4:
      RfcClose(handle);
      exit(0);
      break;
  }
}



/*--------------------------------------------------------------------*/
/* void DisplayText                                                   */
/*--------------------------------------------------------------------*/
/*                                                                    */
/*                                                                    */
/*--------------------------------------------------------------------*/
/*             NAME             DESCRIPTION                           */
/*             ---------------- ------------------------------------  */
/*   INPUT :   ----             ----                                  */
/*   OUTPUT:   ----             ----                                  */
/*--------------------------------------------------------------------*/
/*   Return:   ----             ----                                  */
/*--------------------------------------------------------------------*/
void DisplayText(Widget bboard){
  Arg args[20];
  int n;

  n = 0;
  XtSetArg(args[n], XmNcolumns, 55); n++;
  XtSetArg(args[n], XmNrows, 15); n++;
  XtSetArg(args[n], XmNscrollVertical, True); n++;
  XtSetArg(args[n], XmNscrollHorizontal, True); n++;
  XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  XtSetArg(args[n], XmNvalue, ux_mess); n++;
  XtSetArg(args[n], XmNfontList, newfontlist); n++;
  text1 = XmCreateScrolledText(bboard, "text1", args, n);

  n = 0;
  XtSetArg(args[n], XmNy, 40); n++;
  XtSetValues(XtParent(text1), args, n);
}
#endif
