Application Development 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: 

Store fieldname in internal table

Former Member
0 Kudos

Hi,

How do you store the internal table fieldnames in a internal table of filedname type?

Ex: My table add 3 fields of name field_1, field_2 et field_3. My another table would be 3 records in the fieldname field : field_1, field_2 et field_3.

Thanks.

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

You can check this example..

using the function you can get the fields present in the internal table. in the components table parameter you can see the Fieldnames.

REPORT  zztest_fieldname.

DATA: components TYPE TABLE OF rstrucinfo.

DATA: BEGIN OF it_field OCCURS 0,
       filed1(30),
       field2(30),
       field3(30),
      END OF it_field.

CALL FUNCTION 'GET_COMPONENT_LIST'
  EXPORTING
    program    = sy-repid
    fieldname  = 'IT_FIELD'
  TABLES
    components = components.

break-point.

6 REPLIES 6

Former Member
0 Kudos

so you want to store the "field names" in one internal table as records into another internal table?

0 Kudos

Yes... Just recover the fieldnames...

0 Kudos

Well, then go for this function module, BUKU_GET_FIELD_NAMES

some sample code,


TABLES SPFLI.

DATA:
  T_SPFLI TYPE STANDARD TABLE
            OF SPFLI
       INITIAL SIZE 10.

CALL FUNCTION 'BUKU_GET_FIELD_NAMES'

  EXPORTING
    I_S_STRUCTURE         =  SPFLI
 IMPORTING
   E_T_FIELD_NAMES       =   T_FIELDS.

If you check the entries in T_FIELDS, it will only contain the field names of SPFLI.

Instead of SPFLI you can give your own internal table as export parameter and the other table as importing parameter. But make sure that both the internal tables have exactly the same strucuture.

former_member194669
Active Contributor
0 Kudos

Try to use fm


      call function 'GET_COMPONENT_LIST'
        exporting
          program    = v_repid
          fieldname  = v_fname " Internal table
        tables
          components = i_components.

Here i_components contains all fields declared in the internal table

former_member188685
Active Contributor
0 Kudos

You can check this example..

using the function you can get the fields present in the internal table. in the components table parameter you can see the Fieldnames.

REPORT  zztest_fieldname.

DATA: components TYPE TABLE OF rstrucinfo.

DATA: BEGIN OF it_field OCCURS 0,
       filed1(30),
       field2(30),
       field3(30),
      END OF it_field.

CALL FUNCTION 'GET_COMPONENT_LIST'
  EXPORTING
    program    = sy-repid
    fieldname  = 'IT_FIELD'
  TABLES
    components = components.

break-point.

Former Member
0 Kudos

Hi,

I thinks you could use the function GET_GLOBAL_SYMBOLS

TYPES: BEGIN OF st_char30,
            fieldname TYPE char30,
        END OF st_char30.

DATA: lv_champ1 TYPE char200,
      lv_champ2 TYPE char200,
      lv_champ3 TYPE char200.

DATA: lv_rfieldlist TYPE TABLE OF rfieldlist WITH HEADER LINE.

DATA: lt_table TYPE TABLE OF st_char30 WITH HEADER LINE.

CALL FUNCTION 'GET_GLOBAL_SYMBOLS'
  EXPORTING
    program            = sy-repid
*   NAME_PATTERN       = '*'
  TABLES
    fieldlist          = lv_rfieldlist       .

LOOP AT lv_rfieldlist.
  IF lv_rfieldlist CP 'LV_CHAMP*'.
    APPEND lv_rfieldlist-name TO lt_table.
  ENDIF.
ENDLOOP.