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

create data

Former Member
0 Likes
482

Hi all,

is it possible to create dynamiclly structure from parameters value filled by user on selection screen. (user fill 3 fields on selection screen, can i build a structure from this entries?)

Can "create data" be usefull in that case?

Thanks

J

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
461

Hello Juzio

You can create dynamic data objects using the following coding:

data:
  gdo_data     TYPE REF TO DATA.

field-symbols:
  <gt_itab>         TYPE table,
  <gs_struct>     TYPE any,
  <gd_fld>          TYPE any.

CREATE DATA gdo_data TYPE <type of data>.
ASSIGN gdo_data->* to: <gt_itab>, " in case of an itab
                                    <gs_struct>, " in case of a structure
                                    <gd_fld>.     " in case of a field.

The type of data can be the input from a selection-screen.

Regards

Uwe

Read only

Former Member
0 Likes
461

hi,

thanks for the answer but i dont think ist really answer to my question. Plaese explain me if im wrong. I neen to create STRUCTURE form dynamic filled fields.

So i have fields name (form dicc) given by the users on screen and i want to create structure form them.

Thanks

Juzio

Read only

Former Member
0 Likes
461

Have a look at below code. This is the way in which we can create dynamic internal table.

REPORT zmaschl_create_data_dynamic .

TYPE-POOLS: slis.

DATA: it_fcat TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table TYPE REF TO data.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

  • Build fieldcat

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SYST'

CHANGING

ct_fieldcat = it_fcat[].

LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.

MOVE-CORRESPONDING is_fcat TO is_fieldcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

ENDLOOP.

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

  • Create a new Line with the same structure of the table.

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

  • Test it...

DO 30 TIMES.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

<l_field> = sy-index.

INSERT <l_line> INTO TABLE <l_table>.

ENDDO.

LOOP AT <l_table> ASSIGNING <l_line>.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

WRITE <l_field>.

ENDLOOP.

Also have a look at another example.

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

START-OF-SELECTION.

*line = ' CITYFROM CITYTO '.

line = ' AIRPTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

  • WRITE: / wa-cityfrom, wa-cityto.

WRITE 😕 wa-airpto.

ENDLOOP.

ENDIF.

I hoep it gives u some idea how to deal with dynamic internal table and structure.

Best Regards,

Vibha

*Please mark all the helpful answers