cancel
Showing results for 
Search instead for 
Did you mean: 

Date format issue in SAP C#.Net Conenction

Former Member
0 Kudos

I am using SAPConnectionManager with C# to connect to SAP system.
My connection is successfull but I am not getting any data from SAP.

Initially I suspect there might not be any data for parameter I am passing, but then I found the data is present in SAP system. My code for fetching data is as below.

   SapConnection con = new SapConnection();
  
SAPSystemConnect sapCfg = new SAPSystemConnect();

  
RfcDestinationManager.RegisterDestinationConfiguration(con);
  
RfcDestination dest =RfcDestinationManager.GetDestination("NSP");
  
RfcRepository repo = dest.Repository;

  
IRfcFunction fReadTable =repo.CreateFunction("ZCAR_FI_AGF_GET_INVOICES");
   fReadTable
.SetValue("IM_COMPANYCODE", "0005");
   fReadTable
.SetValue("IM_SAPCUSTOMER", "19273");
   fReadTable
.SetValue("IM_INVDATE_FROM","20130101");
   fReadTable
.SetValue("IM_INVDATE_TO", "20141231");

   fReadTable
.Invoke(dest);
  
IRfcTable objRfcTable = fReadTable[0].GetStructure().GetTable(0);

  
if (objRfcTable.RowCount > 0)
  
{
  
foreach (IRfcStructure row in objRfcTable)
  
{
  
object obj = row[0].GetValue();

I am always getting objRFCTable.RowCount as 0.

I suspect that there might be dateformat issue as date expected in SAP is yyyyMMdd but after passing 20130101 as a prameter when I go to quick watch on the request I see date getting passed as {IMPORT PARAMETER IM_INVDATE_FROM=2013-01-01}.

Can anyone help me with what is the issue. Is there any issue with dateformat or connection.

Thanks In Advance

Accepted Solutions (1)

Accepted Solutions (1)

former_member197445
Contributor
0 Kudos

I would not think that date format is an issue here, although I would advise passing a real date for a date parameter... for example new System.DateTime(2013, 1, 1);

I am also curious about the way you are getting the return table.  Why not use:

fReadTable.GetTable("NameOfTable");

?

Former Member
0 Kudos

Hello Case,

Thanks for reply.

I have updated the code for date time, but still no result.

I also tried using your suggestion to use the

IRfcTable objRfcTable1 = fReadTable.GetTable("ZCAR_AGF_INVOICES_T");

But got run time error as

"Element ZCAR_AGF_INVOICES_T of container metadata ZCAR_FI_AGF_GET_INVOICES unknown"

But when I use my previous code at the time of debug I get following info in quick watch for fReadTable metadata :

{FUNCTION ZCAR_FI_AGF_GET_INVOICES (EXPORT PARAMETER EX_INVOICES=STRUCTURE ZCAR_AGF_INVOICES { FIELD LINE=TABLE ZCAR_AGF_INVOICES_T }, EXPORT PARAMETER EX_RETURN=STRUCTURE BAPIRETURN { FIELD TYPE=E FIELD CODE= FIELD MESSAGE=No data found for selection criteria FIELD LOG_NO= FIELD LOG_MSG_NO=000001 FIELD MESSAGE_V1= FIELD MESSAGE_V2= FIELD MESSAGE_V3= FIELD MESSAGE_V4= }, IMPORT PARAMETER IM_BILLGRP=, IMPORT PARAMETER IM_COMPANYCODE=0005, IMPORT PARAMETER IM_COMPANYID=, IMPORT PARAMETER IM_CUSTOMERID=, IMPORT PARAMETER IM_DUEDATE_FROM=0000-00-00, IMPORT PARAMETER IM_DUEDATE_TO=0000-00-00, IMPORT PARAMETER IM_FISCAL_YEAR=0000, IMPORT PARAMETER IM_INVDATE_FROM=2013-01-01, IMPORT PARAMETER IM_INVDATE_TO=2014-12-31, IMPORT PARAMETER IM_INVOICE=, IMPORT PARAMETER IM_MASTER_CONTRACT=, IMPORT PARAMETER IM_OCCURRENCEDATE=0000-00-00, IMPORT PARAMETER IM_OGM_NO=, IMPORT PARAMETER IM_PAYDATE_FROM=0000-00-00, IMPORT PARAMETER IM_PAYDATE_TO=0000-00-00, IMPORT PARAMETER IM_REFERENCE=, IMPORT PARAMETER IM_REFERENCETP=, IMPORT PARAMETER IM_SAPCUSTOMER=19273, IMPORT PARAMETER IM_SOURCE=, IMPORT PARAMETER IM_SOURCE_REF=, IMPORT PARAMETER IM_ZZBLOCK=)}

So I guess ZCAR_AGF_INVOICE_T is the correct table. But still the issue is unclear for me.

Regards,

Hardik

former_member197445
Contributor
0 Kudos

Actually, now it seems like it should be .GetStructure("EX_INVOICES"); based on your error message.

Former Member
0 Kudos

Hello Case,

Thanks Again.

I have added code

IRfcStructure objRfcStructure = fReadTable.GetStructure("EX_INVOICES");

IRfcTable objRfcTable1 = objRfcStructure.GetTable(0);

Here again table name I was not sure. "ZCAR_AGF_INVOICES_T" was not working so tried with index as param.


But still the Row Count is 0.


I suspect some issue on SAP side.


Do you have any idea about this.


Regards,

Hardik

former_member197445
Contributor
0 Kudos

Can you go to SE37 and copy and paste the signature description from the top of the source code? It seems like all your data is in the output structure EX_INVOICES. If I can see the FM signature, I can tell you how to do the .NET code.

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Hardik,

actually, this looks a little bit odd how the function module is defined: However, according to BAPIRETURN message (EX_RETURN=STRUCTURE BAPIRETURN { FIELD TYPE=E FIELD CODE= FIELD MESSAGE=No data found for selection criteria), the selection criteria, i.e. the time range did not match to any data. Moreover, I consider this a pretty odd export parameter definition: Why is it a structure with a single field line that contains a table? Why isn't the table directly the export parameter or even better a table part of the table parameter list?

I can only agree to Case Ahr: Go to SE37. But I'd suggest to test there and see whether it's working. If so, debug into it and check whether alpha conversion of the SAP GUI has changed some values to internal ones. Such ones you would have to provide on NCo side to get the same result.

Best regards,

Markus


Former Member
0 Kudos

Hello Case,

I got the info on the signature description from SAP team.

*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_COMPANYCODE) TYPE  BUKRS
*"     VALUE(IM_SAPCUSTOMER) TYPE  KUNNR OPTIONAL
*"     VALUE(IM_CUSTOMERID) TYPE  ZZREFNO OPTIONAL
*"     VALUE(IM_COMPANYID) TYPE  STCD1 OPTIONAL
*"     VALUE(IM_REFERENCETP) TYPE  ZREFN_TYPE OPTIONAL
*"     VALUE(IM_REFERENCE) TYPE  ZDPST_REFN OPTIONAL
*"     VALUE(IM_MASTER_CONTRACT) TYPE  ZZM_CONTR OPTIONAL
*"     VALUE(IM_SOURCE) TYPE  ZZSOURCE OPTIONAL
*"     VALUE(IM_SOURCE_REF) TYPE  ZZJUR_NO OPTIONAL
*"     VALUE(IM_BILLGRP) TYPE  ZZFAC_GRP OPTIONAL
*"     VALUE(IM_INVOICE) TYPE  BELNR_D OPTIONAL
*"     VALUE(IM_FISCAL_YEAR) TYPE  GJAHR OPTIONAL
*"     VALUE(IM_INVDATE_FROM) TYPE  BUDAT OPTIONAL
*"     VALUE(IM_INVDATE_TO) TYPE  BUDAT OPTIONAL
*"     VALUE(IM_PAYDATE_FROM) TYPE  BUDAT OPTIONAL
*"     VALUE(IM_PAYDATE_TO) TYPE  BUDAT OPTIONAL
*"     VALUE(IM_DUEDATE_FROM) TYPE  DZFBDT OPTIONAL
*"     VALUE(IM_DUEDATE_TO) TYPE  DZFBDT OPTIONAL
*"     VALUE(IM_OCCURRENCEDATE) TYPE  BUDAT OPTIONAL
*"     VALUE(IM_ZZBLOCK) TYPE  ZZBLOCK OPTIONAL
*"     VALUE(IM_OGM_NO) TYPE  XBLNR OPTIONAL
*"

*"  EXPORTING
*"     VALUE(EX_INVOICES) TYPE  ZCAR_AGF_INVOICES
*"     VALUE(EX_RETURN) TYPE  BAPIRETURN
*"----------------------------------------------------------------------

Regards,

Hardik

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Hardik,

actually, this does not show more than we already know ....

Best regards.

Markus

former_member197445
Contributor
0 Kudos

You need to go to SE11 and redefine your dictionary objects.

  • ZCAR_AGF_INVOICES_T should be the type defined for EX_INVOICES
  • ZCAR_AGF_INVOICES_T should have line type ZCAR_AGF_INVOICES
  • ZCAR_AGF_INVOICES structure definition should have the fields passed by the function modules.

Then and only then will EX_INVOICES contain rows of data.  Hope that helps.

Answers (0)