IF IF: Sy Subrc Sy Subrc LV - Error Abap - True

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

 

 IF 
    IF .

          IF sy-subrc IS INITIAL.  .
      IF sy-subrc IS INITIAL AND lv_error = abap_true.

      ENDIF.
      ENDIF.    
    ENDIF.
  ENDIF.

  METHOD if_ex_workorder_update~before_update.

*&---------------------------------------------------------------------*
* Author Name   : Chittudi Sai Anogna                                  
*
* Date          : 18-May-2021                                          
*
* Developer ID  : SCHITTUDI                                            
*
* Object ID     : RICEFW ID E034                                       
*
* TR Number     : ZSDK901218
* Package       : ZPL2PR
*----------------------------------------------------------------------*
* Preconditions : none
*----------------------------------------------------------------------*
* Short description:                                                   
*
* Prevent Process Order Change                                         
*
*----------------------------------------------------------------------*

    CONSTANTS : lc_appl    TYPE zde_parm_application  VALUE 'PP',
                lc_process TYPE zde_parm_process_id   VALUE 'ORDER_CHANGE_PREV
ENT',
                lc_parm_id TYPE zde_parm_parameter_id VALUE 'USER_STATUS',
                lc_40      TYPE auftyp                VALUE '40',
                lc_cor2    TYPE syst_tcode            VALUE 'COR2'.

*    CLEAR me->c_status_error.

*    me->c_status_error = abap_true.

** First check the Tcode is COR2.
    IF sy-tcode EQ lc_cor2.
** Get the User Status from the CAUFV table based on Process Order.
      READ TABLE it_header INTO DATA(lwa_header) INDEX 1.
      IF sy-subrc IS INITIAL.
        DATA(lv_ustatus) = lwa_header-asttx.
** Check the User Status MOS/MOF/MOA maintained in parameter table.
        SELECT SINGLE rparm1 FROM zxca_param INTO @DATA(lv_param)
                WHERE appl       = @lc_appl
                  AND process_id = @lc_process
                  AND parm_id    = @lc_parm_id
                  AND rparm1     = @lv_ustatus.
        IF sy-subrc IS INITIAL.
** Compare the old and new Quantity and UoM from header table.
** if any of them are different set the error flag as X.
          READ TABLE it_header_old INTO DATA(lwa_header_old)
                                   WITH KEY aufnr = lwa_header-aufnr.
          IF sy-subrc IS INITIAL AND (
                   ( lwa_header_old-gamng NE lwa_header-gamng )
                OR ( lwa_header_old-gmein NE lwa_header-gmein ) ).
            DATA(lv_error) = abap_true.
          ENDIF.

** As per the above logic if there are no changes then check whether
** the changes done in Item table for Batch and Storage Location.
** If any of them changed then set the Flag as X.
          IF lv_error NE abap_true.
            LOOP AT it_item INTO DATA(lwa_item).
              READ TABLE it_item_old INTO DATA(lwa_item_old)
                                     WITH KEY aufnr = lwa_item-aufnr
                                              posnr = lwa_item-posnr.
              IF sy-subrc IS INITIAL AND (
                     ( lwa_item_old-charg NE lwa_item-charg )
                  OR ( lwa_item_old-lgort NE lwa_item-lgort ) ).
                lv_error = abap_true.
                EXIT.
              ENDIF.
            ENDLOOP.
          ENDIF.

** As per the above logic if there are no changes then check whether
** the changes done in Component table for Batch, Storage Location,
** Backflush Indicator, UoM, Material and Quantity.
** If any of them changed then set the Flag as X.
          IF lv_error NE abap_true.
            LOOP AT it_component INTO DATA(lwa_comp).
              READ TABLE it_component_old INTO DATA(lwa_comp_old)
                                     WITH KEY rsnum = lwa_comp-rsnum
                                              rspos = lwa_comp-rspos
                                              rsart = lwa_comp-rsart.
              IF sy-subrc IS INITIAL AND (
                     ( lwa_comp_old-charg NE lwa_comp-charg )
                  OR ( lwa_comp_old-lgort NE lwa_comp-lgort )
                  OR ( lwa_comp_old-rgekz NE lwa_comp-rgekz )
                  OR ( lwa_comp_old-meins NE lwa_comp-meins )
                  OR ( lwa_comp_old-matnr NE lwa_comp-matnr )
                  OR ( lwa_comp_old-bdmng NE lwa_comp-bdmng ) ).
                lv_error = abap_true.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

** Finally if any one of the condition fulfill and error flag hasbeen
** set then through an error "Orders cannot be changed as Execution
**at MES started
    IF lv_error EQ abap_true.
      MESSAGE e005(zmpl2pr_messages).
    ENDIF.

  ENDMETHOD.

You might also like