Show TOC

Procedure documentationSetting Scalar Import Parameters Locate this document in the navigation structure

 

This step calls the BAPI CompanyCode.GetDetail for each company code. The corresponding RFM is BAPI_COMPANYCODE_GETDETAIL. For this RFM, you need to set the scalar import parameter COMPANYCODEID.

Procedure

  1. To access the import parameter list, use getImportParameterList).

  2. The value of the scalar parameter is set using setValue(), in which first the value, and then the name are entered. There are many different versions of setValue() in the SAP JCo to support all existing data types.

  3. SAP JCo converts the values and transfers them to the data type that is assigned to the field. If an error occurs during the conversion, an exception is thrown. The method setValue() is also available in JCoStructure, JCoTable, and JCoField . You can therefore set values from structure fields and fields in a row of a table.

    Setting Scalar Import Parameters

    Syntax Syntax

    1. codes.firstRow();
              for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) 
              {
                  function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETDETAIL");
                  if (function == null) 
                      throw new RuntimeException("BAPI_COMPANYCODE_GETDETAIL not found in SAP.");
                  function.getImportParameterList().setValue("COMPANYCODEID", codes.getString("COMP_CODE"));
                  function.getExportParameterList().setActive("COMPANYCODE_ADDRESS",false);
      
                  try
                  {
                      function.execute(destination);
                  }
                  catch (AbapException e)
                  {
                      System.out.println(e.toString());
                      return;
                  }
                  returnStructure = function.getExportParameterList().getStructure("RETURN");
                  if (! (returnStructure.getString("TYPE").equals("") ||
                         returnStructure.getString("TYPE").equals("S") ||
                         returnStructure.getString("TYPE").equals("W")) ) 
                  {
                      throw new RuntimeException(returnStructure.getString("MESSAGE"));
                  }
      
                  JCoStructure detail = function.getExportParameterList().getStructure("COMPANYCODE_DETAIL");
      
                  System.out.println(detail.getString("COMP_CODE") + '\t' +
                                     detail.getString("COUNTRY") + '\t' +
                                     detail.getString("CITY"));
              }//for
          }
      
    End of the code.
  4. You call firstRow() before the loop, because the row pointer for the table is located on the last row as a result of the previous loop.

    Note Note

    Note that in the BAPI error handling displayed here, "W" (warning) is accepted as well as empty string or "S" (success). This occurs because this particular BAPI sometimes outputs the warning that address data has not been maintained (in the structure parameter COMPANYCODE_ADDRESS). In the current example program this parameter is not relevant, so the warning can be ignored. In a productive program, error handling must be more precisely configured and must also check the number of the warning message.

    End of the note.