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

selecting from an internal table

Former Member
0 Likes
1,994

Can I select from an internal table? here is my code but it says WA_SCHED_DATA is not defined.

WA_SCHED_DATA[] = T_SCHED_DATA[].

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

SELECT VBELN POSNR sched_line DSDEL_DATE req_date ORDER_QTY

INTO TABLE TF_SCHED_DATA

FROM WA_SCHED_DATA

WHERE

VBELN = WA_SCHED_DATA-VBELN

POSNR = WA_SCHED_DATA-POSNR

DSDEL_DATE = WA_SCHED_DATA-REQ_DATE

SCHED_LINE NE WA_SCHED_DATA-SCHED_LINE.

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,927

Hi,

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

read table wa_sched_data with key

VBELN = LS_DATA-VBELN

POSNR = LS_DATA-POSNR

DSDEL_DATE = LS_DATA-REQ_DATE

SCHED_LINE NE LS_DATA-SCHED_LINE.

ENDIF.

endloop.

your wa_sched_data is not a database table from SAP that why it was throughing error that table not found.

select can be used to select from data base only.

if you want to read data from internal table you have to use read statements.

Thanks,

Deepak.

Message was edited by:

KDeepak

Hi,

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

read table wa_sched_data with key

VBELN = LS_DATA-VBELN

POSNR = LS_DATA-POSNR

DSDEL_DATE = LS_DATA-REQ_DATE

SCHED_LINE NE LS_DATA-SCHED_LINE.

ENDIF.

endloop.

your wa_sched_data is not a database table from SAP that why it was throughing error that table not found.

select can be used to select from data base only.

if you want to read data from internal table you have to use read statements.

Thanks,

Deepak.

Message was edited by:

KDeepak

20 REPLIES 20
Read only

Former Member
0 Likes
1,927

Hi,

Check wa_sched_data declerations.

But SELECT statements inside loop is not advisable as it will be performance issue.

You can use for all entries on internal table t_sched_data.

Thanks,

Deepak.

Read only

0 Likes
1,927

how would I do that if I need to check if the qunatity is zero?

Read only

0 Likes
1,927

What you can do is instead of selecting inside loop first select all entries and then do a read inside the loop.This is much better in terms of performance since you reduce the database hits.

If you need some more help on how to use select for all entries, let me know.

Thanks

Amruta

Read only

0 Likes
1,927

What you can do is instead of selecting inside loop first select all entries and then do a read inside the loop.This is much better in terms of performance since you reduce the database hits.

If you need some more help on how to use select for all entries, let me know.

Thanks

Amruta

Read only

Former Member
0 Likes
1,928

Hi,

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

read table wa_sched_data with key

VBELN = LS_DATA-VBELN

POSNR = LS_DATA-POSNR

DSDEL_DATE = LS_DATA-REQ_DATE

SCHED_LINE NE LS_DATA-SCHED_LINE.

ENDIF.

endloop.

your wa_sched_data is not a database table from SAP that why it was throughing error that table not found.

select can be used to select from data base only.

if you want to read data from internal table you have to use read statements.

Thanks,

Deepak.

Message was edited by:

KDeepak

Read only

0 Likes
1,927

I tried this and it doens't seem to like the very last line using NE

Read only

0 Likes
1,927

HI,

You cannot use a select statement on internal table.. use loop or read statement.

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

loop at wa_sched_data where

VBELN = LS_DATA-VBELN

POSNR = LS_DATA-POSNR

DSDEL_DATE = LS_DATA-REQ_DATE

SCHED_LINE NE LS_DATA-SCHED_LINE.

TF_SCHED_DATA-order = wa_sched_data-order.

append tf_sched_data.

ENDIF.

endloop.

Thaks

Mahesh

Read only

0 Likes
1,927

I am now but it doens't like the use of the operator 'NE'

Read only

0 Likes
1,927

use this

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

loop at wa_sched_data where

VBELN = LS_DATA-VBELN

<b>AND</b> POSNR = LS_DATA-POSNR

<b>AND</b> DSDEL_DATE = LS_DATA-REQ_DATE

<b>AND</b> SCHED_LINE NE LS_DATA-SCHED_LINE.

TF_SCHED_DATA-order = wa_sched_data-order.

append tf_sched_data.

ENDIF.

endloop.

Read only

0 Likes
1,927

OKAY i THINK I GET THIS BUT WHAT IS THE FINAL STATEMTN DOING.

TF_SCHED_DATA-order = wa_sched_data-order.

append tf_sched_data.

Read only

0 Likes
1,927

I am trying to put the data into the internal table TF_SCHED_DATA which ever mathces the criteria.

you want to fill this table fields with the required data na..

so

TF_SCHED_DATA-vbeln = wa_sched_data-vbeln.

tf_sched_data-posnr = wa_sched_Data-posnr.

append TF_SCHED_DATA.

Thanks

Mahesh

Read only

0 Likes
1,927

does this make sense what i ma doing?

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

LOOP at wa_sched_data INTO WS_DATA

where

VBELN = LS_DATA-VBELN

AND POSNR = LS_DATA-POSNR

AND DSDEL_DATE = LS_DATA-REQ_DATE

AND SCHED_LINE NE LS_DATA-SCHED_LINE.

APPEND WS_DATA TO tf_sched_data.

  • TF_SCHED_DATA-order = wa_sched_data-order.

append WS_DATA TO tf_sched_data.

ENDLOOP.

ENDIF.

*

ENDLOOP.

Read only

0 Likes
1,927

Yes it does. provided ws_data and tf_sched_data are of same structure...

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

LOOP at wa_sched_data INTO WS_DATA

where

VBELN = LS_DATA-VBELN

AND POSNR = LS_DATA-POSNR

AND DSDEL_DATE = LS_DATA-REQ_DATE

AND SCHED_LINE NE LS_DATA-SCHED_LINE.

APPEND WS_DATA TO tf_sched_data.

ENDLOOP.

ENDIF.

*

ENDLOOP.

Thanks

Mahesh

Read only

0 Likes
1,927

nothing is in ws_data when i debug so what could be worng? wa_sched_data is loaded

Read only

0 Likes
1,927

there may not be the data in table wa_sched_data with this where condition..

check the two internal tables T_SCHED_DATA INTO and wa_sched_data . and also may be the case that the LS_DATA-ORDER_QTY is greater than zero all the time...

loop at <b>T_SCHED_DATA</b> INTO LS_DATA.

IF <b>LS_DATA-ORDER_QTY = 0.</b>

LOOP at wa_sched_data INTO WS_DATA

where

<b>VBELN = LS_DATA-VBELN

AND POSNR = LS_DATA-POSNR

AND DSDEL_DATE = LS_DATA-REQ_DATE

AND SCHED_LINE NE LS_DATA-SCHED_LINE.</b>

APPEND WS_DATA TO tf_sched_data.

ENDLOOP.

ENDIF.

*

ENDLOOP.

Read only

0 Likes
1,927

you keep using LS_data below. is that correct

VBELN = LS_DATA-VBELN

AND POSNR = LS_DATA-POSNR

AND DSDEL_DATE = LS_DATA-REQ_DATE

AND SCHED_LINE NE LS_DATA-SCHED

Read only

0 Likes
1,927

Yes it is... is this not ur requirement that for each record in t_sched_data table if the quantity is eq 0 then select the records from the table wa_sched_data where the order item date and schedule line matches.

check the order_qty field value in the internal table t_sched_data this could be the case that if order_qty is not equal to 0 then the second loop will not exeucte...

do one think put a break point at the second loop and see if it triggers .. if you reach that point it indicates u have atlease one record whose quanity is equla to 0 then see the values in the wa_sched_data table and the ls_data ..

loop at T_SCHED_DATA INTO LS_DATA.

IF LS_DATA-ORDER_QTY = 0.

LOOP at wa_sched_data INTO WS_DATA

where

VBELN = LS_DATA-VBELN

AND POSNR = LS_DATA-POSNR

AND DSDEL_DATE = LS_DATA-REQ_DATE

AND SCHED_LINE NE LS_DATA-SCHED_LINE.

APPEND WS_DATA TO tf_sched_data.

ENDLOOP.

ENDIF.

ENDLOOP.

Read only

0 Likes
1,927

yes records were found = 0 but the line belwo doesn nothing. Nothing is in ws_data

LOOP at wa_sched_data INTO WS_DATA

Read only

0 Likes
1,927

it clearly indicates that wa_sched_data does not have any matching data from ls_data...

Thanks

mahesh

Read only

Former Member
0 Likes
1,927

thanks to all