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:

13 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

yektek training said...

nice post thanks for sharing from Swathi

siva sankar Sankar said...

excellent post thanks for sharing from Sankar

Ramya k said...

Thanks for the great information, was looking for this information from long.Great blogSAP MM Training in Chennai

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...

Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

sanayamohit 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!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

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

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

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

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!!!!!!

Keerthi Suresh said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-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!!!!!!

Ananias MK said...

This is a super useful blog.

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD