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

Extend Materials



 
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 29, 2007 4:36 pm    Post subject: Extend Materials Reply with quote

Code:
* Author Seshu Maramreddy
REPORT Z4PG_EXTEND_MATERIAL
NO STANDARD PAGE HEADING
LINE-SIZE 150
MESSAGE-ID Z4.

* DATABASE TABLE DECLARATIONS
*-------------------------------------------------------------*

TABLES :
mard, "#EC * " Storage Location Data for Material
marc. "#EC * " Plant Data for Material


*-------------------------------------------------------------*
* INTERNAL TABLES DECLARATIONS
*-------------------------------------------------------------*

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


*-------------------------------------------------------------*
* SELECTION PARAMETERS
*-------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK MAIN WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS s_matnr FOR mard-matnr. " Material Number


SELECTION-SCREEN END OF BLOCK MAIN.

*-------------------------------------------------------------*
* SELECTION SCREEN VALIDATION.
*-------------------------------------------------------------*

AT SELECTION-SCREEN .

PERFORM validate_material.



*-------------------------------------------------------------*
* START OF SELECTION
*-------------------------------------------------------------*

START-OF-SELECTION.

PERFORM extract_itmard.
PERFORM extract_itmarc.
PERFORM extract_itverify.
PERFORM verify_material.
PERFORM display_error_report.


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

CLEAR I_HEADDATA.

I_HEADDATA-MATERIAL = P_IT_MARD_MATNR.
I_HEADDATA-MRP_VIEW = 'X'.

CLEAR I_STORAGELOCATIONDATA.
CLEAR I_STORAGELOCATIONDATAX.

I_STORAGELOCATIONDATA-PLANT = P_IT_MARD_WERKS.
I_STORAGELOCATIONDATA-STGE_LOC = '0001'.

I_STORAGELOCATIONDATAX-PLANT = P_IT_MARD_WERKS.
I_STORAGELOCATIONDATAX-STGE_LOC = '0001'.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = i_headdata
* CLIENTDATA =
* CLIENTDATAX =
* PLANTDATA =
* PLANTDATAX =
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
STORAGELOCATIONDATA = i_storagelocationdata
STORAGELOCATIONDATAX = i_storagelocationdatax
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
IMPORTING
RETURN = i_return
TABLES
* MATERIALDESCRIPTION =
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
RETURNMESSAGES = i_returnmessages
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.

LOOP at i_returnmessages.
write: / i_returnmessages-message.
ENDLOOP.

v_str = 'Material No does not Exist'.

IF i_return-type = 'E'.
it_error1-matnr = P_IT_MARD_MATNR.
it_error1-type = i_return-type.
it_error1-id = i_return-id.
it_error1-message = v_str.
APPEND it_error1.
ELSEIF i_return-type = 'S'.
READ TABLE i_returnmessages WITH KEY TYPE = 'S' id = 'M3'.
IF sy-subrc = 0.
it_error1-matnr = P_IT_MARD_MATNR.
it_error1-type = i_return-type.
it_error1-id = i_return-id.
it_error1-message = i_returnmessages-message.
APPEND it_error1.
CLEAR it_error1.
ENDIF.
ENDIF.

REFRESH i_returnmessages.
CLEAR it_error1.
CLEAR i_return.


ENDFORM. " extend_material

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

endform. " validate_material
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.