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: 

Match first three character

former_member216218
Participant
0 Kudos

Hi Expert!

Kindly, need your help and guide.

I want to get customer code, customer name from KNA1 table where customer name start with 'ACP'.


I try to code as below, but, the program return wrong


TABLES: KNA1.

types:

begin of lty_kna1,

   kunnr like kna1-kunnr,

   name1 like kna1-name1,

   end of lty_kna1.

data: it_kna1 type standard table of lty_kna1 with header line.

select kunnr name1

   into table it_kna1

   from kna1 where name1 LIKE 'ACP%'.

if sy-subrc = 0.

   write:/ it_kna1-name1.

else.

   write:/ 'wrong program'.

endif.



Your help is really appreciated,


regards,

Liyana

1 ACCEPTED SOLUTION

former_member216218
Participant
0 Kudos

Hi, Everyone.

thank you for helping,

The program already success with amendment as below:

TABLES: KNA1.

types:

begin of lty_kna1,

   kunnr like kna1-kunnr,

   name1 like kna1-name1,

   end of lty_kna1.

data: it_kna1 type standard table of lty_kna1 with header line.

select kunnr name1

   into table it_kna1

   from kna1 where name1 LIKE 'ACP%'.

   write:/1  'Customer',20 'Name1'.

   LOOP AT it_kna1.

   write:/1 it_kna1-kunnr, 20 it_kna1-name1.

   ENDLOOP.


regards,

liyana

8 REPLIES 8

Former Member
0 Kudos

Hi Liyana

if you manually perform this search how many entries do you find?

Your code looks right

Regards

Arden

0 Kudos

Hi, Arden,
if manually check from table, there are 7 entries found.

reagrds,

liyana

0 Kudos

Hi Liyana

Any chance you can screen shot just the column in question, your code should really be working.

Regards

Arden

former_member185613
Contributor
0 Kudos

Hi Liyana,

The code looks fine but be aware that the LIKE statement is case sensitive. The query is fetching all the customers whose name starts with 'ACP' (all in caps) where as you may be looking for customers whose name starts with 'ACP' irrespective of the letter case.

Hope this helps,

~Athreya

Former Member
0 Kudos

Here you need to do a little change.

data : RESULT(4) type c.

CONCATENATE 'ACP' '%' INTO RESULT.

you just put result after your like clause.

select kunnr name1

   into table it_kna1

   from kna1 where name1 LIKE RESULT.

vinodkumar_thangavel
Participant
0 Kudos

Hi,

You shall try using range table and pass values as

lr_mara-sign = 'I'.

lr_mara-option = 'CP'.

lr_name-low = 'ACP*'.

finally pass this range table in the select query.

Regards,

Vinodkumar.

satvik_panchal
Participant
0 Kudos

I think 'ACP' will be your Customer code(KUNNR) and not Customer Name(NAME1). So check accordingly and write your select query.

select.....

......where kunnr like 'ACP%'..

former_member216218
Participant
0 Kudos

Hi, Everyone.

thank you for helping,

The program already success with amendment as below:

TABLES: KNA1.

types:

begin of lty_kna1,

   kunnr like kna1-kunnr,

   name1 like kna1-name1,

   end of lty_kna1.

data: it_kna1 type standard table of lty_kna1 with header line.

select kunnr name1

   into table it_kna1

   from kna1 where name1 LIKE 'ACP%'.

   write:/1  'Customer',20 'Name1'.

   LOOP AT it_kna1.

   write:/1 it_kna1-kunnr, 20 it_kna1-name1.

   ENDLOOP.


regards,

liyana