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

LOOP and Read statements

Former Member
0 Likes
513

Hi abapers,

I want to know the difference between statements.

SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAKT.

SELECT EBELN EBELP ... ..... ..... FROM EKPO INTO IT_EKPO WHERE MATNR = IT_MAKT-MATNR.

1st statement

LOOP AT IT_MAKT INTO WA_MAKT.

READ TABLE IT_EKPO INTO WA_EKPO WITH KEY MATNR = IT_MAKT-MATNR.

2ND Statement

LOOP AT IT_EKPO INTO WA_EKPO.

READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = IT_EKPO-MATNR.

Frnds , can anyone please help me to understand the exact difference between the above statements.

Thanks,

satish

3 REPLIES 3
Read only

Former Member
0 Likes
441

Hi,

SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAKT.

collects matnr and maktx form makt and stores in it_makt

SELECT EBELN EBELP ... ..... ..... FROM EKPO INTO IT_EKPO WHERE MATNR = IT_MAKT-MATNR.

endselect.

selects ebeln and ebelp from ekpo and stores in it_ekpo

1st statement

LOOP AT IT_MAKT INTO WA_MAKT.

READ TABLE IT_EKPO INTO WA_EKPO WITH KEY MATNR = IT_MAKT-MATNR.

endloop.

looping at it_makt compares matnr from it_makt with it_ekpo. reads and stores in work area wa_makt with primary key as index

2ND Statement

LOOP AT IT_EKPO INTO WA_EKPO.

READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = IT_EKPO-MATNR.

endloop.

looping at it_ekpo compares matnr from it_makt with it_ekpo . reads and stores in work area wa_ekpo with primary key as index

regards

Read only

harimanjesh_an
Active Participant
0 Likes
441

hi satish,

Both the statements results the same.

Basic difference is u r looping at different tables.........

In the first loop, u r selecting the Material Description based on Purchase Order Material.

In the second Loop, u r selecting the PO based on if its Material description is available or not...

Basically both loop statements results in same.

Reward me if useful..........

Harimanjesh AN

Read only

Former Member
0 Likes
441

Hi,

Both the statements will yield the same results.

I think should be this way....

1st statement

<b>LOOP AT IT_MAKT INTO WA_MAKT.

READ TABLE IT_EKPO INTO WA_EKPO WITH KEY MATNR = wa_MAKT-MATNR.</b>

<u>NOT</u>

1st statement

LOOP AT IT_MAKT INTO WA_MAKT.

READ TABLE IT_EKPO INTO WA_EKPO WITH KEY MATNR = IT_MAKT-MATNR.

Similarly for the same other statement also.

1.You are looping the MAKT table into workarea

2. And the reading the EKPO table into workarea with the key field.

Here both the statements infer same meaning.

Regards,

Vani.