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
839

Hi All!

I just start to learn ABAP ...so this question maybe is not difficult but I didn't find an answer on my own. I have the ABAP code:

.....

SELECT AVBELN AFKART AVKORG AVTWEG AKKBER ASPART

AKUNAG AFKDAT AERNAM AERZET B~WERKS

INTO table IT_VBRK

FROM VBRK AS A INNER JOIN

VBRP AS B ON

AVBELN = BVBELN

WHERE FKDAT = DATAF.

SORT IT_VBRK BY VBELN.

LOOP AT IT_VBRK.

AT NEW VBELN.

WRITE : /5 IT_VBRK-VBELN , IT_VBRK-FKDAT , IT_VBRK-FKART .

ENDAT.

AT END OF VBELN.

ENDAT.

ENDLOOP.

......

And the result is:

.........

90080973 *..*** ****

90080974 *..*** ****

90080975 *..*** ****

.........

Why the system don't write the date and the type of the invoices? It's something wrong with the SELECT statement?

Thank you very much.

Florina

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
813

Hi Florina,

Your select is Good.

The Culprit is the at new statement.

you should read the internal table immediatley after a at new statement.

SORT IT_VBRK BY VBELN.

LOOP AT IT_VBRK.

AT NEW VBELN.

<b>read table it_vbrk index sy-tabix.</b>

WRITE : /5 IT_VBRK-VBELN , IT_VBRK-FKDAT , IT_VBRK-FKART .

ENDAT.

AT END OF VBELN.

ENDAT.

ENDLOOP.

Make the highlighted change.

Regards,

Ravi

10 REPLIES 10
Read only

Former Member
0 Likes
813

Why the system don't write the date and the type of the invoices? It's something wrong with the SELECT statement?

There is nothing wrong with the select statement..it is due to the control statement AT NEW.

Basically, the way AT NEW event works is that it asteriks all the fields to the right of the defined field. So in your case AT NEW VBELN all the fields to the right of VBELN in the internal table are replaced be asterix. To get the value you can initialise another field string similar to itab and move that before AT event and you can use the values from field strings.

Message was edited by: Anurag Bankley

Read only

Former Member
0 Likes
814

Hi Florina,

Your select is Good.

The Culprit is the at new statement.

you should read the internal table immediatley after a at new statement.

SORT IT_VBRK BY VBELN.

LOOP AT IT_VBRK.

AT NEW VBELN.

<b>read table it_vbrk index sy-tabix.</b>

WRITE : /5 IT_VBRK-VBELN , IT_VBRK-FKDAT , IT_VBRK-FKART .

ENDAT.

AT END OF VBELN.

ENDAT.

ENDLOOP.

Make the highlighted change.

Regards,

Ravi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
813

The effect is coming from the AT NEW statement, you can get around it by doing this. Define a wa, and move the line into it before the AT NEW, and use the WA to write out the data.

<b>data: wa_vbrk like line of it_vbrk.</b>

LOOP AT IT_VBRK.

<b>wa_vbrk = it_vbrk.</b>

AT NEW VBELN.

<b>WRITE : /5 wa_VBRK-VBELN , wa_VBRK-FKDAT , wa_VBRK-FKART .</b>

ENDAT.

AT END OF VBELN.

ENDAT.

ENDLOOP.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Read only

0 Likes
813

Thank you all!

Maybe was a stupid question but asking stupid question I'm learning .

I hope I didn't offend you ;).

Thanks again.

Florina

Read only

0 Likes
813

"There are no stupid questions. There are only questions"-- Anonymous

Read only

0 Likes
813

Floirna, Ravi's answer may work, but you are then reading the same internal table line twice. This is not a good thing, in my example, you are only reading the line once. This will be important when performance is an issue.

Regards,

Rich Heilman

Read only

0 Likes
813

Thank you.

There is an transaction to measure the report performance?

Florina

Read only

0 Likes
813

Yes .

se30 is the tcode for performance analysis of programs.

regards,

ravi

Read only

0 Likes
813

Transaction SE30.

Regards,

Rich Heilman

Read only

0 Likes
813

Thank you again all of you!

Best regards,

Florina