Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Purchase Requistion Line item Data manipulation using BADI - ME_PROCESS_REQ_CUST.

Link to Content's target Space :

http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Development+and+Programming.

Applies to:

Sample code developed in ECC 5.0

Summary

This post narrates the use of BADI - ME_PROCESS_REQ_CUST, Method - PROCESS_ITEM for manipulating/populating Line item level data.

Author(s):  Vinod Kumar T

   
Company:     NIIT Technologies Limited
Created on:    10.12.2010
Author(s) Bio
Vinod Kumar is an ABAP consultant working for NIIT Technologies Limited

Table of Contents

Processing Steps

  • Create Implementation for BADI using transaction code SE19.
  • Click on Method PROCESS_ITEM
  • Get the Processing Mode (Create/View/Change) using the LOCAL class parameter TRTYP
  • Get Item level data using method IF_PURCHASE_REQUISITION_ITEM~GET_DATA
  • Update requistor name in Line item using method IF_PURCHASE_REQUISTION_ITEM~SET_DATA
  • Update source of supply details using methods
    • IF_PURCHASE_REQUISITION_ITEM~GET_SOURCE_OF_SUPPLY
    • CL_SOURCE_OF_SUPPLY_MM->UPDATE
    • CL_SOURCE_OF_SUPPLY_MM->GET_DATA
  • Get Line item Text Object id using method IF_LONGTEXTS_MM~GET_TEXTOBJECT.
  • Get Line item Text ID details using method IF_LONGTEXTS_MM~GET_TYPES
  • Update Long text data using IF_LONGTEXTS_MM~SET_TEXT.

Purchase Requisition Screen

 

Sample Code in BADI-Method

The sample code mentioned here is only for representational purpose.  Code logic is to be changed as per the requirement 

Error rendering macro 'code': Invalid value specified for parameter 'lang'
METHOD IF_EX_ME_PROCESS_REQ_CUST~PROCESS_ITEM.
  IF IM_COUNT EQ 1.  " to avoid infinate Loop"
    DATA : LS_ITEM_DATA   TYPE MEREQ_ITEM,
           LC_SOURCE      TYPE REF TO CL_SOURCE_OF_SUPPLY_MM,
           LT_SOURCE      TYPE MEREQ_T_SOURCE_OF_SUPPLY,
           LS_SOURCE      TYPE REF TO CL_SOURCE_OF_SUPPLY_MM,
           LS_SOURCE_DATA TYPE MEREQ_SOURCE,
           LV_OBJ         TYPE REF TO OBJECT,
           LV_ATTR        TYPE STRING,
           LV_AKTYP       TYPE AKTYP,
           LV_SOURCE_N    TYPE SY-TABIX.
    DATA : LV_TDOBJECT    TYPE TDOBJECT,
           LV_METAFIELD   TYPE MMPUR_METAFIELD,
           LT_TEXTTYPES   TYPE MMPUR_T_TEXTTYPES,
           LS_TEXTTYPES   TYPE MMPUR_TEXTTYPES,
           LT_TEXTLINES   TYPE MMPUR_T_TEXTLINES,
           LS_TEXTLINES   TYPE MMPUR_TEXTLINES.
    FIELD-SYMBOLS : <FS_LCL> TYPE ANY,
                    <FS_SOURCE> TYPE ANY.
*************************************************
** Access Attributes value of Local Class
** for getting the transaction mode of Line item
** H-> Create
*************************************************
    LV_OBJ ?= IM_ITEM.
    MOVE 'MY_STATE->AKTYP' TO LV_ATTR.
    ASSIGN LV_OBJ->(LV_ATTR) TO <FS_LCL>.
    LV_AKTYP = <FS_LCL>.
    IF LV_AKTYP EQ 'H'.        "While creating line item"
*************************************************
** Extracting existing Item Data and Modify the fields
** Requestor Name (AFNAM) & Source of supply details
*************************************************
      CLEAR : LS_ITEM_DATA.
      LS_ITEM_DATA = IM_ITEM->GET_DATA( ).
      MOVE LS_ITEM_DATA-ERNAM TO LS_ITEM_DATA-AFNAM.
** Get source of supply details
      CLEAR : LS_SOURCE.
      LC_SOURCE = IM_ITEM->GET_SOURCE_OF_SUPPLY( ).
      LT_SOURCE = LC_SOURCE->UPDATE( IM_NOMEI   = 'X' ).
      DESCRIBE TABLE LT_SOURCE LINES LV_SOURCE_N.
      IF LV_SOURCE_N EQ 1.          "Assign the default data otherwise populate the list"
        READ TABLE LT_SOURCE ASSIGNING <FS_SOURCE> INDEX 1.
        IF SY-SUBRC EQ 0.
          LS_SOURCE ?= <FS_SOURCE>.
          LS_SOURCE_DATA = LS_SOURCE->GET_DATA( ).
          MOVE-CORRESPONDING LS_SOURCE_DATA TO LS_ITEM_DATA.
        ENDIF.
      ENDIF.
      IM_ITEM->SET_DATA(
        EXPORTING
          IM_DATA = LS_ITEM_DATA ).
*************************************************
** Populating item text while creating Line item
*************************************************
** Get Text Object **
      CLEAR : LV_METAFIELD, LV_TDOBJECT.
      IM_ITEM->IF_LONGTEXTS_MM~GET_TEXTOBJECT(
            IMPORTING
              EX_TDOBJECT = LV_TDOBJECT
              EX_METAFIELD = LV_METAFIELD ).
** Get Text IDs **
      REFRESH : LT_TEXTTYPES.
      CLEAR   : LS_TEXTTYPES.
      IM_ITEM->IF_LONGTEXTS_MM~GET_TYPES(
            IMPORTING
              EX_TEXTTYPES = LT_TEXTTYPES ).
** Updating Item Text
      LOOP AT LT_TEXTTYPES INTO LS_TEXTTYPES.
        CLEAR : LS_TEXTLINES.
        REFRESH : LT_TEXTLINES.
        MOVE LV_TDOBJECT       TO LS_TEXTLINES-TDOBJECT.
        MOVE LS_TEXTTYPES-TDID TO LS_TEXTLINES-TDID.
        MOVE '*'               TO LS_TEXTLINES-TDFORMAT.
        CONCATENATE 'Test : ' LS_TEXTTYPES-TDTEXT INTO LS_TEXTLINES-TDLINE.
        APPEND LS_TEXTLINES TO LT_TEXTLINES.
        IM_ITEM->IF_LONGTEXTS_MM~SET_TEXT(
            EXPORTING
              IM_TDID = LS_TEXTTYPES-TDID
              IM_TEXTLINES = LT_TEXTLINES ).
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDMETHOD..                    "if_ex_me_process_req_cust~process_item
  

Related Content

Purchase Requisition Header Long Text using Badi - ME_PROCESS_REQ_CUST 

Useful Information

Use of BADI ME_PROCESS_REQ_CUST for Manipulating line item data

4 Comments

  1. Guest

    Hi ,

    I received following error while method set_text on PR item data( Process_item).

    I did exactly same as mentioned in the post.

    http://wiki.sdn.sap.com/wiki/display/ABAP/Purchase+Req.Line+item+Data+manipulation+using+BADI-+ME_PROCESS_REQ_CUST?showComments=true&showCommentArea=true#addcomment

    I received following error.

    System error (text name empty in text object EBAN

    and text ID B02)

    Appreciated your help.

    -Kalpesh





  2. Former Member

    Very useful, thank you!

  3. Dear,

    great work!

    Is there a way to manipulate overall limit and expected value in blanket PR?

    Thanks for any suggestion.

    Rafael

  4. Former Member

    Very good post, 

    The BADI is not called when the PR is created automatically in order creation...