2014 Feb 21 9:35 AM
Hello everyone,
this is what I want to do: I have a work-area with several fields, let's say "field1", "field2", "field3". I do have another workarea with the same structure, but diferent content. I want ty run through both work-areas dynamically and compare the values of both work-areas.
Something like:
if wa_nr1-<dynfield> eq wa_nr2-<dynfield>.
"do some code...
endif.
2014 Feb 21 9:55 AM
Hi Markus,
You can achieve your requirement as below
DATA ls_wa_1 TYPE pa0001. "work area 1
DATA ls_wa_2 TYPE pa0001. " work area 2
DATA lo_structdescr TYPE REF TO cl_abap_structdescr.
DATA lt_fields TYPE cl_abap_structdescr=>component_table.
DATA ls_fields LIKE LINE OF lt_fields.
FIELD-SYMBOLS: <fs_val_1> TYPE any,
<fs_val_2> TYPE any.
"get structure descr reference
lo_structdescr ?= cl_abap_structdescr=>describe_by_data( ls_wa_1 ).
lt_fields = lo_structdescr->get_components( ).
LOOP AT lt_fields INTO ls_fields.
ASSIGN COMPONENT ls_fields-name OF STRUCTURE ls_wa_1 TO <fs_val_1>.
ASSIGN COMPONENT ls_fields-name OF STRUCTURE ls_wa_2 TO <fs_val_2>.
IF <fs_val_1> EQ <fs_val_2>.
" do some thing
ENDIF.
ENDLOOP.
Hope this helps you.
Regards,
Rama
2014 Feb 21 9:43 AM
I do have already assigned the component structure and hold the fieldnames in an array. I am only lacking the last steps to finish.
2014 Feb 21 9:44 AM
Hi Markus,
Look at this example code:
DATA: l_index type sy-index.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = wa_nr1
TABLES
components = lt_nr1.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = wa_nr2
TABLES
components = lt_nr2.
LOOP AT lt_nr1 ASSIGNING <fs_nrq1>.
l_index = sy-tabix.
READ TABLE lt_nr2 ASSIGNING <fs_nr2> INDEX l_index.
IF sy-subrc eq 0.
if <fs_nr1> eq <fs_nr2>.
" Code
endif.
ENDIF.
ENDLOOP.
2014 Feb 21 9:52 AM
first get all the fields of the sturcutre through FM"CATSXT_GET_DDIC_FIELDINFO"
then
create a field symbol
loop at li_field into ls_field.
<fs_field1> = 'StructureName1-ls_field-nam3'
<fs_field2> = 'StructureName2-ls_field-name'
if <fs_field1> eq <fs_field2>
do some code
endif.
endloop
2014 Feb 21 9:55 AM
Hi Markus,
You can achieve your requirement as below
DATA ls_wa_1 TYPE pa0001. "work area 1
DATA ls_wa_2 TYPE pa0001. " work area 2
DATA lo_structdescr TYPE REF TO cl_abap_structdescr.
DATA lt_fields TYPE cl_abap_structdescr=>component_table.
DATA ls_fields LIKE LINE OF lt_fields.
FIELD-SYMBOLS: <fs_val_1> TYPE any,
<fs_val_2> TYPE any.
"get structure descr reference
lo_structdescr ?= cl_abap_structdescr=>describe_by_data( ls_wa_1 ).
lt_fields = lo_structdescr->get_components( ).
LOOP AT lt_fields INTO ls_fields.
ASSIGN COMPONENT ls_fields-name OF STRUCTURE ls_wa_1 TO <fs_val_1>.
ASSIGN COMPONENT ls_fields-name OF STRUCTURE ls_wa_2 TO <fs_val_2>.
IF <fs_val_1> EQ <fs_val_2>.
" do some thing
ENDIF.
ENDLOOP.
Hope this helps you.
Regards,
Rama
2014 Feb 21 10:35 AM
2014 Feb 21 10:47 AM
2014 Feb 21 10:00 AM
Try this & see...
DATA:
lo_struct1 TYPE REF TO cl_abap_structdescr,
li_comp1 TYPE cl_abap_structdescr=>component_table,
li_comp_line1 LIKE LINE OF li_comp,
lo_struct2 TYPE REF TO cl_abap_structdescr,
li_comp2 TYPE cl_abap_structdescr=>component_table,
li_comp_line2 LIKE LINE OF li_comp,
wa_nr1 type STRUCTURE1,
wa_nr2 type STRUCTURE2.
FIELD-SYMBOLS : <fs_1> type any,
<fs_2> type any.
lo_struct1 ?= cl_abap_typedescr=>describe_by_name( 'STRUCTURE1').
li_comp1 = lo_struct->get_components( ).
lo_struct2 ?= cl_abap_typedescr=>describe_by_name( 'STRUCTURE2').
li_comp2 = lo_struct->get_components( ).
LOOP AT li_comp1 INTO li_comp_line1.
ASSIGN COMPONENT li_comp_line1-name OF STRUCTURE wa_nr1TO <fs_1>.
READ TABLE li_comp2 INTO li_comp_line2 WITH KEY name = li_comp_line1-name.
IF sy-subrc EQ 0.
ASSIGN COMPONENT li_comp_line2-name OF STRUCTURE wa_nr2TO <fs_2>.
IF <fs_1> = <fs_2>.
"do some code...
ENDIF.
ENDIF.
ENDLOOP.
Thanks,
Sharath