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

Using offsets in a select

Former Member
0 Likes
1,853

Do you know if i can use offests in a select? It doens't want to pull back the infromations. Here is my select.

SELECT BELNR KOKRS BUZEI GJAHR EBELN EBELP

INTO TABLE T_COEP

FROM COEP

FOR ALL ENTRIES IN T_ICORDCSTA1

WHERE BELNR = T_ICORDCSTA1-BELNR

AND KOKRS = T_ICORDCSTA1-KOKRS

AND BUZEI = T_ICORDCSTA1-BUZEI

AND GJAHR = T_ICORDCSTA1-FISCPER+0(4).

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,738

Hi

Yes you can! But I'm not sure it can do it if it uses FOR ALL ENTRIES because this option doesn't use the header line of the internal table.

Max

18 REPLIES 18
Read only

Former Member
0 Likes
1,738

Hi,

You can you the offset in the select statment,

<b>SELECT BELNR KOKRS BUZEI GJAHR EBELN EBELP
INTO TABLE T_COEP
FROM COEP
FOR ALL ENTRIES IN T_ICORDCSTA1
WHERE BELNR = T_ICORDCSTA1-BELNR
AND KOKRS = T_ICORDCSTA1-KOKRS
AND BUZEI = T_ICORDCSTA1-BUZEI
AND GJAHR = T_ICORDCSTA1-FISCPER+0(4).</b>

The code is ok, but make sure that the field is not having anyu conversion routine and gives the correct value when you use the offset

Regards

Sudheer

Read only

0 Likes
1,738

From what I have been gathering I can' use it with a for all entry

Read only

Former Member
0 Likes
1,739

Hi

Yes you can! But I'm not sure it can do it if it uses FOR ALL ENTRIES because this option doesn't use the header line of the internal table.

Max

Read only

0 Likes
1,738

Yes it gives me the following warning when I do a syntax check which i don't know what it means or how to fix.

Bei der Verwendung von FOR ALL ENTRIES wird die Längenangabe für

"FISCPER" in dieser Bedingung ignoriert.

Read only

0 Likes
1,738

HI,

that means the field FISCPER is unable to access the condition and it is ignoring.

my suggestion is use loop and endloop..

<b>Loop at T_ICORDCSTA1.

SELECT BELNR KOKRS BUZEI GJAHR EBELN EBELP

INTO TABLE T_COEP

FROM COEP

WHERE BELNR = T_ICORDCSTA1-BELNR

AND KOKRS = T_ICORDCSTA1-KOKRS

AND BUZEI = T_ICORDCSTA1-BUZEI

AND GJAHR = T_ICORDCSTA1-FISCPER+0(4).

Endloop.</b>

REgards

SAB

Read only

0 Likes
1,738

IT SAYS IT HAS NO HEADER LINE DEFINED.

Read only

0 Likes
1,738

I think it should be:


APPENDING TABLE T_COEP

Rob

Read only

0 Likes
1,738

You'll have to loop at the table into a work area and use the work area for the SELECT.

Rob

Read only

0 Likes
1,738

So just create a work area of type table and then use my offset there? i am not sure i follow

Read only

0 Likes
1,738

No - not of type table. You need to loop at the table into something the SELECT statement can use.

Rob

Read only

0 Likes
1,738

Like:


DATA wa_icordcsta1 type icordcsta1.

LOOP AT t_icordcsta1 INTO wa_icordcsta1.

  SELECT belnr kokrs buzei gjahr ebeln ebelp
    APPENDING TABLE t_coep
    FROM coep
    WHERE belnr = wa_icordcsta1-belnr
      AND kokrs = wa_icordcsta1-kokrs
      AND buzei = wa_icordcsta1-buzei
      AND gjahr = wa_icordcsta1-fiscper+0(4).

ENDLOOP.

Rob

Read only

0 Likes
1,738

HI Mick,

follow the way as Rob given... i was not sure that u r using Occurs for ur internal table or not.. u need to provide work area to append in t_coep.

or if u use itab like........

<b>Data T_ICORDCSTA1 like ICORDCSTA1 occurs 0 with header line.

Loop at T_ICORDCSTA1.

SELECT BELNR KOKRS BUZEI GJAHR EBELN EBELP

INTO TABLE T_COEP

FROM COEP

WHERE BELNR = T_ICORDCSTA1-BELNR

AND KOKRS = T_ICORDCSTA1-KOKRS

AND BUZEI = T_ICORDCSTA1-BUZEI

AND GJAHR = T_ICORDCSTA1-FISCPER+0(4).

Endloop.</b>

<b>

Reward to all Helpful answers........</b>

<b>

Reward to all Helpful answers........</b>

Regards

SAB

Read only

0 Likes
1,738

I got most to work but now there is someting wrong with the following statement where i do a read into w_coep

IF NOT T_COEP IS INITIAL.

READ TABLE T_COEP INTO W_COEP

WITH KEY BELNR = W_ICORDCSTA1-BELNR

KOKRS = W_ICORDCSTA1-KOKRS

BUZEI = W_ICORDCSTA1-BUZEI

GJAHR = W_ICORDCSTA1-FISCPER+0(4)

BINARY SEARCH.

  • FILL FIELDS WITH DATA FROM COEP (CO OBJECT LINE ITEMS TABLE)

IF SY-SUBRC = 0.

W_ICORDCSTA1-ZZ_PURCHORD1 = W_COEP-EBELN.

W_ICORDCSTA1-ZZ_PURORDLI1 = W_COEP-EBELP.

MODIFY T_ICORDCSTA1 FROM W_ICORDCSTA1 INDEX L_TABIX.

CLEAR W_ICORDCSTA1.

ENDIF.

ENDIF.

CLEAR W_COEP.

CLEAR W_ICORDCSTA1.

ENDLOOP.

ENDIF.

REFRESH C_T_DATA.

C_T_DATA[] = T_ICORDCSTA1[].

REFRESH T_COEP.

FREE T_COEP.

FREE T_ICORDCSTA1.

Read only

0 Likes
1,738

Hello,

Are U sorting the fields of the table T_COEP liike

<b>SORT T_CEOP BY KOKRS BUYEI GJAHR</b>

Check this.

Vasanth

Read only

0 Likes
1,738

This is a different question. Why don't you mark this thread as answered and open a new thread for the new question?

Rob

Read only

0 Likes
1,738

Okay thanks. I just did that. I noticed that even though my talbes are the same the fiedls being moved in are not correct. Like it is shiftled over

Read only

Former Member
0 Likes
1,738

Hi Mick,

The query should still work. U can use offset like that. I think you are not getting year offset in T_ICORDCSTA1-FISCPER correctly.

Just debug the program before executing select query to find the value T_ICORDCSTA1-FISCPER in T_ICORDCSTA1 and see how the value is stored in the field and make changes accordingly in your query.

Cheers,

Vikram

Mark for helpful replies!!

Read only

0 Likes
1,738

It gives me the error above so it will not work