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

String Comparison with selection-options

Former Member
0 Likes
1,069

Hi,

I am now developing a program which needs comparison to string. There are several checkbox on the selection screen, when the checkbox is checked, data contains certain string needed to pass the authority checking. Here are my codes:

NOTE: data type : lifnr_c type c(10).

  if ( P_402 = 'X' and inven_data-lifnr_c CS '402' )  or
     ( P_403 = 'X' and inven_data-lifnr_c CS '403' ) or  
     ( P_410 = 'X' and inven_data-lifnr_c CS '410' ).
       allow = 'X'.
  endif.

First of all, does the code correct syntax-wise?

Also, I am sure there are some data contains '402', '403' or '410', however, I can get no result in this case, what will be possible errors?

Thanks,

Regards,

Mandy

8 REPLIES 8
Read only

Former Member
0 Likes
1,025

Hi,

Syntax wise the code is correct.

if ( P_402 = 'X' and inven_data-lifnr_c CS '402' )  or
     ( P_403 = 'X' and inven_data-lifnr_c CS '403' ) or  
     ( P_410 = 'X' and inven_data-lifnr_c CS '410' ).
       allow = 'X'.
  endif.

Here for two condition you have put AND operator so both should be true, in any of the three conditions. Then only you will get result. For eg: suppose inven_data-lifnr_c CS '402' is true and checkbox you have selected is P_410. Then no result will come. Check in debugging.

Try like below also.

if ( P_402 = 'X' and inven_data-lifnr_c CS '402 ' )  or
     ( P_403 = 'X' and inven_data-lifnr_c CS '403 ' ) or  
     ( P_410 = 'X' and inven_data-lifnr_c CS '410 ' ).
       allow = 'X'.
  endif.

If this is not working, try with string operator CP. Check this [link |http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/content.htm] for more details.

if ( P_402 = 'X' and inven_data-lifnr_c CP '*402* ' )  or
     ( P_403 = 'X' and inven_data-lifnr_c CP '*403*' ) or  
     ( P_410 = 'X' and inven_data-lifnr_c CP '*410*' ).
       allow = 'X'.
  endif.

Read only

0 Likes
1,025

I have tried, but both doesn't work.

Read only

Former Member
0 Likes
1,025

Hi Mandy,

the issue may be caused by field inven_data-lifnr ! What is the content of the field while debugging your code ? Is inven_data a structure or the header line of an internal table ?

Regards,

Klaus

Read only

0 Likes
1,025

Dear Klaus,

The INVEN_DATA is declare as follow:

INVEN_DATA type ZABC occurs 0 with header line,

While ZABC is the customized table.

When runniing the debug mode the data type : char (10)

value '0000004021', '0000004031' or '0000004101'

Regards,

Mandy

Edited by: Mandy Au on Oct 10, 2011 10:01 AM

Read only

0 Likes
1,025

Hi Mandy,

this look fine. What is the exact definition of your P_402, P_403 and P_403 parameters.

Are they type FLAG or c(1) ? Are they defines as checkbox ?

While debugging, which one is marked, or do you mark all of them ?

Regards,

Klaus

Read only

0 Likes
1,025

Dear Klaus,

All are checkbox:

PARAMETERS: p_datum type sy-datum default sy-datum OBLIGATORY ,
            p_402   AS CHECKBOX DEFAULT 'X',
            p_403   AS CHECKBOX DEFAULT 'X',
            p_410   AS CHECKBOX DEFAULT 'X'.

All parameters return 'X' when the program is run.

Regards,

Mandy

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,025

Hello Mandy,

In which event have you written this IF ... ENDIF block? (For e.g., AT SELECTION-SCREEN, START-OF-SELECTION etc.)

Also in your code you're accessing the header-line of the internal table, are you looping on the internal table as well?

BR,

Suhas

PS: Avoid using internal table with HEADER LINE!

Read only

0 Likes
1,025

Dear Suhas,

This is the process after all selection ends.

After the END-OF-SELECTION.

I know, however, this is some enhancement that I have no choice but an intenral table with header line. >.<

Regards,

Mandy