Help with our Project

We were given a project more of a group/individual project and I have to score 72 to pass this training. I already have a code but there are a lot of errors. I’ll be attaching my code here including the requirements for the program. I hope you guys can help me with my program. We will be presenting this Oct 7, 2024 so I hope you guys can help me before our presentation day. 

REPORT TEST_PROGRAM.

TYPESBEGIN OF ty_output,
         matnr TYPE maramatnr,
         maktx TYPE maktmaktx,
         werks TYPE marcwerks,
         name1 TYPE t001wname1,
         ersda TYPE maraersda,
         ernam TYPE maraernam,
         laeda TYPE maralaeda,
         aenam TYPE maraaenam,
         pstat TYPE marcpstat,
         dismm TYPE marcdismm,
         dispo TYPE marcdispo,
         disls TYPE marcdisls,
         beskz TYPE marcbeskz,
         herkl TYPE marcherkl,
         losgr TYPE marclosgr,
         perkz TYPE marcperkz,
         mtart TYPE maramtart,
         mbrsh TYPE marambrsh,
         matkl TYPE maramatkl,
         bismt TYPE marabismt,
         meins TYPE marameins,
       END OF ty_output.

DATAlt_output TYPE STANDARD TABLE OF ty_output,
      ls_output TYPE ty_output,
      lt_fieldcat TYPE lvc_t_fcat,
      ls_fieldcat TYPE lvc_s_fcat.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text001.
  PARAMETERSp_matno TYPE maramatnr OBLIGATORY,
             p_ers TYPE maraersda OBLIGATORY.
  PARAMETERSp_plant TYPE marcwerks OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

PARAMETERSp_write RADIOBUTTON GROUP rb1,
            p_alv RADIOBUTTON GROUP rb1 DEFAULT ‘X’,
            p_desc AS CHECKBOX DEFAULT ‘ ‘.

CLASS lhc_material DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      validate_material IMPORTING iv_material TYPE matnr,
      validate_created_on IMPORTING iv_created_on TYPE ersda,
      validate_plant IMPORTING iv_plant TYPE MARCWERKS,
      retrieve_data IMPORTING iv_material TYPE matnr
                     RETURNING VALUE(et_final_outputTYPE TABLE OF ty_output.
  PRIVATE SECTION.
ENDCLASS.

CLASS lhc_material IMPLEMENTATION.

  METHOD validate_material.
    IF iv_material IS NOT INITIAL.
      SELECT SINGLE matnr FROM mara
        INTO @DATA(lv_matnr)
        WHERE matnr @iv_material.
      IF sysubrc <> 0.
        MESSAGE ‘Invalid Material’ TYPE ‘E’.
      ENDIF.
    ENDIF.
  ENDMETHOD.

  METHOD validate_created_on.
    IF iv_created_on IS NOT INITIAL AND iv_created_on > sydatum.
      MESSAGE ‘Date specified is in the future, enter a valid date’ TYPE ‘E’.
    ENDIF.
  ENDMETHOD.

  METHOD validate_plant.
    IF iv_plant IS NOT INITIAL.
      SELECT SINGLE werks FROM t001w
        INTO @DATA(lv_werks)
        WHERE werks @iv_plant.
      IF sysubrc <> 0.
        MESSAGE ‘Invalid Plant’ TYPE ‘E’.
      ENDIF.
    ENDIF.
  ENDMETHOD.

  METHOD retrieve_data.
    DATAlt_makt TYPE TABLE OF makt,
          ls_makt TYPE makt,
          lt_t001w TYPE TABLE OF t001w,
          ls_t001w TYPE t001w.

    SELECT a~matnra~ersdaa~ernama~laedaa~aenama~mtarta~mbrsha~matkla~bismta~meins,
           c~werksc~pstatc~dismmc~dispo c~dislsc~beskzc~herklc~losgrc~perkz
      FROM mara AS a
      INNER JOIN marc AS c
      ON a~matnr c~matnr
      INTO CORRESPONDING FIELDS OF TABLE et_final_output
      WHERE a~matnr iv_material.

    SELECT maktx FROM makt
      INTO CORRESPONDING FIELDS OF TABLE lt_makt
      FOR ALL ENTRIES IN et_final_output
      WHERE matnr et_final_outputmatnr AND spras sylangu.

    SELECT name1 FROM t001w
      INTO CORRESPONDING FIELDS OF TABLE lt_t001w
      FOR ALL ENTRIES IN et_final_output
      WHERE werks et_final_outputwerks AND spras sylangu.

    LOOP AT et_final_output INTO DATA(ls_output).
      READ TABLE lt_makt INTO ls_makt WITH KEY matnr ls_outputmatnr.
      IF sy subrc =  0.
        ls_outputmaktx ls_maktmaktx.
      ENDIF.

      READ TABLE lt_t001w INTO ls_t001w WITH KEY werks ls_outputwerks.
      IF sysubrc 0.
        ls_outputname1 ls_t001wname1.
      ENDIF.

      MODIFY et_final_output INDEX sytabix FROM ls_output.
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATAlv_matnr TYPE maramatnr,
        lv_ersda TYPE maraersda,
        lv_werks TYPE marcwerks.

  lv_matnr p_matno.
  lv_ersda p_ers.
  lv_werks p_plant.

  CALL METHOD lhc_material=>validate_material
    EXPORTING
      iv_material lv_matnr.

  CALL METHOD lhc_material=>validate_created_on
    EXPORTING
      iv_created_on lv_ersda.

  CALL METHOD lhc_material=>validate_plant
    EXPORTING
      iv_plant lv_werks.

  IF p_alv ‘X’.
    DATA(lt_outputlhc_material=>retrieve_dataiv_material lv_matnr ).

    ls_fieldcatfieldname ‘MATNR’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘MAKTX’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘WERKS’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_field catkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘NAME1’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘ERSDA’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘ERNAM’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘LAEDA’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘AENAM’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘PSTAT’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘DISMM’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘DISPO’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘DISLS’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls _fieldcatfieldname ‘BESKZ’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘HERKL’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘LOSGR’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘PERKZ’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘MTART’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_field cat.

    ls_fieldcatfieldname ‘MBRSH’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘MATKL’.
    ls_field cattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘BISMT’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    ls_fieldcatfieldname ‘MEINS’.
    ls_fieldcattabname   ‘LT_OUTPUT’.
    ls_fieldcatkey       ‘X’.
    APPEND ls_fieldcat TO lt_fieldcat.

    TRY.
        CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
          EXPORTING
            it_outtab                     lt_output
            it_fieldcat                   lt_fieldcat
          EXCEPTIONS
            program_error                 1
            OTHERS                        2.
      CATCH cx_root INTO DATA(lx_root).
        MESSAGE lx_root->get_textTYPE ‘E’.
    ENDTRY.
  ENDIF.

 

As for the requirements: 

1.     In SE38, create a program.

  • Use naming convention, Y<SAP ID>_MMR_MATREP, where SAP ID = User ID, MM = Material Management, R = Report (Ex: Y19999999_MMR_MATREP)
  • Set program attributes:
    1.      Title: ‘Material Master Report – Plant View’
    2.      Type: ‘Executable Program’.
  •      Package: $tmp or save as local object

2.     Create the screen criteria.

  • Create two select-options: Material (MARA-MATNR) and Created On (MARA-ERSDA).
  • Create one parameter: Plant (MARC-WERKS).
  • Use the table field’s data element short text as screen labels. Do not use technical names as labels.
  • Use SELECTION-SCREEN BLOCK (open the link to read further) syntax to enclose the input fields and checkbox. Add a frame and title. Use text symbol TEXT-T01 as title. Fill TEXT-T01 with ‘Criteria:’.
  • Add two radio buttons: ‘Display report with WRITE’ and ‘Display report as ALV’. Select by default the radio button with the ALV display.
  • Add a checkbox called ‘Display Material Description’ and default it to false.
  • Enclose the radio buttons and checkbox in another selection-screen block. Use text symbol TEXT-T02 as title. Fill TEXT-T01 with ‘Select a View:’.

 

Sample output:

3.     Create a local model class. Define STATIC method for each validation below in PUBLIC SECTION. Use method parameter to import the select-option or parameter into each method.

  1. Validate Material input.
    1.      When a value is entered in the screen, check if value exists in MARA. If no value exists, display error message ‘Invalid Material’ on the status bar. The selection screen must still be visible and editable.
    2.      When no value entered in the screen, no validation needed.
  2. Validate Created On input.
    1.      When a value entered in the screen is greater than the current date (sy-datum), display error message ‘Date specified is in the future, enter a valid date’.
    2.      When no value entered in the screen, no validation needed.
  3. Validate Plant input.
    1.      When a value is entered in the screen, check if value exist in T001W. If no value exists, display error message ‘Invalid Plant’ on the status bar. The selection screen must still be visible and editable.
    2.      When no value entered in the screen, no validation needed.

 

Sample syntax for error message (in event block AT SELECTION-SCREEN).

 

Hint:

  • Use the appropriate SELECT statement to validate if a value exists in a database table. Use SELECT SINGLE or SELECT UP TO 1 ROWS ENDSELECT and use WHERE to compare the correct field with the input.
  • To transfer select-option values into a method, use data dictionary table type rseloption as data type for method parameters. Make sure to apply same data type to the select-option before transferring into the method.

4.     After SELECTION-SCREEN blocks, add event block AT SELECTION-SCREEN (open the link to read further). In AT SELECTION-SCREEN, call the STATIC methods created earlier to validate screen inputs. Do unit testing and make sure validation are working well.

5.     In model class, create INSTANCE method to retrieve and process data from database.

  1. Create an internal table with data dictionary type RSELOPTION. Use the ABAP 740 syntax, append one entry where field SIGN = ‘I’, OPTION ‘EQ’, LOW = screen criteria plant.

 

  1. Get data from table MARC and MARA using JOIN (see ‘Report Fields’ below to check what relevant fields to retrieve). . Check what similar fields (primary key = foreign key) in these two tables to use for the JOIN. Filter with screen criteria material and created on whether user entered values or not. Filter with internal table from 5.a that stores the screen criteria material type whether user entered values or not. Filter with internal table from 5.a that stores the screen criteria material type whether user entered values or not. If there is no data returned, issue error message ‘No data found.’

 

Sample syntax for error message (in event block START-OF-SELECTION)

MESSAGE TEXT-XXX TYPE ‘S’ DISPLAY LIKE ‘E’ (open the link to read further)

LEAVE LIST-PROCESSING (open the link to read further)

 

  1. Check if internal table from previous step has entries before proceeding to next steps.

 

  1. Get MATNR, MAKTX from MAKT using FOR ALL ENTRIES in internal table retrieved from 5.b. Check what similar fields in these two tables to use for the FOR ALL ENTRIES. Filter field SPRAS with SY-LANGU. Default system language is ‘EN’ for English. Sort the internal table based on primary keys.

 

  1. Get plant and plant name from T001W using FOR ALL ENTRIES in internal table retrieved from 5.b. Filter SPRAS with SY-LANGU. Default system language is ‘EN’ for English. Sort the internal table based on primary keys.

 

  1. Use LOOP and READ to transfer all field values retrieved from multiple database tables from previous steps into a final internal table. In Plant field/column, concatenate the Plant and Plant Name separated with dash.

 

  1. Export the final internal table.

 

Hint: You may declare internal tables in class definition so that it can be accessible to every method inside a class.

6.     After AT SELECTION-SCREEN, add event block START-OF-SELECTION. In START-OF-SELECTION(open the link to read further), create an object or instance of the model class. Call the method that retrieve data. Do unit testing and make sure logic is working well.

7.     Create a local view class. In view class, create INSTANCE method to display report fields using WRITE and import the final internal table from previous method. And create another INSTANCE METHOD to display reports using SALV(open the link to read further) and import the final internal table from previous method as well. Check below for report fields to be displayed.

  1. Follow column label/description below.
  2. Follow column sequence below on how they will be displayed.
  3. For WRITE method, Write the column headers/descriptions first before writing the final internal table.
  4. For ALV, use SALV. See YSAMPLE_OO_SALV for sample syntax.

 

Report Fields

Column

Description

Source Table

Field

Comments

Sort Criteria

1

Material

MARA

MATNR

Hotspot to MM03

1 ASC

2

Mat Description

MAKT

MAKTX

Log on Language; Display Material Description when checkbox is marked.

 

3

Plant

MARC &

T001W

WERKS &

NAME1

Concatenate Plant and Name to display ‘Plant – Name’. Name is based on Log on Language

2 ASC

4

Created On

MARA

ERSDA

MM/DD/YYYY format

3 DESC

5

Created By

MARA

ERNAM

 

 

6

Changed On

MARA

LAEDA

MM/DD/YYYY format

4 DESC

7

Changed By

MARA

AENAM

 

 

8

Maint. status

MARC

PSTAT

 

 

9

MRP Type

MARC

DISMM

 

 

10

MRP Controller

MARC

DISPO

 

 

11

Lot size

MARC

DISLS

 

 

12

Procurement

MARC

BESKZ

 

 

13

Ctry of origin

MARC

HERKL

 

 

14

Cstg Lot Size

MARC

LOSGR

 

 

15

Period Ind.

MARC

PERKZ

 

 

16

Material Type

MARA

MTART

 

 

17

Industry Sector

MARA

MBRSH

 

 

18

Material Group

MARA

MATKL

 

 

19

Old matl number

MARA

BISMT

 

 

20

Base Unit

MARA

MEINS

 

 

 

Basic SALV Syntax:

             cl_salv_table=>factory(

                          IMPORTING

                                       r_salv_table = DATA(lo_alv)

                          CHANGING

                                       t_table      = lt_final_output ).

 

lo_alv->display( ). “Display the ALV Grid

 

Note: TRY. CATCH. ENDTRY(open the link to read further)  is important to prevent possible runtime errors.          

8.     Go back to START-OF-SELECTION, create an object or instance of the view class. Call the method for WRITE when radio button ‘Display report with WRITE’ is selected else Call the method for SALV when radio button ‘Display report as ALV’ is selected.

9.     In the same method to display report ALV, add ALV functionality below. See YSAMPLE_OO_SALV for sample syntax:

  1. Set main heading: Material Master Report
  2. Add subheading below:

Material Plant View

Executed by: <sy-uname>

Executed on: <sy-datum> – <sy-uzeit>

Note: Date is in MM/DD/YYYY format. Time is in usual SY-UZEIT (military time) format (For ex: 04/28/2023 – 14:00:01).

Be reminded that Subheading loads slower in Eclipse, not because of performance issue. Subheading loads normal when run in SAP GUI.

 

  1. Add hotspot on Material column. Set the parameter ID value first like below:

SET PARAMETER ID ‘MAT’ FIELD lv_field.

Then use syntax, CALL TRANSACTION to ‘MM03’ WITH AUTHORITY-CHECK and SKIP FIRST SCREEN. When Material is clicked, screen MM03 is displayed with the Material selected.

  1. Enable default ALV toolbar functions.
  2. Set YELLOW colour for Material column. 
  3. Optimize column width.
  4. Set zebra stripes layout.
  5. Add ALV sorting. Follow sorting criteria column in ‘Report Fields’ below. ASC – Ascending order while DESC – Descending order.
  6. Display Material Description when checkbox is marked.
  7. Field/Column descriptions should be in text elements and not hardcoded.
  8. Don’t display ALV output if there are no data present. Display error ‘No data found’ in the status bar.
  9. Do component testing and make sure logic is working well.

 

*******************************************************************************************************

 

 

Sample Output (There might be differences with the actual requirement)

 

 

Scroll to Top