Posted: Sat Oct 06, 2007 2:09 am Post subject: Create/change the Material BOM
Code:
REPORT sy-repid NO STANDARD PAGE HEADING
LINE-SIZE 255
LINE-COUNT 65.
TABLES: mara,
marc,
mbew,
mast,
stpo,
t001w,
mvke,
t460a.
TYPE-POOLS slis .
CONSTANTS: id LIKE thead-tdid VALUE '0001',
object LIKE thead-tdobject VALUE 'MVKE',
call_mode_ale LIKE mmdcmode-call_mode VALUE 'ALE'.
* *--------------------------------*
*-* I N T E R N A L T A B L E S *------------------------------------
* *--------------------------------*
* Internal table description
Data: begin of t_mara occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
werks like marc-werks,
matkl like mara-matkl,
mtpos_mara like mara-mtpos_mara,
zzmtpos like marc-zzmtpos,
lvorm like mara-lvorm,
stlan like marc-stlan,
sobsk like marc-sobsk,
pstat like marc-pstat,
ncost type c,
stdpd like marc-stdpd,
beskz like marc-beskz,
sobsl like marc-sobsl,
schgt like marc-schgt,
created like marc-ncost,
ekalr like mbew-ekalr,
hkmat like mbew-hkmat,
hrkft like mbew-hrkft,
mvkemtpos like mvke-mtpos,
error(220) type c,
end of t_mara.
Data: begin of t_sobsl occurs 0,
sobsl like t460a-sobsl,
end of t_sobsl.
Data: begin of t_stpo occurs 0,
matnr like mast-matnr,
werks like mast-werks,
stlan like mast-stlan,
stlnr like stpo-stlnr,
idnrk like stpo-idnrk,
posnr like stpo-posnr,
aennr like stpo-aennr,
BULK(1) type c,
mmbulk like marc-schgt,
valid_from like STKO_API02-valid_from,
error(220) type c,
end of t_stpo.
Data: begin of t_plants occurs 0,
werks like marc-werks,
name1 like t001w-name1,
end of t_plants.
Data: t_temp_stpo like t_stpo occurs 0 with header line.
DATA: mara_ueb LIKE mara_ueb OCCURS 0 WITH HEADER LINE,
makt_ueb LIKE makt_ueb OCCURS 0 WITH HEADER LINE,
marc_ueb LIKE marc_ueb OCCURS 0 WITH HEADER LINE,
mard_ueb LIKE mard_ueb OCCURS 0 WITH HEADER LINE,
mbew_ueb LIKE mbew_ueb OCCURS 0 WITH HEADER LINE,
t_mfieldres LIKE mfieldres OCCURS 0,
d_mfieldres like mfieldres,
tranc LIKE mara_ueb-tranc VALUE '0000000001',
merrdat LIKE merrdat OCCURS 0 WITH HEADER LINE,
messg LIKE message,
wrk_length TYPE i,
ermsg(220) type c,
v_temp_tranc LIKE mara_ueb-tranc.
data: wrk_origin_group like mbew_ueb-hrkft.
DATA: tcode LIKE sy-tcode VALUE 'MM02'.
DATA: fieldcat TYPE slis_t_fieldcat_alv,
fieldcat_ln LIKE LINE OF fieldcat,
sortcat TYPE slis_t_sortinfo_alv,
sortcat_ln LIKE LINE OF sortcat,
eventcat TYPE slis_t_event,
eventcat_ln LIKE LINE OF eventcat,
col_pos TYPE i,
ls_line TYPE slis_listheader,
l_line TYPE slis_listheader-info,
wrk_ucomm TYPE slis_formname,
v_layout TYPE slis_layout_alv.
DATA: wultb LIKE stpov OCCURS 0 WITH HEADER LINE,
equicat LIKE cscequi OCCURS 0 WITH HEADER LINE,
kndcat LIKE cscknd OCCURS 0 WITH HEADER LINE,
matcat LIKE cscmat OCCURS 0 WITH HEADER LINE,
stdcat LIKE cscstd OCCURS 0 WITH HEADER LINE,
tplcat LIKE csctpl OCCURS 0 WITH HEADER LINE,
t_stpo_read like STPO_API02 occurs 0 with header line,
t_stpo_update like STPO_API03 occurs 0 with header line,
i_stko LIKE stko_api01,
T_STKO LIKE STKO_API02 OCCURS 0 WITH HEADER LINE,
wrk_date like CSAP_MBOM-DATUV.
data: t_wultb like wultb occurs 0 with header line.
*---------------------*
*-* V A R I A B L E S *-----------------------------------------------
* *---------------------*
DATA: WRK_COUNT TYPE I,
WRK_LINES TYPE I,
wrk_line type i,
wrk_message(50) type c,
validityflag like marc-lvorm,
ermsg_update(220) type c,
w_error(40) type c.
** Grid Controls.
DATA: gt_events TYPE slis_t_event,
gt_list_top_of_page TYPE slis_t_listheader,
g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
g_layout TYPE slis_layout_alv,
gt_fieldcat TYPE slis_t_fieldcat_alv,
g_fieldcat TYPE LINE OF slis_t_fieldcat_alv,
prog LIKE sy-repid,
l_mode VALUE 'E'.
DATA: g_grid_data TYPE zty_condition_find,
gt_keys TYPE zty_condition_find OCCURS 0,
gt_grid_data TYPE zty_condition_find OCCURS 0,
gt_bdc_tab TYPE bdcdata OCCURS 20 WITH HEADER LINE.
* *---------------------*
*-* C O N S T A N T S *-----------------------------------------------
* *---------------------*
* *--------------------------*
*-* F I E L D - S Y M B O L *------------------------------------------
* *--------------------------*
* *----------------------------------*
*-* S E L E C T I O N S C R E E N *---------------------------------
* *----------------------------------*
*
SELECTION-SCREEN BEGIN OF BLOCK PC WITH FRAME.
*
select-options: s_mtart for mara-mtart.
select-options: s_matkl for mara-matkl.
select-options: s_mtpos for mara-MTPOS_MARA.
select-options: s_zmtpos for marc-zzmtpos.
select-options: s_werks for marc-werks.
select-options: s_matnr for mara-matnr.
select-options: s_sobsl for marc-sobsl.
select-options: s_beskz for marc-beskz.
*select-options: s_ekalr for mbew-ekalr.
*select-options: s_hkmat for mbew-hkmat.
*select-options: s_hrkft for mbew-hrkft.
selection-screen skip 1.
parameters: p_test radiobutton group rad1 default 'X',
p_update radiobutton group rad1.
selection-screen skip 1.
parameters: p_succ as checkbox default 'X'.
selection-screen skip 1.
parameters: p_cost radiobutton group rad2 default 'X',
p_trim radiobutton group rad2,
p_crel radiobutton group rad2,
p_rp radiobutton group rad2.
selection-screen skip 1.
parameters: p_date like rc29l-datub default sy-datum.
SELECTION-SCREEN END OF BLOCK PC.
* ****************************************** *
**************** A T S E L E C T I O N - S C R E E N ****************
* ****************************************** *
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.
* PERFORM FILE_SELECTION_BOX USING P_IFILE.
*if p_v1 = 'X'.
* if s_mtart[] is initial.
* MOVE 'Material Type' TO w_error.
* MESSAGE ID 'ZVC' TYPE 'E' NUMBER '000' WITH w_error.
* endif.
*endif.
*
* ************************************
***************** E V E N T P R O C E S S I N G *********************
* ************************************
**********************
** AT LINE-SELECTION *
**********************
*
* ***************************
********************* S U B R O U T I N E S **************************
* ***************************
*&---------------------------------------------------------------------*
*& Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_EVENTS[] text
*----------------------------------------------------------------------*
FORM eventtab_build USING rt_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event.
* CALL FUNCTION 'REUSE_ALV_EVENTS_GET' " STC009
* EXPORTING
* i_list_type = 0
* IMPORTING
* et_events = rt_events.
*
* READ TABLE rt_events WITH KEY name = slis_ev_top_of_page
* INTO ls_event.
* IF sy-subrc = 0.
ls_event-name = slis_ev_top_of_page. " STC009
MOVE g_top_of_page TO ls_event-form.
APPEND ls_event TO rt_events.
* ENDIF.
ENDFORM. " EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = gt_list_top_of_page.
ENDFORM. " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form BUILD_HEADER_LINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
* CLEAR ls_line.
* ls_line-typ = 'S'.
*
*
* DESCRIBE TABLE s_idnrk LINES wrk_line.
* IF wrk_line <> 0.
* LOOP AT s_idnrk.
* CLEAR ls_line.
* ls_line-typ = 'S'.
*
* CASE s_idnrk-option.
*
*
* WHEN 'EQ'.
* CONCATENATE 'Component:' s_idnrk-low INTO
* ls_line-info SEPARATED BY space.
*
* WHEN 'CP'.
* CONCATENATE 'Components Containing:' s_idnrk-low INTO
* ls_line-info SEPARATED BY space.
* WHEN OTHERS.
* CONCATENATE 'Component:' s_idnrk-low INTO
* ls_line-info SEPARATED BY space.
* ENDCASE.
* APPEND ls_line TO gt_list_top_of_page.
*
* ENDLOOP.
* ENDIF.
**
**---------------------
** Work Center
**---------------------
**
* CLEAR ls_line.
* ls_line-typ = 'S'.
*
* DESCRIBE TABLE s_arbpl LINES wrk_line.
* IF wrk_line <> 0.
* LOOP AT s_arbpl.
* CLEAR ls_line.
* ls_line-typ = 'S'.
*
* CASE s_arbpl-option.
*
*
* WHEN 'EQ'.
* CONCATENATE 'Work Center:' s_arbpl-low INTO
* ls_line-info SEPARATED BY space.
*
* WHEN 'CP'.
* CONCATENATE 'Work Center Containing:' s_arbpl-low INTO
* ls_line-info SEPARATED BY space.
* WHEN OTHERS.
* CONCATENATE 'Work Center:' s_arbpl-low INTO
* ls_line-info SEPARATED BY space.
* ENDCASE.
* APPEND ls_line TO gt_list_top_of_page.
*
* ENDLOOP.
* ENDIF.
ENDFORM. " BUILD_HEADER_LINE
*&---------------------------------------------------------------------*
*& Form PRINT_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form print_report.
if not p_crel = 'X'.
describe table t_mara lines wrk_lines.
*
if wrk_lines > 0.
PERFORM build_fieldcat USING 'MARA'
'MATNR' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARA'
'MTART' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'WERKS' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARA'
'MTPOS_MARA' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'ZZMTPOS' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARA'
'MATKL' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARA'
'LVORM' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'STLAN' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'SOBSK' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'PSTAT' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'NCOST' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'STDPD' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'BESKZ' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'SOBSL' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MARC'
'SCHGT' 'X' space space space space space 0.
PERFORM build_fieldcat USING ' '
'CREATED' 'X' space space space space 'Bom Created' 12.
PERFORM build_fieldcat USING 'MBEW'
'EKALR' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MBEW'
'HKMAT' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MBEW'
'HRKFT' 'X' space space space space space 0.
PERFORM build_fieldcat USING ' '
'MVKEMTPOS' 'X' space space space space 'Sales Org Item Category' 23.
PERFORM build_fieldcat USING ' '
'ERROR' 'X' space space space space 'MESSAGE' 40.
PERFORM build_fieldcat USING 'MAST'
'MATNR' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MAST'
'WERKS' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'MAST'
'STLAN' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'STPO'
'STLNR' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'STPO'
'IDNRK' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'STPO'
'POSNR' 'X' space space space space space 0.
PERFORM build_fieldcat USING 'STPO'
'AENNR' 'X' space space space space space 0.
PERFORM build_fieldcat USING ' '
'BULK' 'X' space space space space 'Bulk Material' 15.
PERFORM build_fieldcat USING ' '
'MMBULK' 'X' space space space space 'Bulk Material Material Master' 30.
PERFORM build_fieldcat USING 'STKO_API02'
'VALID_FROM' 'X' space space space space space 0.
PERFORM build_fieldcat USING ' '
'ERROR' 'X' space space space space 'Message' 220.
move 'No Records Found' TO wrk_message.
MESSAGE ID 'ZVC' TYPE 'S' NUMBER '000' WITH wrk_message.
CLEAR wrk_message.
endif.
endif.
endform. " PRINT_REPORT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_2793 text
* -->P_2794 text
* -->P_2795 text
* -->P_SPACE text
* -->P_SPACE text
* -->P_SPACE text
* -->P_SPACE text
* -->P_2800 text
* -->P_0 text
*----------------------------------------------------------------------*
FORM
build_fieldcat USING tabname LIKE fieldcat_ln-ref_tabname
fieldname LIKE fieldcat_ln-fieldname
key LIKE fieldcat_ln-key
do_sum LIKE fieldcat_ln-do_sum
no_out LIKE fieldcat_ln-no_out
qfieldname LIKE fieldcat_ln-qfieldname
hotspot LIKE fieldcat_ln-hotspot
reptext_ddic LIKE fieldcat_ln-reptext_ddic
outputlen LIKE fieldcat_ln-outputlen.
*&---------------------------------------------------------------------*
*& Form FILE_SELECTION_BOX
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_IFILE text
*----------------------------------------------------------------------*
FORM FILE_SELECTION_BOX USING FILENAME.
IF SY-SUBRC <> 0.
MESSAGE ID 'ZVC' TYPE 'E' NUMBER '000' WITH 'UPLOAD FAILED'.
ENDIF.
ENDFORM. " FILE_SELECTION_BOX
*&---------------------------------------------------------------------*
*& Form PROCESS_HOTSPOTS
*&---------------------------------------------------------------------*
* Call correct transaction based on which hotspot was selected
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process_hotspots USING ucomm ps_selfield TYPE slis_selfield.
if p_crel = 'X'.
READ TABLE t_stpo INTO t_stpo INDEX ps_selfield-tabindex.
CHECK sy-subrc = 0.
*
REFRESH gt_bdc_tab.
* CASE ps_selfield-fieldname.
IF t_stpo-matnr = ps_selfield-value. " stc008
* WHEN 'MATNR'. "material
CHECK NOT t_stpo-matnr IS INITIAL.
SET PARAMETER ID 'MAT' FIELD t_stpo-matnr.
set parameter id 'WRK' field t_stpo-werks.
set parameter id 'CSV' field t_stpo-stlan.
set parameter id 'AEN' field t_stpo-aennr.
CALL TRANSACTION 'CS02'.
* when 'VBELN'. "order
* check not t_orders-vbeln is initial.
* set parameter id 'AUN' field t_orders-vbeln.
* call transaction 'VA03' and skip first screen.
* when 'VBELNS'. "Steelcase purchase orders
* check not t_orders-vbelns is initial.
* call transaction 'ME23N'.
* ENDCASE.
endif.
endif.
endform. "process_hotspots
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA.
* Select mara~matnr mara~mtart marc~werks mara~matkl mara~mtpos_mara mara~lvorm marc~stlan marc~sobsk marc~zzlastmad marc~zzlastoe marc~pstat marc~ncost
* marc~zzmtpos marc~stdpd marc~beskz marc~sobsl marc~schgt into table t_mara from mara
* join marc on marc~matnr = mara~matnr
* where marc~matnr in s_matnr and
* mara~lvorm <> 'X' and
* mtart in s_mtart and
* matkl in s_matkl and
* MTPOS_MARA in s_mtpos and
* zzmtpos in s_zmtpos and
* marc~lvorm <> 'X' and
* marc~werks in s_werks and
* marc~sobsl in s_sobsl and
* ( marc~zzlastmad ge sy-datum or
* marc~zzlastmad = '00000000' ).
Select mara~matnr mara~mtart marc~werks mara~matkl mara~mtpos_mara marc~zzmtpos mara~lvorm marc~stlan marc~sobsk marc~pstat marc~ncost
marc~stdpd marc~beskz marc~sobsl marc~schgt into table t_mara from marc
inner join mara on marc~matnr = mara~matnr
where mara~matnr in s_matnr and
mara~lvorm <> 'X' and
mtart in s_mtart and
matkl in s_matkl and
MTPOS_MARA in s_mtpos and
zzmtpos in s_zmtpos and
marc~lvorm <> 'X' and
marc~werks in s_werks and
marc~sobsl in s_sobsl and
marc~beskz in s_beskz and
( marc~zzlastmad ge sy-datum or
marc~zzlastmad = '00000000' ) and
( marc~zzlastoe ge sy-datum or
marc~zzlastoe = '00000000').
* if not s_ekalr[] is initial or not s_hkmat[] is initial or not s_hrkft[] is initial.
*Delete materials in obsolete plants.
sort t_mara by werks.
Select werks name1 from t001w into table t_plants where name1 = 'OBSOLETE'.
loop at t_plants.
delete t_mara where werks = t_plants-werks.
endloop.
loop at t_mara.
* if p_nocost <> 'X'.
clear: mbew-ekalr,
mbew-hkmat,
mbew-hrkft.
if not t_mara-stdpd is initial.
move: t_mara-stdpd to t_mara-stdpd.
endif.
select single ekalr hkmat hrkft from mbew into (mbew-ekalr, mbew-hkmat, mbew-hrkft) where matnr = t_mara-matnr
and bwkey = t_mara-werks.
if sy-subrc = 0.
move: mbew-ekalr to t_mara-ekalr,
mbew-hkmat to t_mara-hkmat,
mbew-hrkft to t_mara-hrkft.
modify t_mara.
endif.
if t_mara-mtpos_mara is initial.
clear: mvke-mtpos.
select single mtpos from mvke into mvke-mtpos where matnr = t_mara-matnr and vkorg = '1000'.
if sy-subrc = 0.
move: mvke-mtpos to t_mara-mvkemtpos.
move: mvke-mtpos to t_mara-mtpos_mara.
modify t_mara.
endif.
endif.
endloop.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form update_materials
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM update_materials .
loop at t_mara.
if p_cost = 'X'.
refresh mara_ueb.
clear mara_ueb.
SELECT SINGLE * FROM mara INTO CORRESPONDING FIELDS OF mara_ueb
WHERE matnr = t_mara-matnr.
if sy-subrc = 0.
mara_ueb-tcode = tcode.
mara_ueb-tranc = tranc.
append mara_ueb.
v_temp_tranc = tranc.
*check if costing information needs to be updated if so update it.
if t_mara-pstat cs 'G'.
refresh: mbew_ueb.
clear: mbew_ueb.
select single * from mbew into corresponding fields of mbew_ueb
where matnr = t_mara-matnr and
bwkey = t_mara-werks.
if sy-subrc = 0.
*only want to set the material origin, Origin group and the qty with structure fields
*if product is a trim unit.
* if t_mara-matkl = 'T01' or t_mara-matkl = 'T04' or t_mara-matkl = 'T05'.
if t_mara-ekalr <> 'X'.
mbew_ueb-ekalr = 'X'.
endif.
if t_mara-hkmat <> 'X'.
mbew_ueb-hkmat = 'X'.
endif.
if t_mara-mtart = 'ZTRG' and t_mara-hrkft <> '0300'.
mbew_ueb-hrkft = '0300'.
endif.
if t_mara-mtart = 'FERT' and t_mara-hrkft <> '0200'.
mbew_ueb-hrkft = '0200'.
endif.
* endif.
refresh: marc_ueb.
clear: marc_ueb.
select single * from marc into corresponding fields of marc_ueb
where matnr = t_mara-matnr and
werks = t_mara-werks.
*
if sy-subrc = 0.
if t_mara-schgt = 'X'.
clear marc_ueb-schgt.
d_mfieldres-tranc = tranc.
d_mfieldres-fname = 'MARC-SCHGT'.
append d_mfieldres to t_mfieldres.
endif.
if marc_ueb-ncost = 'X'.
CLEAR marc_ueb-ncost.
d_mfieldres-tranc = tranc.
d_mfieldres-fname = 'MARC-NCOST'.
append d_mfieldres to t_mfieldres.
endif.
EXCEPTIONS
KSTATUS_EMPTY = 1
TKSTATUS_EMPTY = 2
T130M_ERROR = 3
INTERNAL_ERROR = 4
TOO_MANY_ERRORS = 5
UPDATE_ERROR = 6
OTHERS = 7
.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*-If error, assemble error message. Error messages are returned
* in a table, so could have multiples. If an error encountered,
* then raise exception and exit.
*search message text for material number if not found and error message
*less than 220 characters long then add it to the beginning of the
*message for message resolution. "<--STC012
CLEAR: wrk_length.
SEARCH messg-msgtx FOR merrdat-matnr. "<--STC012
IF sy-subrc <> 0. "not found "<--STC012
wrk_length = strlen( messg-msgtx ). "<--STC012
IF wrk_length < 202. "<--STC012
*Add the material number to the error message for error resolution
CONCATENATE merrdat-matnr messg-msgtx INTO ermsg SEPARATED BY
space.
ELSE. "<--STC012
ermsg = messg-msgtx.
ENDIF. "<--STC012
* ROLLBACK WORK.
ENDIF. "<--STC012
ENDLOOP.
if not ermsg is initial.
move ermsg to t_mara-error.
modify t_mara.
* rollback work.
refresh: merrdat.
clear merrdat.
clear t_mara-error.
clear ermsg.
else.
commit work.
move 'Updated successfully' to t_mara-error.
modify t_mara.
clear t_mara-error.
endif.
* endif.
endif.
*set the bom and the special procurement cost
elseif p_trim = 'X'.
check t_mara-sobsk is initial or
t_mara-stlan is initial.
*check if costing information needs to be updated if so update it.
if t_mara-pstat cs 'G'.
EXCEPTIONS
KSTATUS_EMPTY = 1
TKSTATUS_EMPTY = 2
T130M_ERROR = 3
INTERNAL_ERROR = 4
TOO_MANY_ERRORS = 5
UPDATE_ERROR = 6
OTHERS = 7
.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*-If error, assemble error message. Error messages are returned
* in a table, so could have multiples. If an error encountered,
* then raise exception and exit.
*search message text for material number if not found and error message
*less than 220 characters long then add it to the beginning of the
*message for message resolution. "<--STC012
CLEAR: wrk_length.
SEARCH messg-msgtx FOR merrdat-matnr. "<--STC012
IF sy-subrc <> 0. "not found "<--STC012
wrk_length = strlen( messg-msgtx ). "<--STC012
IF wrk_length < 202. "<--STC012
*Add the material number to the error message for error resolution
CONCATENATE merrdat-matnr messg-msgtx INTO ermsg SEPARATED BY
space.
ELSE. "<--STC012
ermsg = messg-msgtx.
ENDIF. "<--STC012
* ROLLBACK WORK.
ENDIF. "<--STC012
ENDLOOP.
if not ermsg is initial.
move ermsg to t_mara-error.
modify t_mara.
refresh: merrdat.
clear merrdat.
clear t_mara-error.
clear ermsg.
else.
commit work.
move 'Updated successfully' to t_mara-error.
modify t_mara.
clear t_mara-error.
endif.
if p_succ = 'X'.
delete t_mara where error = 'Updated successfully'.
endif.
ENDFORM. " update_materials
*&---------------------------------------------------------------------*
*& Form check_costing_boms
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_costing_boms .
loop at t_mara where not stdpd is initial.
check t_mara-matkl = 'P04' or t_mara-matkl = 'P05' or t_mara-matkl = 'T05'.
check t_mara-mtpos_mara <> '002' and t_mara-mtpos_mara <> 'ZX02' and
t_mara-zzmtpos <> 'ZRMH'.
*if stock id or alias need to check configurable material to see if costing bom
*has been created check for configurable material and load to internal table for processing
*need to still check the variant to verify its settings are correct.
*only need to check if material is not high level product.
* if not t_mara-stdpd is initial and ( t_mara-matkl = 'P04' or t_mara-matkl = 'P05' ).
* move: t_mara-stdpd to t_mara-matnr.
select single stlan sobsk zzmtpos ncost stdpd beskz sobsl schgt from marc
into (marc-stlan, marc-sobsk, marc-zzmtpos, marc-ncost, marc-stdpd, marc-beskz, marc-sobsl, marc-schgt) where
matnr = t_mara-stdpd and werks = t_mara-werks.
if sy-subrc = 0.
select single mtart matkl mtpos_mara from mara into (mara-mtart, mara-matkl, mara-mtpos_mara) where matnr = t_mara-stdpd.
if sy-subrc = 0.
move: marc-stlan to t_mara-stlan,
marc-sobsk to t_mara-sobsk,
marc-zzmtpos to t_mara-zzmtpos,
marc-ncost to t_mara-ncost,
* marc-stdpd to t_mara-stdpd,
marc-beskz to t_mara-beskz,
marc-sobsl to t_mara-sobsl,
marc-schgt to t_mara-schgt,
mara-mtart to t_mara-mtart,
mara-matkl to t_mara-matkl,
mara-mtpos_mara to t_mara-mtpos_mara,
t_mara-stdpd to t_mara-matnr.
append t_mara.
endif.
endif.
endloop.
loop at t_mara.
check t_mara-mtpos_mara <> '002' and t_mara-mtpos_mara <> 'ZX02' and
t_mara-zzmtpos <> 'ZRMH'.
clear mast-matnr.
*if stock id it will not need a 6 bom, only the configurable material
*therefore load an X so that if the usage and special procurement have
*been set the record will be deleted as nothing else is required.
* if t_mara-matkl = 'P04' or t_mara-matkl = 'P05' or t_mara-matkl = 'T05'.
* move 'X' to t_mara-created.
* modify t_mara.
* continue.
* endif.
select single matnr from mast into mast-matnr where matnr = t_mara-matnr and werks = t_mara-werks and
stlan = '6'.
if sy-subrc = 0.
move 'X' to t_mara-created.
modify t_mara.
else.
move: 'No Costing Bom' to t_mara-error.
modify t_mara.
endif.
endloop.
ENDFORM. " check_costing_boms
*&---------------------------------------------------------------------*
*& Form delete_entries
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM delete_entries .
*retrieve all of the special procurement keys for remote or vended
select sobsl into table t_sobsl from t460a where wrk02 = '6500' or
wrk02 = '8800' or wrk02 ='8300'.
sort t_sobsl by sobsl.
delete adjacent duplicates from t_sobsl.
if p_cost = 'X'.
sort t_mara by matnr mtart werks.
loop at t_mara.
*sdp only need material origin, origin group and qty with structure checked.
case t_mara-matkl.
when 'SDP07' or 'SDP08'.
if ( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X'.
delete t_mara.
endif.
when 'P04'. "STOCK Id
if ( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) or
( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X' and
t_mara-beskz = 'F' and
( t_mara-werks = '8800' or
t_mara-werks = '8300' or
t_mara-werks = '6500' ).
delete t_mara.
else.
if ( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) or
( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X' and
( t_mara-werks <> '8800' or
t_mara-werks <> '8300' or
t_mara-werks <> '6500' ).
delete t_mara.
endif.
endif.
when others.
*check procurement type.
check t_mara-mtart = 'ZTRG' or t_mara-mtart = 'FERT'.
if ( t_mara-mtpos_mara = 'CONS' or
t_mara-mtpos_mara = 'DROP' or
t_mara-mtpos_mara = 'ZREM' ) and
( t_mara-zzmtpos is initial or t_mara-zzmtpos = 'CONS'
or t_mara-zzmtpos = 'DROP' or t_mara-zzmtpos = 'ZREM' ).
if t_mara-beskz = 'F' and
( ( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X' and
( t_mara-werks = '8800' or
t_mara-werks = '8300' or
t_mara-werks = '6500' ).
delete t_mara.
continue.
else.
if ( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X'.
delete t_mara.
continue.
endif.
endif.
endif.
* if ( t_mara-zzmtpos = 'CONS' or
* t_mara-zzmtpos = 'DROP' or
* t_mara-zzmtpos = 'ZREM' ) and
* t_mara-mtpos_mara = ' '.
* if t_mara-beskz = 'F' and
* ( ( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
* ( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) ) and
* t_mara-ekalr = 'X' and
* t_mara-schgt <> 'X' and
* ( t_mara-werks <> '8800' or
* t_mara-werks <> '8300' or
* t_mara-werks <> '6500' ).
* delete t_mara.
* continue.
* endif.
if ( t_mara-mtpos_mara = 'CONH' or
t_mara-mtpos_mara = 'DRPH' or
t_mara-mtpos_mara = 'ZRMH' ) and
t_mara-zzmtpos is initial.
if t_mara-beskz = 'E' and
( ( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X' and
( t_mara-werks = '8800' or
t_mara-werks = '8300' or
t_mara-werks = '6500' ).
delete t_mara.
continue.
else.
if ( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X'.
delete t_mara.
continue.
endif.
endif.
endif.
if t_mara-werks <> '8800' and
t_mara-werks <> '8300' and
t_mara-werks <> '6500' and
t_mara-sobsl is initial.
delete t_mara.
continue.
elseif not t_mara-sobsl is initial.
read table t_sobsl with key sobsl = t_mara-sobsl
binary search.
if sy-subrc <> 0.
delete t_mara.
continue.
endif.
endif.
*if fert and general item category = 0004 and item category override is
*blank and plant is <> 8300 then delete entry
if t_mara-matkl = 'S01'.
if t_mara-mtpos_mara = '0004' and t_mara-zzmtpos is initial and
t_mara-beskz = 'F'.
delete t_mara.
endif.
else.
if t_mara-mtpos_mara = '0004' and t_mara-zzmtpos is initial.
delete t_mara.
continue.
endif.
endif.
*if fert and item category = 0004
if t_mara-mtpos_mara ='0004' and t_mara-zzmtpos = 'ZREM'
and ( t_mara-werks = '6500' or
t_mara-werks = '8300' )
and t_mara-mtart = 'FERT'
and t_mara-hrkft = '0200'
and t_mara-ekalr = 'X'
and t_mara-schgt <> 'X'
and t_mara-beskz = 'F'.
delete t_mara.
continue.
endif.
*if fert and high level and
if t_mara-mtpos_mara ='0002' and t_mara-zzmtpos = 'ZRMH'
and ( t_mara-werks = '6500' or
t_mara-werks = '8300' )
and t_mara-mtart = 'FERT'
and t_mara-hrkft = '0200'
and t_mara-ekalr = 'X'
and t_mara-schgt <> 'X'
and t_mara-beskz = 'E'.
delete t_mara.
continue.
endif.
*if fert and high level and item category override is blank
if t_mara-mtpos_mara = '0002'
and t_mara-zzmtpos is initial
and t_mara-werks = '8800'
and t_mara-mtart = 'FERT'
and t_mara-hrkft = '0200'
and t_mara-ekalr = 'X'
and t_mara-schgt <> 'X'
and t_mara-beskz = 'E'.
delete t_mara.
continue.
endif.
if t_mara-zzmtpos is initial and
t_mara-mtpos_mara is initial and
t_mara-mvkemtpos is initial and
( t_mara-mtart = 'FERT' and t_mara-hrkft = '0200' ) or
( t_mara-mtart = 'ZTRG' and t_mara-hrkft = '0300' ) and
t_mara-ekalr = 'X' and
t_mara-schgt <> 'X' and
t_mara-beskz = 'F'.
delete t_mara.
continue.
endif.
endcase.
endloop.
sort t_mara by werks matnr.
elseif p_trim = 'X'.
loop at t_mara.
if t_mara-sobsk = 'ZC' and t_mara-stlan = '6' and t_mara-created = 'X'.
delete t_mara.
endif.
*do not need costing boms on high level product.
if t_mara-mtpos_mara = '0002' or t_mara-mtpos_mara = 'ZX02' or
t_mara-ZZMTPOS = 'ZRMH'.
delete t_mara.
endif.
endloop.
* elseif p_pur = 'X'.
*
* if not s_zmtpos[] is initial.
* delete t_mara where zzmtpos = 'ZRMH' and beskz = 'E'.
* endif.
*
* if not s_mtpos[] is initial.
*
* delete t_mara where mtpos_mara = 'ZRMH' and beskz = 'E'.
* endif.
endif.
ENDFORM. " delete_entries
*&---------------------------------------------------------------------*
*& Form check_costing_relevancy
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_costing_relevancy .
delete wultb where datuv = '12319999'.
delete wultb where sanka = 'X'.
append lines of wultb to t_wultb.
refresh wultb.
endif.
endloop.
loop at t_wultb.
*check if bom material has been marked for deletion.
select single matnr from mara into mara-matnr where matnr = t_wultb-matnr
and lvorm <> 'X'.
check sy-subrc = 0.
select single zzlastoe zzlastmad from marc into (marc-zzlastoe, marc-zzlastmad) where matnr = t_wultb-matnr
and werks = t_wultb-werks
and lvorm <> 'X'.
*CHECK FOR BULK MATERIAL INDICATOR.
CLEAR T_STPO-BULK.
IF T_WULTB-SCHGT = 'X'.
MOVE 'X' TO T_STPO-BULK.
ENDIF.
*check for bulk indicator on the material master.
select single schgt from marc into marc-schgt where matnr = t_wultb-idnrk
and werks = t_wultb-werks and
lvorm <> 'X'.
if marc-schgt = 'X'.
move 'X' to t_stpo-mmbulk.
endif.
move: t_wultb-matnr to t_stpo-matnr,
t_wultb-werks to t_stpo-werks,
t_wultb-stlan to t_stpo-stlan,
t_wultb-stlnr to t_stpo-stlnr,
t_wultb-idnrk to t_stpo-idnrk,
t_wultb-posnr to t_stpo-posnr,
t_wultb-aennr to t_stpo-aennr.
append t_stpo.
endif.
if sy-subrc NE 0.
PERFORM api_log_to_return USING ermsg_update.
if not ermsg_update is initial.
move ermsg_update to t_stpo-error.
modify t_stpo.
endif.
else.
move 'Update successful' to t_stpo-error.
modify t_stpo.
endif.
REFRESH T_STPO_UPDATE.
endloop.
else.
PERFORM api_log_to_return USING ermsg_update.
if not ermsg_update is initial.
move ermsg_update to t_stpo-error.
modify t_stpo.
endif.
endif.
endloop.
endif.
ENDFORM. " check_costing_relevancy
*&---------------------------------------------------------------------*
*& Form api_log_to_return
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ERMSG_UPDATE text
*----------------------------------------------------------------------*
FORM api_log_to_return USING p_msg.
DATA: obj LIKE balhdr-object VALUE 'CAPI'.
DATA: sub LIKE balhdr-subobject VALUE 'CAPI_LOG'.
DATA: BEGIN OF xbalhdr OCCURS 0.
INCLUDE STRUCTURE balhdr.
DATA: END OF xbalhdr.
DATA: BEGIN OF xbalhdrp OCCURS 0.
INCLUDE STRUCTURE balhdrp.
DATA: END OF xbalhdrp.
DATA: BEGIN OF xbalm OCCURS 0.
INCLUDE STRUCTURE balm.
DATA: END OF xbalm.
DATA: BEGIN OF xbalmp OCCURS 0.
INCLUDE STRUCTURE balmp.
DATA: END OF xbalmp.
DATA messg LIKE message.
ENDFORM. " API_LOG_TO_RETUR
*&---------------------------------------------------------------------*
*& Form begin_of_api
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_2892 text
*----------------------------------------------------------------------*
FORM begin_of_api USING api_name.
CALL FUNCTION 'CALO_INIT_API'.
*---- initialize log
CALL FUNCTION 'STAP_INIT_SINGLE_API'
EXPORTING
api_name = api_name.
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.