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.
TYPES: BEGIN OF ty_output,
matnr TYPE mara–matnr,
maktx TYPE makt–maktx,
werks TYPE marc–werks,
name1 TYPE t001w–name1,
ersda TYPE mara–ersda,
ernam TYPE mara–ernam,
laeda TYPE mara–laeda,
aenam TYPE mara–aenam,
pstat TYPE marc–pstat,
dismm TYPE marc–dismm,
dispo TYPE marc–dispo,
disls TYPE marc–disls,
beskz TYPE marc–beskz,
herkl TYPE marc–herkl,
losgr TYPE marc–losgr,
perkz TYPE marc–perkz,
mtart TYPE mara–mtart,
mbrsh TYPE mara–mbrsh,
matkl TYPE mara–matkl,
bismt TYPE mara–bismt,
meins TYPE mara–meins,
END OF ty_output.
DATA: lt_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 text–001.
PARAMETERS: p_matno TYPE mara–matnr OBLIGATORY,
p_ers TYPE mara–ersda OBLIGATORY.
PARAMETERS: p_plant TYPE marc–werks OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
PARAMETERS: p_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 MARC–WERKS,
retrieve_data IMPORTING iv_material TYPE matnr
RETURNING VALUE(et_final_output) TYPE 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 sy–subrc <> 0.
MESSAGE ‘Invalid Material’ TYPE ‘E’.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD validate_created_on.
IF iv_created_on IS NOT INITIAL AND iv_created_on > sy–datum.
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 sy–subrc <> 0.
MESSAGE ‘Invalid Plant’ TYPE ‘E’.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD retrieve_data.
DATA: lt_makt TYPE TABLE OF makt,
ls_makt TYPE makt,
lt_t001w TYPE TABLE OF t001w,
ls_t001w TYPE t001w.
SELECT a~matnr, a~ersda, a~ernam, a~laeda, a~aenam, a~mtart, a~mbrsh, a~matkl, a~bismt, a~meins,
c~werks, c~pstat, c~dismm, c~dispo , c~disls, c~beskz, c~herkl, c~losgr, c~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_output–matnr AND spras = sy–langu.
SELECT name1 FROM t001w
INTO CORRESPONDING FIELDS OF TABLE lt_t001w
FOR ALL ENTRIES IN et_final_output
WHERE werks = et_final_output–werks AND spras = sy–langu.
LOOP AT et_final_output INTO DATA(ls_output).
READ TABLE lt_makt INTO ls_makt WITH KEY matnr = ls_output–matnr.
IF sy –subrc = 0.
ls_output–maktx = ls_makt–maktx.
ENDIF.
READ TABLE lt_t001w INTO ls_t001w WITH KEY werks = ls_output–werks.
IF sy–subrc = 0.
ls_output–name1 = ls_t001w–name1.
ENDIF.
MODIFY et_final_output INDEX sy–tabix FROM ls_output.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: lv_matnr TYPE mara–matnr,
lv_ersda TYPE mara–ersda,
lv_werks TYPE marc–werks.
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_output) = lhc_material=>retrieve_data( iv_material = lv_matnr ).
ls_fieldcat–fieldname = ‘MATNR’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘MAKTX’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘WERKS’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_field cat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘NAME1’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘ERSDA’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘ERNAM’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘LAEDA’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘AENAM’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘PSTAT’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘DISMM’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘DISPO’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘DISLS’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls _fieldcat–fieldname = ‘BESKZ’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘HERKL’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘LOSGR’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘PERKZ’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘MTART’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_field cat.
ls_fieldcat–fieldname = ‘MBRSH’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘MATKL’.
ls_field cat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘BISMT’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat–fieldname = ‘MEINS’.
ls_fieldcat–tabname = ‘LT_OUTPUT’.
ls_fieldcat–key = ‘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_text( ) TYPE ‘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:
- Title: ‘Material Master Report – Plant View’
- 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.
- Validate Material input.
- 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.
- When no value entered in the screen, no validation needed.
- Validate Created On input.
- 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’.
- When no value entered in the screen, no validation needed.
- Validate Plant input.
- 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.
- When no value entered in the screen, no validation needed.
Sample syntax for error message (in event block AT SELECTION-SCREEN).
- MESSAGE TEXT-XXX TYPE ‘E’. (open the link to read further)
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.
- 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.
- 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)
- Check if internal table from previous step has entries before proceeding to next steps.
- 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.
- 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.
- 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.
- 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.
- Follow column label/description below.
- Follow column sequence below on how they will be displayed.
- For WRITE method, Write the column headers/descriptions first before writing the final internal table.
- 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:
- Set main heading: Material Master Report
- 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.
- 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.
- Enable default ALV toolbar functions.
- Set YELLOW colour for Material column.
- Optimize column width.
- Set zebra stripes layout.
- Add ALV sorting. Follow sorting criteria column in ‘Report Fields’ below. ASC – Ascending order while DESC – Descending order.
- Display Material Description when checkbox is marked.
- Field/Column descriptions should be in text elements and not hardcoded.
- Don’t display ALV output if there are no data present. Display error ‘No data found’ in the status bar.
- Do component testing and make sure logic is working well.
******************************************************************************************************* |
|
|
Sample Output (There might be differences with the actual requirement) |
|
|