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.
************************************************************************
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.
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.
************************************************************************
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
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.