Sorting technique in OOPS ALV in ABAP (Non event functionality).
1. Goto SE38.
2. Give program name and click on create.
3. Give title and click on save.
4. Write code.
REPORT ZAB_RP_OOPS_ALV_SORT.
TABLES: ekko,ekpo.
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bstyp TYPE ekko-bstyp,
bsart TYPE ekko-bsart,
END OF ty_ekko.
TYPES: BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
END OF ty_ekpo.
TYPES: BEGIN OF ty_final,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bstyp TYPE ekko-bstyp,
bsart TYPE ekko-bsart,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
END OF ty_final.
DATA: lt_ekko TYPE TABLE OF ty_ekko,
lr_ekko TYPE ty_ekko,
lt_ekpo TYPE TABLE OF ty_ekpo,
lr_ekpo TYPE ty_ekpo,
lt_final TYPE TABLE OF ty_final,
lr_final TYPE ty_final.
DATA: lt_fieldcat TYPE lvc_t_fcat,
lr_fieldcat TYPE lvc_s_fcat,
lo_container TYPE REF TO cl_gui_custom_container,
lo_grid TYPE REF TO cl_gui_alv_grid.
DATA: lt_sort TYPE lvc_t_sort,
lr_sort TYPE lvc_s_sort.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
IF s_ebeln IS INITIAL.
MESSAGE 'Pls enter purchasing doc number' TYPE 'E'.
ELSE.
SELECT ebeln
bukrs
bstyp
bsart
FROM ekko
INTO TABLE lt_ekko
WHERE ebeln IN s_ebeln.
ENDIF.
IF lt_ekko IS NOT INITIAL.
SELECT ebeln
ebelp
matnr
werks
FROM ekpo
INTO TABLE lt_ekpo
FOR ALL ENTRIES IN lt_ekko
WHERE ebeln = lt_ekko-ebeln.
ENDIF.
LOOP AT lt_ekko INTO lr_ekko.
lr_final-ebeln = lr_ekko-ebeln.
lr_final-bukrs = lr_ekko-bukrs.
lr_final-bstyp = lr_ekko-bstyp.
lr_final-bsart = lr_ekko-bsart.
LOOP AT lt_ekpo INTO lr_ekpo WHERE ebeln = lr_ekko-ebeln.
lr_final-ebelp = lr_ekpo-ebelp.
lr_final-matnr = lr_ekpo-matnr.
lr_final-werks = lr_ekpo-werks.
APPEND lr_final TO lt_final.
CLEAR lr_final.
ENDLOOP.
ENDLOOP.
CREATE OBJECT lo_container
EXPORTING
container_name = 'CONT'.
CREATE OBJECT lo_grid
EXPORTING
i_parent = lo_container.
lr_sort-fieldname = 'EBELN'.
lr_sort-up = 'X'. " Diplay in assending order.
*lr_sort-down = 'X'. " Display in desecending order.
APPEND lr_sort TO lt_sort.
CALL METHOD lo_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZAB_STR_EKKO_EKPO_OOPS'
CHANGING
it_outtab = lt_final
* it_fieldcatalog = lt_fieldcat
it_sort = lt_sort
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
CALL SCREEN '123'.
MODULE user_command_0123 INPUT.
IF sy-ucomm = 'BACK'.
LEAVE TO SCREEN '0'.
ENDIF.
ENDMODULE.
*************************Create structure******************
* Goto SE11.
* Select data type and give name and select type structure.
* Give fields.
* Check and activate.
*********************End of create structure**************
**************************Call screen 123*********************
* Double clicks on screen number.
* Give description.
* Uncomment the 'MODULE USER_COMMAND_123.' in under flow logic tab.
- Double click on 'USER_COMMAND_123'. and write code.
MODULE user_command_1234 INPUT.
IF sy-ucomm = 'BACK'.
LEAVE TO SCREEN '0'.
ENDIF.
ENDMODULE.
* Click on layout.
* Click on custom container button and drag.
* Give name (used in container creation).
* Go back and activate the screen.
**************************End of screen 123*********************
Input
Output
************************Thank You************************
Comments
Post a Comment