2

標準 BAPI (PurchaseRequisition.CreateFromData) を使用して、購買要求に「挿入」(または) 「行を追加」しようとしています。

JCo3を使用しています。JCo3 の例は、table.appendRow() または table.insertRow() メソッドを使用する必要があることを示しています。table.appendRow() & table.appendRows(1) を試しています。行を挿入しようとすると、エラーが発生せず、行が挿入されません。

以下は、私が実行しようとしているプログラムです。/** 以下は、このプログラムを実行するために必要な入力です// ステップ 1 ** / String BAPI_NAME = "BAPI_REQUISITION_CREATE";

    /** Step 2 **/
    String query_input_column1 = "DOCUMENTY_TYPE"; 
    String query_input_column1_value = "NB";

    String query_input_column2 = "PREQ_NAME";
    String query_input_column2_value = "Name";

    String query_input_column3 = "ACCTASSCAT";
    String query_input_column3_value = "U";

    String query_input_column4 = "DELIV_DATE";
    String query_input_column4_value = "20131101";

    String query_input_column5 = "MATERIAL";
    String query_input_column5_value = "DELL-RQ2013";

    String query_input_column6 = "QUANITY";
    int query_input_column6_value = 10100;




    /** Step 3 **/
    String targetTableUnderBAPI = "REQUISITION_ITEMS";

    /** Step 4 **/
    /** For the confirmation read the value from export parameter after insertion execution **/
    String result_column1 = "NUMBER";


    JCoDestination destination = null;
    try {
        destination = JCoDestinationManager.getDestination(DestinationManager.DESTINATION_NAME1);
        JCoRepository repository = destination.getRepository();
        JCoContext.begin(destination);

        JCoFunction function = repository.getFunction(BAPI_NAME);

        if(function == null)
            throw new RuntimeException(BAPI_NAME + " not found in SAP.");

        System.out.println("BAPI Name from function object: " + function.getName());            

        //function.getImportParameterList().setValue(query_input_column1, query_input_column1_value);
        JCoTable table = function.getTableParameterList().getTable(targetTableUnderBAPI); //it is taken from the response value of metadata
        //System.out.println("No of Columns: "+ table.getNumColumns());
        System.out.println("Trying to execute append row");

        table.appendRow();
            table.setValue(query_input_column1,query_input_column1_value);
            table.setValue(query_input_column2,query_input_column2_value);
            table.setValue(query_input_column3,query_input_column3_value);
            //table.setValue(query_input_column4,new java.util.Date(query_input_column4_value));

//スキップされた他の列関連のコード

        try{
            function.execute(destination);
        }
        catch(AbapException e){
            System.out.println(e.toString());
            return;
        }

        System.out.println("Let us check the result from export parameter");
        String exportParamStructure = (String)function.getExportParameterList().getValue(result_column1); //getStructure(result_column1); // getValue(result_column1);
        System.out.println("Resulting PR#: "+exportParamStructure);

    } catch (JCoException e) {
        e.printStackTrace();
    }
    finally
    {
        try {
            JCoContext.end(destination);
        } catch (JCoException e) {
            e.printStackTrace();
        }
    }

レスポンスの読み方が分からず、exportParameters から取得しようとしています!!

  1. 挿入するコードを誰かが共有できますか
  2. 確認応答を取得する (応答で PREQ_NO を取得しますか?)
  3. 日付フィールドの値を「20131101」として追加していますが、形式とアプローチが正しいかどうかわかりませんか?
  4. Quantity 列の値を追加しようとすると、この列は BAPIEBANC の一部ではないというエラー メッセージが表示されます。ただし、列は BAPIEBANC タイプで表示されます。
  5. チェックする SAP 側の構成はありますか?
  6. JCo 側のフィールドを有効にする必要がありますか? もしそうなら、どのように

SAP に関する私の知識は非常に限られていることに注意してください。

専門家の回答を待っています。

ありがとう。

4

2 に答える 2

1

最初に、SAP JCoのドキュメントを参照する必要があります。

あなたのコードについて:

  • テーブルに(1)行を追加すると、一見すると正しく見えます。
  • あなたのコードは、QUANTITY ではなく QUANITY を示しています。
  • 日付値を java.util.Date; として追加する必要があります。文字列形式から日付を作成する場合は、java.text.DateFormat.parse() を使用する必要があります。http://docs.oracle.com/javase/6/docs/api/java/util/Date.htmlを参照してください(ただし、これは Java 固有のものであり、JCo とは関係ありません)。
  • SAP で何かを変更する場合は、最後に BAPI_TRANSACTION_COMMIT を呼び出して作業の論理単位 (別名トランザクション) を終了することを忘れないでください。そうしないと、実際には何も変更されません。

多かれ少なかれ複雑で冗長な JCo API をいじりたくない場合は、SAP ERP で関数を呼び出すときに、より優れたプログラミング モデルを提供する Hibersap を使用してみてください: http://hibersap.org

ただし、SAP 関数モジュールが技術的にどのように機能するか (パラメーターの型やデータ型など)、およびその背後にあるドメイン固有のモデル (この場合は、要求の作成) についての基本的な理解が必要です。つまり、SAP エキスパートとのコミュニケーションが必要になる場合があります。

于 2013-11-04T10:27:33.840 に答える
1

ここでは、2 種類の挿入を追加しました。

  1. insertval()ユーザー定義モジュールの関数は、abap プログラマーの助けを借りて sap に存在します
  2. jco を使用してチケットを SOLMAN システムに挿入するための標準モジュールです。最初に、インポート、エクスポート、テーブルと構造のパラメーターを分析する必要があり、それに応じて値を渡し、応答を取得する必要があります。2 番目の関数では、solman へのチケットの挿入が成功した後、チケット n° を返します。

このサンプル コードがお役に立てば幸いです。

  public class jco
    {

    static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
        static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";

    static
        {

            Properties connectProperties = new Properties();
            connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.1.1.1");
            connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "01");
            connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
            connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "uname");
            connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "pwd");
            connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");

            createDestinationDataFile(DESTINATION_NAME1, connectProperties);
            connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
            connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");
            createDestinationDataFile(DESTINATION_NAME2, connectProperties);
            System.err.println("hai");

        }

        static void createDestinationDataFile(String destinationName, Properties connectProperties)
        {
            File destCfg = new File(destinationName+".jcoDestination");
            try
            {
                try (FileOutputStream fos = new FileOutputStream(destCfg, false)) {
                    connectProperties.store(fos, "for tests only !");
                }
            }
            catch (IOException e)
            {
                throw new RuntimeException("Unable to create the destination files", e);
            }
        }






        public void insertval() throws JCoException
        {

            JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);

          JCoFunction jf=destination.getRepository().getFunction("ZUSER_DET");

       jf.getImportParameterList().setValue("FIRST_NAME","member");
      jf.getImportParameterList().setValue("LAST_NAME","c");
         jf.getImportParameterList().setValue("USER_NO","1000");

         jf.execute(destination);
    System.out.println(jf);
        }





public void insertticket() throws JCoException
    { 
        JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
        System.out.println("test"+"\n");
      JCoFunction jf=destination.getRepository().getFunction("BAPI_NOTIFICATION_CREATE");

      JCoTable jt1=jf.getTableParameterList().getTable("APPX_HEADERS");


      JCoTable jt2=jf.getTableParameterList().getTable("APPX_LINES");


      JCoTable jt3=jf.getTableParameterList().getTable("APPX_LINES_BIN");


      JCoTable jt4=jf.getTableParameterList().getTable("NOTIF_NOTES");



      JCoTable jt5=jf.getTableParameterList().getTable("NOTIF_PARTNERS");
      JCoTable jt6=jf.getTableParameterList().getTable("NOTIF_SAP_DATA");
      JCoTable jt7=jf.getTableParameterList().getTable("NOTIF_TEXT_HEADERS");
      JCoTable jt8=jf.getTableParameterList().getTable("NOTIF_TEXT_LINES");


      JCoStructure jfn1=jf.getImportParameterList().getStructure("NOTIF_EXT");
  JCoStructure jfn2=jf.getImportParameterList().getStructure("NOTIF_CRM");
JCoStructure jfn3=jf.getImportParameterList().getStructure("IBASE_DATA");
jfn1.setValue("NUMB","1234");
jfn1.setValue("REFNUM","123");
jfn1.setValue("TYPE_NOTIF","SLFN");
jfn1.setValue("SUBJECT","tl");
jfn1.setValue("PRIORITY","2");
jfn1.setValue("LANGUAGE","EN");
jfn1.setValue("CATEGORY","Z01");
 jfn2.setValue("CODE","0011");
 jfn2.setValue("CODEGROUP","0011");
   jfn2.setValue("CATEGORY","Z01");
jfn3.setValue("INSTANCE","489");
  jfn3.setValue("IBASE","500");



jt1.appendRow();
jt1.setValue("DESCR","practise");
 jt2.appendRow();

      jt2.setValue("LINE","CVXCVXCV");
  jt3.appendRow();
      jt3.setValue("LINE","second text line");
      jt4.appendRow();
      jt4.setValue("TYPE_NOTE","my");
      jt4.setValue("IDENT","hoe twwrtgw");
      jt4.setValue("DESCRIPTION","its description ");
jt5.appendRow();

jt5.setValue("PARNR","new ");
jt5.setValue("TYPE_PAR","FN");
jt5.setValue("FUNC_PAR","EN");
jt5.setValue("PAR_ACTIVE","1");
jt6.appendRow();
jt6.setValue("INSTN","0020214076");
jt6.setValue("COMP","FI-AA");
jt6.setValue("SYSTYPE","P");
jt6.setValue("SYSID","PRD");
jt6.setValue("MANDT","900");
jt8.appendRow();
jt8.setValue("TXT_NUM","1");
jt8.setValue("TDFORMAT",">X");
jt8.setValue("TDLINE","/(performing all test)");






jf.execute(destination);
String jfex=jf.getExportParameterList().getString("REFNUM");

               System.out.println("hi "+jfex);

    }
于 2013-12-28T07:12:27.680 に答える