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 while reading internal table

Former Member
0 Likes
7,949


Hi All,

I have an internal table which has consolidated records from several tables.

Now I want to READ only those records where the coloumn : OBJNR starts with ZZ.

Now, we cannot use LIKE 'ZZ*' in READ statements like we can use in SELECT statements.

Other option for me is using offset.

READ t_itab into w_itab.

     if w_itab-objnr+0(2) eq 'ZZ'.

something like this.

IS there any other better way?

REgards,

Faiz

11 REPLIES 11
Read only

ramakrishnappa
Active Contributor
0 Likes
2,812

Hi,

Use LOOP & CP ( contains pattern ) statements as below


LOOP AT t_tab INTO w_itab WHERE objnr CP  'ZZ*'.

" Here you can collect into other internal table, or exit if u need only 1 record

ENDLOOP.

Hope this helps you.

Regards,

Rama

Read only

0 Likes
2,812

This will fetch all those records which contain the substring 'ZZ' at any position in the string.In my case it should be right at the beginning .I will try 'ZZ*' .

Read only

0 Likes
2,812

Hi,

as suggested in my previous reply, it gets you all records which starts from ZZ......

Example:

let us say internal table is having records as below

ZZ123

ZX123

ZY123

ZZ222

ZX222

ZY222

Now,

LOOP AT t_tab INTO w_itab WHERE objnr CP  'ZZ*'.

" we get only ZZ123 & ZZ222


ENDLOOP

.

Regards,

Rama

Read only

0 Likes
2,812

Hi  , thanks for your answer, but i have a doubt ..  what will happen if suppose column name is AAZZBBC? , it will consider it or not ? can you clarify me please?

Read only

0 Likes
2,812

Hi Karthi,


Karthi Mrvk wrote:

what will happen if suppose column name is AAZZBBC? , it will consider it or not ? can you clarify me please?

Well, if your column contains a value AAZZBBC, it will not consider this record as we are looking for only ZZ*....

To consider your value we need to be like this AA* or *ZZ*

Regards,

Rama

Read only

matt
Active Contributor
0 Likes
2,812

Why not write a test program and see what happens?

Read only

arivazhagan_sivasamy
Active Contributor
0 Likes
2,812

Hi Faizur,

LOOP AT t_tab INTO w_itab WHERE objnr CP  'ZZ*'  from 1 to 1.


endloop.


Now you will get only one record.


Arivazhagan S

Read only

0 Likes
2,812

WRONG FOR TWO REASONS!

1. The syntax should be LOOP AT t_tab INTO w_itab FROM 1 TO 1 WHERE objnr CP 'ZZ*'.

2. Unless the first record begins ZZ, you'll get nothing.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,812

You could use a READ TABLE on partial value (here ZZ) and then a LOOP, exit when no longer leading 'ZZ'. (cf. attached sample) you will be required to use a sorted type table or to sort the table to use a binary-search implicitly or explicitly.

Regards,

Raymond

Read only

Former Member
0 Likes
2,812

hi Faizur,

LOOP t_itab into w_itab.

  FIND ALL OOCUREENCES OF REGEX 'ZZ*'

          IN w_itab-objnr

          MATCH OFFSET moff.

  if moff eq 0.

  .....

 

ENDLOOP.

Another way is move all objnr data to it_itab that only have one field 'OBJNR'.

FIND ALL OOCURRENCES OF REGEX 'ZZ*'

        IN TABLE it_itab

        RESULTS result_tab.

the result_tab is what you wanted, which start will 'ZZ'.

regards,

Archer

Read only

ThangaPrakash
Active Contributor
2,812

Use CP (Contains pattern)