OO ALV WITH SUBTOTAL AND TOTAL TEXT


TYPES : BEGIN OF tab,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
text1(20), ” FOR TOTAL TEXT
text2(20), ” FOR SUBTOTAL TEXT
END OF tab.

DATA : it_flight TYPE TABLE OF tab,
wa_flight TYPE tab,
it_fcat  TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat,
wa_layo TYPE lvc_s_layo,
it_sort TYPE lvc_t_sort,
wa_sort TYPE lvc_s_sort,
o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
ok_code TYPE sy-ucomm.

START-OF-SELECTION.
PERFORM fetch_data.
PERFORM build_text.
PERFORM build_fieldcat.
PERFORM build_layout.
PERFORM build_sort.

END-OF-SELECTION.
CALL SCREEN 100.
*———————————————————————-*
FORM fetch_data .
SELECT carrid
connid
fldate      price FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_flight.
SORT it_flight BY carrid ASCENDING.
ENDFORM.                    ” FETCH_DATA

*———————————————————————-*
FORM build_text .
DATA : carr TYPE sflight-carrid,
txt TYPE char20.
LOOP AT it_flight INTO wa_flight.
wa_flight-text1 = ‘Total Price = ‘.
IF wa_flight-carrid NE carr.
carr = wa_flight-carrid.
CONCATENATE ‘Subtotal (‘ carr ‘) =’ INTO txt SEPARATED BY space.
ENDIF.
wa_flight-text2 = txt.
MODIFY it_flight FROM wa_flight.
ENDLOOP.
ENDFORM.                    ” BUILD_TEXT

*———————————————————————-*
FORM build_fieldcat .
wa_fcat-col_pos  = 1.
wa_fcat-fieldname = ‘TEXT1’.
wa_fcat-tech = ‘X’.
wa_fcat-no_out = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos  = 2.
wa_fcat-fieldname = ‘TEXT2’.
wa_fcat-tech = ‘X’.
wa_fcat-no_out = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos  = 3.
wa_fcat-fieldname = ‘CARRID’.
wa_fcat-tabname = ‘IT_FLIGHT’.
wa_fcat-scrtext_m = ‘CARRID’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos  = 4.
wa_fcat-fieldname = ‘CONNID’.
wa_fcat-tabname = ‘IT_FLIGHT’.
wa_fcat-scrtext_m = ‘CONNID’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos  = 5.
wa_fcat-fieldname = ‘FLDATE’.
wa_fcat-tabname = ‘IT_FLIGHT’.
wa_fcat-scrtext_m = ‘FLIGHT DATE’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos  = 6.
wa_fcat-fieldname = ‘PRICE’.
wa_fcat-tabname = ‘IT_FLIGHT’.
wa_fcat-scrtext_m = ‘PRICE’.
wa_fcat-do_sum = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

ENDFORM.                    ” BUILD_FIELDCAT
*————————————————————*
FORM build_layout .
wa_layo-cwidth_opt = ‘X’.
wa_layo-zebra = ‘X’.
wa_layo-no_totline = ‘X’.
ENDFORM.                    ” BUILD_LAYOUT
*————————————————————-*
FORM build_sort .
wa_sort-spos = 1.
wa_sort-fieldname = ‘TEXT1’.
wa_sort-up = ‘X’.
wa_sort-subtot = ‘X’.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.

wa_sort-spos = 2.
wa_sort-fieldname = ‘TEXT2’.
wa_sort-up = ‘X’.
wa_sort-subtot = ‘X’.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
ENDFORM.                    ” BUILD_SORT
*————————————————————-*
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘STATUS’.
ENDMODULE.                 ” STATUS_0100  OUTPUT
*————————————————————*
MODULE display_alv_grid OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING 

 container_name = ‘CONT’.”CREATE A CUSTOM CONT WITH NAME ‘CONT’
ENDIF.
IF o_alv IS  NOT BOUND.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_cust.
ENDIF.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
is_layout       = wa_layo
CHANGING
it_outtab       = it_flight
it_fieldcatalog = it_fcat

      it_sort         = it_sort.


ENDMODULE.                 ” DISPLAY_ALV_GRID  OUTPUT
*———————————————————–*
MODULE user_command_0100 INPUT.
CASE  ok_code.
WHEN ‘BACK’.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.                 ” USER_COMMAND_0100  INPUT

*————————————————————*

  SCREEN 100 FLOW LOGIC

PROCESS BEFORE OUTPUT.

  MODULE status_0100.

  MODULE display_alv_grid.

PROCESS AFTER INPUT.

  MODULE user_command_0100. 

1

 


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s