Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get variable name from abap report

Former Member
0 Likes
3,923

Hello

I have the next scenario:

- i have a GUI structure that contains some fields. These fields have to be saved in the db, but the data elements in the table have different names.Therefore i have to do a mapping between the gui field and the db field. For this i need the variable name from the gui in order to search for the gui field in the table . This has to be done dynamically.

For ex:

i need a method that does the next:

data: ls_matnr type mara.

call method obj->get_var_name(

          exporting

               field = ls_mara-matnr

          importing

               name = lv_var           )

write lv_result.

Result should be in this case "LS_MARA-MATNR"

Thank you

Hello

I have the next scenario:

- i have a GUI structure that contains some fields. These fields have to be saved in the db, but the data elements in the table have different names.Therefore i have to do a mapping between the gui field and the db field. For this i need the variable name from the gui in order to search for the gui field in the table . This has to be done dynamically.

For ex:

i need a method that does the next:

data: ls_matnr type mara.

call method obj->get_var_name(

          exporting

               field = ls_mara-matnr

          importing

               name = lv_var           )

write lv_result.

Result should be in this case "LS_MARA-MATNR"

Thank you

10 REPLIES 10
Read only

Former Member
0 Likes
2,176

HI SV,

     By using Function Module 'DDIF_FIELDINFO_GET' you can get the field information.

Regards,

Surendra Gupta.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,176

These fields have to be saved in the db, but the data elements in the table have different names.

The field names of the GUI structure & the DB table are same? If yes, can you not use MOVE-CORRESPONDING?

Read only

Former Member
0 Likes
2,176

Hello everybody

thanks for the replies.

Unfortunately, the DDIF FM needs as parameters the Table and Field. I know the table, but the reference field is exactly what i need to find out before i call the fm.

If i call the fm with the next param:

CALL FUNCTION 'DDIF_FIELDINFO_GET'

   EXPORTING

     tabname              = 'MARA'

     fieldname            = lv_matnr

i get a shortdpump, which is normal because lv_matnr does not have the expected type.

Suhas, the logic is more complex. I have  up to 3 tables in the background to which i have to map my fields and they do not have the same naming. That's why move-corresponding will not work in this case.

Any other ideas?

Thanks

Read only

0 Likes
2,176

Hi,

can you provide an example with snapshot please?

thanks

Read only

former_member182877
Participant
0 Likes
2,176

Hi Sebastian,

If I understand your question correctly.

You have a SAP structure with fields A, B, C and data elements X, Y, Z?

Your DB fields would be M, N, O with type P,Q,R?

Now you have to map A B C to M N O? - Right?

I have 2 questions here

1. Is your DB different from the DB table generated when you activated your SAP DDIC structure?

2. This atleast can be thought only when you have a Pattern!! say your fields should be declared in sequence (or) if you are matching with data types then for each field... data typ should be unique!!?

Cheers,

Kripa Rangachari.

Read only

0 Likes
2,176

Hi Kripa,

I think the problem is that his fields name, even if the date elements are different, but at least the fields shoud be same, to use MOVE-CORRESPONDING.,

but if the SAP/GUI-Fields are different from hist fields, how can he knows that A = Z?

I think, in this way, he can compares the date elements, when the fields are different, then he can use same date elements with different fields name.

Regards

Ebrahim

Read only

0 Likes
2,176

Hi Ebrahim,

I dont think data element mismatch should be a problem from 'NAME' perspective... if the types are matching then we can just match the fields.... dataelement should not be a hinderance here!....

I think we need more insight on his issue and as u asked for it will be easier if we get some screen examples as well!..

We will wait and watch

Cheers,

Kripa Rangachari.

Read only

0 Likes
2,176

Hello Everybody

I have the next concrete case:

structure fieldname nameon screen: gs_screen-kunnr type ZSCR-KNRE   (ZSCR is a structure in DDIC)

and the fieldname in my ddic tables where i have to store them,look like this:

ZTAB1-YAXKNRE

ZTAB2-YAYKNRE

ZTAB3-YAZKNRE

So, i have to get the type of the field gs_screen-kunnr, in this case ZSCR-KNRE and take only the fieldname KNRE. Based on another logic, i get my table name, for ex ZTAB1 and from here, i know that the corresponding fielname ends with KNRE = > the mapped db field is YAXKNRE.

Please tell me if it is clear now.

thank you.

Read only

0 Likes
2,176

Hello Sebastian,

You can try as-

Create a Data Elemenet ZKNRE which is same as ZSCR-KNRE and declare as -

Data : gs_screen-kunnr type ZKNRE.

This reduces one part of your problem.

Now the mapping logic is not clear as how are you getting the field name from table. As in your example -

ZTAB1-YAXKNRE

ZTAB2-YAYKNRE

ZTAB3-YAZKNRE

all field names end with KNRE so all of them should be mapped with ZKNRE??

BR.

Read only

jrg_wulf
Active Contributor
0 Likes
2,176

Hi Sebastian,

easiest way to achieve your objective is by using

data: struct_descriptor  type ref to cl_abap_structdescr.

data: a_component type abap_compdescr_tab.

field-symbols: <a_field> type any.

struct_descriptor = CL_ABAP_STRUCTDESCR=>describe_by_data( your_GUI_structure ).

LOOP AT struct_descriptor->components into a_component.

  assign compont a_component-Name of structure your_GUI_structure to <a_field>.

* do something clever with <a_field>

ENDLOOP.

Best regards - Jörg