SAP Interface Programming JCo3.0 series: Table Parameters

Source: Internet
Author: User
Tags call back

Table parameter as export parameter

BAPI_COMPANYCODE_GETDETAILis a function that is suitable for demonstration, without the import paramter parameter, the call back COMPANYCODE_GETDETAIL table parameter returns a list of all company codes in the SAP system. Includes only the company code ID and the company code name two fields.

In Jco, the two interfaces associated with the table parameter are and are the metadata of the JCoTable JCoRecordMetaDta JCoTable tabl parameter in JCoRecordMetaDta RfM JCoTable JCoStructure .

In the. NET environment, I like to convert Irfctable to a DataTable, but Java doesn't have a similar data structure, so I decided to pass jcotable in the method directly. For ease of display, however, you might consider using a common code for output:

Package Jco3.utils;import Com.sap.conn.jco.jcofield;import Com.sap.conn.jco.jcorecordmetadata;import com.sap.conn.jco.JCoTable;PublicClassjcoutils{PublicStaticvoidPrintjcotable (Jcotable jcotable) {HeaderJcorecordmeatadata is the meta data of either a structure or a table.Each element describes a field of the structure or table. Jcorecordmetadata Tablemeta = Jcotable.getrecordmetadata ();Forint i = 0; i < Tablemeta.getfieldcount (); i++) {System.out.print (String.Format ( "%s\t", Tablemeta.getname (i)));} System. out.println (); //New line //line items for (int i = 0; i < jcotable.getnumrows (); i++) { //sets the row pointer to the specified position (beginning from zero) jcotable.setrow (i); 
                            
                             //each line is of type jcostructure 
                             for (Jcofield fld:jcotable) {Syste M.out.print (String.Format (out.println (); }}
                            

Key Notes :

For jcotable, output header and line items. The table header is obtained by JCoTable Meta-data and then using the Meta-data getName () method.

JCoRecordMetaData tableMeta = jcoTable.getRecordMetaData();        for(int i = 0; i < tableMeta.getFieldCount(); i++){      System.out.print(String.format("%s\t", tableMeta.getName(i))); }

Jcotable each row is one JCoStructure , you can setRow() set the position of the pointer, and then traverse each field:

 For (int i = 0; I < jcotable.getnumrows (); i++) {//sets the row pointer to T He specified Position (beginning from zero) jcotable.setrow (i) ;//line is of type jcostructure for< Span class= "Hljs-list" > (jcofield fld:jcotable) {System.out.print  (string.format ( "%s\t", Fld.getvalue ())) ; System.out.println;       

After the output is complete, the RFM call is next:

Package Jco3.demo5;Import Org.junit.Test;Import com.sap.conn.jco.*;Import Jco3.utils.JCoUtils;PublicClassjcotabledemo{Public jcotableGetcocdlist()Throws Jcoexception {/** * Get company code list in SAP * using BAPI bapi_companycode_getlist. * * Since jcotable Rather flexible, we simply use * This interface as return value */jcodestination dest = Jcodestinationmanager.getdestina tion ( "ECC"); Jcofunction fm = Dest.getrepository (). GetFunction ( "bapi_companycode_getlist"); Fm.execute (dest); Jcotable companies = Fm.gettableparameterlist (). getTable (return companies; }  @Test public void printcompanies () throws jcoexception {jcotable companies = this.getcocdlist (); Jcoutils.printjcotable (companies); }} 
Table parameter as import parameter

Table as input parameters, mainly to solve the problem of filling table, the basic mode is as follows:

someTable.appendRow();someTable.setValue("FLDNAME", someValue);

Take rfc_read_table as an example to read the SAP USR04 table.

Package Jco3.demo5;Import Org.junit.Test;Import com.sap.conn.jco.*;Import Jco3.utils.JCoUtils;PublicClassjcotableasimport{Public jcotableReadtable()Throws Jcoexception {/** * shows how to process jcotable (as importing) */jcodestination dest = Jcodestinationmanager.getdestination ("ECC"); Jcofunction fm = Dest.getrepository (). GetFunction ("Rfc_read_table");Table we want to query is USR04Which is the user authorization table in SAP fm.getimportparameterlist (). SetValue ("Query_table","USR04");Output data is delimited by comma fm.getimportparameterlist (). SetValue ("DELIMITER",",");Processing table parameters Jcotable options = Fm.gettableparameterlist (). GetTable ("OPTIONS");Modification date >= 2012.01.01 and <= 2015.12.31 Options.appendrow (); Options.setvalue ("TEXT","Modda GE ' 20120101 '"); Options.appendrow (); Options.setvalue ("TEXT","and Modda LE ' 20151231 '");We only care about the fields of [user ID] and [modification Date] string[] Outputfields =New string[] {"Bname","Modda"}; jcotable fields = Fm.gettableparameterlist (). GetTable ("Fields"); int count = outputfields.length; fields.appendrows (count); for (int i = 0; i < count; i++) {fields.setrow (i); Fields.setvalue ("FIELDNAME", Outputfields[i]);} FM. Execute (dest); jcotable data = Fm.gettableparameterlist (). GetTable ("data"); return data;} @Test public void printusers() throws jcoexception {jcotable users = this.readtable (); Jcoutils.printjcotable (users); }}

In the code we used two methods to insert a table row item, the first method:

JCoTable options = fm.getTableParameterList().getTable("OPTIONS");// modification date >= 2012.01.01 and <= 2015.12.31options.appendRow();options.setValue("TEXT", "MODDA GE ‘20120101‘ ");options.appendRow();options.setValue("TEXT", "AND MODDA LE ‘20151231‘ ");

The second method:

new String[] {"BNAME", "MODDA"};JCoTable fields = fm.getTableParameterList().getTable("FIELDS");int count = outputFields.length;fields.appendRows(count);for (int i = 0; i < count; i++){ fields.setRow(i); fields.setValue("FIELDNAME", outputFields[i]); }
Summary of important methods of jcotable
Jcotable_methods.gif



Wen/stonewm (author of Jane's book)
Original link: http://www.jianshu.com/p/a088510cf965
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

SAP Interface Programming JCo3.0 series: Table Parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.