Skip to end of metadata
Go to start of metadata

Purchase Order Release using ABAP Classes

Applies to:

Sample Program Developed in ECC 5.0 

Summary

This post narrates the use of ABAP classes for Releasing Purchase Order.A Sample Program is also mentioned below.

Author(s):  Vinod Kumar T

   
Company:     NIIT Technologies Limited
Created on:    20.11.2010
Author(s) Bio
Vinod Kumar is an ABAP Consultant working for NIIT Technologies Limited.

Table of Contents

Class & Methods Used

Class/Interface

Method

Description

CL_PO_HEADER_HANDLE_MM

SET_STATE

Set Purchase Order State

CL_PO_HEADER_HANDLE_MM

PO_INITIALIZE

Initialize Purchase Order Enviornment

CL_PO_HEADER_HANDLE_MM

PO_READ

Read Purchase Order Instance

CL_PO_HEADER_HANDLE_MM

IF_RELEASE_STATE_MM~CAN_RELEASE

Check Whether PO can be released?

CL_PO_HEADER_HANDLE_MM

IF_RELEASE_STATE_MM~RELEASE

Release PO

CL_PO_HEADER_HANDLE_MM

PO_POST

Post the changes & commit

CL_PO_HEADER_HANDLE_MM

PO_CLOSE

Close PO Instance

CL_PO_HEADER_HANDLE_MM

GET_DATA

Get PO Header Data

CL_PO_HEADER_HANDLE_MM

IF_RELEASE_STATE_MM~GET_STRATEGY

Get Release Strategy of PO

IF_RELEASE_STRATEGY_MM

GET_CODES_FOR_RELEASE

Get Rel.Codes which are not released

Processing in Sample Code

Sample code includes the option to Release the Purchase Order Completely & Step by Step Release of PO.

Following are the steps used in program for releasing the PO* Create PO instance with class CL_PO_HEADER_HANDLE_MM

  • Set the PO State as available using method SET_STATE
  • Initialize PO environment using method PO_INITIALIZE
  • Read PO using method PO_READ, with parameter IM_TCODE = 'ME29N'.
  • Check whether PO can be released using method IF_RELEASE_STATE_MM~CAN_RELEASE.
  • If the Option is "Complete Release", release PO using method IF_RELEASE_STATE_MM~RELEASE with parameter IM_ALL = 'X'
  • If the Option is "Single Step Release", Get PO Header data using method GET_DATA
    • Get release Strategy using method IF_RELEASE_STATE_MM~GET_STRATEGY
    • Get Pending Release codes using method GET_CODES_FOR_RELEASE
    • Get the First Record from the internal table created from previous step
    • Release PO using the method IF_RELEASE_STATE_MM~RELEASE with parameter IM_ALL = ' ' and IM_CODE = code from previous step
  • Commit the Changes using the method PO_POST
  • Close the PO enviornment using the method PO_CLOSE.

Selection Screen

Processing Log


 

Sample Code

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
 *&---------------------------------------------------------------------*
*& Report  ZVK_CL_PO2
*&---------------------------------------------------------------------*
*& Program to Release/Reset-Release of Purchase Order
*&---------------------------------------------------------------------*
REPORT  ZVK_CL_PO2 NO STANDARD PAGE HEADING.
TABLES : EKKO.
TYPE-POOLS : MMPUR, ABAP.

DATA : ZCL_PO TYPE REF TO CL_PO_HEADER_HANDLE_MM.
** Definition for header **
DATA : LS_DOCUMENT   TYPE MEPO_DOCUMENT,
       LV_RESULT     TYPE MMPUR_BOOL,
       LS_MEPOHEADER TYPE MEPOHEADER.
** Definition for Release Parameters **
DATA : LV_RELEASE   TYPE MMPUR_BOOL,
       LV_CODE      TYPE FRGCO,
       LV_ALL       TYPE MMPUR_BOOL.
DATA : LT_RE_CODES  TYPE MEREL_T_CODES,
       LS_RE_CODES  TYPE MEREL_S_CODE.
** Definition for Release Strategy Instance.
DATA : ZIF_STRATEGY TYPE REF TO IF_RELEASE_STRATEGY_MM.

SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME.
PARAMETERS : P_EBELN TYPE EKKO-EBELN.
SELECTION-SCREEN END OF BLOCK B.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS : RB_REL  RADIOBUTTON GROUP RG1 DEFAULT 'X' USER-COMMAND RADIO.
PARAMETERS : RB_STEP RADIOBUTTON GROUP RG1.
SELECTION-SCREEN END OF BLOCK B1.
** ----------------------------------------------------**
** Populate header data for Class instance **
** ----------------------------------------------------**
CLEAR : LS_DOCUMENT.
MOVE MMPUR_PO_PROCESS    TO LS_DOCUMENT-PROCESS.
MOVE 'V'                 TO LS_DOCUMENT-TRTYP.
MOVE P_EBELN             TO LS_DOCUMENT-DOC_KEY(10).
MOVE MMPUR_INITIATOR_REL TO LS_DOCUMENT-INITIATOR-INITIATOR.
** ----------------------------------------------------**
** Create Instance of Purchase Order **
** ----------------------------------------------------**
CREATE OBJECT ZCL_PO
  EXPORTING
    IM_PO_NUMBER = P_EBELN
  EXCEPTIONS
    FAILURE = 1
    OTHERS  = 2.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF ZCL_PO IS NOT INITIAL.
** ----------------------------------------------------**
** Set PO State as existing PO
** ----------------------------------------------------**
  ZCL_PO->SET_STATE( IM_STATE = CL_PO_HEADER_HANDLE_MM=>C_AVAILABLE ).
** ----------------------------------------------------**
** Initialize the environment
** ----------------------------------------------------**
  ZCL_PO->PO_INITIALIZE( IM_DOCUMENT = LS_DOCUMENT ).
** ----------------------------------------------------**
** Read PO Document
** ----------------------------------------------------**
  ZCL_PO->PO_READ(
    EXPORTING
      IM_TCODE     = 'ME29N'
      IM_TRTYP     = LS_DOCUMENT-TRTYP
      IM_AKTYP     = LS_DOCUMENT-TRTYP
      IM_PO_NUMBER = P_EBELN
      IM_DOCUMENT  = LS_DOCUMENT
    IMPORTING
      EX_RESULT    = LV_RESULT ).
  IF LV_RESULT EQ ABAP_TRUE.
*************************************************
** If selected the option for Complete release **
*************************************************
    IF RB_REL EQ ABAP_TRUE.
      ULINE /1(50).
      WRITE :/ 'Option : PO Complete Release'.
      ULINE /1(50).
** ----------------------------------------------------**
** Check whether Release is possible ? **
** ----------------------------------------------------**
      LV_RELEASE = ZCL_PO->IF_RELEASE_STATE_MM~CAN_RELEASE( ).
      IF LV_RELEASE EQ ABAP_TRUE.
** ----------------------------------------------------**
** Release PO in One Step (All Release Codes) **
** ----------------------------------------------------**
        ZCL_PO->IF_RELEASE_STATE_MM~RELEASE(
          EXPORTING
            IM_ALL               = MMPUR_YES
          EXCEPTIONS
            NO_AUTHORITY         = 1
            PREREQUISITE_MISSING = 2
            ALREADY_RELEASED     = 3
            NOT_RESPONSIBLE      = 4
            ILLEGAL_CALL         = 5
            ILLEGAL_INDICATOR    = 6
            OTHERS               = 7 ).
        IF SY-SUBRC <> 0.
          WRITE :/ SY-MSGV1, SY-MSGV2, SY-MSGV3, SY-MSGV4.
        ELSE.
** ----------------------------------------------------**
** Post the PO **
** ----------------------------------------------------**
          ZCL_PO->PO_POST(
            EXPORTING
              IM_UNCOMPLETE  = MMPUR_NO
              IM_NO_COMMIT   = MMPUR_NO
              IM_COMMIT_WAIT = MMPUR_YES
            EXCEPTIONS
              FAILURE        = 1
              OTHERS         = 2 ) .
          IF SY-SUBRC <> 0.
            WRITE :/ SY-MSGV1, SY-MSGV2, SY-MSGV3, SY-MSGV4.
          ELSE.
            WRITE :/ 'PO ', P_EBELN, ' is Released Completely'.
          ENDIF.
        ENDIF.
** ----------------------------------------------------**
** Close the PO Instance **
** ----------------------------------------------------**
        ZCL_PO->PO_CLOSE( ).
      ELSE.
        ZCL_PO->PO_CLOSE( ).
        WRITE :/ 'Release of Purchase Order Not possible'.
      ENDIF.
    ENDIF.
***************************************************
** Single Step release **
***************************************************
    IF RB_STEP EQ ABAP_TRUE.
      ULINE /1(50).
      WRITE :/ 'Option : PO Single Step Release'.
      ULINE /1(50).
      CLEAR : LS_MEPOHEADER.
      ZCL_PO->GET_DATA(
        IMPORTING
          EX_DATA = LS_MEPOHEADER
        EXCEPTIONS
          FAILURE = 1
          OTHERS  = 2 ).
      IF SY-SUBRC EQ 0.
** ----------------------------------------------------**
** Get PO Release Strategy **
** ----------------------------------------------------**
        ZIF_STRATEGY = ZCL_PO->IF_RELEASE_STATE_MM~GET_STRATEGY( ).
        IF ZIF_STRATEGY IS NOT INITIAL.
          REFRESH : LT_RE_CODES.
** ----------------------------------------------------**
** Get pending Codes for Release **
** ----------------------------------------------------**
          LT_RE_CODES = ZIF_STRATEGY->GET_CODES_FOR_RELEASE( IM_FRGZU = LS_MEPOHEADER-FRGZU ).
          IF LT_RE_CODES[] IS NOT INITIAL.
            WRITE :/ 'Release Codes to be released'.
            WRITE :/ '********************************'.
            LOOP AT LT_RE_CODES[] INTO LS_RE_CODES.
              WRITE :/ LS_RE_CODES-REL_CODE.
            ENDLOOP.
            ULINE /1(50).
            CLEAR : LS_RE_CODES.
            READ TABLE LT_RE_CODES INTO LS_RE_CODES INDEX 1.
** ----------------------------------------------------**
** Release PO with given release code **
** ----------------------------------------------------**
            ZCL_PO->IF_RELEASE_STATE_MM~RELEASE(
              EXPORTING
                IM_CODE              = LS_RE_CODES-REL_CODE
                IM_ALL               = MMPUR_NO
              EXCEPTIONS
                NO_AUTHORITY         = 1
                PREREQUISITE_MISSING = 2
                ALREADY_RELEASED     = 3
                NOT_RESPONSIBLE      = 4
                ILLEGAL_CALL         = 5
                ILLEGAL_INDICATOR    = 6
                OTHERS               = 7 ).
            IF SY-SUBRC <> 0.
              WRITE :/ 'Purchase Order ', P_EBELN,
                       'Cannot be released with Rel Code => ',
                       LS_RE_CODES-REL_CODE.
              WRITE :/ SY-MSGV1, SY-MSGV2, SY-MSGV3, SY-MSGV4.
            ELSE.
** ----------------------------------------------------**
** Post the PO **
** ----------------------------------------------------**
              ZCL_PO->PO_POST(
                EXPORTING
                  IM_UNCOMPLETE  = MMPUR_NO
                  IM_NO_COMMIT   = MMPUR_NO
                  IM_COMMIT_WAIT = MMPUR_YES
                EXCEPTIONS
                  FAILURE        = 1
                  OTHERS         = 2 ) .
              IF SY-SUBRC <> 0.
                WRITE :/ SY-MSGV1, SY-MSGV2, SY-MSGV3, SY-MSGV4.
              ELSE.
                DELETE LT_RE_CODES INDEX 1.
                WRITE :/ 'Purchase Order ', P_EBELN,
                         'Released with Rel Code => ',
                         LS_RE_CODES-REL_CODE.
                ULINE /1(50).
                IF LT_RE_CODES[] IS INITIAL.
                  WRITE :/ 'PO Released Completely'.
                ELSE.
                  WRITE :/ 'Release Codes yet to be released'.
                  WRITE :/ '********************************'.
                  LOOP AT LT_RE_CODES[] INTO LS_RE_CODES.
                    WRITE :/ LS_RE_CODES-REL_CODE.
                  ENDLOOP.
                ENDIF.
              ENDIF.
            ENDIF.
** ----------------------------------------------------**
** Close the PO Instance **
** ----------------------------------------------------**
            ZCL_PO->PO_CLOSE( ).
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

Related Content

 

Useful Information

Purchase Order Release using ABAP Classes