2

I develop a PHP 7.0 program and use sapnwrfc extension to connect to a SAP system.

The program executes the function ZCLSC_SEARCH_OBJECTS remotely on the SAP system, but the method invoke returns this error:

ATINN of type RFCTYPE_NUM value=Q1_NUMBER cannot be converted to type RFCTYPE_NUM

If I try with PHP 5.6 using saprfc extension, it works.

What is wrong, what to correct?

$connection = $this->connect_sap();
        if ($connection->ping() === true) {
            try {
                $today_str = date("Ymd");
                $f = $connection->getFunction('ZCLSC_SEARCH_OBJECTS');

                foreach ($query as $key => $val) {
                    $qualifier = $val['q1'];
                    $q1 = "Q1_NUMBER";

                    // $q1 = settype($q1, 'string');
                    $r = $f->invoke([
                        "I_CLASSTYPE" => "001",
                        "I_TOP_CLASS_STRUC" => array(
                            "MANDT" => $this->client,
                            "CLINT" => "0000000017",
                            "KLART" => "001",
                            "CLASS" => "ZSP_INFO",
                            "STATU" => "1",
                        ),
                        "I_KEYDATE" => $today_str,
                        "I_LANGUAGE" => "EN",
                        "I_STATUS_FREE" => "X",
                        "I_R_OBJECTTYPES_TAB" => array([
                            "SIGN" => "I",
                            "OPTION" => "EQ",
                            "LOW" => "MARA",
                        ]),
                        "I_SELECTION_CRITERIA_TAB" => array([
                            "ATINN" => $q1,
                            "ATWRT" => $qualifier,
                            "ATCOD" => "1",
                            "STATU" => "H",
                            "ATFOR" => "CHAR",
                            "SLCOD" => "1",
                        ]),
                        "I_R_CHARACTERISTICS_TAB" => array([
                            "SIGN" => "I",
                            "OPTION" => "EQ",
                            "LOW" => $q1,
                        ]),

                    ]);

                    echo "result";
                    print_r($r);
                    exit;

                    //     // if (is_array($r['MATNRLIST']) and sizeof($r['MATNRLIST']) > 0) {
                    //     //     $ret['st'] = 0;
                    //     //     $ret['msg'] = 'Have description ' . $val['material_description_1'] . ' already';
                    //     //     return $ret;
                    //     // }

                    //     // if ($val['q19'] == 'Krones') { //สลับการค้นหา

                    //     // }

                }
                // $ret['st'] = 1;
                // $ret['msg'] = '';
                // return $ret;

            } catch (SapException $ex) {
                print_r($ex);
                print_r($ex->getErrorInfo());
                exit;
            }

        }
        $connection->close();
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

3

The data type RFCTYPE_NUM means that the variable holds only numeric characters, but you pass the value 'Q1_NUMBER' which contains non-numeric characters, hence the error.

Your SAP ABAP system has probably the Cross-Application component "CA-CL" (classification) : the ATINN column exists in the table CABN to identify a "characteristic" uniquely by a number, and in the same table there's the ATNAM column which identifies the characteristic uniquely by a name.

So I assume that you want to query the characteristic Q1_NUMBER. But you should pass its number instead of its name.

To determine its number, log in your SAP system, display the contents of the table CABN (via the transaction code SE16 for instance), search Q1_NUMBER, look at its corresponding number, and adapt your code (change the variable $q1).

PS: I don't know why SAPRFC doesn't fail. I guess that SAPRFC just doesn't implement "type mismatch" checks.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    Not completely sure, but my guess would be that SAPRFC still uses the old librfc32.dll, which went out of support in 2016, instead of the newer sapnwrfc.dll. librfc32.dll did indeed not perform type checks on FM parameters. (Which leads to "funny" results, if you pass a 4-byte integer into a CHAR field or vice versa…) – Lanzelot Sep 17 '19 at 12:27