SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

MB58: Special stocks V and W



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Thu Feb 19, 2009 3:47 pm    Post subject: MB58: Special stocks V and W Reply with quote

Code:
************************************************************************
* MB58: Special stocks V and W                                         *
* Last modification: 16.02.1999, jkr                                   *
************************************************************************
**** Auteur : Mickael QUESNOT        Ste : CODILOG                  ****
***************************************************transaction standard*
**** DTI: BFEU-74ZK38  Date: 31032008  QTMS:  SC1000035             ****
************************************************************************
 
REPORT rm07mkon MESSAGE-ID m7.
 
CLASS cl_mmim_auth DEFINITION LOAD.
 
TABLES: msku, makt, mara, t001w, kna1, mch1, knmt.
 
SELECTION-SCREEN: BEGIN OF BLOCK dba WITH FRAME TITLE text-001.
SELECT-OPTIONS: matnr FOR mara-matnr,
                werks FOR t001w-werks MEMORY ID wrk,
                charg FOR msku-charg,
                kunnr FOR msku-kunnr,
                vkorg FOR knmt-vkorg OBLIGATORY MEMORY ID vko.
PARAMETERS: sobkz_w LIKE am07m-kukns AS CHECKBOX DEFAULT 'X',
            sobkz_v LIKE am07m-lhgut AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN: END OF BLOCK dba.
 
SELECTION-SCREEN: BEGIN OF BLOCK anz WITH FRAME TITLE text-005.
PARAMETERS: alv_def     LIKE disvariant-variant,
            zero LIKE am07m-xmnul AS CHECKBOX.
SELECTION-SCREEN: END OF BLOCK anz.
 
INCLUDE rm07alvi.
 
DATA: BEGIN OF itab OCCURS 0.
        INCLUDE STRUCTURE msku.
DATA:   maktx LIKE makt-maktx,
        name1_w LIKE t001w-name1,
        name1_k LIKE kna1-name1,
        meins LIKE mara-meins,
        licha LIKE mch1-licha,
        kdmat LIKE knmt-kdmat.
DATA: END OF itab.
 
DATA ti_mch1 TYPE mcha OCCURS 0 WITH HEADER LINE.
 
DATA ti_knmt TYPE knmt OCCURS 0 WITH HEADER LINE.
 
DATA: BEGIN OF list OCCURS 0.
        INCLUDE STRUCTURE itab.
DATA: END OF list.
 
DATA: BEGIN OF header OCCURS 0,
        kunnr LIKE kna1-kunnr,
        name1_k LIKE kna1-name1,
      END OF header.
 
DATA: fc TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.
DATA: detail.
 
INITIALIZATION.
  PERFORM alv_init.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR alv_def.
  PERFORM alv_f4.


 
AT SELECTION-SCREEN.
  CALL FUNCTION 'MMIM_ENTRYCHECK_MAIN'
       TABLES
            it_matnr = matnr
            it_werks = werks
            it_kunnr = kunnr.
  IF sobkz_w = space AND sobkz_v = space.
    MESSAGE e159(at) WITH text-002.
  ENDIF.
  PERFORM alv_check.
 
START-OF-SELECTION.
  PERFORM data_selection.
 
END-OF-SELECTION.
  PERFORM calculate_and_colorize.
  PERFORM fieldcatalog.
  PERFORM list_display.
 
 
************************************************************************
FORM data_selection.
  DATA: BEGIN OF makt_key OCCURS 0,
          matnr LIKE makt-matnr,
        END OF makt_key.
  DATA: BEGIN OF imakt OCCURS 0,
          matnr LIKE makt-matnr,
          maktx LIKE makt-maktx,
        END OF imakt.
  DATA: BEGIN OF mara_key OCCURS 0,
          matnr LIKE mara-matnr,
        END OF mara_key.
  DATA: BEGIN OF imara OCCURS 0,
          matnr LIKE mara-matnr,
          meins LIKE mara-meins,
        END OF imara.
  DATA: BEGIN OF t001w_key OCCURS 0,
          werks LIKE t001w-werks,
        END OF t001w_key.
  DATA: BEGIN OF it001w OCCURS 0,
          werks LIKE t001w-werks,
          name1 LIKE t001w-name1,
        END OF it001w.
  DATA: BEGIN OF kna1_key OCCURS 0,
          kunnr LIKE kna1-kunnr,
        END OF kna1_key.
  DATA: BEGIN OF ikna1 OCCURS 0,
          kunnr LIKE kna1-kunnr,
          name1 LIKE kna1-name1,
        END OF ikna1.
  RANGES sobkz FOR msku-sobkz.
* Main data
  REFRESH sobkz.
  sobkz-sign = 'I'. sobkz-option = 'EQ'.
  IF sobkz_w = 'X'. sobkz-low = 'W'. APPEND sobkz. ENDIF.
  IF sobkz_v = 'X'. sobkz-low = 'V'. APPEND sobkz. ENDIF.
  SELECT * FROM msku INTO CORRESPONDING FIELDS OF TABLE itab
     WHERE matnr IN matnr
       AND werks IN werks
       AND charg IN charg
       AND sobkz IN sobkz
       AND kunnr IN kunnr.


 
  IF sy-subrc = 0.
 
*Batches
    CLEAR   ti_mch1.
    REFRESH ti_mch1.
    SELECT * FROM mch1 INTO CORRESPONDING FIELDS OF TABLE ti_mch1
    FOR ALL ENTRIES IN itab
    WHERE matnr = itab-matnr
    AND   charg = itab-charg.
 
*Customer-Material Info Record Data Table
    CLEAR   ti_knmt.
    REFRESH ti_knmt.
    SELECT * FROM knmt INTO CORRESPONDING FIELDS OF TABLE ti_knmt
    FOR ALL ENTRIES IN itab
    WHERE matnr = itab-matnr
    AND   werks = itab-werks
    AND   kunnr = itab-kunnr
    AND   vkorg IN vkorg.
 
  ENDIF. " subrc
 
 
 
* Additional info: material text, plant name, debitor name
  LOOP AT itab.
    makt_key-matnr = itab-matnr. COLLECT makt_key.
    mara_key-matnr = itab-matnr. COLLECT mara_key.
    t001w_key-werks = itab-werks. COLLECT t001w_key.
    kna1_key-kunnr  = itab-kunnr. COLLECT kna1_key.
 
* Additional info: Vendor batch number, Material number used by customer
    CLEAR ti_mch1.
    READ TABLE ti_mch1 WITH KEY matnr = itab-matnr
                                charg = itab-charg.
    IF sy-subrc = 0.
      itab-licha = ti_mch1-licha.
      MODIFY itab TRANSPORTING licha .
    ENDIF.
 
    CLEAR ti_knmt.
    READ TABLE ti_knmt WITH KEY matnr = itab-matnr
                                werks = itab-werks
                                kunnr = itab-kunnr.
    IF sy-subrc = 0.
      itab-kdmat = ti_knmt-kdmat.
      MODIFY itab TRANSPORTING kdmat.
    ENDIF.
 
  ENDLOOP." itab
 
  READ TABLE makt_key INDEX 1.
  IF sy-subrc = 0.
    SELECT matnr maktx INTO CORRESPONDING FIELDS OF TABLE imakt
      FROM makt FOR ALL ENTRIES IN makt_key
      WHERE matnr = makt_key-matnr
        AND spras = sy-langu.
    SORT imakt BY matnr.
  ENDIF.
  READ TABLE mara_key INDEX 1.
  IF sy-subrc = 0.
    SELECT matnr meins INTO CORRESPONDING FIELDS OF TABLE imara


      FROM mara FOR ALL ENTRIES IN mara_key
      WHERE matnr = mara_key-matnr.
    SORT imara BY matnr.
  ENDIF.
  READ TABLE t001w_key INDEX 1.
  IF sy-subrc = 0.
    SELECT werks name1 INTO CORRESPONDING FIELDS OF TABLE it001w
      FROM t001w FOR ALL ENTRIES IN t001w_key
      WHERE werks = t001w_key-werks.
    SORT it001w BY werks.
  ENDIF.
  READ TABLE kna1_key INDEX 1.
  IF sy-subrc = 0.
    SELECT kunnr name1 INTO CORRESPONDING FIELDS OF TABLE ikna1
      FROM kna1 FOR ALL ENTRIES IN kna1_key
      WHERE kunnr = kna1_key-kunnr.
    SORT ikna1 BY kunnr.
  ENDIF.
  LOOP AT itab.
    READ TABLE imakt WITH KEY matnr = itab-matnr BINARY SEARCH.
    IF sy-subrc = 0. itab-maktx = imakt-maktx. ENDIF.
    READ TABLE imara WITH KEY matnr = itab-matnr BINARY SEARCH.
    IF sy-subrc = 0. itab-meins = imara-meins. ENDIF.
    READ TABLE it001w WITH KEY werks = itab-werks BINARY SEARCH.
    IF sy-subrc = 0. itab-name1_w = it001w-name1. ENDIF.
    READ TABLE ikna1 WITH KEY kunnr = itab-kunnr BINARY SEARCH.
    IF sy-subrc = 0. itab-name1_k = ikna1-name1. ENDIF.
    MODIFY itab.
  ENDLOOP.
  SORT itab BY kunnr matnr charg.
ENDFORM.
 
************************************************************************
FORM fieldcatalog.
  REFRESH fc. CLEAR fc.
 
  fc-tabname = 'HEADER'.
  fc-fieldname = 'KUNNR'.
  fc-ref_tabname = 'MSKU'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'HEADER'.
  fc-fieldname = 'NAME1_K'.
  fc-ref_tabname = 'KNA1'.
  fc-ref_fieldname = 'NAME1'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'MATNR'.
  fc-ref_tabname = 'MSKU'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'MAKTX'.
  fc-ref_tabname = 'MAKT'.
  fc-no_out = 'X'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'CHARG'.
  fc-ref_tabname = 'MSKU'.
  APPEND fc. CLEAR fc.
*
  fc-tabname = 'LIST'.
  fc-fieldname = 'LICHA'.
  fc-ref_tabname = 'MCH1'.
  APPEND fc. CLEAR fc.


  fc-tabname = 'LIST'.
  fc-fieldname = 'KDMAT'.
  fc-ref_tabname = 'KNMT'.
  APPEND fc. CLEAR fc.
*
  fc-tabname = 'LIST'.
  fc-fieldname = 'WERKS'.
  fc-ref_tabname = 'MSKU'.
  fc-no_out = 'X'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'NAME1_W'.
  fc-ref_tabname = 'T001W'.
  fc-ref_fieldname = 'NAME1'.
  fc-no_out = 'X'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'SOBKZ'.
  fc-ref_tabname = 'MSKU'.
  fc-no_out = 'X'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'KULAB'.
  fc-qfieldname = 'MEINS'.
  fc-ref_tabname = 'MSKU'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'KUINS'.
  fc-qfieldname = 'MEINS'.
  fc-ref_tabname = 'MSKU'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'KUEIN'.
  fc-qfieldname = 'MEINS'.
  fc-ref_tabname = 'MSKU'.
  APPEND fc. CLEAR fc.
  fc-tabname = 'LIST'.
  fc-fieldname = 'MEINS'.
  fc-ref_tabname = 'MARA'.
  APPEND fc. CLEAR fc.
 
 
 
ENDFORM.
 
************************************************************************
FORM list_display.
  REFRESH header.
  LOOP AT list.
    ON CHANGE OF list-kunnr.
      MOVE-CORRESPONDING list TO header.
      APPEND header.
    ENDON.
  ENDLOOP.
 
  alv_keyinfo-header01 = 'KUNNR'.
  alv_keyinfo-item01   = 'KUNNR'.
  alv_keyinfo-item02   = 'MATNR'.
 
  CLEAR detail.
 
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
       EXPORTING


            i_interface_check        = ' '
            i_callback_program       = alv_repid
            i_callback_pf_status_set = 'SET_STATUS'
            i_callback_user_command  = 'USER_COMMAND'
            is_layout                = alv_layout
            it_fieldcat              = fc[]
            i_default                = 'X'
            i_save                   = 'A'
            is_variant               = alv_variant
            i_tabname_header         = 'HEADER'
            i_tabname_item           = 'LIST'
            is_keyinfo               = alv_keyinfo
            is_print                 = alv_print
       TABLES
            t_outtab_header          = header
            t_outtab_item            = list.
 
ENDFORM.
 
 
************************************************************************
 
************************************************************************
FORM calculate_and_colorize.
  DATA: sum LIKE msku-kulab.
  REFRESH list.
  LOOP AT itab.
    CHECK cl_mmim_auth=>check( i_object = 'M_MATE_WRK'
                               i_value1 = itab-werks ) IS INITIAL.
    IF zero = ' '.
      sum = itab-kulab + itab-kuein + itab-kuins.
      CHECK sum <> 0.
    ENDIF.
    MOVE-CORRESPONDING itab TO list.
    APPEND list.
  ENDLOOP.
ENDFORM.
 
************************************************************************
FORM set_status USING rt_extab TYPE slis_t_extab.
  DATA: wa TYPE slis_extab.
  IF cl_mmim_auth=>level( ) IS INITIAL.
    APPEND 'AUTH' TO rt_extab.
  ENDIF.
  IF cl_mmim_auth=>level( ) = cl_mmim_auth=>c_error.
    MESSAGE s124(m7).
  ENDIF.
* Deactivate detail list if in detail list
  IF detail = 'X'.
    wa-fcode = 'DETAIL'.
    APPEND wa TO rt_extab.
  ENDIF.
  SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
ENDFORM.
 
************************************************************************
FORM user_command USING rf_ucomm LIKE sy-ucomm
                          rs TYPE slis_selfield.
 
* Call from detail list: Change tablename
  IF rs-tabname = '1'.
    rs-tabname = 'LIST'.
  ENDIF.


* Read the correct table
  CLEAR: list, header.
  CASE rs-tabname.
    WHEN 'HEADER'.
      READ TABLE header INDEX rs-tabindex.
      MOVE-CORRESPONDING header TO list.
    WHEN 'LIST'.
      READ TABLE list INDEX rs-tabindex.
  ENDCASE.
  CHECK sy-subrc = 0.
* Double click targets
  IF rf_ucomm = '&IC1'.
    CASE rs-tabname.
      WHEN 'HEADER'.
        rf_ucomm = 'ADDR'.
      WHEN 'LIST'.
        CASE rs-fieldname.
          WHEN 'MATNR'.
            rf_ucomm = 'MMBE'.
          WHEN OTHERS.
            rf_ucomm = 'DOCU'.
        ENDCASE.
    ENDCASE.
  ENDIF.
* Commands
  CASE rf_ucomm.
    WHEN 'MMBE'.
      CHECK rs-tabname = 'LIST'.     "only for items
      SET PARAMETER ID 'MAT' FIELD list-matnr.
      SET PARAMETER ID 'WRK' FIELD list-werks.
      CALL TRANSACTION 'MMBE' AND SKIP FIRST SCREEN.
    WHEN 'DOCU'.
      CHECK rs-tabname = 'LIST'.
      SUBMIT rm07docs WITH matnr = list-matnr
                      WITH werks = list-werks
                      WITH charg = list-charg
                      WITH sobkz = list-sobkz
                      WITH kunnr = list-kunnr
                      AND RETURN.
    WHEN 'ADDR'.
      SET PARAMETER ID 'KUN' FIELD list-kunnr.
      CALL TRANSACTION 'VD03' AND SKIP FIRST SCREEN.
    WHEN 'AUTH'.
      CALL METHOD cl_mmim_auth=>display.
    WHEN 'DETAIL'.
      PERFORM detail_list.
  ENDCASE.
  CLEAR rf_ucomm.
ENDFORM.
 
************************************************************************
FORM detail_list.
  DATA: fc_detail TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.
  DATA: variant_detail      LIKE disvariant.
  DATA: lt_base_list LIKE list[].                           "401421
* The detail ALV may modify the list (sorting). If returned to the
* base list, the original list needs to be restored.
  lt_base_list[] = list[].                                  "401421
  REFRESH fc_detail.
  LOOP AT fc.
    MOVE-CORRESPONDING fc TO fc_detail.
    CLEAR fc_detail-tabname.
    APPEND fc_detail.


  ENDLOOP.
  CLEAR variant_detail.
  variant_detail-report = alv_repid.
  variant_detail-handle = 'DETA'.
  detail = 'X'. "needed for GUI status differentiation
 
  CALL FUNCTION alv_detail_func
       EXPORTING
            i_callback_program       = alv_repid
            i_callback_pf_status_set = 'SET_STATUS'
            i_callback_user_command  = 'USER_COMMAND'
            it_fieldcat              = fc_detail[]
            i_default                = 'X'
            is_variant               = variant_detail
            i_save                   = 'A'
            is_layout                = alv_layout
            is_print                 = alv_print
       TABLES
            t_outtab                 = list[].
  CLEAR detail.
  list[] = lt_base_list[].                                  "401421
ENDFORM.
 
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.