A simple example of an ABAP report

Source: Internet
Author: User

ABAP report development instance.
Here is an example to illustrate the simple process of developing a report for ABAP. We do not discuss the correctness or rejection of the program. We only care about the compiling process of the program.
First, at the beginning of any program, we need to determine the tables that will be used. The procedure we are talking about is to check whether the purchase order has been completed. The following three tables are used: Ekko, Ekpo, and eket. The program starts with report test.
Tables: Ekko, eket, Ekpo.
Now we have defined the table to be used. The next step is to define the internal table and data. The internal table is used to store the data we have queried from the preceding three tables. Data: Begin of itab occurs 0, ebeln like EKKO-EBELN, menge like EKPO-MENGE, wemng like EKET-WEMNG, end of itab.
Now we have defined the inner table itab. Next we should define the data. Data is like a constant in C. Its definition is as follows:
Data: matnr like the EKPO-MATNR, menge like EKPO-MENGE, wemng like EKET-WEMNG, ebeln like EKPO-EBELN.
Here we have defined both the data used in the program and the internal table. Next, we need to select the screen. The so-called screen selection refers to the content you want to input from the screen when the program is running. For example, when a program is running, you can enter a material number to get the current inventory quantity of the material. Then you need to write a screen for the queryer to enter the query conditions. The related definitions are as follows: select-options: ebeln1 for EKKO-EBELN, bedat for EKKO-BEDAT,

Ekgrp for EKKO-EKGRP. parameters: r1 radiobutton group Radi, R2 radiobutton group Radi, R3 radiobutton group Radi.
Now that we have completed the preliminary preparation of the program, we will start to query the required data in the table. The Code is as follows: Select K ~ Ebeln
Into corresponding fields of table itab from Ekko as K where K ~ Ebeln in ebeln1 and K ~ Bedat in bedat and K ~ Ekgrp in ekgrp. Loop at itab.
Select sum (menge) into ITAB-MENGE from Ekpo
Where ebeln EQ ITAB-EBELN. Modify itab. endloop. Loop at itab.
Select sum (wemng) into ITAB-WEMNG from eket
Where ebeln EQ ITAB-EBELN. Modify itab. endloop.
Then we need to define the output interface. When outputting the data we have queried, we need an output format, which makes it easy for everyone to look. The Code is as follows: top-of-page.

Write:/'purchase credential No. ', 22 'item No.', 47 'purchase order qty ', 77 'receipt qty', 95 'completion flag '. uline at/1 (130 ). end-of-page.
Start-of-selection.
Finally, we output the data we found. As a matter of fact, the program I mentioned interspersed with some queries at this step, so it is relatively long. The Code is as follows: if R1 = 'x'. Loop at itab.
Select S ~ Matnr S ~ Menge p ~ Wemng S ~ Ebeln into (matnr, menge, wemng, ebeln) from Ekpo as s inner join eket as P
On S ~ Ebelp = P ~ Ebelp and S ~ Ebeln = P ~ Ebeln where S ~ Ebeln = ITAB-EBELN. If ITAB-MENGE> ITAB-WEMNG.
Write:/2 ebeln, 23 matnr, 41 menge, 71 wemng, 97 'no'. uline at/1 (130 ).
Clear: ebeln, matnr, menge, wemng. endif.
Endselect. endloop.
Elseif r2 = 'x'. Loop at itab.
Select S ~ Matnr S ~ Menge p ~ Wemng S ~ Ebeln into (matnr, menge, wemng, ebeln)

From Ekpo as s inner join eket as P
On S ~ Ebelp = P ~ Ebelp and S ~ Ebeln = P ~ Ebeln where S ~ Ebeln = ITAB-EBELN. If ITAB-MENGE <= ITAB-WEMNG.
Write:/2 ebeln, 23 matnr, 41 menge, 71 wemng, 97 'is'. uline at/1 (130 ).
Clear: ebeln, matnr, menge, wemng. endif.
Endselect. endloop. Else. Loop at itab.
Select S ~ Matnr S ~ Menge p ~ Wemng S ~ Ebeln into (matnr, menge, wemng, ebeln) from Ekpo as s inner join eket as P
On S ~ Ebelp = P ~ Ebelp and S ~ Ebeln = P ~ Ebeln where S ~ Ebeln = ITAB-EBELN. If ITAB-MENGE> ITAB-WEMNG.
Write:/2 ebeln, 23 matnr, 41 menge, 71 wemng, 97 'no'. uline at/1 (130 ).
Clear: ebeln, matnr, menge, wemng. endif.
Endselect. endloop. endif.

Loop at itab.
If R3 = 'X' and ITAB-MENGE <= ITAB-WEMNG.
Select S ~ Matnr S ~ Menge p ~ Wemng S ~ Ebeln into (matnr, menge, wemng, ebeln) from Ekpo as s inner join eket as P
On S ~ Ebelp = P ~ Ebelp and S ~ Ebeln = P ~ Ebeln where S ~ Ebeln = ITAB-EBELN. Write:/2 ebeln, 23 matnr, 41 menge, 71 wemng, 97 'is'. uline at/1 (130 ).
Clear: ebeln, matnr, menge, wemng. endselect. endif. endloop.
Then the program ends. In fact, this example is intended to let everyone know a general process of developing reports for ABAP. It is not about any skills or the like. I hope it will be useful for beginners.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.