cancel
Showing results for 
Search instead for 
Did you mean: 

How to set telephone and mobile using JCo BAPI_USER_CREATE1

0 Kudos

I can set the telephone number in

the ADDRESS structure TEL1_NUMBER field.

I can set the mobile number using

the ADDTEL table TELEPHONE field,

and R_3_USER=3.

So far no success when I tried to set both the

telephone number and mobile.

Thanks in advance for a code snippet!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Did you resolve this? I'm having the same issue. Also, how were you able to set the mobile phone by itself using ADDTEL? I don't see a place to put the communication type (MOB).

0 Kudos

Not yet.

My test class is at the end of this reply.

The following table->field seem to do the job of

setting the mobile.

ADDTEL->TELEPHONE:832-347-9484

ADDTEL->R_3_USER:3

ADDTEL->CONSNUMBER:1

I found R_3_USER:3 by setting the mobile in transaction SU01,

and then use BAPI_USER_GETDETAIL.

input file JCOBAPI_USER_CREATE1_phone.txt works:

ADDRESS->FIRSTNAME:Len

ADDRESS->TITLE_P:Mr.

ADDRESS->TITLE:SAP Consultant

ADDRESS->TITLE_ACA1:Ph.D.

ADDRESS->TITLE_ACA2:B.S.

ADDRESS->LANGUP_ISO:EN

ADDRESS->DEPARTMENT:Web Operations

ADDRESS->FUNCTION:00141488

ADDRESS->BUILDING_P:NABS

ADDRESS->FLOOR_P:2

ADDRESS->ROOM_NO_P:OW240

ADDRESS->COMM_TYPE:INT

COMPANY->COMPANY:BAYLOR COLLEGE OF MEDICINE

ADDRESS->TIME_ZONE:CST

ADDRESS->TEL1_NUMBR:713-798-2316

ADDRESS->FAX_NUMBER:713-798-7417

ADDRESS->E_MAIL:Len.Spinelli@gmail.com

DEFAULTS->DATFM:6

DEFAULTS->DCPFM:X

input file JCOBAPI_USER_CREATE1_mobile.txt works:

ADDRESS->FIRSTNAME:Len

ADDRESS->TITLE_P:Mr.

ADDRESS->TITLE:SAP Consultant

ADDRESS->TITLE_ACA1:Ph.D.

ADDRESS->TITLE_ACA2:B.S.

ADDRESS->LANGUP_ISO:EN

ADDRESS->DEPARTMENT:Web Operations

ADDRESS->FUNCTION:00141488

ADDRESS->BUILDING_P:NABS

ADDRESS->FLOOR_P:2

ADDRESS->ROOM_NO_P:OW240

ADDRESS->COMM_TYPE:INT

COMPANY->COMPANY:BAYLOR COLLEGE OF MEDICINE

ADDRESS->TIME_ZONE:CST

ADDRESS->FAX_NUMBER:713-798-7417

ADDRESS->E_MAIL:Len.Spinelli@gmail.com

DEFAULTS->DATFM:6

DEFAULTS->DCPFM:X

ADDTEL->NEW_ROW:Y

ADDTEL->TELEPHONE:832-347-9484

ADDTEL->R_3_USER:3

ADDTEL->CONSNUMBER:1

input file JCOBAPI_USER_CREATE1_phone_mobile.txt does not work:

ADDRESS->FIRSTNAME:Len

ADDRESS->TITLE_P:Mr.

ADDRESS->TITLE:SAP Consultant

ADDRESS->TITLE_ACA1:Ph.D.

ADDRESS->TITLE_ACA2:B.S.

ADDRESS->LANGUP_ISO:EN

ADDRESS->DEPARTMENT:Web Operations

ADDRESS->FUNCTION:00141488

ADDRESS->BUILDING_P:NABS

ADDRESS->FLOOR_P:2

ADDRESS->ROOM_NO_P:OW240

ADDRESS->COMM_TYPE:INT

COMPANY->COMPANY:BAYLOR COLLEGE OF MEDICINE

ADDRESS->TIME_ZONE:CST

  1. ADDRESS->TEL1_NUMBR:713-798-2316

ADDRESS->FAX_NUMBER:713-798-7417

ADDRESS->E_MAIL:Len.Spinelli@gmail.com

DEFAULTS->DATFM:6

DEFAULTS->DCPFM:X

ADDTEL->NEW_ROW:Y

  1. ADDTEL->STD_NO:X

ADDTEL->TELEPHONE:713-798-2316

ADDTEL->R_3_USER:1

  1. ADDTEL->HOME_FLAG:X

ADDTEL->CONSNUMBER:1

ADDTEL->NEW_ROW:Y

ADDTEL->TELEPHONE:832-347-9484

ADDTEL->R_3_USER:3

ADDTEL->CONSNUMBER:2

java -cp .:sapjco.jar JCOBAPI_USER_CREATE1 NSP_BCUSER.properties lspinelli1 secret01 Spinelli JCOBAPI_USER_CREATE1_phone.txt

java -cp .:sapjco.jar JCOBAPI_USER_CREATE1 NSP_BCUSER.properties lspinelli2 secret01 Spinelli JCOBAPI_USER_CREATE1_mobile.txt

java -cp .:sapjco.jar JCOBAPI_USER_CREATE1 NSP_BCUSER.properties lspinelli3 secret01 Spinelli JCOBAPI_USER_CREATE1_phone_mobile.txt

The file NSP_BCUSER.properties has the usual logon properties:

jco.client.client=000

jco.client.user=bcuser

jco.client.passwd=minisap

jco.client.lang=EN

jco.client.ashost=10.27.11.133

jco.client.sysnr=00

import com.sap.mw.jco.*;

import java.io.*;

import java.util.*;

public class JCOBAPI_USER_CREATE1

{

Properties login_properties = null;

JCO.Client jcoconn;

IRepository irepository;

String my_line_separator = System.getProperty("line.separator");

public JCOBAPI_USER_CREATE1(String[] args)

{

try

{

jcoconn = JCO.createClient(getLoginProperties(args[0]));

jcoconn.connect();

irepository = JCO.createRepository("myrepo", jcoconn);

IFunctionTemplate ft = irepository.getFunctionTemplate("BAPI_USER_CREATE1");

JCO.Function function = new JCO.Function(ft);

JCO.ParameterList ipl = function.getImportParameterList();

ipl.setValue(args[1], "USERNAME");

ipl.setValue("X", "SELF_REGISTER");

JCO.Structure s_password = ipl.getStructure("PASSWORD");

s_password.setValue(args[2], "BAPIPWD");

JCO.Structure s_address = ipl.getStructure("ADDRESS");

s_address.setValue(args[3], "LASTNAME");

if (args[4].length() > 0)

{

BufferedReader br = new BufferedReader(new FileReader(args[4]));

String line;

while ((line = br.readLine()) != null)

{

System.out.println(line);

if (line.startsWith("#")) continue;

StringTokenizer st1 = new StringTokenizer(line, ":");

if (st1.countTokens() != 2) continue;

String mapName = st1.nextToken();

String value = st1.nextToken();

StringTokenizer st2 = new StringTokenizer(mapName, "->");

if (st2.countTokens() != 2) continue;

String structOrTable = st2.nextToken();

String attributeName = st2.nextToken();

System.out.println("structOrTable=" + structOrTable + ", attributeName=" + attributeName + ", value=" + value);

JCO.Structure s = null;

JCO.Table t = null;

boolean structure = false;

boolean table = false;

try

{

s = ipl.getStructure(structOrTable);

structure = true;

System.out.println(structOrTable + " is a structure");

}

catch (JCO.Exception ex1)

{

System.out.println(ex1.toString());

try

{

t = function.getTableParameterList().getTable(structOrTable);

table = true;

System.out.println(structOrTable + " is a table");

}

catch (JCO.Exception ex2) { System.out.println(ex2.toString()); }

}

if (structure)

{

s.setValue(value, attributeName);

}

else if (table)

{

if (attributeName.equalsIgnoreCase("NEW_ROW")) { System.out.println("calling appendRow()"); t.appendRow(); continue; }

System.out.println("calling setValue(): " + value + " " + attributeName);

t.setValue(value, attributeName);

}

else

{

ipl.setValue(value, attributeName);

}

}

br.close();

}

jcoconn.execute(function);

JCO.ParameterList tpl = function.getTableParameterList();

StringBuffer sb = new StringBuffer();

printTable(tpl, "RETURN", sb);

System.out.println(sb.toString());

}

catch (Exception e)

{

e.printStackTrace();

System.out.println(e.getMessage());

System.out.println("error: " + e);

}

jcoconn.disconnect();

}

public static void main(String[] args)

{

JCOBAPI_USER_CREATE1 app = new JCOBAPI_USER_CREATE1(args);

}

public Properties getLoginProperties(String fname)

{

if (login_properties == null) {

login_properties = new Properties();

try { login_properties.load(new FileInputStream(fname)); }

catch (IOException e) {

System.out.println(e);

System.exit(1);

}

}

return login_properties;

}

public void printTable(JCO.ParameterList tpl, String n, StringBuffer sb)

{

JCO.Table t = tpl.getTable(n);

int nrows = t.getNumRows();

sb.append(my_line_separator);

sb.append("table " + n + ": " + nrows + " row(s)" + my_line_separator);

if (nrows == 0) return;

for (int i=0;i<nrows;i++)

{

t.setRow(i);

for (JCO.FieldIterator fit = t.fields(); fit.hasMoreElements(); )

{

JCO.Field f = fit.nextField();

String fname = f.getName();

String fstr = f.getString();

if (fstr.equals("") || fstr == null) continue;

sb.append(n + "(" + i + ")->" + fname + ": " + fstr + my_line_separator);

}

}

}

}

Former Member
0 Kudos

Very nice.

That worked for me.

Thanks.