Mastering ABAP Reports: Building a Classical Report with Input Selection and Data Retrieval from Order Header and Item Tables
Welcome back everyone, In our last blog we were discussing about Classical Reports. So, let’s create a program on some complex scenario than yesterday.
Requirement :-
1. Suppose we have our Order header and Order item table.
2.Now, On the selection screen, we want to take input as order number using select options, make select option as mandatory and also write select option in a box.
3. On the basis of above input, we want to display the below output :-
4. Use the below logic :-
Solution :-
- I think we are clear with the requirement, So let’s develop a classical report
Process :-
- Step 1 :- Create a executable Program in ABAP Editor.
-
Step 2 :- Create the type structure for both header and item table and also declare a final type structure to display the output.
-
Step 3 :- Declare the internal table and work area for the above three type structure.
-
Step 4 :- Defining a block for selection screen and writing select option in it.
-
Step 5 :- Go to text elements and give a meaningful name for the selection screen and activate it.
-
Step 6 :- Write select queries to store data in in the internal table of both order header and order item.
-
Step 7 :- Loop on item table and perform read operation on header table to store data in final.
-
Step 8 :- displaying the output.
Entire Program :
**************************************************************************
*start of Program
*Declaring the type structure
TYPES: BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
END OF ty_header.
TYPES : BEGIN OF ty_item,
order_number TYPE zar_order_number,
order_item_number TYPE zar_order_item_number,
item_cost TYPE zar_total_amount,
END OF ty_item.
*Declaring the final type structure
TYPES: BEGIN OF ty_final,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
order_item_number TYPE zar_order_item_number,
item_cost TYPE zar_total_amount,
END OF ty_final.
*********************************************************
*Declaring the internal table and work area
DATA : lt_header TYPE TABLE OF ty_header,
ls_header TYPE ty_header,
lt_item TYPE TABLE OF ty_item,
ls_item TYPE ty_item,
lt_final TYPE TABLE OF ty_final,
ls_final TYPE ty_final.
********************************************************
****************************************
*Defining Selection Screen
DATA : lv_order TYPE zar_order_number.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : s_order FOR lv_order.
SELECTION-SCREEN : END OF BLOCK b1.
*end of Selection Screen
***************************************************************
****************************************
*Writing Select queries
SELECT * FROM zar_header INTO CORRESPONDING FIELDS OF
TABLE lt_header WHERE order_number IN s_order.
IF lt_header IS NOT INITIAL.
SELECT * FROM zar_item INTO CORRESPONDING FIELDS OF
TABLE lt_item FOR ALL ENTRIES IN lt_header
WHERE order_number = lt_header-order_number.
*****************************************************
*Looping to store data in final table
IF lt_item IS NOT INITIAL.
LOOP AT lt_item INTO ls_item.
ls_final-order_item_number = ls_item-order_item_number.
ls_final-item_cost = ls_item-item_cost.
*Performing Read operation
READ TABLE lt_header INTO ls_header WITH KEY
order_number = ls_item-order_number.
IF sy-subrc EQ 0.
ls_final-order_number = ls_header-order_number.
ls_final-order_date = ls_header-order_date.
ls_final-payment_mode = ls_header-payment_mode.
ls_final-total_amount = ls_header-total_amount.
ls_final-currency = ls_header-currency.
ENDIF.
APPEND ls_final TO lt_final.
CLEAR : ls_final, ls_header, ls_item.
ENDLOOP.
***End of Loop
*************************************************
*Displaying the output.
Loop at lt_final into ls_final.
Write :/ ls_final-ORDER_NUMBER,
ls_final-order_date,
ls_final-payment_mode,
ls_final-total_amount,
ls_final-currency,
ls_final-ORDER_ITEM_NUMBER,
ls_final-ITEM_COST.
ENDLOOP.
ENDIF.
ENDIF.
*end of Program
**************************************************************************
Now execute the program.
-
Enter data on selection screen.
-
Press F8, you will see the output on output screen.
JOINS in ABAP :-
- With the help of joins we can access the data from multiple tables in a single select statement.
Types Of Joins :-
1. Inner Join :-
- An inner join finds and returns matching data from tables based upon specified conditions.
- If one or more criteria are not met, no data records are created in the result set.
2. Outer Join :-
- Outer join finds and returns matching data and non-matching data from the tables.
Outer join is of 2 types :-
a) LEFT OUTER JOIN (LEFT JOIN) :-
- The left outer join takes all the values from the left table and combines them with the values from the right table that meet the criteria.
b) RIGHT OUTER JOIN (RIGHT JOIN ) :-
- The right outer join takes all the values from the right table and combines them with the values from the left table that meet the criteria.
So, that’s enough for today.
We will implement joins in our next blog.
Thanx alot for being a part of this wonderful journey.
Comments
Post a Comment