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

Dynamic programming

Former Member
0 Likes
378

hi any body has any sample of dynamic coding

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
351
  • Prog dynamically create itab structure.

report zrich_0002 .

data: begin of itab occurs 0,

tabname(20) type c,

fldname(20) type c,

end of itab.

data: ref_descr type ref to cl_abap_structdescr.

data: where_clause(100) type c occurs 0 with header line.

data: it_details type abap_compdescr_tab,

wa_details type abap_compdescr.

data: new_table type ref to data,

new_line type ref to data,

it_fldcat type lvc_t_fcat,

wa_it_fldcat type lvc_s_fcat.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

start-of-selection.

itab-tabname = 'T000'.

itab-fldname = 'MANDT'.

append itab.

  • itab-tabname = 'T001'.

  • itab-fldname = 'BUKRS'.

  • append itab.

*

*

loop at itab.

  • Get the structure of the table.

refresh it_fldcat.

refresh where_clause.

ref_descr ?= cl_abap_typedescr=>describe_by_name( itab-tabname ).

it_details[] = ref_descr->components[].

loop at it_details into wa_details.

clear wa_it_fldcat.

wa_it_fldcat-fieldname = wa_details-name .

wa_it_fldcat-datatype = wa_details-type_kind.

wa_it_fldcat-inttype = wa_details-type_kind.

wa_it_fldcat-intlen = wa_details-length.

wa_it_fldcat-decimals = wa_details-decimals.

append wa_it_fldcat to it_fldcat .

endloop.

if <dyn_table> is assigned.

refresh <dyn_table>.

unassign <dyn_table>.

endif.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fldcat

importing

ep_table = new_table.

assign new_table->* to <dyn_table>.

concatenate itab-fldname '<> ''' '''' into where_clause

separated by space.

append where_clause.

select * from (itab-tabname) into table <dyn_table>

where (where_clause).

break-point.

endloop.

2 REPLIES 2
Read only

Former Member
0 Likes
351

Hi,

Requirement is to create a dynamic input field and dynamic attributes, these attributes are to be binded with the dynamic input field.

Sol.

Try out the following code in WDDOMODIFYVIEW.

IF first_time = abap_true.

DATA: inp_fld type ref to cl_wd_input_field,

lbl type ref to cl_wd_label,

context_info type ref to if_wd_context_node_info,

attr_info type wdr_context_attribute_info,

root_container type ref to cl_wd_transparent_container.

context_info = wd_context->get_node_info( ).

attr_info-name = 'INP1'.

attr_info-type_name = 'STRING'.

CALL METHOD context_info->ADD_ATTRIBUTE

EXPORTING

attribute_info = attr_info.

root_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

inp_fld = cl_wd_input_field=>new_input_field( id = 'INP' bind_value = 'INP1').

lbl = cl_wd_label=>new_label( id = 'LBL' label_for = 'INP' ).

wd_context->set_attribute( name = 'INP1' value = 'DEFAULT' ).

CALL METHOD CL_WD_MATRIX_LAYOUT=>NEW_MATRIX_LAYOUT

EXPORTING

CONTAINER = root_container.

CALL METHOD CL_WD_MATRIX_HEAD_DATA=>NEW_MATRIX_HEAD_DATA

EXPORTING

ELEMENT = lbl.

CALL METHOD CL_WD_MATRIX_DATA=>NEW_MATRIX_DATA

EXPORTING

ELEMENT = inp_fld.

root_container->add_child( lbl ).

root_container->add_child( inp_fld ).

ENDIF.

(or )

/people/thomas.szcs/blog/2006/02/22/dynamic-programming-in-web-dynpro-abap--part-iii-aggregations-and-ddic-binding-of-viewelements

Reward if helpful.

Regards,

Harini.S

Read only

Former Member
0 Likes
353
  • Prog dynamically create itab structure.

report zrich_0002 .

data: begin of itab occurs 0,

tabname(20) type c,

fldname(20) type c,

end of itab.

data: ref_descr type ref to cl_abap_structdescr.

data: where_clause(100) type c occurs 0 with header line.

data: it_details type abap_compdescr_tab,

wa_details type abap_compdescr.

data: new_table type ref to data,

new_line type ref to data,

it_fldcat type lvc_t_fcat,

wa_it_fldcat type lvc_s_fcat.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

start-of-selection.

itab-tabname = 'T000'.

itab-fldname = 'MANDT'.

append itab.

  • itab-tabname = 'T001'.

  • itab-fldname = 'BUKRS'.

  • append itab.

*

*

loop at itab.

  • Get the structure of the table.

refresh it_fldcat.

refresh where_clause.

ref_descr ?= cl_abap_typedescr=>describe_by_name( itab-tabname ).

it_details[] = ref_descr->components[].

loop at it_details into wa_details.

clear wa_it_fldcat.

wa_it_fldcat-fieldname = wa_details-name .

wa_it_fldcat-datatype = wa_details-type_kind.

wa_it_fldcat-inttype = wa_details-type_kind.

wa_it_fldcat-intlen = wa_details-length.

wa_it_fldcat-decimals = wa_details-decimals.

append wa_it_fldcat to it_fldcat .

endloop.

if <dyn_table> is assigned.

refresh <dyn_table>.

unassign <dyn_table>.

endif.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fldcat

importing

ep_table = new_table.

assign new_table->* to <dyn_table>.

concatenate itab-fldname '<> ''' '''' into where_clause

separated by space.

append where_clause.

select * from (itab-tabname) into table <dyn_table>

where (where_clause).

break-point.

endloop.