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

Material Stock report



 
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: 1640

PostPosted: Sat Sep 20, 2008 8:36 pm    Post subject: Material Stock report Reply with quote

Code:
REPORT zm07mkon MESSAGE-ID m7.
*ENHANCEMENT-POINT RM07MKON_G4 SPOTS ES_RM07MKON STATIC.
*ENHANCEMENT-POINT RM07MKON_G5 SPOTS ES_RM07MKON.
*ENHANCEMENT-POINT RM07MKON_G6 SPOTS ES_RM07MKON STATIC.
*ENHANCEMENT-POINT RM07MKON_G7 SPOTS ES_RM07MKON.

CLASS cl_mmim_auth DEFINITION LOAD.

TABLES: msku, makt, mara, t001w, kna1.

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.
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,
dummy TYPE alv_dummy,
farbe TYPE slis_t_specialcol_alv, " color
kunres LIKE mbew-salk3, "total unrestricted stock
kinqul LIKE mbew-salk3, "total in quality inspection
krest LIKE mbew-salk3. "total restricted stock

ctotal LIKE mbew-salk3.
DATA: END OF itab.

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,
ctotal LIKE mbew-salk3,
END OF header.

DATA: fc TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.
DATA: detail.

INITIALIZATION.
*ENHANCEMENT-POINT RM07MKON_01 SPOTS ES_RM07MKON.
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 changed from e159(at) to e831 "XJD 14.11.2001
SET CURSOR FIELD 'SOBKZ_W'. "XJD 14.11.2001
MESSAGE e831. "Please choose at least one stock type
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.

New table to hold the costs
DATA: BEGIN OF imbew_key OCCURS 0,
charg LIKE mchb-charg,
END OF imbew_key.

DATA: BEGIN OF imbew OCCURS 0,
matnr LIKE mbew-matnr,
bwkey LIKE mbew-bwkey,
salk3 LIKE mbew-salk3,
charg LIKE mchb-charg,
END OF imbew.

DATA: imbew TYPE STANDARD TABLE OF smbew.

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.

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.
imbew_key-charg = itab-charg. COLLECT imbew_key.
ENDLOOP.

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.
**new code to get costs
*selecting data into imbew, later reading imbew based on batch number
and placing the necessary values in the final structure itab-.

SELECT a~matnr a~bwkey a~salk3 b~charg INTO TABLE imbew
FROM mbew AS a
JOIN mchb AS b
ON a~matnr = b~matnr AND
a~bwkey = b~werks
FOR ALL ENTRIES IN imbew_key
WHERE b~charg = imbew_key-charg AND
a~bwkey = t001w_key-werks.

SORT imbew BY matnr bwkey charg.
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.
*new code
*get data from imbew to final structure

READ TABLE imbew WITH KEY matnr = itab-matnr
bwkey = itab-werks
charg = itab-charg BINARY SEARCH.
IF sy-subrc = 0. itab-kunres = imbew-salk3. ENDIF.

MODIFY itab.
ENDLOOP.
SORT itab BY kunnr matnr charg.
ENDFORM. "data_selection

************************************************************************
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 = 'HEADER'.
fc-fieldname = 'TOTAL'.
fc-ref_tabname = 'MBEW'.
fc-ref_fieldname = 'SALK3'.

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 = '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'.
fc-seltext_l = 'WMU'.
fc-seltext_m = 'WMU'.
fc-seltext_s = 'WMU'.
APPEND fc. CLEAR fc.

fc-tabname = 'HEADER'.
fc-fieldname = 'CTOTAL'.
fc-ref_tabname = 'MARA'.
fc-seltext_l = 'WMU'.
fc-seltext_m = 'WMU'.
fc-seltext_s = 'WMU'.
APPEND fc. CLEAR fc.
*New code
fc-fieldname = 'DUMMY'.
fc-tabname = 'LIST'.
fc-row_pos = '2'.
fc-outputlen = 59.
APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.
fc-fieldname = 'KUNRES'.
fc-row_pos = '2'.
fc-seltext_s = 'Total'.
fc-do_sum = 'X'.
APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.
fc-fieldname = 'KINQUL'.
fc-row_pos = '2'.
fc-seltext_s = 'Total'.
fc-outputlen = 18.
fc-do_sum = 'X'.
APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.
fc-fieldname = 'KREST'.
fc-row_pos = '2'.
fc-seltext_s = 'Total'.
fc-outputlen = 18.
fc-do_sum = 'X'.
APPEND fc. CLEAR fc.

ENDFORM. "fieldcatalog

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

************************************************************************

************************************************************************
FORM calculate_and_colorize.
DATA: sum LIKE msku-kulab,
cust_sum LIKE mbew-salk3.
REFRESH list.

LOOP AT itab.

CHECK cl_mmim_auth=>check( i_object = 'M_MATE_WRK'
i_value1 = itab-werks ) IS INITIAL.

Authorization for total fields
CHECK ZCL_NAME1_AUTH=>check( i_object = 'ZSALK3'
i_value1 = itab-kunres ) IS INITIAL.

cust_sum = itab-kunres + cust_sum.

AT NEW kunnr.

itab-ctotal = cust_sum.
CLEAR cust_sum.
ENDAT.

IF zero = ' '.
sum = itab-kulab + itab-kuein + itab-kuins.
CHECK sum 0.
ENDIF.
MOVE-CORRESPONDING itab TO list.

PERFORM convert_to_ea.

APPEND list.
ENDLOOP.
ENDFORM. "calculate_and_colorize

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

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

************************************************************************
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. "detail_list
&---------------------------------------------------------------------
*& Form convert_to_ea
&---------------------------------------------------------------------

text

--> p1 text
<-- p2 text
FORM convert_to_ea .
DATA: l_lvsme TYPE lvs_lvsme,
l_lgnum TYPE lgnum,
l_lbkum TYPE lbkum,
l_salk3 TYPE salk3,
l_peinh TYPE peinh,
l_verpr TYPE verpr,
l_bwtty TYPE bwtty_d,
factor TYPE f.

l_lgnum = list-werks+1.

SELECT SINGLE lvsme
INTO l_lvsme
FROM mlgn
WHERE matnr = list-matnr
AND lgnum = l_lgnum.

*...for Standard materials...
SELECT SINGLE lbkum salk3 peinh verpr bwtty
INTO (l_lbkum, l_salk3, l_peinh, l_verpr, l_bwtty)
FROM mbew
WHERE matnr = list-matnr
AND bwkey = list-werks.

IF l_lbkum = 0.
factor = l_verpr / l_peinh.
ELSE.
factor = l_salk3 / l_lbkum.
ENDIF.

*Totals

Total unrestricted stock
list-kunres = list-kulab * factor.

Total stock in quality
list-kinqul = list-kuins * factor.

Total restricted stock
list-krest = list-kuein * factor.

*.......for Configurable items.........
IF l_bwtty = 'X'.
SELECT SINGLE salk3 INTO (l_salk3)
FROM mbew
WHERE matnr = list-matnr AND
bwkey = list-werks AND
bwtar = list-charg.
list-kunres = l_salk3.
ENDIF.
*.........................................
IF NOT l_lvsme IS INITIAL.
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
input = list-kulab
matnr = list-matnr
meinh = l_lvsme
meins = list-meins
charge = list-charg
werks = list-werks
IMPORTING
output = list-kulab
EXCEPTIONS
conversion_not_found = 1
input_invalid = 2
material_not_found = 3
meinh_not_found = 4
meins_missing = 5
no_meinh = 6
output_invalid = 7
overflow = 8
OTHERS = 9.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
input = list-kuins
matnr = list-matnr
meinh = l_lvsme
meins = list-meins
charge = list-charg
werks = list-werks
IMPORTING
output = list-kuins
EXCEPTIONS
conversion_not_found = 1
input_invalid = 2
material_not_found = 3
meinh_not_found = 4
meins_missing = 5
no_meinh = 6
output_invalid = 7
overflow = 8
OTHERS = 9.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
input = list-kuein
matnr = list-matnr
meinh = l_lvsme
meins = list-meins
charge = list-charg
werks = list-werks
IMPORTING
output = list-kuein
EXCEPTIONS
conversion_not_found = 1
input_invalid = 2
material_not_found = 3
meinh_not_found = 4
meins_missing = 5
no_meinh = 6
output_invalid = 7
overflow = 8
OTHERS = 9.

list-meins = l_lvsme.
ENDIF.

ENDFORM. " convert_to_ea
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.