Purchase Order Release using ABAP Classes

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


  *&---------------------------------------------------------------------*
*& 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

Labels

po po Delete
release release Delete
porelease porelease Delete
classes classes Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.