Mastering SAP ABAP: Enhancing Reports with Left Outer Join, Column Labels, and Formatting Techniques
Welcome back everyone, We have implemented inner join in our last blog, So let’s continue it.
Requirement :- Suppose, there are 7 elements in header table and for only 5 elements of header table, we have elements in item table.
Now, the Customer wants that the matching data between should be displayed, also rest elements of header table should be displayed in the output.
Solution :-
-
In that scenario, we will use left outer join.
Code :-
***********************************************************
*Start of Program
*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_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 OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.
*end of Selection Screen
*************************************************************
*****************************************
*Select queries along with left outer join
SELECT a~order_number a~order_date a~payment_mode a~total_amount a~currency b~order_item_number b~item_cost
FROM zar_header AS a LEFT OUTER JOIN zar_item AS b ON a~order_number = b~order_number
INTO TABLE lt_final WHERE a~order_number IN s_order.
IF lt_final IS NOT INITIAL.
*******************************************
*Displaying the data
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.
***********************
*End of Program
*****************************************************************************
- Execute this program and we will give input from 1 to 7.
- You can see the output after pressing F8.
- In the output, we can see that it contains the combined data of both tables and also those records which are not in item table.
Column Labels :-
- In the above output, we can see that although we are able to display the details of order number but we have not displayed the name for each columns in the output.
- Now suppose the customer wants to see the columns Labels for each column in the classical report.
Solution :-
-
We will GOTO text elements and we will write Column name for each column.
-
Then, we will use the WRITE statement just above our loop.
Code :-
***********************************************************
*Start of Program
*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_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 OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.
*end of Selection Screen
*************************************************************
*****************************************
*Select queries along with left outer join
SELECT a~order_number a~order_date a~payment_mode a~total_amount a~currency b~order_item_number b~item_cost
FROM zar_header AS a LEFT OUTER JOIN zar_item AS b ON a~order_number = b~order_number
INTO TABLE lt_final WHERE a~order_number IN s_order.
IF lt_final IS NOT INITIAL.
*******************************************
*Displaying the data
WRITE :/ text-001, 15 text-002, 27 text-003, 41 text-004, 51 text-005, 66 text-006, 77 text-007.
LOOP AT lt_final INTO ls_final.
WRITE :/ ls_final-order_number,
15 ls_final-order_date,
27 ls_final-payment_mode,
41 ls_final-total_amount,
51 ls_final-currency,
66 ls_final-order_item_number,
77 ls_final-item_cost.
ENDLOOP.
ENDIF.
***********************
*End of Program
*****************************************************************************
Execute the Program :-
- Now, We can see the Column Labels for each column in the output.
Note :-
- We are trying to achieve our requirement through classical reports, later we will see the ALV report as well.
SY-ULINE and SY-VLINE :-
1. SY-ULINE :-
- It is a system variable for horizontal line.
2. SY-VLINE :-
- It is a system variable for vertical line.
Requirement :-
-
Till now, we have seen how to display using loop concepts and how to show the column name for each column. Now Suppose, If our Customer wants us to display the data in a box as given below using Classical Report.
Solution:-
-
We will use the concept of SY-ULINE and SY-VLINE to achieve that requirement.
Code :-
***********************************************************
*Start of Program
*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_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 OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.
*end of Selection Screen
*************************************************************
*****************************************
*Select queries along with left outer join
SELECT a~order_number a~order_date a~payment_mode a~total_amount a~currency b~order_item_number b~item_cost
FROM zar_header AS a LEFT OUTER JOIN zar_item AS b ON a~order_number = b~order_number
INTO TABLE lt_final WHERE a~order_number IN s_order.
IF lt_final IS NOT INITIAL.
*******************************************
*Displaying the data
WRITE : sy-uline(102).
WRITE :/ sy-vline, text-001,
15 sy-vline, text-002,
27 sy-vline, text-003,
42 sy-vline, text-004,
58 sy-vline, text-005,
70 sy-vline, text-006,
90 sy-vline, text-007,
102 sy-vline.
LOOP AT lt_final INTO ls_final.
WRITE :/ sy-uline(102).
WRITE :/ sy-vline, ls_final-order_number,
15 sy-vline, ls_final-order_date,
27 sy-vline, ls_final-payment_mode,
42 sy-vline, ls_final-total_amount,
58 sy-vline, ls_final-currency,
70 sy-vline, ls_final-order_item_number,
90 sy-vline, ls_final-item_cost,
102 sy-vline.
ENDLOOP.
WRITE :/ sy-uline(102).
ENDIF.
***********************
*End of Program
*****************************************************************************
Output :-
Note :- So, this is how we can use the concept of SY-ULINE and SY-VLINE to show our output in a table format.
Message Class :-
- Messages always plays an important role for end user.
- The various types of messages are - A(abort), E(error), I(information), S(success/status), W(warning), X(exit).
- The transaction code for message class is SE91.
So, that’s enough for today.
We will see how to implement, messages in our code in the next blog.
Thanx alot for being a part of this wonderful journey.
Comments
Post a Comment