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

Comparing two character fields

Former Member
0 Likes
2,298

Dear Expert,

I am facing a peculiar issue even though it is an easy one but i am facing and so far unable to find the solution. in my reporting to create vendor, i have to compare to fields of character type, and if both character fields having the same content then CONTINUE should be triggered. but in my case it is not at all triggering the CONTINUE. my sample code is as follow. am just giving an abstract code as original is restricted.

types: begin of gty_itab,

       f1 type char10,

       f2 type char24,

       f3 type char10,

       end of gty_itab.

data : gt_itab type table of gty_itab,

       gw_itab type gty_itab.

constants: c_text type c length 24 value 'DO NOT ADD TO THE OUTPUT'.

gw_itab-f1 = '1st qtr'.

gw_itab-f2 = 'do not add to the output'.

gw_itab-f3 = 'vendor'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = '2nd qtr'.

gw_itab-f2 = 'Regular'.

gw_itab-f3 = 'customer'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = '3rd qtr'.

gw_itab-f2 = 'do not add to the output'.

gw_itab-f3 = 'vendor1'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = '4th qtr'.

gw_itab-f2 = 'irregular'.

gw_itab-f3 = 'vendor'.

append gw_itab to gt_itab.

clear gw_itab.

loop at gt_itab into gw_itab.

*translate gw_itab-f2 to upper case.

if ( gw_itab-f2 = c_text )..

continue.

endif.

write: / gw_itab-f1, gw_itab-f2, gw_itab-f3.

endloop.

Early reply will be apprecieated and rewarded.

Regards

1 ACCEPTED SOLUTION
Read only

sivaganesh_krishnan
Contributor
0 Likes
2,259

hi pritee,

just uncoment your  line which starts wit translate it works fine..

15 REPLIES 15
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
2,259

Uncomment this line

 

translate gw_itab-f2 to upper case.


Read only

0 Likes
2,259

Hi Naveet,

Translate gw_itab-f2 to upper case is needed as sometime the user may input "Do not add to the output" and there is a chance that some time the user may give "do not add to the output".so need to change it to upper case and checking against the content of c_text(DO NOT ADD TO THE OUTPUT). if both are same then CONTINUE should be executed and that particular line should not be displayed in the output.

Please suggest if you any other solution.

Regards

Read only

0 Likes
2,259

Hi Madan,

Even after commenting the "translate gw_itab-f2 to upper case", it is still not executing the CONTINUE statement.

Regards

Read only

0 Likes
2,259

it is executing , in my case . i just uncommented it and it worked as you suggested . check whether the condition values are equal or not.

Read only

sivaganesh_krishnan
Contributor
0 Likes
2,260

hi pritee,

just uncoment your  line which starts wit translate it works fine..

Read only

0 Likes
2,259

Hi Sivaganesh,

thanks for your reply. and also thanks to Nabheet also for his response.

Even after uncommenting the "translate gw_itab-f2 to upper case", it is still not executing the CONTINUE statement.

Any other solution for this.

Regards

Read only

0 Likes
2,259

Hi,

it works fine... but you can try this:

if ( gw_itab-f2 CS c_text ).

continue.

endif.

Regards,

Read only

0 Likes
2,259

you can try with CO (Contains only ) also

if ( gw_itab-f2 CO c_text ).

continue.

endif.

Read only

0 Likes
2,259

Thanks Bernat,

For your timely help. it solved my problem.thanks to Nabheet and Sivaganesh also. for ref purpose I am putting the code as follow.

types: begin of gty_itab,

       f1 type char10,

       f2 type char21,

       f3 type char10,

       end of gty_itab.

data : gt_itab type table of gty_itab,

       gw_itab type gty_itab.

constants: c_text type c length 21 value 'Non-entity contractor'."'NON-ENTITY CONTRACTOR'.

gw_itab-f1 = 'rajesh'.

gw_itab-f2 = 'Non-entity Contractor'.

gw_itab-f3 = 'vendor'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = 'rajesh1'.

gw_itab-f2 = 'Regular'.

gw_itab-f3 = 'customer'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = 'rajesh2'.

gw_itab-f2 = 'Non-entity Contractor'.

gw_itab-f3 = 'vendor1'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = 'rajesh5'.

gw_itab-f2 = 'irregular'.

gw_itab-f3 = 'vendor'.

append gw_itab to gt_itab.

clear gw_itab.

loop at gt_itab into gw_itab.

*translate gw_itab-f2 to upper case.

if ( gw_itab-f2 CS c_text )..

continue.

endif.

write: / gw_itab-f1, gw_itab-f2, gw_itab-f3.

endloop.

Regards

Read only

0 Likes
2,259

Your sample code works as expected.

It is not the continue line but the translate line you should bother about. Make sure it is executed.

set a break-point after the translate statemnt and check in debugger.

If in doubt, make use of the compare feature in debugger (second last tab).

Regards Jörg

Read only

0 Likes
2,259

Thanks Siva Ganesh,

Will try out your suggested solution.

Regards

Priteeranjan Nayak

Read only

0 Likes
2,259

Thanks Jorg,

for the input. for the time being it is working. will be waiting for the client to come up with any other requirement related to this. will be trying out as told by you.

Thanks

Regards

Priteeranjan Nayak

Read only

bernat_loscos
Explorer
0 Likes
2,259

Pritee, If you need more information about comparing two strings, check this link.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/content.htm

Thanks and regards !!

Read only

0 Likes
2,259

Thanks again Bernat.

Regards

Priteeranjan Nayak

Read only

Former Member
0 Likes
2,259

Hi Pritee Ranjan Nayak,

In your code you have a field  ' c_text' which contains a constant value 'DO NOT ADD TO THE OUTPUT'.

You are filling the internal table with the 4 rows of values.

I have rewritten your code  plz go through it.

REPORT  ZTEM.

types: begin of gty_itab,

        f1 type char10,

        f2 type char24,

        f3 type char10,

        end of gty_itab.

data : gt_itab type table of gty_itab,

           gw_itab type gty_itab.

constants: c_text(24) type value 'DO NOT ADD TO THE OUTPUT'.

gw_itab-f1 = '1st qtr'.

gw_itab-f2 = 'do not add to the output'.

gw_itab-f3 = 'vendor'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = '2nd qtr'.

gw_itab-f2 = 'Regular'.

gw_itab-f3 = 'customer'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = '3rd qtr'.

gw_itab-f2 = 'do not add to the output'.

gw_itab-f3 = 'vendor1'.

append gw_itab to gt_itab.

clear gw_itab.

gw_itab-f1 = '4th qtr'.

gw_itab-f2 = 'irregular'.

gw_itab-f3 = 'vendor'.

append gw_itab to gt_itab.

clear gw_itab.

loop at gt_itab into gw_itab.

translate gw_itab-f2 to upper case.

if c_text eq gw_itab-f2  .

continue.

endif.

write: / gw_itab-f1, gw_itab-f2, gw_itab-f3.

  clear gw_itab.

endloop.



Output of your code.


Hope this helps you



Regards

Rounak