Purchase Order Header and Item
Purchase Order Header and Item
Here is a program by which Purchase Order Header and Item are displayed separately by classic report format. We are taking proper Purchase Order (EBELN) from Selection Screen with Select Options and displaying the output by using two separatedmethods.
Selection Screen:
REPORT zsr_test NO STANDARD PAGE HEADING.
*-----Declaring tables for Select Option-------------------------------*
TABLES: ekko.
*-----Event Initialization---------------------------------------------*
INITIALIZATION.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
*----------------------------------------------------------------------*
* CLASS header DEFINITION
*----------------------------------------------------------------------*
* PO Header class definition
*----------------------------------------------------------------------*
CLASS header DEFINITION.
PUBLIC SECTION.
"Declaring structures for work area & internal tables
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
aedat TYPE ekko-aedat,
ernam TYPE ekko-ernam,
END OF ty_ekko,
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
END OF ty_ekpo.
"Declaring work areas & internal tables
DATA: wa_ekko TYPE ty_ekko,
it_ekko TYPE TABLE OF ty_ekko,
wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE TABLE OF ty_ekpo,
v_flag TYPE c.
"Declaring methods
METHODS: m_ekko, m_ekko_output,
m_ekpo, m_ekpo_output.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS. "header DEFINITION
*----------------------------------------------------------------------*
* CLASS header IMPLEMENTATION
*----------------------------------------------------------------------*
* PO Header class implementation
*----------------------------------------------------------------------*
CLASS header IMPLEMENTATION.
"Method to select data from header table
METHOD m_ekko.
IF s_ebeln IS NOT INITIAL.
SELECT ebeln bukrs aedat ernam
FROM ekko INTO TABLE it_ekko
WHERE ebeln IN s_ebeln.
IF sy-subrc = 0.
SORT it_ekko.
ENDIF.
ENDIF.
ENDMETHOD. "m_ekko
"Method to select data from item table
METHOD m_ekpo.
IF it_ekko IS NOT INITIAL.
SELECT ebeln ebelp menge meins netpr
FROM ekpo INTO TABLE it_ekpo
FOR ALL ENTRIES IN it_ekko
WHERE ebeln = it_ekko-ebeln.
IF sy-subrc = 0.
SORT it_ekpo.
ENDIF.
ENDIF.
ENDMETHOD. "m_ekpo
"Method to display header output
METHOD m_ekko_output.
IF it_ekko IS NOT INITIAL.
LOOP AT it_ekko INTO wa_ekko.
AT FIRST.
WRITE: 'Purchase Order' COLOR 1,
20 'Company Code' COLOR 1,
35 'Creation Date' COLOR 1,
50 'Created by' COLOR 1.
ULINE.
ENDAT.
WRITE: / wa_ekko-ebeln,
20 wa_ekko-bukrs,
35 wa_ekko-aedat,
50 wa_ekko-ernam.
AT LAST.
WRITE: / '~~~~~~~~~~~End of PO Header~~~~~~~~~~~'.
SKIP.
ENDAT.
ENDLOOP.
ENDIF.
ENDMETHOD. "m_ekko_output
"Method to display item wise output
METHOD m_ekpo_output.
IF it_ekpo IS NOT INITIAL.
LOOP AT it_ekpo INTO wa_ekpo.
AT FIRST.
WRITE: / 'Purchase Order' COLOR 1,
20 'Item' COLOR 1,
35 'Quantity' COLOR 1,
45 'Unit' COLOR 1,
54 'Net Price' COLOR 1.
ULINE.
ENDAT.
AT NEW ebeln.
v_flag = 'X'.
ENDAT.
IF v_flag = 'X'.
WRITE: / wa_ekpo-ebeln,
20 wa_ekpo-ebelp,
27 wa_ekpo-menge,
45 wa_ekpo-meins,
50 wa_ekpo-netpr.
ELSE.
WRITE: /20 wa_ekpo-ebelp,
27 wa_ekpo-menge,
45 wa_ekpo-meins,
50 wa_ekpo-netpr.
ENDIF.
AT END OF ebeln.
SUM.
WRITE: /27 '=================',
50 '=============='.
WRITE: / 'Sub Total: ' COLOR 5,
27 wa_ekpo-menge,
50 wa_ekpo-netpr.
SKIP.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: / 'Grand Total: ' COLOR 3,
27 wa_ekpo-menge,
50 wa_ekpo-netpr.
ENDAT.
CLEAR: v_flag, wa_ekpo.
ENDLOOP.
ENDIF.
ENDMETHOD. "m_ekpo_output
ENDCLASS. "header IMPLEMENTATION
*-----Event Start of Selection-----------------------------------------*
START-OF-SELECTION.
"Declaring object with the class type reference
DATA: obj_header TYPE REF TO header.
"Creating object
CREATE OBJECT: obj_header.
"Calling the methods via created object
CALL METHOD: obj_header->m_ekko,
obj_header->m_ekko_output,
obj_header->m_ekpo,
obj_header->m_ekpo_output.
*-----Declaring tables for Select Option-------------------------------*
TABLES: ekko.
*-----Event Initialization---------------------------------------------*
INITIALIZATION.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
*----------------------------------------------------------------------*
* CLASS header DEFINITION
*----------------------------------------------------------------------*
* PO Header class definition
*----------------------------------------------------------------------*
CLASS header DEFINITION.
PUBLIC SECTION.
"Declaring structures for work area & internal tables
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
aedat TYPE ekko-aedat,
ernam TYPE ekko-ernam,
END OF ty_ekko,
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
END OF ty_ekpo.
"Declaring work areas & internal tables
DATA: wa_ekko TYPE ty_ekko,
it_ekko TYPE TABLE OF ty_ekko,
wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE TABLE OF ty_ekpo,
v_flag TYPE c.
"Declaring methods
METHODS: m_ekko, m_ekko_output,
m_ekpo, m_ekpo_output.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS. "header DEFINITION
*----------------------------------------------------------------------*
* CLASS header IMPLEMENTATION
*----------------------------------------------------------------------*
* PO Header class implementation
*----------------------------------------------------------------------*
CLASS header IMPLEMENTATION.
"Method to select data from header table
METHOD m_ekko.
IF s_ebeln IS NOT INITIAL.
SELECT ebeln bukrs aedat ernam
FROM ekko INTO TABLE it_ekko
WHERE ebeln IN s_ebeln.
IF sy-subrc = 0.
SORT it_ekko.
ENDIF.
ENDIF.
ENDMETHOD. "m_ekko
"Method to select data from item table
METHOD m_ekpo.
IF it_ekko IS NOT INITIAL.
SELECT ebeln ebelp menge meins netpr
FROM ekpo INTO TABLE it_ekpo
FOR ALL ENTRIES IN it_ekko
WHERE ebeln = it_ekko-ebeln.
IF sy-subrc = 0.
SORT it_ekpo.
ENDIF.
ENDIF.
ENDMETHOD. "m_ekpo
"Method to display header output
METHOD m_ekko_output.
IF it_ekko IS NOT INITIAL.
LOOP AT it_ekko INTO wa_ekko.
AT FIRST.
WRITE: 'Purchase Order' COLOR 1,
20 'Company Code' COLOR 1,
35 'Creation Date' COLOR 1,
50 'Created by' COLOR 1.
ULINE.
ENDAT.
WRITE: / wa_ekko-ebeln,
20 wa_ekko-bukrs,
35 wa_ekko-aedat,
50 wa_ekko-ernam.
AT LAST.
WRITE: / '~~~~~~~~~~~End of PO Header~~~~~~~~~~~'.
SKIP.
ENDAT.
ENDLOOP.
ENDIF.
ENDMETHOD. "m_ekko_output
"Method to display item wise output
METHOD m_ekpo_output.
IF it_ekpo IS NOT INITIAL.
LOOP AT it_ekpo INTO wa_ekpo.
AT FIRST.
WRITE: / 'Purchase Order' COLOR 1,
20 'Item' COLOR 1,
35 'Quantity' COLOR 1,
45 'Unit' COLOR 1,
54 'Net Price' COLOR 1.
ULINE.
ENDAT.
AT NEW ebeln.
v_flag = 'X'.
ENDAT.
IF v_flag = 'X'.
WRITE: / wa_ekpo-ebeln,
20 wa_ekpo-ebelp,
27 wa_ekpo-menge,
45 wa_ekpo-meins,
50 wa_ekpo-netpr.
ELSE.
WRITE: /20 wa_ekpo-ebelp,
27 wa_ekpo-menge,
45 wa_ekpo-meins,
50 wa_ekpo-netpr.
ENDIF.
AT END OF ebeln.
SUM.
WRITE: /27 '=================',
50 '=============='.
WRITE: / 'Sub Total: ' COLOR 5,
27 wa_ekpo-menge,
50 wa_ekpo-netpr.
SKIP.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: / 'Grand Total: ' COLOR 3,
27 wa_ekpo-menge,
50 wa_ekpo-netpr.
ENDAT.
CLEAR: v_flag, wa_ekpo.
ENDLOOP.
ENDIF.
ENDMETHOD. "m_ekpo_output
ENDCLASS. "header IMPLEMENTATION
*-----Event Start of Selection-----------------------------------------*
START-OF-SELECTION.
"Declaring object with the class type reference
DATA: obj_header TYPE REF TO header.
"Creating object
CREATE OBJECT: obj_header.
"Calling the methods via created object
CALL METHOD: obj_header->m_ekko,
obj_header->m_ekko_output,
obj_header->m_ekpo,
obj_header->m_ekpo_output.
Selection Screen:
The output is as follows:
Post a Comment