‎2012 May 23 1:38 AM
Hello All,
I have an internal table with one field that contains the name of all the customers and the name can be in lower case, upper case or a mix of both, now I need to read this table into another table for all the names those have the word 'DEPARTMENT'. So if there are entries in the internal table like IT_DEPARTMENT or it_department or It_Department then all these should show up when I read my internal table.
I tried the below code but it's not correct :
read table it_data into wa_data with TABLE KEY name CO 'DEPARTMENT'
if sy-subrc = 0.
append wa_data to it_final_data.
CLEAR wa_data.
endif.
can you please help me this.
Thanks.
‎2012 May 23 2:26 AM
Hi,
Try to loop in it_data and append the matching records which has DEPARTMENT in customer field using Contains Pattern(CP).
Ex:-
TYPES : BEGIN OF ty_itab,
kunnr TYPE c LENGTH 20,
END OF ty_itab.
DATA : i_itab TYPE STANDARD TABLE OF ty_itab,
i_itab1 TYPE STANDARD TABLE OF ty_itab,
wa_itab TYPE ty_itab,
v_kunnr TYPE c LENGTH 20.
wa_itab-kunnr = 'it_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'It_Department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'lt_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'Nt_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'Ot_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'Bala Krishna'.
APPEND wa_itab TO i_itab.
SORT i_itab.
LOOP AT i_itab INTO wa_itab.
v_kunnr = wa_itab-kunnr.
TRANSLATE v_kunnr TO UPPER CASE.
IF v_kunnr CP '*DEPARTMENT'.
APPEND wa_itab TO i_itab1. " you will have only records with customer with DEPARTMENT
ENDIF.
CLEAR : v_kunnr, wa_itab.
ENDLOOP.
*Note If for some customers other texts exists after 'Department' use '*DEPARTMENT*', just click F1 on CP option, it will list you all the available options on that.
Thanks & Regards
Bala Krishna
‎2012 May 23 2:26 AM
Hi,
Try to loop in it_data and append the matching records which has DEPARTMENT in customer field using Contains Pattern(CP).
Ex:-
TYPES : BEGIN OF ty_itab,
kunnr TYPE c LENGTH 20,
END OF ty_itab.
DATA : i_itab TYPE STANDARD TABLE OF ty_itab,
i_itab1 TYPE STANDARD TABLE OF ty_itab,
wa_itab TYPE ty_itab,
v_kunnr TYPE c LENGTH 20.
wa_itab-kunnr = 'it_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'It_Department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'lt_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'Nt_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'Ot_department'.
APPEND wa_itab TO i_itab.
wa_itab-kunnr = 'Bala Krishna'.
APPEND wa_itab TO i_itab.
SORT i_itab.
LOOP AT i_itab INTO wa_itab.
v_kunnr = wa_itab-kunnr.
TRANSLATE v_kunnr TO UPPER CASE.
IF v_kunnr CP '*DEPARTMENT'.
APPEND wa_itab TO i_itab1. " you will have only records with customer with DEPARTMENT
ENDIF.
CLEAR : v_kunnr, wa_itab.
ENDLOOP.
*Note If for some customers other texts exists after 'Department' use '*DEPARTMENT*', just click F1 on CP option, it will list you all the available options on that.
Thanks & Regards
Bala Krishna
‎2012 May 23 2:51 AM
Hi Bala,
Thanks a lot for the reply and it works. I I have another can I do something same with the select statement. Can I select the data from table KNA1...and the scenario is still the same that I listed above.
‎2012 May 23 3:29 AM
Hi,
Yes, you can use LIKE operator in WHERE clause.
SELECT kunnr
FROM kna1
INTO TABLE i_itab
WHERE kunnr LIKE '%115'.
SAP help on Select
Comparing Strings
To find out whether the value of a column matches a pattern, use:
SELECT ... WHERE <s> [NOT ] LIKE <f> [ESCAPE <h>] ...
The condition is true if the value of the column <s> matches [does not match] the pattern in the data object <f>. You can only use this test for text fields. The data type of the column must be alphanumeric. <f> must have data type C.
You can use the following wildcard characters in <f>:
For example, ABC_EFG% matches the strings ABCxEFGxyz and ABCxEFG, but not ABCEFGxyz. If you want to use the two wildcard characters explicitly in the comparison, use the ESCAPE option. ESCAPE <h> specifies an escape symbol <h>. If preceded by <h>, the wildcards and the escape symbol itself lose their usual function within the pattern <f>. The use of _ and % corresponds to Standard SQL usage. Logical expressions elsewhere in ABAP use other wildcard characters (+ and *).
Thanks & Regards
Bala Krishna
‎2012 May 23 3:52 AM
You can use
SELECT name1 from Kna1 into table lt_kna1 where name CS 'department'.
The CS operator is not Case sensitive.
‎2012 May 23 4:06 AM
When I tried using operator CS I got this error message:
'CS' is not a valid comparison operator
‎2012 May 23 4:14 AM
You cannot use 'CS' or 'CP' etc in SELECT statements, have you tries with LIKE statement which i gave in my last post.
‎2012 May 23 4:25 AM
Hi,
Sorry for misleading.
We cannot use CS and I dont beleive LIKE will solve your issue here.
LIKE is case sensitive.
You can use
SELECT name1 from Kna1 into table lt_kna1 where name1 LIKE '%department%' or name1 like '%Department%'. IF these are the only two combinations.
If you have multiple combinations like DePartMent, then this will not work.
You can use native sql to solve this or select all the entries and then eliminate the entries as told in the first question.
Check some posts on Case insensitive select queries.
‎2012 May 23 3:12 PM
Depending on your database, you may be able to use native SQL to SELECT data regardless of case.
Rob
‎2012 May 23 4:42 PM
If you need to match more strict format checking you can use find instead, with regex and ignoring case addition.
Regular Expressions are just too powerful.
‎2012 May 23 7:58 AM
For time being convert the internal table value to upper case and also the comparing value to upper case. Then loop and check it using CP *DEPARTMENT*
‎2012 May 23 11:58 AM
in select queries you can't use, CP CS CO etc. just translate everything in the internal table to upper case and then check for the pattern. If that matches the pattern move it to the another table.
‎2012 May 23 4:59 PM