-4

There are 100 students and 7 subjects. how to calculate the average of each student . when student id is selected in selection screen it should display the average for that particular student .

source code

TYPES:
    test_1 TYPE SORTED TABLE OF ztest_03
                      WITH UNIQUE DEFAULT KEY.

DATA:
    it_test     TYPE test_1,
    wa_test     LIKE LINE OF IT_TEST,
    total(3) TYPE n,
    average(2) TYPE n.

SELECT-OPTIONS:
    std_id for wa_test-studentid.
PARAMETERS:
    test_id TYPE ztest_03-test.


START-OF-SELECTION.

 SELECT *
      FROM ztest_03
      INTO CORRESPONDING FIELDS OF TABLE it_test
      WHERE test = test_id
    and     studentid in std_id.

 IF sy-subrc <> 0.
    MESSAGE A123(Z455).
  ENDIF.

END-OF-SELECTION.

 LOOP AT it_test INTO wa_test.

*    WRITE: /
*        wa_test-studentid.
*        wa_test-subjectid,
*        wa_test-test,
*        wa_test-marks.
total = total + wa_test-marks.


   at END OF studentid.
      IF TEST_ID = 'FINALS'.
     WRITE:/ 'Test FINALS Details for student ID:' ,  WA_TEST-STUDENTID.
     ELSE.
       WRITE:/ 'Test CYCLE TEST Details for student ID:', WA_TEST-STUDENTID.
       ENDIF.
      average = total / 7.
      uline.
      WRITE:/ WA_TEST-STUDENTID, 'Average %:', average.
      if average Le 50.
        write:/ 'Grade E'.
        ULINE.
        ELSEif average le 60.
          write:/ 'Grade D'.
          ULINE.
          ELSEIF average le 70.
            WRITE:/ 'Grade C'.
            ULINE.
            ELSEIF average le 80.
              WRITE:/ 'Grade B'.
              ULINE.
              ELSEIF average le 90.
                WRITE:/ 'Grade A'.
                ULINE.
                ELSEIF average le 100.
                  WRITE:/ 'Grade O'.
                  ULINE.
                  ENDIF.
      ENDAT.
  ENDLOOP.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
mohd amir
  • 1
  • 3
  • 4
    please add a description of what you have tried and what else you've done to try and solve this. For example, can you calculate the average overall, but are having trouble with student wise averaging? If so, paste your code of what you have so far. – Anton Codes Jun 21 '17 at 15:18
  • What is exactly what you want to know? – Sergio Prats Jun 21 '17 at 20:24
  • i have share the source code , actually its only calculate the average of first student rest student are not calculating – mohd amir Jun 22 '17 at 10:43

1 Answers1

1

Assuming your data is stored in the database, see SAP's help on AVG

Gert Beukema
  • 2,510
  • 1
  • 17
  • 18