SAP ABAP - Sample Report Program For Shelf Life Of Materials.
A sample report program that gives a report on Material Shelf Life.
REPORT:ztest_mat_shelf_life NO STANDARD PAGE HEADING
LINE-COUNT 65
LINE-SIZE 90.
TABLES: mara, mseg, mkpf, mbew, makt, mard, qals.
DATA: char_count(2).
DATA: tem_no LIKE mara-matnr VALUE space.
DATA: temp_stock LIKE mbew-lbkum.
DATA: wa_matnr LIKE mara-matnr.
TYPES: BEGIN OF st_mara,
matnr TYPE mara-matnr,
mhdhb TYPE mara-mhdhb,
END OF st_mara.
DATA: it_mara TYPE STANDARD TABLE OF st_mara.
DATA: wa_mara TYPE st_mara.
TYPES: BEGIN OF st_mbew,
matnr TYPE mbew-matnr,
bwtar TYPE mbew-bwtar,
lbkum TYPE mbew-lbkum,
END OF st_mbew.
DATA: it_mbew TYPE STANDARD TABLE OF st_mbew.
DATA: wa_mbew TYPE st_mbew.
DATA: it_makt TYPE STANDARD TABLE OF makt.
DATA: wa_makt TYPE makt.
TYPES: BEGIN OF st_mseg,
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
bwart TYPE mseg-bwart,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
bwtar TYPE mseg-bwtar,
menge TYPE mseg-menge,
END OF st_mseg.
DATA: it_mseg TYPE STANDARD TABLE OF st_mseg.
DATA: wa_mseg TYPE st_mseg.
TYPES: BEGIN OF st_mkpf,
mblnr TYPE mkpf-mblnr,
mjahr TYPE mkpf-mjahr,
budat TYPE mkpf-budat,
END OF st_mkpf.
DATA: it_mkpf TYPE STANDARD TABLE OF st_mkpf.
DATA: wa_mkpf TYPE st_mkpf.
TYPES: BEGIN OF st_mard,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
lgpbe TYPE mard-lgpbe,
END OF st_mard.
DATA: it_mard TYPE STANDARD TABLE OF st_mard.
DATA: wa_mard TYPE st_mard.
DATA: count TYPE i VALUE 0.
DATA: BEGIN OF itab OCCURS 0,
part_no LIKE mara-matnr,
desc LIKE makt-maktx,
doc_no LIKE mseg-mblnr,
doc_dat LIKE mkpf-budat,
total_shelf_life LIKE mara-mhdhb,
total_stock LIKE mbew-lbkum,
menge LIKE mseg-menge,
stg_loc LIKE mseg-lgort,
stg_plant LIKE mseg-werks,
stg_bin LIKE mard-lgpbe,
expiry_dt LIKE sy-datum,
bwtar LIKE mseg-bwtar,
END OF itab.
DATA: itab1 LIKE itab OCCURS 10 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: werks LIKE mseg-werks OBLIGATORY,
wa_lgort LIKE mseg-lgort OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
TOP-OF-PAGE.
FORMAT COLOR COL_HEADING.
FORMAT INVERSE ON.
WRITE: 30 'REPORT FOR SHELF LIFE OF MATERIALS',70 'Date:',76 sy-datum.
FORMAT INVERSE OFF.
FORMAT COLOR OFF.
WRITE /.
WRITE:/ 'STORAGE LOCN: ', wa_lgort.
WRITE:55 'STORAGE PLANT:', werks.
WRITE:/ sy-uline.
WRITE:/ 'Part Number',
20 'Part Description',
49 'Shelf',
56 'St.Bin',
67 'Total Stock',
82 'Val.type'.
WRITE:/ sy-uline.
START-OF-SELECTION.
SELECT SINGLE matnr FROM mard INTO wa_matnr
WHERE werks = werks
AND lgort = wa_lgort.
SELECT matnr mhdhb FROM mara INTO TABLE it_mara WHERE mhdhb > 0.
SELECT mblnr
mjahr
bwart
matnr
werks
bwtar
menge
FROM mseg INTO TABLE it_mseg
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr AND werks EQ werks .
IF sy-subrc = 0.
SELECT matnr bwtar lbkum FROM mbew INTO TABLE it_mbew
FOR ALL ENTRIES IN it_mseg
WHERE matnr EQ it_mseg-matnr
AND lbkum > 0
AND bwtar EQ it_mseg-bwtar.
IF sy-subrc EQ 0.
SELECT * FROM makt INTO TABLE it_makt
FOR ALL ENTRIES IN it_mseg
WHERE matnr EQ it_mseg-matnr
AND spras EQ 'EN'.
SELECT mblnr mjahr budat FROM mkpf INTO TABLE it_mkpf
FOR ALL ENTRIES IN it_mseg
WHERE mblnr = it_mseg-mblnr
AND mjahr = it_mseg-mjahr.
SELECT matnr werks lgort labst lgpbe FROM mard INTO TABLE it_mard
FOR ALL ENTRIES IN it_mseg
WHERE matnr EQ it_mseg-matnr
AND lgort EQ wa_lgort
AND werks EQ it_mseg-werks.
ENDIF.
LOOP AT it_mara INTO wa_mara.
LOOP AT it_mseg INTO wa_mseg WHERE matnr = wa_mara-matnr.
READ TABLE it_mbew INTO wa_mbew WITH KEY matnr = wa_mara-matnr.
IF sy-subrc = 0.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr .
READ TABLE it_mkpf INTO wa_mkpf WITH KEY mblnr = wa_mseg-mblnr.
READ TABLE it_mard INTO wa_mard WITH KEY matnr = wa_mara-matnr .
ENDIF.
IF sy-subrc = 0.
itab1-part_no = wa_mseg-matnr.
IF wa_mseg-bwart = '101'.
itab1-doc_no = wa_mseg-mblnr.
ELSE.
CLEAR itab1-doc_no.
ENDIF.
itab1-total_stock = wa_mard-labst.
itab1-total_shelf_life = wa_mara-mhdhb.
itab1-desc = wa_makt-maktx.
itab1-doc_dat = wa_mkpf-budat.
itab1-stg_loc = wa_lgort.
itab1-stg_plant = wa_mseg-werks.
itab1-stg_bin = wa_mard-lgpbe.
itab1-menge = wa_mseg-menge.
itab1-bwtar = wa_mseg-bwtar.
APPEND itab1.
CLEAR itab1.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
SORT itab1 BY stg_bin part_no doc_dat DESCENDING.
LOOP AT itab1.
IF NOT itab1-doc_no IS INITIAL.
SELECT SINGLE * FROM qals WHERE mblnr = itab1-doc_no AND
stat35 = 'X'.
IF sy-subrc NE 0.
DELETE itab1.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT itab1.
tem_no = itab1-part_no.
EXIT.
ENDLOOP.
LOOP AT itab1.
IF itab1-part_no EQ tem_no.
IF itab1-total_stock > temp_stock.
IF NOT itab1-doc_no IS INITIAL.
temp_stock = temp_stock + itab1-menge.
ENDIF.
ELSE.
DELETE itab1.
ENDIF.
tem_no = itab1-part_no.
ELSE.
IF NOT itab1-doc_no IS INITIAL .
temp_stock = itab1-menge .
ELSE.
temp_stock = 0 .
ENDIF.
tem_no = itab1-part_no.
ENDIF.
ENDLOOP.
DATA: $lincnt TYPE i.
DESCRIBE TABLE itab1 LINES $lincnt.
IF $lincnt = 0.
MESSAGE i100(zmyw).
ENDIF.
LOOP AT itab1.
AT NEW part_no.
WRITE: /.
READ TABLE itab1 INDEX sy-tabix.
count = 0.
WRITE: /01 itab1-part_no,
20 itab1-desc(28) ,
49 itab1-total_shelf_life LEFT-JUSTIFIED,
56 itab1-stg_bin,
67 itab1-total_stock LEFT-JUSTIFIED.
ENDAT.
IF NOT itab1-doc_no IS INITIAL.
itab1-expiry_dt = itab1-doc_dat + itab1-total_shelf_life.
count = count + 1.
char_count = count.
CONDENSE char_count.
WRITE:/ char_count,'. ','DOC NO:', itab1-doc_no.
WRITE:25 ' Exp. DT.: ', itab1-expiry_dt,
50 'QTY.: ', itab1-menge,
80 itab1-bwtar.
ENDIF.
AT LAST.
WRITE:/ .
ULINE.
FORMAT COLOR COL_HEADING.
FORMAT INVERSE ON.
WRITE:/40 'END OF THE REPORT'.
FORMAT INVERSE OFF.
FORMAT COLOR OFF.
ULINE.
ENDAT.
ENDLOOP.
MORE PROGRAMS ON REPORT PROGRAMMING:
- Finding User Exits, Badi's & Enhancements For Any Transaction Or Program.
- Upload Excel Sheet Data Into Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE.
- Uploading Large Data From Excel Sheet To Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE
- Send an excel sheet to the concerned person in an email format via SAP System.
- Upload the financial documents from a legacy system (excel file) into SAP using transaction code FB01.
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.
REPORT:ztest_mat_shelf_life NO STANDARD PAGE HEADING
LINE-COUNT 65
LINE-SIZE 90.
TABLES: mara, mseg, mkpf, mbew, makt, mard, qals.
DATA: char_count(2).
DATA: tem_no LIKE mara-matnr VALUE space.
DATA: temp_stock LIKE mbew-lbkum.
DATA: wa_matnr LIKE mara-matnr.
TYPES: BEGIN OF st_mara,
matnr TYPE mara-matnr,
mhdhb TYPE mara-mhdhb,
END OF st_mara.
DATA: it_mara TYPE STANDARD TABLE OF st_mara.
DATA: wa_mara TYPE st_mara.
TYPES: BEGIN OF st_mbew,
matnr TYPE mbew-matnr,
bwtar TYPE mbew-bwtar,
lbkum TYPE mbew-lbkum,
END OF st_mbew.
DATA: it_mbew TYPE STANDARD TABLE OF st_mbew.
DATA: wa_mbew TYPE st_mbew.
DATA: it_makt TYPE STANDARD TABLE OF makt.
DATA: wa_makt TYPE makt.
TYPES: BEGIN OF st_mseg,
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
bwart TYPE mseg-bwart,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
bwtar TYPE mseg-bwtar,
menge TYPE mseg-menge,
END OF st_mseg.
DATA: it_mseg TYPE STANDARD TABLE OF st_mseg.
DATA: wa_mseg TYPE st_mseg.
TYPES: BEGIN OF st_mkpf,
mblnr TYPE mkpf-mblnr,
mjahr TYPE mkpf-mjahr,
budat TYPE mkpf-budat,
END OF st_mkpf.
DATA: it_mkpf TYPE STANDARD TABLE OF st_mkpf.
DATA: wa_mkpf TYPE st_mkpf.
TYPES: BEGIN OF st_mard,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
lgpbe TYPE mard-lgpbe,
END OF st_mard.
DATA: it_mard TYPE STANDARD TABLE OF st_mard.
DATA: wa_mard TYPE st_mard.
DATA: count TYPE i VALUE 0.
DATA: BEGIN OF itab OCCURS 0,
part_no LIKE mara-matnr,
desc LIKE makt-maktx,
doc_no LIKE mseg-mblnr,
doc_dat LIKE mkpf-budat,
total_shelf_life LIKE mara-mhdhb,
total_stock LIKE mbew-lbkum,
menge LIKE mseg-menge,
stg_loc LIKE mseg-lgort,
stg_plant LIKE mseg-werks,
stg_bin LIKE mard-lgpbe,
expiry_dt LIKE sy-datum,
bwtar LIKE mseg-bwtar,
END OF itab.
DATA: itab1 LIKE itab OCCURS 10 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: werks LIKE mseg-werks OBLIGATORY,
wa_lgort LIKE mseg-lgort OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
TOP-OF-PAGE.
FORMAT COLOR COL_HEADING.
FORMAT INVERSE ON.
WRITE: 30 'REPORT FOR SHELF LIFE OF MATERIALS',70 'Date:',76 sy-datum.
FORMAT INVERSE OFF.
FORMAT COLOR OFF.
WRITE /.
WRITE:/ 'STORAGE LOCN: ', wa_lgort.
WRITE:55 'STORAGE PLANT:', werks.
WRITE:/ sy-uline.
WRITE:/ 'Part Number',
20 'Part Description',
49 'Shelf',
56 'St.Bin',
67 'Total Stock',
82 'Val.type'.
WRITE:/ sy-uline.
START-OF-SELECTION.
SELECT SINGLE matnr FROM mard INTO wa_matnr
WHERE werks = werks
AND lgort = wa_lgort.
SELECT matnr mhdhb FROM mara INTO TABLE it_mara WHERE mhdhb > 0.
SELECT mblnr
mjahr
bwart
matnr
werks
bwtar
menge
FROM mseg INTO TABLE it_mseg
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr AND werks EQ werks .
IF sy-subrc = 0.
SELECT matnr bwtar lbkum FROM mbew INTO TABLE it_mbew
FOR ALL ENTRIES IN it_mseg
WHERE matnr EQ it_mseg-matnr
AND lbkum > 0
AND bwtar EQ it_mseg-bwtar.
IF sy-subrc EQ 0.
SELECT * FROM makt INTO TABLE it_makt
FOR ALL ENTRIES IN it_mseg
WHERE matnr EQ it_mseg-matnr
AND spras EQ 'EN'.
SELECT mblnr mjahr budat FROM mkpf INTO TABLE it_mkpf
FOR ALL ENTRIES IN it_mseg
WHERE mblnr = it_mseg-mblnr
AND mjahr = it_mseg-mjahr.
SELECT matnr werks lgort labst lgpbe FROM mard INTO TABLE it_mard
FOR ALL ENTRIES IN it_mseg
WHERE matnr EQ it_mseg-matnr
AND lgort EQ wa_lgort
AND werks EQ it_mseg-werks.
ENDIF.
LOOP AT it_mara INTO wa_mara.
LOOP AT it_mseg INTO wa_mseg WHERE matnr = wa_mara-matnr.
READ TABLE it_mbew INTO wa_mbew WITH KEY matnr = wa_mara-matnr.
IF sy-subrc = 0.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr .
READ TABLE it_mkpf INTO wa_mkpf WITH KEY mblnr = wa_mseg-mblnr.
READ TABLE it_mard INTO wa_mard WITH KEY matnr = wa_mara-matnr .
ENDIF.
IF sy-subrc = 0.
itab1-part_no = wa_mseg-matnr.
IF wa_mseg-bwart = '101'.
itab1-doc_no = wa_mseg-mblnr.
ELSE.
CLEAR itab1-doc_no.
ENDIF.
itab1-total_stock = wa_mard-labst.
itab1-total_shelf_life = wa_mara-mhdhb.
itab1-desc = wa_makt-maktx.
itab1-doc_dat = wa_mkpf-budat.
itab1-stg_loc = wa_lgort.
itab1-stg_plant = wa_mseg-werks.
itab1-stg_bin = wa_mard-lgpbe.
itab1-menge = wa_mseg-menge.
itab1-bwtar = wa_mseg-bwtar.
APPEND itab1.
CLEAR itab1.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
SORT itab1 BY stg_bin part_no doc_dat DESCENDING.
LOOP AT itab1.
IF NOT itab1-doc_no IS INITIAL.
SELECT SINGLE * FROM qals WHERE mblnr = itab1-doc_no AND
stat35 = 'X'.
IF sy-subrc NE 0.
DELETE itab1.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT itab1.
tem_no = itab1-part_no.
EXIT.
ENDLOOP.
LOOP AT itab1.
IF itab1-part_no EQ tem_no.
IF itab1-total_stock > temp_stock.
IF NOT itab1-doc_no IS INITIAL.
temp_stock = temp_stock + itab1-menge.
ENDIF.
ELSE.
DELETE itab1.
ENDIF.
tem_no = itab1-part_no.
ELSE.
IF NOT itab1-doc_no IS INITIAL .
temp_stock = itab1-menge .
ELSE.
temp_stock = 0 .
ENDIF.
tem_no = itab1-part_no.
ENDIF.
ENDLOOP.
DATA: $lincnt TYPE i.
DESCRIBE TABLE itab1 LINES $lincnt.
IF $lincnt = 0.
MESSAGE i100(zmyw).
ENDIF.
LOOP AT itab1.
AT NEW part_no.
WRITE: /.
READ TABLE itab1 INDEX sy-tabix.
count = 0.
WRITE: /01 itab1-part_no,
20 itab1-desc(28) ,
49 itab1-total_shelf_life LEFT-JUSTIFIED,
56 itab1-stg_bin,
67 itab1-total_stock LEFT-JUSTIFIED.
ENDAT.
IF NOT itab1-doc_no IS INITIAL.
itab1-expiry_dt = itab1-doc_dat + itab1-total_shelf_life.
count = count + 1.
char_count = count.
CONDENSE char_count.
WRITE:/ char_count,'. ','DOC NO:', itab1-doc_no.
WRITE:25 ' Exp. DT.: ', itab1-expiry_dt,
50 'QTY.: ', itab1-menge,
80 itab1-bwtar.
ENDIF.
AT LAST.
WRITE:/ .
ULINE.
FORMAT COLOR COL_HEADING.
FORMAT INVERSE ON.
WRITE:/40 'END OF THE REPORT'.
FORMAT INVERSE OFF.
FORMAT COLOR OFF.
ULINE.
ENDAT.
ENDLOOP.
MORE PROGRAMS ON REPORT PROGRAMMING:
- Finding User Exits, Badi's & Enhancements For Any Transaction Or Program.
- Upload Excel Sheet Data Into Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE.
- Uploading Large Data From Excel Sheet To Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE
- Send an excel sheet to the concerned person in an email format via SAP System.
- Upload the financial documents from a legacy system (excel file) into SAP using transaction code FB01.
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.