* 1. INTERNAL TABLE FOR MATERIALS THAT ARE MAINTAINED FOR lgort = '0001'.
DATA : BEGIN OF it_mard OCCURS 0,
matnr LIKE mard-matnr, " Material No.
werks LIKE mard-werks, " Plant
lgort LIKE mard-lgort, " Storage Location
END OF it_mard.
* 2. INTERNAL TABLE TO STORE MATERIALS WHICH ARE ALREADY MAINTAINED FOR lgort = 'ABCD'.
DATA: BEGIN OF it_verify OCCURS 0,
matnr LIKE mard-matnr, " Material No.
werks LIKE mard-werks, " Plant
lgort LIKE mard-lgort, " Storage Location
dismm LIKE marc-dismm, " MRP type
END OF it_verify.
* 3. INTERNAL TABLE TO STORE MATERIALS WHICH HAS NO MRP TYPE ASSIGNED.
DATA: BEGIN OF it_marc OCCURS 0,
matnr LIKE marc-matnr, " Material No.
werks LIKE marc-werks, " Plant
dismm LIKE marc-dismm, " MRP type
END OF it_marc.
* 3. INTERNAL TABLE TO STORE MATERIALS WHICH ARE ALREADY MAINTAINED FOR lgort = 'ABCD'.
DATA: BEGIN OF it_error OCCURS 0, "#EC *
index TYPE I,
fname(25),
fval(30),
err_msg(40),
END OF it_error.
DATA: BEGIN OF it_error1 OCCURS 0, "#EC *
matnr LIKE mard-matnr,
type LIKE bapiret2-type,
id LIKE bapiret2-id,
message LIKE bapiret2-message,
END OF it_error1.
*-------------------------------------------------------------*
* TABLES FOR FUNCTION - BAPI_MATERIAL_SAVEDATA
*-------------------------------------------------------------*
DATA: I_HEADDATA LIKE BAPIMATHEAD, " HEADER DATA
I_STORAGELOCATIONDATA LIKE BAPI_MARD, " STORAGE LOCATION SPECIFIC MATERIAL DATA
I_STORAGELOCATIONDATAX LIKE BAPI_MARDX, " Information on update for STORAGELOCATIONDATA
I_RETURN LIKE BAPIRET2, " RETURN FROM BAPI
I_RETURNMESSAGES LIKE BAPI_MATRETURN2 OCCURS 0 WITH HEADER LINE.
*&---------------------------------------------------------------------*
*& Form extract_itmard
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form extract_itmard .
SELECT matnr werks lgort
FROM mard
INTO TABLE it_mard
WHERE matnr IN s_matnr AND
werks = 'RAPI' AND " Plant
lgort = 'RAPI' . " Storage Location
IF sy-subrc NE 0.
MESSAGE s114. " Success Message --> Data Not Available
STOP.
ENDIF.
endform. " extract_itmard
*&---------------------------------------------------------------------*
*& Form extract_itmarc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form extract_itmarc . "Fetch Materials for which the MRP Type is not maintained
SELECT matnr werks dismm
FROM marc
INTO TABLE it_marc
FOR ALL ENTRIES IN it_mard
WHERE matnr = it_mard-matnr AND
werks = it_mard-werks AND
dismm = ' '.
endform. " extract_itmarc
*&---------------------------------------------------------------------*
*& Form extract_itverify
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form extract_itverify . " Fetch All the Materials which are already extended for the Storage Location
IF it_mard[] IS NOT INITIAL. "Check it_likp for not null
SELECT matnr werks lgort
FROM mard
INTO TABLE it_verify
FOR ALL ENTRIES IN it_mard
WHERE matnr = it_mard-matnr AND
werks = 'RAPI' AND " For Plant
lgort = '0001'. " For Storage Location
ELSE.
MESSAGE s114. "Success Message --> Data Not Available
STOP.
ENDIF.
endform. " extract_itverify
*&---------------------------------------------------------------------*
*& Form verify_material
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM verify_material .
DATA: v_cnt TYPE I.
v_cnt = 1.
IF it_verify[] IS NOT INITIAL AND it_marc[] IS NOT INITIAL. "Check it_likp for not null
SORT it_mard BY matnr.
SORT it_verify BY matnr.
ENDIF.
LOOP AT it_mard.
IF it_verify[] IS NOT INITIAL. " Check it_verify for not null
READ TABLE it_verify WITH KEY matnr = it_mard-matnr BINARY SEARCH. " Check Material is not extended
IF sy-subrc <> 0.
READ TABLE it_marc WITH KEY matnr = it_mard-matnr BINARY SEARCH. " Check MRP Type for the Material is Maintained
IF sy-subrc <> 0.
PERFORM extend_material USING it_mard-matnr " Extend Material
it_mard-werks.
ELSE.
it_error-index = v_cnt. " Generate Error Report
it_error-fname = 'MATERIAL NO'.
it_error-fval = it_mard-matnr.
it_error-err_msg = 'MRP Type Not Maintained'.
APPEND it_error.
v_cnt = v_cnt + 1.
ENDIF.
ENDIF.
ELSE.
READ TABLE it_marc WITH KEY matnr = it_mard-matnr BINARY SEARCH.
IF sy-subrc <> 0.
PERFORM extend_material USING it_mard-matnr
it_mard-werks.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " verify_material
*&---------------------------------------------------------------------*
*& Form extend_material
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_MARD_MATNR text
* -->P_IT_MARD_WERKS text
* -->P_IT_MARD_LGORT text
*----------------------------------------------------------------------*
FORM extend_material USING P_IT_MARD_MATNR TYPE mard-matnr
P_IT_MARD_WERKS TYPE mard-werks.
DATA: v_str(50).
*&---------------------------------------------------------------------*
*& Form display_error_report
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_error_report .
LOOP AT it_error1.
WRITE:/ it_error1-matnr COLOR 5, 15 it_error1-type COLOR 5,
30 it_error1-id COLOR 6, 55 it_error1-message COLOR 6.
ENDLOOP.
WRITE:/30 'FOLLOWING MATERIALS CAUSED ERROR' COLOR 1 .
SKIP 2.
LOOP AT it_error.
WRITE:/ it_error-index COLOR 5, 15 it_error-fname COLOR 5,
30 it_error-fval COLOR 6, 55 it_error-err_msg COLOR 6.
ENDLOOP.
ENDFORM. " display_error_report
*&---------------------------------------------------------------------*
*& Form validate_material
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form validate_material .
IF NOT s_matnr[] IS INITIAL.
SELECT matnr
INTO mard-matnr
FROM mard
UP TO 1 ROWS
WHERE matnr IN s_matnr.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE E115 WITH 'Invalid' mard-matnr. " Error Message-->Invalid Parameters
ENDIF.
ENDIF.
IF NOT s_matnr[] IS INITIAL.
SELECT matnr
INTO marc-matnr
FROM marc
UP TO 1 ROWS
WHERE matnr IN s_matnr.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE s114. "Success Message --> Data Not Available
STOP.
ENDIF.
ENDIF.
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.