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

Select Statement

Former Member
0 Likes
1,277

Hello Friends,

I am having some problem in this select statement and

I dont want to use Loop..Endloop.

I have to extract from COBRB table based on OBJNR and am using for all entries on T_COSS table.

I want to extract everything from COBRB where the first 12 characters of OBJNR are in same as T_COSS-PAROB.

Here is the select statement I am using and its not working.

      SELECT * FROM COBRB
   APPENDING TABLE T_COBRB
         FOR ALL ENTRIES IN T_COSS
       WHERE OBJNR = T_COSS-PAROB+0(12)%.

ANy Suggestions,

Ster

1 ACCEPTED SOLUTION
Read only

former_member187255
Active Contributor
0 Likes
1,228

Ster,

Can you try this......

    
CONCATENATE T_COSS-PAROB+0(12) '%' INTO L_OBJNR.

SELECT * FROM COBRB
   APPENDING TABLE T_COBRB
         FOR ALL ENTRIES IN T_COSS
       WHERE OBJNR LIKE L_OBJNR.

Hope this helps..

Chandra.

11 REPLIES 11
Read only

Former Member
0 Likes
1,228

Ster,

Good!

whats the message its giving?

Read only

0 Likes
1,228

Its not selecting the data. However it selecting only one row.

Ster

Read only

Former Member
0 Likes
1,228

Hi,

do like this

SELECT * FROM COBRB

INTO TABLE T_COBRB

FOR ALL ENTRIES IN T_COSS

WHERE OBJNR = T_COSS-PAROB+0(12).

for performane provide field names instead of *.

<b>Reward for helpful answers</b>

Satish

Read only

Former Member
0 Likes
1,228

do like this.

if T_COSS[] is not initial.

SELECT * FROM COBRB

into TABLE T_COBRB

FOR ALL ENTRIES IN T_COSS

WHERE OBJNR = T_COSS-PAROB+0(12).

endif.

Read only

0 Likes
1,228

Satish, Sreejith.

Objnr is not a 12 character field. I need to do a comparison only for the first 12 fields in both the tables.

Ster

Read only

Former Member
0 Likes
1,228

Hi

here you are using both Offsetting of a field as well as % parameter which is separately used with LIKE word in where clause of the select.

use any one of them

use Objnr = T_COSS-PAROB+0(12). or

objnr like 'ORD000%'.

generally we use KOSTL cost center for fetching data and for all entries of that CORB entries we fetch data from COEP or COSP

see sample code

clear cobrb_tab.

refresh cobrb_tab.

select objnr " Object No

rec_objnr1 " Ref Object No

bureg " Dostribution Rule

lfdnr " Sequence No

perbz " Settlement Rule

konty " Acct Assign Category

bukrs " Company Code

kostl " Cost Center

into table cobrb_tab

from cobrb

where kostl in rn_kostl.

sort cobrb_tab by objnr rec_objnr1.

delete adjacent duplicates from cobrb_tab comparing objnr.

  • Get the Settlement Costs from COEP Table

clear it_set_tab.

refresh it_set_tab.

if not cobrb_tab[] is initial.

select kokrs " Controlling Area

belnr " Acc Document

buzei " Line Item

perio " Period Block

wkgbtr " Value in CO Curr

lednr " Ledger No

objnr " Object No

gjahr " Fiscal Year

wrttp " Actuals

versn " Version

kstar " Cost Element

beknz " Dr/Cr Indicator

parob1 " Partner Object

into table it_set_tab

from coep

for all entries in cobrb_tab

where lednr = c_lednr and

wrttp = c_wrttp2 and

versn = c_versn and

gjahr = p_gjahr and

objnr = cobrb_tab-objnr and

parob1 = cobrb_tab-rec_objnr1 and

beknz in (c_o, c_a).

endif.

Regards

Anji

Read only

0 Likes
1,228

Thanks Anji,

use Objnr = T_COSS-PAROB+0(12). I cant use the above statement as OBJNR is not a 12 char field.

Ster

Read only

ferry_lianto
Active Contributor
0 Likes
1,228

Hi,

Please try this.


SELECT * FROM COBRB
FOR ALL ENTRIES IN T_COSS
WHERE OBJNR = T_COSS-PAROB.

  IF COBRB-OBJNR(12) = T_COSS-PAROB(12). 
    MOVE COBRB TO T_COBRB.
    APPEND T_COBRB.
  ENDIF.

ENDSELECT.

Regards,

Ferry Lianto

Read only

former_member187255
Active Contributor
0 Likes
1,229

Ster,

Can you try this......

    
CONCATENATE T_COSS-PAROB+0(12) '%' INTO L_OBJNR.

SELECT * FROM COBRB
   APPENDING TABLE T_COBRB
         FOR ALL ENTRIES IN T_COSS
       WHERE OBJNR LIKE L_OBJNR.

Hope this helps..

Chandra.

Read only

0 Likes
1,228

Thanks Everyone.

This is how i got it resolved.

LOOP AT T_COSS.

CONCATENATE T_COSS-PAROB+0(12) '%' INTO L_OBJNR.

        SELECT * FROM COBRB
     APPENDING TABLE T_COBRB
         WHERE OBJNR LIKE L_OBJNR
           AND ( ( ( ERSJA GE V_YEAR_2 AND ERSJA LE V_YEAR_0 )
                OR ( LETJA GE V_YEAR_2 AND LETJA LE V_YEAR_0 ) )
            OR      ( ERSJA LE V_YEAR_2 AND LETJA GE V_YEAR_0 ) )
           AND KOSTL IN S_KOSTL
           AND KONTY = 'KS'.

      ENDLOOP.

Ster

Read only

ferry_lianto
Active Contributor
0 Likes
1,228

Hi Ster,

You said earlier you don't want to use Loop .. Endloop.

But your final solution is using loop

Regards,

Ferry Lianto