Sunteți pe pagina 1din 4

*-------Declaring the line type of database tables---------------------*

TABLES: mara, marc, mard.


*------Declaring the types of work areas & internal tables-------------*
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
END OF ty_mara,
BEGIN OF ty_marc,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
xchar TYPE marc-xchar,
END OF ty_marc,
BEGIN OF ty_mard,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
pstat TYPE mard-pstat,
END OF ty_mard,
BEGIN OF ty_out,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
lgort TYPE mard-lgort,
mtart TYPE mara-mtart,
xchar TYPE marc-xchar,
pstat TYPE mard-pstat,
END OF ty_out.

"Material
"Plant
"Storage Location
"Material Type
"Batch number
"Maintenance Status

*-----Declaring work areas & internal tables---------------------------*


DATA: wa_mara TYPE ty_mara,
wa_marc TYPE ty_marc,
wa_mard TYPE ty_mard,
wa_out TYPE ty_out,
it_mara TYPE STANDARD TABLE OF ty_mara,
it_marc TYPE STANDARD TABLE OF ty_marc,
it_mard TYPE STANDARD TABLE OF ty_mard,
it_out TYPE STANDARD TABLE OF ty_out,
v_prog TYPE sy-repid, "Program name
v_date TYPE sy-datum, "Current date
v_time TYPE sy-uzeit. "Current time
*----------Declaring constants to
CONSTANTS: c_material TYPE char12
c_plant
TYPE char5
c_storage TYPE char8
c_type
TYPE char6
c_batch
TYPE char6
c_maint
TYPE char18
c_end
TYPE char40

avoid
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

the hard codes-----------------*


'MATERIAL NO',
'PLANT',
'STORAGE',
'M TYPE',
'BATCH',
'MAINTENANCE STATUS',
'End of Material Details'.

*------Event initialization--------------------------------------------*
INITIALIZATION.
v_prog = sy-repid.
v_date = sy-datum.
v_time = sy-uzeit.

*-----------Declaring selection screen with select option for input----*


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK b1.
*-----Event start of selection-----------------------------------------*
START-OF-SELECTION.
PERFORM get_mara.
PERFORM get_marc.
PERFORM get_mard.
*---Event end of selection---------------------------------------------*
END-OF-SELECTION.
PERFORM get_output.
PERFORM display.
*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
PERFORM top_of_page.
*&---------------------------------------------------------------------*
*&
Form GET_MARA
*&---------------------------------------------------------------------*
*
Select data from MARA table
*----------------------------------------------------------------------*
FORM get_mara .
IF s_matnr IS NOT INITIAL.
SELECT matnr mtart
FROM mara INTO TABLE it_mara
WHERE matnr IN s_matnr.
IF sy-subrc = 0.
SORT it_mara BY matnr.
ELSE.
MESSAGE 'Material doesn''t exist' TYPE 'I'.
ENDIF.
ENDIF.
ENDFORM.
" GET_MARA
*&---------------------------------------------------------------------*
*&
Form GET_MARC
*&---------------------------------------------------------------------*
*
Select data from MARC table
*----------------------------------------------------------------------*
FORM get_marc .
IF it_mara IS NOT INITIAL. "Prerequisite of FOR ALL ENTRIES IN
SELECT matnr werks xchar
FROM marc INTO TABLE it_marc
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr.
IF sy-subrc = 0.
SORT it_marc BY matnr.
ELSE.
MESSAGE 'Plant doesn''t exist' TYPE 'I'.
ENDIF.
ENDIF.

ENDFORM.
" GET_MARC
*&---------------------------------------------------------------------*
*&
Form GET_MARD
*&---------------------------------------------------------------------*
*
Select data from MARD table
*----------------------------------------------------------------------*
FORM get_mard .
IF it_marc IS NOT INITIAL. "Prerequisite of FOR ALL ENTRIES IN
SELECT matnr werks lgort pstat
FROM mard INTO TABLE it_mard
FOR ALL ENTRIES IN it_marc
WHERE matnr = it_marc-matnr
AND werks = it_marc-werks.
IF sy-subrc = 0.
SORT it_mard BY matnr.
ELSE.
MESSAGE 'Storage Location doesn''t exist' TYPE 'I'.
ENDIF.
ENDIF.
ENDFORM.
" GET_MARD
*&---------------------------------------------------------------------*
*&
Form GET_OUTPUT
*&---------------------------------------------------------------------*
*
Preparing the output table by using Loop
*----------------------------------------------------------------------*
FORM get_output .
IF it_mara IS NOT INITIAL.
LOOP AT it_mara INTO wa_mara.
wa_out-matnr = wa_mara-matnr.
wa_out-mtart = wa_mara-mtart.
LOOP AT it_marc INTO wa_marc
WHERE matnr = wa_mara-matnr.
wa_out-werks = wa_marc-werks.
wa_out-xchar = wa_marc-xchar.
LOOP AT it_mard INTO wa_mard
WHERE matnr = wa_marc-matnr
AND werks = wa_marc-werks.
wa_out-lgort = wa_mard-lgort.
wa_out-pstat = wa_mard-pstat.
APPEND wa_out TO it_out.
CLEAR: wa_out, wa_mara, wa_marc, wa_mard.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDFORM.
" GET_OUTPUT
*&---------------------------------------------------------------------*
*&
Form DISPLAY
*&---------------------------------------------------------------------*
*
Displaying the classical output by using WRITE statement
*----------------------------------------------------------------------*
FORM display .

IF it_out IS NOT INITIAL.


LOOP AT it_out INTO wa_out.
AT FIRST. "Control break statement
WRITE: / c_material,
21 c_plant,
27 c_storage,
37 c_type,
45 c_batch,
54 c_maint.
ULINE.
SKIP.
ENDAT.
WRITE: /
21
27
37
45
54

display one time at first

wa_out-matnr,
wa_out-werks,
wa_out-lgort,
wa_out-mtart,
wa_out-xchar,
wa_out-pstat.

IF wa_out-matnr IS INITIAL.
AT END OF matnr. "Control break statement
SKIP.
ENDAT.
ENDIF.
AT LAST. "Control break statement
ULINE.
WRITE: / c_end.
ENDAT.
ENDLOOP.
ENDIF.

display one time at last

ENDFORM.
" DISPLAY
*&---------------------------------------------------------------------*
*&
Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
*
Top of page of Classical output
*----------------------------------------------------------------------*
FORM top_of_page .
WRITE: / v_prog,
/ v_date DD/MM/YYYY,
/ v_time.
ULINE.
ENDFORM.

" TOP_OF_PAGE

S-ar putea să vă placă și