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

FS to Structure

former_member426550
Participant
0 Likes
1,730

good day experts...

how can i create a structure with reference to a FS?

data <gt_itab> TYPE table.

CREATE DATA gdo_data TYPE (p_tabnam).

ASSIGN gdo_data->* TO <gt_itab>.

from the code above..i want to create a structure with the fields like <gt_itab>.

1 ACCEPTED SOLUTION
Read only

former_member426550
Participant
0 Likes
1,609

help...any?

10 REPLIES 10
Read only

Former Member
0 Likes
1,609

Try to add the following coding:

FIELD-SYMBOLS:

<fs_general>.

DATA:

lc_description(100) TYPE c.

field-symbols:

<ld_descr> type any. " additional field symbol

<fs_general> = i_fs.

assign component 'Z_DESCRIPTION' OF STRUCTURE <fs_general> TO <ld_descr>.

IF ( <ld_descr> IS ASSIGNED ).

lc_description = <ld_descr>.

ENDIF.

Read only

0 Likes
1,609

thank u naresh for ur reply...

IF ( <ld_descr> IS ASSIGNED ).

endif.

the result is always unASSIGNED...

whats the purpose of variable i_fs?

Read only

Former Member
0 Likes
1,609

data: wa TYPE gt_itab.

Read only

Former Member
0 Likes
1,609

TABLES bkpf.

data : gdo_data type REF TO data,

p_tabnam(30) type c.

field-SYMBOLS: <gt_itab> TYPE ANY TABLE,

<FS>.

p_tabnam = 'BKPF'.

ASSIGN (p_tabnam) to <FS>.

CREATE DATA gdo_data LIKE TABLE OF <FS>.

ASSIGN gdo_data->* TO <gt_itab>.

Read only

Clemenss
Active Contributor
0 Likes
1,609

Hi jr,

I think Naresh's code does not answer your question at all.


CREATE DATA gdo_data TYPE (p_tabnam).

creates a structured variable, not an internal table.

Startig with ECC600 this should be


CREATE DATA gdo_data TYPE table of (p_tabnam).

The declaration of field symbol is wrong, should be

FIELD-SYMBOLS: <gt_itab> TYPE ANY TABLE.

If you want a structure, add

FIELD-SYMBOLS: <gs_struc> TYPE ANY.
CREATE DATA gdo_data LIKE LINE OF <gt_itab>.
ASSIGN gdo_data->* TO <gs_struc>.

Note that gdo_data is declared as TYPE REF TO DATA and can be re-used to take reference to created data objects. The refernce is the assigned to a field-symbol.

Regards,

Clemens

Read only

0 Likes
1,609

hi clemens,

based on ur source code....

how can i convert FS <gs_struc> to a structure?

thanks,

Read only

Clemenss
Active Contributor
0 Likes
1,609

jr_sap_developer,

<gs_struc> is a field-symbol assigned to a structure and can be used as a structure.

Because the field-symbol itself is of type any, you can't access it's components directly. If, i.e., the table and table line is of type vbap, you can't use <gs_struc>-vbeln. This will result in a syntax error.

But you can declare another field-symbol and assign it:


field-symbols <component> type any.
assign component 'VBELN' of structure <gs_struc> to <component>.

Now you can use it.

If you don't know the field names of your structure, you can get them using this little method:


CLASS cc DEFINITION.
    CLASS-METHODS:
      fieldtab
        IMPORTING is_any                  TYPE any
        RETURNING value(rt_field)         TYPE ttfieldname.
ENDCLASS.    
CLASS cc IMPLEMENTATION.
**********************************************************************
* METHOD    :        fieldtab
* returns component names of structure or table
* result to be used for dynamic programming
* ATTN: This method is not release-stable: SAP redesigned the TYPE
*       concept with major changes to classes cl_abap_*descr
*       The type_kind attribute is replaced with type attribute
*       with changed values.
*       Release change/porting note:
*       activate lines with comment "starting rel 4.7
*       deactivate lines with comment "before rel 4.7
**********************************************************************
  METHOD fieldtab.
    DATA:
      lt_comp                             TYPE abap_compdescr_tab,
      lr_dat                              TYPE REF TO data,
      lr_typedescr                        TYPE REF TO cl_abap_typedescr,
      lr_structdescr                      TYPE REF TO
        cl_abap_structdescr.
    FIELD-SYMBOLS:
      <fs>                                TYPE ANY,
      <ft>                                TYPE ANY TABLE,
      <comp>                              TYPE LINE OF
        abap_compdescr_tab.
    lr_typedescr                          =
    cl_abap_typedescr=>describe_by_data( is_any ).
*    CASE lr_typedescr->type.                       "starting rel 4.7
*      WHEN cl_abap_structdescr=>KIND_STRUCT.       "starting rel 4.7
    CASE lr_typedescr->type_kind.                   "before rel 4.7
      WHEN cl_abap_structdescr=>typekind_struct1    "before rel 4.7
        OR cl_abap_structdescr=>typekind_struct2.   "before rel 4.7
        lr_structdescr ?= lr_typedescr.
        lt_comp                           = lr_structdescr->components.
*      WHEN cl_abap_structdescr=>KIND_TABLE.       "starting rel 4.7
      WHEN cl_abap_structdescr=>typekind_table.    "before rel 4.7
        ASSIGN is_any TO <ft>.
        CREATE DATA lr_dat                LIKE LINE OF <ft>.
        ASSIGN lr_dat->* TO <fs>.
        lr_structdescr ?= cl_abap_structdescr=>describe_by_data( <fs> ).
        lt_comp                           = lr_structdescr->components.
      WHEN OTHERS.
        MESSAGE e241(00).
*   Function is invalid in this environment
    ENDCASE.
    LOOP AT lt_comp ASSIGNING <comp>.
      APPEND <comp>-name TO rt_field.
    ENDLOOP." at lt_comp assigning <comp>.
  ENDMETHOD.                    "fieldtab
ENDCLASS.                    "cc IMPLEMENTATION
* . to be used as i.e.
DATA:                                                               
  lt_field                              TYPE ttfieldname.
lt_field = cc=>fieldtab( <gs_struc> ).                              
* ... 

As I don't know exactly what you are going to solve, I'll stop right here.

Regards,

Clemens

Read only

former_member426550
Participant
0 Likes
1,609

any update?....

my requirement is to create a structure based on <FS>.

data <gt_itab> TYPE table.

CREATE DATA gdo_data TYPE (p_tabnam).

ASSIGN gdo_data->* TO <gt_itab>.

data gs_struc type <gt_itab>..----->like this

thanks...

Read only

former_member426550
Participant
0 Likes
1,610

help...any?

Read only

0 Likes
1,609

Hi jr,

if you create data dynamically using the create data statement, the only way to access them is via field-symbol.

You can use the field-symbol in the same way you would use a structure cerated with DATA ... LIKE or TYPE ...

Regards,

Clemens