cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with perl SAPNW::Rfc script

Former Member
0 Kudos

I have an older script that uses SAP::Rfc to execute RFC_READ_TABLE as follows:

my $IT = $RFC->discover("RFC_READ_TABLE");
$IT->QUERY_TABLE('TBTCO');
$IT->OPTIONS( ["ENDDATE = '$MAXDATE' AND ENDTIME > '$MAXTIME' OR ENDDATE > '$MAXDATE'"] );
my @FLDARRAY = qw(JOBNAME JOBCOUNT JOBCLASS PERIODIC REAXSERVER RELUNAME 
SDLUNAME AUTHCKMAN EVENTID SDLSTRTDT SDLSTRTTM STRTDATE STRTTIME ENDDATE 
ENDTIME STATUS);
$IT->FIELDS([@FLDARRAY]);
$RFC->callrfc( $IT );

Trying this under SAPNW::Rfc however, I can't get it to work with multiple field names. For example, this works:


my $RFC = SAPNW::Rfc->rfc_connect;
my $IT = $RFC->function_lookup("RFC_READ_TABLE");    
my $RC = $IT->create_function_call;
$RC->QUERY_TABLE("TBTCO");
$RC->FIELDS([{'FIELDNAME' => JOBNAME}]);
$RC->ROWCOUNT(10);
$RC->invoke;

But, if I try to set @FLDARRAY to multiple field names as in the older example, and reference that with

$RC->FIELDS([@FLDARRAY]);

I either get an error or a segmentation fault. I've looked at the examples that came with the source code, but they're only (as far as I can tell) inputting multiple values for a single line in an internal table, rather than mutliple lines in an internal table. So, instead of "column1 = value1, column2 = value 2, column3 = value3", I need "column1row1 = value1, column1row2 = value2, column1row3 = value3".

I've also tried using a multidimensional array, as well as a hash, but given that the column name (FIELDNAME) is always the same for every key/value pair, I only ever seem to get it to recognize the last value (column name).

I should mention that the older script works on an older system (R/3 4.6/ERP 5.0) that I no longer have access to, and I'm on a newer system now (ERP 6.0), so I don't know if the structure in the RFC has changed. If so, this may be causing my problem rather than the newer rfc module.

Am I simply missing something syntactically here?

Cheers,

David.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi -

This works fine:


use sapnwrfc;
use Data::Dumper;
SAPNW::Rfc->load_config;
my $conn = SAPNW::Rfc->rfc_connect;
my $rd = $conn->function_lookup("RFC_READ_TABLE");
my $rc = $rd->create_function_call;
$rc->QUERY_TABLE("TBTCO");
$rc->FIELDS([{'FIELDNAME' => 'JOBNAME'},{'FIELDNAME' => 'JOBCOUNT'},{'FIELDNAME' => 'STRTDATE'}]);
$rc->ROWCOUNT(10);
$rc->invoke;
warn "function result: ".Dumper($rc->DATA)."\n";
$conn->disconnect;

Cheers.

Former Member
0 Kudos

Works perfectly as usual, thanks Piers!

Cheers,

David.

Answers (0)