Report - Get Delivery and PO Details from Internal TU (EWM) - Type 1


We can also use the below program, or, to be more precise with the same business object, see next post.

*&---------------------------------------------------------------------*
*& Report ZAG_TU_DEL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zag_tu_del.

*-> Selection Screen
PARAMETERSp_whse TYPE /scwm/lgnum OBLIGATORY,
            p_itu  
TYPE /scwm/de_tu_num OBLIGATORY,
            p_pdi  
TYPE char1 RADIOBUTTON GROUP g1 DEFAULT 'X',
            p_pdo  
TYPE char1 RADIOBUTTON GROUP g1.

*-> Local Data Declarations
TYPESBEGIN OF lty_dlv_po,
         docno 
TYPE /scdl/dl_docno_int,
         po    
TYPE /scdl/dl_refdocno,
       
END OF lty_dlv_po.

DATAls_tu_sr_act_num TYPE /scwm/s_tu_sr_act_num,
      lt_tu_dlv_temp   
TYPE /scwm/tt_bo_tu_dlv_no_sort,
      lv_doccat        
TYPE /scdl/dl_doccat,
      lt_selection     
TYPE /scwm/dlv_selection_tab,
      ls_read_options  
TYPE /scwm/dlv_query_contr_str,
      ls_include_data  
TYPE /scwm/dlv_query_incl_str_prd,
      ls_exclude_data  
TYPE /scwm/dlv_query_excl_str,
      ls_t300_md       
TYPE /scwm/s_t300_md,
      lt_dlv_po        
TYPE STANDARD TABLE OF lty_dlv_po.

CONSTANTS lc_refdoccat_po TYPE /scdl/dl_refdoccat VALUE 'PO'.

*-> Selection Variable
IF p_pdi IS NOT INITIAL.
  lv_doccat 
wmegc_doccat_pdi.
ELSE.
  lv_doccat 
wmegc_doccat_pdo.
ENDIF.

*-> Get Shipping and Receiving Activity
SELECT tu_sr_act_num
  
UP TO ROWS
  
FROM /scwm/tu_dlv
  
INTO @DATA(lv_tu_sr_act_num)
 
WHERE tu_num @p_itu.
ENDSELECT.
IF sy-subrc 0.
*-> Get Instance - Shipping & Receiving Business Object Manager
  
TRY.
      
CALL METHOD /scwm/cl_sr_bom=>get_instance
        RECEIVING
          ro_bom 
DATA(lo_sr_bom).
    
CATCH /scwm/cx_sr_error.
      
RETURN.
  
ENDTRY.

  
IF lo_sr_bom IS BOUND.
*-> Prepare Key
    ls_tu_sr_act_num
-tu_num        p_itu.
    ls_tu_sr_act_num
-tu_sr_act_num lv_tu_sr_act_num.

*-> Get Business Object of Transportation Unit
    
TRY.
        
CALL METHOD lo_sr_bom->get_bo_tu_by_key
          
EXPORTING
            is_tu_sr_act_num 
ls_tu_sr_act_num
          RECEIVING
            ro_bo_tu         
DATA(lo_bo_tu).
      
CATCH /scwm/cx_sr_error.
        
RETURN.
    
ENDTRY.

    
IF lo_bo_tu IS BOUND.
*-> Get TU Data
      
TRY.
          
CALL METHOD lo_bo_tu->get_data
            
IMPORTING
              et_tu_dlv 
DATA(lt_tu_dlv).
        
CATCH /scwm/cx_sr_error.
          
RETURN.
      
ENDTRY.

      
IF lt_tu_dlv IS NOT INITIAL.
*-> Get Unique Deliveries
        lt_tu_dlv_temp 
lt_tu_dlv.
        
SORT lt_tu_dlv_temp BY docno.
        
DELETE ADJACENT DUPLICATES FROM lt_tu_dlv_temp
                              
COMPARING docno.
        
IF lt_tu_dlv_temp IS NOT INITIAL.
*-> Prepare EXPORTING parameters
*-> Get Supply Chain Unit GUID
          
CALL FUNCTION '/SCWM/T300_MD_READ_SINGLE'
            
EXPORTING
              iv_lgnum   
p_whse
            
IMPORTING
              es_t300_md 
ls_t300_md
            
EXCEPTIONS
              not_found  
1
              
OTHERS     2.
          
IF sy-subrc 0.
            
APPEND INITIAL LINE TO lt_selection ASSIGNING FIELD-SYMBOL(<lfs_selection>).
            <lfs_selection>
-fieldname /scdl/if_dl_logfname_c=>sc_locationid_wh_h.
            <lfs_selection>
-option    wmegc_option_eq.
            <lfs_selection>
-sign      wmegc_sign_inclusive.
            <lfs_selection>
-low       ls_t300_md-scuguid.

            
LOOP AT lt_tu_dlv_temp ASSIGNING FIELD-SYMBOL(<lfs_tu_dlv>).
              
APPEND INITIAL LINE TO lt_selection ASSIGNING <lfs_selection>.
              <lfs_selection>
-fieldname /scdl/if_dl_logfname_c=>sc_docno_h.
              <lfs_selection>
-option    wmegc_option_eq.
              <lfs_selection>
-sign      wmegc_sign_inclusive.
              <lfs_selection>
-low       <lfs_tu_dlv>-docno.
            
ENDLOOP.

            ls_read_options
-data_retrival_only      abap_true.
            ls_read_options
-mix_in_object_instances abap_true.

            ls_exclude_data
-head_all abap_true.

*-> Get Delivery Details
*-> Get Instance - Obj. Man. Delivery PRD Objects
            
CALL METHOD /scwm/cl_dlv_management_prd=>get_instance
              RECEIVING
                eo_instance 
DATA(lo_dlv_man_prd).
            
IF lo_dlv_man_prd IS BOUND.
*-> Query
              
TRY.
                  
CALL METHOD lo_dlv_man_prd->query
                    
EXPORTING
                      it_selection    
lt_selection
                      iv_doccat       
lv_doccat
                      is_read_options 
ls_read_options
                      is_exclude_data 
ls_exclude_data
                      is_include_data 
ls_include_data
                    
IMPORTING
                      et_items        
DATA(lt_items).
                  
IF lt_items IS NOT INITIAL.
                    
LOOP AT lt_tu_dlv_temp ASSIGNING <lfs_tu_dlv>.
                      
APPEND INITIAL LINE TO lt_dlv_po ASSIGNING FIELD-SYMBOL(<lfs_dlv_po>).
                      <lfs_dlv_po>
-docno <lfs_tu_dlv>-docno.
                      
READ TABLE lt_items ASSIGNING FIELD-SYMBOL(<lfs_item>)
                                          
WITH KEY docno <lfs_tu_dlv>-docno.
                      
IF sy-subrc 0.
                        
READ TABLE <lfs_item>-refdoc ASSIGNING FIELD-SYMBOL(<lfs_refdoc>)
                                                     
WITH KEY refdoccat lc_refdoccat_po.
                        
IF sy-subrc 0.
                          <lfs_dlv_po>
-po <lfs_refdoc>-refdocno.
                        
ENDIF.
                      
ENDIF.
                    
ENDLOOP.
                  
ENDIF"lt_items NOT INITIAL
                
CATCH /scdl/cx_delivery.
                  
RETURN.
              
ENDTRY.
            
ENDIF.
          
ENDIF.
        
ENDIF" FM - /SCWM/T300_MD_READ_SINGLE
      
ENDIF"lt_tu_dlv NOT INITIAL
    
ENDIF"lo_bo_tu BOUND
  
ENDIF"lo_sr_bom BOUND
ENDIF"SELECT /SCWM/TU_DLV

END-OF-SELECTION.
  
IF lt_dlv_po IS NOT INITIAL.
    
TRY.
        
CALL METHOD cl_salv_table=>factory
          
IMPORTING
            r_salv_table 
DATA(lo_salv_table)
          
CHANGING
            t_table      
lt_dlv_po.
        
IF lo_salv_table IS BOUND.
          
CALL METHOD lo_salv_table->display.
        
ENDIF.
      
CATCH cx_salv_msg.
    
ENDTRY.
  
ENDIF"lt_dlv_po NOT INITIAL

Comments

Popular posts from this blog

EWM PPF Trigger the existing PPF Action through Custom Program

ABAP 7.5 - FILTER Statement

Useful Transaction Codes / Tools in OData ABAP Service / SAP UI5/ SAP Fiori