*&---------------------------------------------------------------------*
*& Report Z_LIST_PROCESSING
*&
*&---------------------------------------------------------------------*
REPORT Z_LIST_PROCESSING .
*&---------------------------------------------------------------------*
* Declare global object and selection screen.
*&---------------------------------------------------------------------*
*-----------------------------------------------------------------------
* TYPE POOL
*-----------------------------------------------------------------------
TYPE-POOLS:
SLIS.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES:MARA.
*----------------------------------------------------------------------*
* TYPES
*----------------------------------------------------------------------*
*Struct MARA
TYPES: BEGIN OF GTY_MARA,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,
END OF GTY_MARA.
*Struct MAKT
TYPES: BEGIN OF GTY_MAKT,
MATNR TYPE MAKT-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,
END OF GTY_MAKT.
*Struct OUTPUT
TYPES: BEGIN OF GTY_OUTPUT,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,"MATERIAL TYPE
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT.
*----------------------------------------------------------------------*
* Internal table
*----------------------------------------------------------------------*
DATA: GT_OUTPUT TYPE STANDARD TABLE OF GTY_OUTPUT,
GT_MARA TYPE STANDARD TABLE OF GTY_MARA,
GT_MAKT TYPE STANDARD TABLE OF GTY_MAKT,
*----------------------------------------------------------------------*
* Work area
*----------------------------------------------------------------------*
GS_OUTPUT TYPE GTY_OUTPUT,
GS_MARA TYPE GTY_MARA,
GS_MAKT TYPE GTY_MAKT.
*----------------------------------------------------------------------*
* Selection screen
*----------------------------------------------------------------------*
SELECT-OPTIONS: S_ERDA FOR MARA-ERSDA default '20111017 ' OBLIGATORY.
PARAMETERS:
pa_lim_1 RADIOBUTTON GROUP lim ,"JOIN
pa_lim_2 RADIOBUTTON GROUP lim,"FOR ALL ENTRIES
*----------------------------------------------------------------------*
* INITIALIZATION.
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*Select data
IF PA_LIM_1 IS NOT INITIAL.
*Join
SELECT
M~MATNR
M~MTART
M2~MAKTX
INTO TABLE GT_OUTPUT
FROM
MARA AS M
JOIN MAKT AS M2 ON M~MATNR = M2~MATNR
WHERE M~ERSDA IN S_ERDA AND
M2~SPRAS = 'E'.
ELSE.
*For all entries
SELECT
MATNR
MTART
FROM MARA
INTO TABLE GT_MARA
WHERE ERSDA IN S_ERDA.
DELETE ADJACENT DUPLICATES FROM GT_MARA COMPARING MATNR.
IF GT_MARA IS NOT INITIAL.
SELECT
MATNR
MAKTX
FROM MAKT
INTO TABLE GT_MAKT
FOR ALL ENTRIES IN GT_MARA
WHERE MATNR = GT_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
SORT GT_MAKT BY MATNR.
LOOP AT GT_MARA INTO GS_MARA.
CLEAR: GS_MAKT.
READ TABLE GT_MAKT BINARY SEARCH WITH KEY MATNR = GS_MARA-MATNR
INTO GS_MAKT.
GS_OUTPUT-MATNR = GS_MARA-MATNR.
GS_OUTPUT-MTART = GS_MARA-MTART.
GS_OUTPUT-MAKTX = GS_MAKT-MAKTX.
APPEND GS_OUTPUT TO GT_OUTPUT.
ENDLOOP.
ENDIF.
*----------------------------------------------------------------------*
* End-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* Output data
LIST PROCESSING
* Struct
TYPES: BEGIN OF GTY_OUTPUT1,
MTART TYPE MARA-MTART,"MATERIAL TYPE
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT1.
DATA: GT_OUTPUT1 TYPE STANDARD TABLE OF GTY_OUTPUT1,
GS_OUTPUT1 TYPE GTY_OUTPUT1.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
GS_OUTPUT1-MTART = GS_OUTPUT-MTART.
GS_OUTPUT1-MATNR = GS_OUTPUT-MATNR.
GS_OUTPUT1-MAKTX = GS_OUTPUT-MAKTX.
APPEND GS_OUTPUT1 TO GT_OUTPUT1.
ENDLOOP.
SORT GT_OUTPUT1 BY MTART MATNR.
LOOP AT GT_OUTPUT1 INTO GS_OUTPUT1.
AT FIRST.
WRITE: / 'AT FIRST'.
ENDAT.
AT NEW MTART.
WRITE: /.
WRITE: /10(15) 'MATERIAL TYPE:'.
WRITE: 26(10) GS_OUTPUT1-MTART.
WRITE: /1(15) 'Material number'.
WRITE: 17(20) 'Material description'.
ENDAT.
WRITE: /1(10) GS_OUTPUT1-MATNR.
WRITE: 17(20) GS_OUTPUT1-MAKTX.
AT END OF MTART.
WRITE: /.
ULINE 10(30).
ENDAT.
AT LAST.
WRITE: / 'AT last'.
ENDAT.
ENDLOOP.
ENDIF.
No comments:
Post a Comment