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: 

How to Compare field values in a Field-Symbols

Former Member
0 Kudos

Hi Experts,

I am facing one problem.

MATNR New MATNR LIFNR New LIFNR KUNNR New KUNNR

10 11 20 21 30 31

In the above,Column headings are in one Internal Table and the Column Values are in Field Symbols . Now how to compare the column values.

Matnr & New Matnr I have to compare and do something.Similarly for Lifnr & New Lifnr ,Kunnr & Kunnr.

Thanks for your Help.

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Simply compare field symbols:


if <MATNR> =  <NEW_MATNR>.
   "values are the same, react accordingly
endif.

Regards

Marcin

8 REPLIES 8

MarcinPciak
Active Contributor
0 Kudos

Simply compare field symbols:


if <MATNR> =  <NEW_MATNR>.
   "values are the same, react accordingly
endif.

Regards

Marcin

0 Kudos

Hi Marcin,

Thanks for your Reply,But the problem is that the Internal table is dynamic one ,not fixed so how will i figure out Matnr & New Matnr.Here it was given as a example.How to track the Headings and compare values as Column name come from Dynamic Internal table .

0 Kudos

To be more Precise.If Internal table has

A B C D E F as first entry.

How to compare A & B ,C & D, E&F.....

And the Internal table is in a loop.

0 Kudos

Not sure where your values are stored. I assumed there are in dynamic table VALUE_TAB, but you don't know column names until runtime. So you can write something like this:


data: begin of value_tab occurs 0, "your value table crrated dynamicaly
           matnr type ....
           new_matnr type...
         end of value_tab,
          
         begin of header_tab occurs 0, "header table created dynamically
          header....
         end of header_tab.

"fill in header_tab and value_tab
...

field-symbols: <value1>, <value2>.

data: i_lines type i, 
         idx type i,
         comp_name type c length 40.

describe table header_tab lines i_lines.
divide i_lines by 2.     "we will compare components in pairs for each entry in VALUE_TAB

loop at value_tab.
  do i_lines times.
    idx = sy-index * 2.   

    read table header_tab index idx.
    concatenate 'VALUE_TAB-' header_tab-header into comp_name.  "i.e VALUE_TAB-NEW_MATNR
    condense comp_name.
    assign (comp_name) to <value2>.   "<value2> stores value of first component (i.e NEW_MATNR)

    idx = idx - 1.
    read table header_tab index idx.
    concatenate 'VALUE_TAB-' header_tab-header into comp_name. "i.e VALUE_TAB-MANTR
    condense comp_name.
    assign (comp_name) to <value1>.   "<value1> store value of first component (i.e MATNR)

    if <value1> = <value2>.
      "components are the same....
    endif.
   
  enddo. "do the same for next pair of components
endloop.

Regards

Marcin

Edited by: Marcin Pciak on May 17, 2009 9:31 AM

0 Kudos

Hi Marcin,

Thanks for your Response.Let me tell the requirement .

I have one Internal Table which has one field .

data : begin of out_field1 occurs 0,

fname type char30,

end of out_field1.

The above internal table will be filled with N field names.

And I have one Field Symbol which has field values.

Loop at Internal Table ..

Loop at field Symbolu2026

ENDLOOP.

ENDLOOP.

While Processing I need to take care of the following.

For Eg the values are as follows

Matnr NewMatnr Lifnr Kunnr NewKunnr  Internal Table with file name

10 12 17 19 20  Field Values from Field-Symbo

AS in the Above I can see that I have New Matnr,in this case I need to compare 10 & 12 ,since they are different I need to color New Matnr.Similarly for Kunnr as again it has New Kunnr column.For Lifnr I should not do anything.

The problem is how to compare the values and highlight the same.

I hope I am clear of my requirements.

Thanks for your Help.

0 Kudos

Hi,

Still some question arises here:

1) field names will appear in out_field1 table during runtime right. So the question is: if there is some rule which fields should be compared?

You say if there is New Matnr then you have to compare it with old Matnr . But how do you know if there is New. Should the comparison be based on new addtion. I mean something like this:


data: new_fname type char30.

Loop at out_field1.
   concatenate 'New' out_field1-fname into new_fname.   "NewMatnr, NewKunnr ...

   "check if new field available in out_field1 table
   read table out_field1 with key fname = new_fname.
   if sy-subrc = 0.
     "we have new field so compare values in field symbols
   else.
     continue.   "check next entry
   endif.
endloop.

2) how field-symbol is typed - is it a table type (but fields are always the same as their names in out_field1 ) ?


field-symbols <fs_tab> like table of .... "structured like table which components are same as in out_field1 table?

If so, then add the following to above code:


"use another field symbol to address line of <fs_tab>
field-symbols <fs_struct> like line of <fs_tab>.

"use additional field symbols to address fields of <fs_struct> 
field-symbols <fs_comp1>, <fs_comp2>. 

Loop at <fs_tab> assigning <fs_struct>.  "for each line with values
  Loop at out_field1.
   read table out_field1 with key fname = new_fname.   "look for NewMatrnr..
   if sy-subrc = 0.     
     "get Matnr value and NewMatnr value from field symbol <fs_struct>
     assign component out_field1-fname of structure <fs_struct> to <fs_comp1>.  "address component Matnr in structure <fs> and get its value to <fs_comp1>

     assign component new_fname of structure <fs_struct> to <fs_comp2> . "do the same to get NewMatnr value

     if <fs_comp1> ne <fs_comp2>.  "compare values 10 and 12 etc
        "write old field without a color
        write: <fs_comp1>.
        "color the output of new field
        write <fs_comp2> color COL_POSITIVE.
     endif.
   else.
     continue.   "check next entry
   endif.
  endloop.
endloop.

Let me know if this is clear enought. If not, please provide your code, so it will be easier for both of us:)

Regards

Marcin

former_member555112
Active Contributor
0 Kudos

Hi,

Please check my WIKI.

https://wiki.sdn.sap.com/wiki/x/UYA_Bg

It might be helpful.

Regards,

Ankur Parab

0 Kudos

Given link is no more useful. Error: Page not found.