FM to generate Planned Independent Requirement (PIR)

FM to generate Planned Independent Requirement (PIR)

Planned Independent Requirement (PIR) are managed through transaction MD6x.
(Do not confuse with Purchase infos records 😉)

FM to manage PIR with ABAP are :

  • BAPI_REQUIREMENTS_CREATE
  • BAPI_REQUIREMENTS_CHANGE

Implementation example to create / update PIR


  DATA : ls_req_item      TYPE bapisitemr,
         lt_schedule_in   TYPE STANDARD TABLE OF bapisshdin,
         lt_return        TYPE STANDARD TABLE OF bapireturn1.

  " Sélection des lignes BIP exitantes (pour savoir lesquelles sont à créer).
  SELECT matnr FROM pbim INTO TABLE @DATA(lt_pbim)
  WHERE matnr    IN @s_matnr
    AND werks     = @p_werks
    AND bedae     = 'VSFB'
    AND versb     = 'PV'
    AND pbdnr     = ''
    AND vervs     = 'X'.

  LOOP AT lt_op_simulation ASSIGNING FIELD-SYMBOL(<fs_op>).

    AT NEW matnr.

      ls_req_item-material            = <fs_op>-matnr.      "  Numéro d'article (18 caractères)
      ls_req_item-plant               = <fs_op>-plwrk.      "  Division
      ls_req_item-requ_type           = 'VSFB'.             "  Type de besoin
      ls_req_item-version             = 'PV'.               "  Nº version du besoin indépendant
      ls_req_item-vers_activ          = 'X'.                "  Code : version active
*      ls_req_item-req_number          = <fs_op>-verid.     "  Plan de besoins

    ENDAT.

    APPEND INITIAL LINE TO lt_schedule_in ASSIGNING FIELD-SYMBOL(<fs_in>).
    <fs_in>-date_type  = '1'.                     " Type de date (jour, semaine, mois, intervalle)
    <fs_in>-req_date   = <fs_op>-pedtr.           " Date de l'échéance
    <fs_in>-req_qty    = <fs_op>-gsmng.           " Quantité planifiée
    <fs_in>-unit       = <fs_op>-meins.           " Unité de quantité de base
*    <fs_in>-bomexpl    = <fs_op>-bom_versn.       " Nº éclat. nomencl.
*    <fs_in>-prod_ves   = <fs_op>-verid.           " Version de fabrication


    AT END OF matnr.
      " Si les besoin sont déjà loggué dans PBIM ==> Modif, sinon, Création.
      READ TABLE lt_pbim TRANSPORTING NO FIELDS WITH KEY matnr =  ls_req_item-material.

      IF sy-subrc = 0.

        CALL FUNCTION 'BAPI_REQUIREMENTS_CHANGE'
          EXPORTING
            material                 = ls_req_item-material
            plant                    = ls_req_item-plant
            requirementstype         = ls_req_item-requ_type
            version                  = ls_req_item-version
            reqmtsplannumber         = ls_req_item-req_number
            vers_activ               = 'X'
            do_commit                = 'X'
            update_mode              = 'X'
          TABLES
            requirements_schedule_in = lt_schedule_in
            return                   = lt_return.

      ELSE.

        CALL FUNCTION 'BAPI_REQUIREMENTS_CREATE'
          EXPORTING
            requirements_item        = ls_req_item
            do_commit                = 'X'
            update_mode              = 'X'
          TABLES
            requirements_schedule_in = lt_schedule_in
            return                   = lt_return.
      ENDIF.

      CLEAR : lt_schedule_in,
              ls_req_item.
    ENDAT.

  ENDLOOP.

Read table LT_RETURN to check if errors occured or not. If empty, no errors.

Search tag: BIP, besoins indépendants prévisionnels, planification

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply