Monday, February 11, 2013

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 separated methods.


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.

Selection Screen:


The output is as follows:

6 comments:

From.Ae said...

Quality stuff may be the key to invite the users to visit begin to see the blog site, that’s what this site provides.

HGH Fragment

Anonymous said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Unknown said...

Best SAP Success Factors Training Institute in Chennai
Best SAP MM Training in Chennai
Best SAP SD Training in Chennai
Best SAP ABAP Training in Chennai
Best SAP FICO Training in Chennai
Best SAP BASIS Training in Chennai

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-sd-training-in-chennai/
http://thecreatingexperts.com/sap-hr-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/
http://thecreatingexperts.com/sap-abap-training-in-chennai/
http://thecreatingexperts.com/sap-basis-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Unknown said...

This is a super useful blog.

Unknown said...

This post is really nice and informative. The explanation given is really comprehensive and informative..sap hr apap training

Unknown said...

This statement cause a problem , if people is not able to see the output . Please comment this statement and will be able to view the output.
no need to clear the work area in this statement and the correct one is :

clear : v_flag.