Monday, June 30, 2008

SAP PLant for a Material

SAP PLant for a Material

To obtain a list of PLANTS for a given MATERIAL you can use the following function module.

SAP Function Module for obtaining list of PLANTS for a given Material

K_VALID_PLANTS_OF_MATERIAL
_____________________________________________________

Here you will get a drop down list of all the PLANTS associated with a MATERIAL

Find the code Below.


REPORT ZEX_VALIDPLANTFORMAT .

Parameter: p_matnr like MARA-MATNR.

Data: int_werks TYPE TABLE OF T001W.

CALL FUNCTION 'K_VALID_PLANTS_OF_MATERIAL'
  EXPORTING
    I_MATNR               = p_matnr
    I_DISPLAY             = ' '
* IMPORTING
*    E_PLANT               =
 TABLES
   I_T001W               = int_werks
 EXCEPTIONS
   NO_VALID_PLANTS       = 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.

See Also:
SAP Locating Plants for a Given Material
SAP get Plant Description For a given Material
SAP PLANT MATERIAL and STORAGE LOCATION
Plant for a Company Code


SAP Company Code for a Plant

SAP Company Code for a Plant

For determining the company code for a plant the following function module can be used.

SAP Function Module for determining company code for a Plant.

HRCA_PLANT_GET_COMPANYCODE
___________________________________________________


Please note that

A PLANT can be assigned to only one COMPANY CODE.
A COMPANY CODE can have several PLANTS assigned to it.

You need to pass the PLANT to the above mentioned Function Module.

Find the code below.

REPORT ZEX_PLANTCOMPANYCODE .


Parameter: p_werk like HRCA_PLANT-PLANT.

Data: d_bukrs like HRCA_COMPANY-COMP_CODE.


CALL FUNCTION 'HRCA_PLANT_GET_COMPANYCODE'
  EXPORTING
    PLANT                       = p_werk
 IMPORTING
   COMPANYCODE                  = d_bukrs
 EXCEPTIONS
   NO_COMPANY_CODE_FOUND        = 1
   PLANT_NOT_FOUND              = 2
   OTHERS                       = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

See Also:
SAP Locating Plants for a Given Material
SAP get Plant Description For a given Material
SAP PLANT MATERIAL and STORAGE LOCATION


SAP Plant Material and Storage Location

SAP Plant Material and Storage Location

For retrieving Storage Location related data for a Material, you can use the following SAP ABAP function module.

SAP Storage Location related data for a Material.

MARD_GENERIC_READ_MATNR_PLANT
___________________________________________________________


The following are the IMPORT parameters:

KZRFB            Indicator: Lock
MATNR           Material
WERKS            Plant
MAXTZ            Maximum number of table lines
____________________________________________________________


The following values are retrieved.

Values from Table
MARD     Storage Location Data for Material
_____________________________________________________________



Code is given below.

REPORT ZEX_STORAGELOC .


Parameter: p_matnr like MARD-MATNR,
           p_werks like MARD-WERKS.


data: int_MARD TYPE TABLE OF MARD.


CALL FUNCTION 'MARD_GENERIC_READ_MATNR_PLANT'
  EXPORTING
*   KZRFB            = ' '
    MATNR            = p_matnr
    WERKS            = p_werks
*   MAXTZ            = 0
  TABLES
    MARD_TAB         = int_MARD
 EXCEPTIONS
   WRONG_CALL       = 1
   NOT_FOUND        = 2
   OTHERS           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

See Also:
SAP Locating Plants for a Given Material
SAP get Plant Description For a given Material