cancel
Showing results for 
Search instead for 
Did you mean: 

passing multiple rows to bapi

Former Member
0 Kudos

I have a bapi which has a table structure which is acting as import parameters..

Any sample <b>java codes</b> to add multiple rows to the table structure?

Thank you in advance

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

hi,

see this code(sales order create). here i add multiple item to itemtable , i think it will helpful to u.

public ClsSuper salesOrderCreate(String strSAPClient, String strSAPUser, String strSAPPwd, String strSAPLang, String strSAPHost, String strSAPSysNo, String strCustomerNo, String strSalesOrg, String strDistChan, String strDivision, String strCreateDate, String strReqData, ItemVO[] objItemVO, String strPurchNo) {
		
		            
		            ClsSuper objClsSuper=new ClsSuper();
		            String DocType = "TA";
					String xUploadFlag = "I";
					String xDocType = "X";
					String xSalesOrg = "X";
					String xDisChan = "X";
					String xDivision = "X";
					String xPurchNo = "X";
					String PartnerRole = "AG";
		            Bapi_Salesorder_Createfromdat2_Output output = null;
					SalesOrderCreate_PortType mysalesorder = new SalesOrderCreate_PortType();
					Bapi_Salesorder_Createfromdat2_Input input = null;
					SalesOrderCommit_PortType mycommit = new SalesOrderCommit_PortType();

			
		try {

						jcoclient =
							JCO.createClient(
								strSAPClient,
								strSAPUser,
								strSAPPwd,
								strSAPLang,
								strSAPHost,
								strSAPSysNo);

						jcoclient.connect();
					} catch (Exception e1) {
						
						objClsSuper.setStrErrorCode("J113");
						objClsSuper.setStrErrorMsg("Could't Connect to SAP System"+e1);
						return objClsSuper;
						
		}
		String test="";
		try{
		
 
		Date reqdate = getDate(strReqData);

		input = new Bapi_Salesorder_Createfromdat2_Input();

		Bapisdhd1Type headerin = new Bapisdhd1Type();

	
     	headerin.setDoc_Type(DocType);
		headerin.setSales_Org(strSalesOrg);
		headerin.setDistr_Chan(strDistChan);
		headerin.setDivision(strDivision);
		headerin.setPurch_No_C(strPurchNo);
		input.setOrder_Header_In(headerin);
 
		Bapisdhd1XType headerinx = new Bapisdhd1XType();

		headerinx.setUpdateflag(xUploadFlag);
		headerinx.setDoc_Type(xDocType);
		headerinx.setSales_Org(xSalesOrg);
		headerinx.setDistr_Chan(xDisChan);
		headerinx.setDivision(xDivision);
		headerinx.setPurch_No_C(xPurchNo);
		input.setOrder_Header_Inx(headerinx);
 
		BapisditmType_List itemsinlist = new BapisditmType_List();
		BapisditmxType_List iteminxlist = new BapisditmxType_List();

		BapischdlType_List schdllist = new BapischdlType_List();
		BapischdlxType_List schdllistx = new BapischdlxType_List();
 
		for (int i = 0; i < objItemVO.length; i++) {
			String Material = objItemVO<i>.getStrItem();
			String ReqQty1 = objItemVO<i>.getStrQty();
			int rqqty = Integer.parseInt(ReqQty1);
			String ReqQty = "" + (rqqty);  
			String itemNo = objItemVO<i>.getStrItemNo();
 		 
			BigDecimal reqqty = new BigDecimal(ReqQty.trim());

			 

			BapischdlType schdlin = new BapischdlType();
			BapischdlxType schdlinx = new BapischdlxType();

			schdlin.setReq_Date(reqdate);
			schdlin.setReq_Qty(reqqty);
 
			schdlin.setItm_Number(itemNo);
		 

			schdlinx.setUpdateflag("I");
			schdlinx.setReq_Date("X");
			schdlinx.setReq_Qty("X");
			schdlinx.setItm_Number(itemNo);
			 
 
			schdllist.addBapischdlType(schdlin);
			schdllistx.addBapischdlxType(schdlinx);

			 
			BapisditmType itemsin = new BapisditmType();
			BapisditmxType iteminx = new BapisditmxType();
 
		 
			itemsin.setMaterial(Material);
			itemsin.setItm_Number(itemNo);
		 

		 
			itemsinlist.addBapisditmType(itemsin);

		 	iteminx.setMaterial("X");
		 	iteminx.setUpdateflag("I");
			iteminx.setItm_Number(itemNo);
		 
			iteminxlist.addBapisditmxType(iteminx);

			 
		}
 	 
		input.setOrder_Items_In(itemsinlist);
		input.setOrder_Items_Inx(iteminxlist);

		input.setOrder_Schedules_In(schdllist);
		input.setOrder_Schedules_Inx(schdllistx);
 	
		BapiparnrType partner = new BapiparnrType();
		partner.setPartn_Role(PartnerRole);
		partner.setPartn_Numb(strCustomerNo);
		BapiparnrType_List partnrlist = new BapiparnrType_List();
		partnrlist.addBapiparnrType(partner);
		input.setOrder_Partners(partnrlist);
 	
			
	
 	
		mysalesorder.messageSpecifier.setJcoClient(jcoclient);
	
		mycommit.messageSpecifier.setJcoClient(jcoclient);
 		
		output = mysalesorder.bapi_Salesorder_Createfromdat2(input);
		String docno = output.getSalesdocument();

		Bapi_Transaction_Commit_Input commitinput =
				new Bapi_Transaction_Commit_Input();
 	
			commitinput.setWait(docno);
			Bapi_Transaction_Commit_Output outcommit =mycommit.bapi_Transaction_Commit(commitinput);			 
					 
 	
		 
	

		String error="";
		if ((docno == null) || (docno.trim().equals(""))) {
			Bapiret2Type_List objReturn=output.get_as_listReturn();
		
			test+="-------->one in if null";	
			for(int errorCount=0;errorCount<	objReturn.size();errorCount++){
				
				Bapiret2Type ret=objReturn.getBapiret2Type(errorCount);
			error+=	ret.getMessage();
				
			}
			
			objClsSuper.setStrErrorCode("J126");
			objClsSuper.setStrErrorMsg("Could't Create SalesOrder Reason By"+error);
			return objClsSuper;
			
		}
		
		jcoclient.disconnect();
		objClsSuper.setStrErrorCode("J000");
		objClsSuper.setStrErrorMsg("Success"+error);
		objClsSuper.setStrDocNo(docno);
		return objClsSuper;
		}catch(Exception e){
			
			objClsSuper.setStrErrorCode("J110");
					objClsSuper.setStrErrorMsg(e.toString()+test);
				 
					return objClsSuper;
			
		}
		 
	}
	private Date getDate(String date) {

			java.sql.Date sqlDate = null;
			try {
				StringTokenizer st = new StringTokenizer(date, ".");
				String strdate = st.nextToken();
				String strmonth = st.nextToken();
				String stryear = st.nextToken();
				int intdate = Integer.parseInt(strdate);
				int intmonth = Integer.parseInt(strmonth);
				int intyear = Integer.parseInt(stryear);
				Calendar cal = Calendar.getInstance();
				cal.set(Calendar.YEAR, intyear);
				cal.set(Calendar.MONTH, intmonth - 1);
				cal.set(Calendar.DATE, intdate);
				long l = cal.getTimeInMillis();
				sqlDate = new java.sql.Date(l);
			} catch (Exception e) {

				 
				return null;
			}
			return sqlDate;

		}

regards

Guru

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi duxton,

See this thread:

Regards, Suresh KB

Former Member
0 Kudos

Hi,

Write a for loop for i=0 to i=row size

Instantiate the table object for every row and set the parameters to the table object

Then add the table object to the BAPI input object(for every row)

regards,

Sujesh