平均计算
Average calculation
有 100 名学生和 7 个科目。如何计算每个学生的平均分。当在选择屏幕中选择学生 ID 时,它应该显示该特定学生的平均值。
源代码
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.
假设您的数据存储在数据库中,请参阅 SAP 在 AVG
上的帮助
有 100 名学生和 7 个科目。如何计算每个学生的平均分。当在选择屏幕中选择学生 ID 时,它应该显示该特定学生的平均值。
源代码
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.
假设您的数据存储在数据库中,请参阅 SAP 在 AVG
上的帮助