cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the column name of a table from sap system using C#?

Former Member
0 Kudos

Hi!!

I am using SAP .NET connector and creating a windows application.

Now I wanna read the column name when a table name is given....

Connection is done, but I don't know the code to read the column names alone...

Can anyone help me with the code??

Accepted Solutions (1)

Accepted Solutions (1)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

HI Jeswin,

Assuming that destination is the RfcDestination that is used for your secnario, you can get the columns of a table NAME by looping over the line type metadata:

RfcStructureMetaData lineType=destination.Repository.GetTableMetaData("NAME").LineType.

String[] columns=new String[lineType.FieldCount];

for (int i; i<columns.Length; i++)

{

     columns[i]=lineType[i].Name;

}

Best regards,

Markus

Former Member
0 Kudos

yeah I am using RfcDestination,

It says that Type of namespace could not be found for  RfcStructureMetaData (assembly reference missing)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Jeswin,

oops, a small typo: RfcStructureMetadata is correct ... in SAP.Middleware.Connector namespace.

Best regards,

Markus

Former Member
0 Kudos

I m using SAP.Middleware.Conncetor.. Current Code:

this displays only one column name.. It shows element count as 0... but it has 12 element in the table...

IRfcTable addressData = customerList.GetTable("AddressData");

             

              

             

                for (int i = 0; i <= addressData.ElementCount; i++)

                {

                    RfcElementMetadata metadata = addressData.GetElementMetadata(i);

                    listBox1.Items.Add(metadata.Name);

                }

Former Member
0 Kudos

wow!! No error!!

But it's saying that no active tabs in the table....

SAP.Middleware.Connector.RfcInvalidStateException: metadata for TableOnly ADDRESSDATA not available: NOT_FOUND: No active nametab exists for ADDRESSDATA

   at SAP.Middleware.Connector.RfcRepository.LookupRecordMetadataNew(String name, RecordType recordType)

   at SAP.Middleware.Connector.RfcRepository.LookupRecordMetadata(String name, RecordType recordType)

   at SAP.Middleware.Connector.RfcRepository.GetTableMetadata(String name)

   at sapapplication.systems.GetCustomerDetails(RfcDestination destination) in d:\Client\sapapplication\sapapplication\systems.cs:line 502

   at sapapplication.systems.btntest_Click(Object sender, EventArgs e) in d:\Client\sapapplication\sapapplication\systems.cs:line 395}

Wat does it mean ?

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Jeswin,

ADDRESSDATA is not the type name, but the table name within a function module. In this case, you need to retrieve the linetype from the IRfcTable via addressData.Metadata.LineType and proceed as mentioned above.

Best regards,

Markus

Former Member
0 Kudos

Yeah!! Now i got that point Thanks a lot Markus....

Another Doubt, I have called a function called:

IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_GETLIST");

then  I call table name AddressData:

IRfcTable addressData = customerList.GetTable("AddressData");

It works fine....

But when I use change the function as:

IRfcFunction customerList = repo.CreateFunction("RFC_READ_TABLE");

and I call the same table AddressData, it shows exception as

"Element AddressData of container metadata RFC_READ_TABLE unknown"..


I don't know SAP, my work is to extract data from SAP System using .NET(C#).

Can u plz explain clearly???

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Jeswin,

these are two function modules: One has a parameter ADDRESSDATA, the other one - RFC_READ_TABLE -  doesn't. Function parameters are address in in ABAP via their name and thus also in NCo.

Bets regards,

Markus

Former Member
0 Kudos

fine!!

So if i give the table name, which the RFC_READ_TABLE function module have, will it run properly? or i wanna change all the codes in order to support RFC_READ_TABLE function module?

Because from the beginning I was using BAPI_CUSTOMER_GETLIST function, but my client requirement is to use ERP function module RFC_READ_TABLE, he didn't give any table name also..

This is my code: What I have to change in this???


ECCDestinationConfig ECCDestination = new ECCDestinationConfig();

            RfcDestinationManager.RegisterDestinationConfiguration(ECCDestination);

            RfcDestination rfcDest = null;

            rfcDest = RfcDestinationManager.GetDestination(a);

           

                RfcRepository repo = rfcDest.Repository;

                IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_GETLIST");

               

                IRfcTable addressData = customerList.GetTable("AddressTable"));

                int j = addressData.Metadata.LineType.FieldCount;

                for (int i = 0; i < j; i++)

                {

                    RfcElementMetadata metadata = addressData.GetElementMetadata(i);

                    listallcolumn.Items.Add(metadata.Name);

                }

Message was edited by: Jeswin Rebil

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos


Hi Jeswin,

you should not use RFC_READ_TABLE in a productive scenario. From security point of view, this is really a bad approach: Thus, you bypass the authority checks in application code that protect the data in the respective table. Instead, you should implement an RFC function module that fits to your scenario in the ABAP system, if there isn't one that fits in the standard. There you can do authority checks. In principle you need to replace BAPI_CUSTOMER_GETLIST with the new function module and change also the name of the table parameters if there are some.

In principle it depends heavily on what you want to achieve.

Best regards,

Markus

former_member197445
Contributor
0 Kudos

I agree with Markus.  Using RFC_READ_TABLE for extraction purposes is not advisable.  Not just from a security standpoint, but if you're extracting large tables on a regular basis (e.g. nightly), then performance could really suffer in your system.

Answers (1)

Answers (1)

Former Member
0 Kudos

Ok!! Thanks a lot Markus, I will look on that