cancel
Showing results for 
Search instead for 
Did you mean: 

Java Web Dynpro. Writing duplicate values to a table

Former Member
0 Kudos

Hi,

I've managed to populate the table and execute the bapi but my code is not behaving as I expected...

When I execute this if I populate E_Mail1 and not E_mail2 then the bapi is not executed.

If I populate both E_Mail1 and E_Mail2 then the value in E_Mail2 is written out twice to the table

Any help appreciated

			//Populate email table object
			Bapiadsmtp Email_table = new Bapiadsmtp()			
                          if (wdContext
				.nodeE_Mail_List()
				.currentE_Mail_ListElement()
				.getE_Mail1()
				.length()
				> 1) {
				Email_table.setE_Mail(
					wdContext
						.nodeE_Mail_List()
						.currentE_Mail_ListElement()
						.getE_Mail1());
				input_crtbp.addIt_Email(Email_table);
			}
			if (
				wdContext
						.nodeE_Mail_List()
						.currentE_Mail_ListElement()
						.getE_Mail2()
						.length()
						> 1) {
				Email_table.setE_Mail(
					wdContext
						.nodeE_Mail_List()
						.currentE_Mail_ListElement()
						.getE_Mail2());
				input_crtbp.addIt_Email(Email_table);
			}
			
			//Execute bapi
			wdContext
				.currentZbapi_Bupa_Create_InputElement()
				.modelObject()
				.execute();

Accepted Solutions (1)

Accepted Solutions (1)

former_member197348
Active Contributor
0 Kudos

Hi Rob,

The code looks to be fine. But can you check once the following?

1.The structure <b>Bapiadsmtp </b>is same of <b>input_crtbp</b>

If you can provide the architecture of the context. It is easy to analyze.

regards,

Siva

Former Member
0 Kudos

Hi,

Yes the structure is identical.

Zbapi_Bupa_Create_Input input_crtbp;

to set the structure of input_crtbp.

Context Zbapi_Bupa_Create_Input

Table Node 'It_Email'

Cosnumber

E_Mail

Email_Srch

Encode

Errorflag

Flg_Nouse

Home_Flag

R_3_User

Std_no

Std_Recip

Tnef

Valid_From

Valid_To

This structure is exactly the same as the model class Bapiadsmtp

former_member197348
Active Contributor
0 Kudos

Hi Rob,

Add this code in first of your method.

try

{

wdContext.currentZbapi_Bupa_Create_InputElement().modelObject().getIt_Email().clear();

}

catch (Exception e1)

{

}

Change the code

// input_crtbp.addIt_Email(Email_table);

insted of this use the following.

<b>wdContext.currentZbapi_Bupa_Create_InputElement().modelObject().addIt_Email(Email_table);

</b>

And check this <u>wdContext.nodeE_Mail_List()

.currentE_Mail_ListElement()

.getE_Mail1());</u> whether this is giving correct values by printing the values in if condition.

regards

Siva

former_member197348
Active Contributor
0 Kudos

Hi Rob,

Are you still facing problems for this issue? if you have solved the issue ,can you please close the thread by posting the exact solution and rewarding points for helpful answers?

Best regards.

Siva

Former Member
0 Kudos

Hi,

No I have the same problem.

I'm still getting the second email address written out twice.

Any help greatly appreciated as I'm running out of ideas...

Rob

former_member197348
Active Contributor
0 Kudos

Hi Rob,

Change your code <i>current Element</i> with <i>getElementAt(index)</i> index starts from 0. And do null check, finally add model object

//Populate email table object
try
{
wdContext.currentZbapi_Bupa_Create_InputElement().modelObject().getIt_Email().clear();
}
catch (Exception e1)
{
}
if (wdContext.nodeE_Mail_List().getE_Mail_ListElementAt(index).getE_Mail1()!=null
&&wdContext.nodeE_Mail_List().getE_Mail_ListElementAt(index).getE_Mail1().length()
> 1) {
Bapiadsmtp Email_table = new Bapiadsmtp();					
Email_table.setE_Mail
(wdContext.nodeE_Mail_List().getE_Mail_ListElementAt(index).getE_Mail1());
//Verify Email1 
wdComponentAPI.getMessageManager().reportException(Email_table.getE_Mail());

wdContext.currentZbapi_Bupa_Create_InputElement().modelObject().addIt_Email(Email_table);
}
if (wdContext.nodeE_Mail_List().getE_Mail_ListElementAt(index).getE_Mail2()!=null
&&wdContext.nodeE_Mail_List().getE_Mail_ListElementAt(index).getE_Mail2().length()> 1)
 {
	Bapiadsmtp Email_table = new Bapiadsmtp();	
	Email_table.setE_Mail(
wdContext.nodeE_Mail_List().getE_Mail_ListElementAt(index).getE_Mail2());

// Verify Email2	
wdComponentAPI.getMessageManager().reportException(Email_table.getE_Mail());
	wdContext.currentZbapi_Bupa_Create_InputElement().modelObject().addIt_Email(Email_table);
			}
			
			//Execute bapi
			wdContext
				.currentZbapi_Bupa_Create_InputElement()
				.modelObject()
				.execute();

Try with this code

regards,

Siva

former_member751941
Active Contributor
0 Kudos

Hi Rob,

After executing the model invalidate the output node.

wdContext.nodeE_Mail_List().invalidate();

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/301ff0bb-74ca-2910-fa99-eae39269...

Regards,

Mithu

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you all.

It now works.

Code below


try {
	wdContext.currentZbapi_Bupa_Create_InputElement()
				.modelObject()
				.getIt_Email()
				.clear();
			
						
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		try {

			if (wdContext
				.nodeE_Mail_List()
				.currentE_Mail_ListElement()
				.getE_Mail1()
				!= null
				&& wdContext
					.nodeE_Mail_List()
					.currentE_Mail_ListElement()
					.getE_Mail1()
					.length()
					> 1) {
				Bapiadsmtp Email_table = new Bapiadsmtp();
				Email_table.setE_Mail(
					wdContext
						.nodeE_Mail_List()
						.currentE_Mail_ListElement()
						.getE_Mail1());

				wdContext
					.currentZbapi_Bupa_Create_InputElement()
					.modelObject()
					.addIt_Email(
					Email_table);
			}
			if (wdContext
				.nodeE_Mail_List()
				.currentE_Mail_ListElement()
				.getE_Mail2()
				!= null
				&& wdContext
					.nodeE_Mail_List()
					.currentE_Mail_ListElement()
					.getE_Mail2()
					.length()
					> 1) {
				Bapiadsmtp Email_table = new Bapiadsmtp();
				Email_table.setE_Mail(
					wdContext
						.nodeE_Mail_List()
						.currentE_Mail_ListElement()
						.getE_Mail2());

				wdContext
					.currentZbapi_Bupa_Create_InputElement()
					.modelObject()
					.addIt_Email(
					Email_table);
			}

			//Execute bapi
			wdContext
				.currentZbapi_Bupa_Create_InputElement()
				.modelObject()
				.execute();
			wdContext.nodeOutput().invalidate();
		} catch (Exception e2) {
			e2.printStackTrace();
		}

Former Member
0 Kudos

Hi Rob,

Have u tried debugging the application?? check what values are getting passed to bapi in debug mode in sap logon??

regards

Sumit