Get Packaging Material of a Product in EWM

Assumption: The relationship between the Product and its Packaging Specification is one-to-one.
Note: Multiple Pack. Spec. for a Product should be handled accordingly.

Report Code:

*&---------------------------------------------------------------------*
*& Report ZAG_GET_PMAT_PRODUCT
*&---------------------------------------------------------------------*
*& Developed by Arun Ganesh
*&---------------------------------------------------------------------*
REPORT zag_get_pmat_product.

*-> Selection Screen
PARAMETERS p_mat TYPE /scwm/de_matnr.

*-> Local Data Declarations
DATAls_content_query TYPE /scwm/s_ps_content_query,
      lt_ps_keys       
TYPE /scwm/tt_ps_header_key,
      lv_severity      
TYPE bapi_mtype,
      lt_return        
TYPE bapirettab,
      lv_matid_16      
TYPE /scwm/de_matid,
      lt_matid_tab     
TYPE /scmb/mdl_matid_tab,
      lt_object        
TYPE /scwm/tt_ps_object.

*-> Get Packaging Specifications of the Product
SELECT SINGLE matid "Secondary Index fetch
         
FROM /sapapo/matkey
         
INTO @DATA(lv_matid_22)
        
WHERE matnr @p_mat.
IF sy-subrc 0.
  
CALL FUNCTION '/SCMB/MDL_GUID_CONVERT'
    
EXPORTING
      iv_guid22 
lv_matid_22
    
IMPORTING
      ev_guid16 
lv_matid_16.
  
IF lv_matid_16 IS NOT INITIAL.

    
APPEND INITIAL LINE TO lt_matid_tab ASSIGNING FIELD-SYMBOL(<lfs_matid_tab>).
    <lfs_matid_tab>
-matid lv_matid_16.

    ls_content_query
-matid lt_matid_tab.

    
CALL FUNCTION '/SCWM/API_PACKSPEC_GETLIST'
      
EXPORTING
        is_content_query 
ls_content_query
      
IMPORTING
        et_ps_keys       
lt_ps_keys
        ev_severity      
lv_severity
        et_return        
lt_return.
    
IF NOT lv_severity CA wmegc_severity_eax AND
      lt_ps_keys 
IS NOT INITIAL.
      
CLEARlv_severity,
             lt_return
.

*-> Get Pack. Spec. details
      
CALL FUNCTION '/SCWM/API_PACKSPEC_READ'
        
EXPORTING
          it_ps_id    
lt_ps_keys
        
IMPORTING
          et_object   
lt_object
          ev_severity 
lv_severity
          et_return   
lt_return.
      
IF NOT lv_severity CA wmegc_severity_eax AND
         lt_object 
IS NOT INITIAL.
        
READ TABLE lt_object ASSIGNING FIELD-SYMBOL(<lfs_object>)
                             
INDEX 1.
        
IF sy-subrc 0.
          
READ TABLE <lfs_object>-levels ASSIGNING FIELD-SYMBOL(<lfs_level>)
                                         
INDEX 2"2nd level read
          
IF sy-subrc  0.
            
WRITE <lfs_level>-hu_mat.
          
ENDIF.
        
ENDIF.
      
ENDIF.
    
ENDIF.
  
ENDIF"lv_matid_16 NOT INITIAL
ENDIF"SELECT matid from /SAPAPO/MATKEY

Comments

Popular posts from this blog

EWM PPF Trigger the existing PPF Action through Custom Program

ABAP 7.5 - FILTER Statement