PROGRAM ztest_sum. TYPES: BEGIN OF x_sbook, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, luggweight TYPE s_lugweigh, wunit TYPE s_weiunit, END OF x_sbook. DATA: i_sbook TYPE STANDARD TABLE OF x_sbook INITIAL SIZE 0, i_final1 TYPE STANDARD TABLE OF x_sbook INITIAL SIZE 0, i_final2 TYPE STANDARD TABLE OF x_sbook INITIAL SIZE 0, i_final3 TYPE STANDARD TABLE OF x_sbook INITIAL SIZE 0, wa_sbook TYPE x_sbook, rtime1 TYPE i, rtime2 TYPE i, rtime3 TYPE i. PARAMETERS: p_rec TYPE i. SELECT carrid connid fldate luggweight wunit FROM sbook UP TO p_rec ROWS INTO TABLE i_sbook. CHECK sy-subrc = 0. APPEND LINES OF i_sbook TO i_sbook. SORT i_sbook BY carrid connid fldate. PERFORM collect. PERFORM at_end_of_sum. PERFORM sum_by_variable. END-OF-SELECTION. PERFORM display.
FORM collect . DATA: time1 TYPE i, time2 TYPE i. GET RUN TIME FIELD time1. LOOP AT i_sbook INTO wa_sbook. COLLECT wa_sbook INTO i_final1. ENDLOOP. GET RUN TIME FIELD time2. rtime1 = time2 - time1. ENDFORM.
FORM at_end_of_sum . DATA: time1 TYPE i, time2 TYPE i. GET RUN TIME FIELD time1. LOOP AT i_sbook INTO wa_sbook. AT END OF fldate. SUM. APPEND wa_sbook TO i_final2. ENDAT. ENDLOOP. GET RUN TIME FIELD time2. rtime2 = time2 - time1. ENDFORM.
FORM sum_by_variable . DATA: time1 TYPE i, time2 TYPE i, i_temp TYPE STANDARD TABLE OF x_sbook INITIAL SIZE 0, l_index TYPE i, wa_temp TYPE x_sbook, l_weight TYPE s_lugweigh, wa_final TYPE x_sbook. GET RUN TIME FIELD time1. i_temp = i_sbook. DELETE ADJACENT DUPLICATES FROM i_temp COMPARING carrid connid fldate. LOOP AT i_temp INTO wa_temp. READ TABLE i_sbook TRANSPORTING NO FIELDS WITH KEY carrid = wa_temp-carrid connid = wa_temp-connid fldate = wa_temp-fldate BINARY SEARCH. IF sy-subrc = 0. l_index = sy-tabix. LOOP AT i_sbook INTO wa_sbook FROM l_index. IF wa_sbook-carrid <> wa_temp-carrid OR wa_sbook-connid <> wa_temp-connid OR wa_sbook-fldate <> wa_temp-fldate. EXIT. ENDIF. l_weight = wa_sbook-luggweight + l_weight. ENDLOOP. wa_final = wa_sbook. wa_final-luggweight = l_weight. APPEND wa_sbook TO i_final3. CLEAR l_weight. ENDIF. ENDLOOP. GET RUN TIME FIELD time2. rtime3 = time2 - time1. ENDFORM.
FORM display . DATA: wa_final TYPE x_sbook. DATA: l_lines TYPE i. l_lines = LINES( i_final1 ). ULINE. FORMAT COLOR 2 ON. WRITE: /5 'Using COLLECT Statement',':', l_lines. WRITE: /5 'Run Time:',rtime1,'microseconds'. FORMAT COLOR 2 OFF. ULINE. l_lines = LINES( i_final2 ). FORMAT COLOR 1 ON. WRITE: /5 'Using Control Break statement AT-END-OF, SUM', ':', l_lines. WRITE: /5 'Run Time:',rtime2,'microseconds'. FORMAT COLOR 1 OFF. ULINE. l_lines = LINES( i_final3 ). FORMAT COLOR 4 ON. WRITE: /5 'Using Parallel Cursor',':', l_lines. WRITE: /5 'Run Time:',rtime3,'microseconds'. FORMAT COLOR 4 OFF. ULINE. ENDFORM. |
Thanks for your valuable information good post
ReplyDelete