An Inbound Example

The inbound example creates a very simple IDoc of type MATMAS02. This program uses the CIDoc object’s AppendSegment function to create the IDoc segments, and the CIDocIterator object’s Field function to fill in field values.

The program will successfully transfer the IDoc to the R/3, provided that the connection parameters are correct for the intended R/3 system. However, the ALE system will not accept the IDoc as currently coded, since the example does not provide values for all mandatory fields.

For users of Microsoft Windows NT and 95, this sample program must be compiled by Microsoft Visual C++ 5.0.

#define USE_STL

#include "crfclass.h"

#include "idoclink.h"

#include "idocidoc.h"

#include "idocglob.h"

#include <string>

using namespace std;

//--------------------

// Global variables

//--------------------

//---------------------

// Function prototypes

//---------------------

//---------------------

// Main

//---------------------

void main()

{

 

CRfcConnection Connection;

RFC_USER_INFO UserInfo; //All user login info

RFC_CONNECT_INFO ConnectInfo; //R/3 system connection info

//Define user logon info

ConnectInfo.rstrDestination = "USA";

ConnectInfo.rstrHostName = "usa.earth.solar";

ConnectInfo.nSystemNo = 00;

ConnectInfo.rstrSystemName = "USA";

UserInfo.rstrClient ="001";

UserInfo.rstrUserName = "bclinton";

UserInfo.rstrPassword = "coffeegate";

UserInfo.rstrLanguage = "E";

//Define system connection info

ConnectInfo.rfcMode = RFC_MODE_R3ONLY ;

//Fill user info and connection info into the

//connection object so that they will be used

//when starting logon

Connection.SetUserInfo(UserInfo);

Connection.SetConnectInfo(ConnectInfo);

try

{

// create a TID management object

CIDocTID TidMgr("inbound.tid","inbound.lck","mms");

// create a CIDocLink object: inbound, and will connect

// to an R/3 system that is at least 3.1G

CIDocLink MyLink(INBOUND_LINK,

&Connection,

TRUE,

&TidMgr);

// Add an IDoc into the link

CIDoc& IDoc1 = MyLink.AddIDoc("MATMAS02","31G","34567");

// create an iterator to help creating the new IDoc

CIDocIterator it1(IDoc1);

// Append an E2MARAM segment

it1 = IDoc1.AppendSegment("E2MARAM");

// Fill in fields

it1.Field("MATNR") = "IDOCCL-TEST-999";

it1.Field("ERSDA") = string("19970425");

it1.Field("ERNAM") = "BClinton";

it1.Field("LAEDA") = "19970425";

it1.Field("AENAM") = "BClinton";

it1.Field("BRGEW") = 4202.518;

it1.Field("NTGEW") = 3773.261;

it1.Field("GEWEI") = "GRM";

it1.Field("VOLUM") = 1892.356;

it1.Field("VOLEH") = "LTR";

it1.Field("MTART") = "HAWA";

it1.Field("MEINS") = "GRM";

it1.Field("STFAK") = 3;

it1.Field("SPART") = 12;

it1.Field("VPSTA") = "KVEDLSQBG";

it1.Field("MBRSH") = "A";

it1.Field("MATKL") = 206;

// append new E2MAKTM

it1 = IDoc1.AppendSegment("E2MAKTM");

it1.Field("SPRAS") ="E";

it1.Field("MAKTX") = "An inbound example program";

// append new E2MAKTM

it1 = IDoc1.AppendSegment("E2MAKTM");

it1.Field("SPRAS") ="S";

it1.Field("MAKTX") = "Un programa ejemplar de inbound";

// append new E2MAKTM

it1 = IDoc1.AppendSegment("E2MAKTM");

it1.Field("SPRAS") ="D";

it1.Field("MAKTX") = "Ein Beispielprogramm fur Eingang";

// append new E2MARCM

it1 = IDoc1.AppendSegment("E2MARCM");

it1.Field("WERKS") ="3000";

it1.Field("EKGRP") = "017";

it1.Field("AUSME") = "FAß";

it1.Field("PERKZ") = "T";

// The following commented-out line of code attempts to

// append a E2MAKTM segment after a E2MARCM segment,

// which is an illegal position for the E2MAKTM

// segment. This line of should cause an exception to

// be thrown.

//it1 = IDoc1.AppendSegment("E2MAKTM");

// append new E2MARDM

it1 = IDoc1.AppendSegment("E2MARDM");

it1.Field("LGORT") ="0001";

it1.Field("LMINB") = 0;

it1.Field("LBSTF") = 0;

MyLink.SendIDocsToR3(string("IDOCCLASS"),

string("LS"),

string("MATMAS"));

}

catch(IDOC_ERROR_INFO err)

{

DumpIDocErrInfo(err);

}

catch(RFC_ERROR_INFO err)

{

DumpRFCErrInfo(err);

}

}