Google Search - Blog...........

Showing posts with label function module fm 'REUSE_ALV_LIST_DISPLAY'. Show all posts
Showing posts with label function module fm 'REUSE_ALV_LIST_DISPLAY'. Show all posts

ABAP - Including Line After Subtotal In ALV Display.

REPORT ztest_alv.

*---type pools
TYPE-POOLS: slis.

*---internal tables
DATA: BEGIN OF it_flight OCCURS 0,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
END OF it_flight,

*--internal tables for alv
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF it_fieldcat,
layout TYPE slis_layout_alv,
it_sort type slis_t_sortinfo_alv,
wa_sort like line of it_sort.

*---start-of-selection .

START-OF-SELECTION.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_FLIGHT'
i_inclname = sy-repid
CHANGING
ct_fieldcat = it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2.

*----get data
SELECT carrid
connid
fldate
seatsmax
seatsocc
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE it_flight
UP TO 20 ROWS.
.
wa_fcat-do_sum = 'X'.
MODIFY it_fieldcat FROM wa_fcat TRANSPORTING do_sum
WHERE fieldname = 'SEATSOCC' .

wa_sort-fieldname = 'CARRID'.
wa_sort-group = 'UL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.

wa_sort-fieldname = 'CONNID'.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = layout
it_fieldcat = it_fieldcat
it_sort = it_sort
TABLES
t_outtab = it_flight
EXCEPTIONS
program_error = 1.




ABAP - Simple ALV Interactive Report Program.

REPORT ZPURCHASE_ORDER.
*--type pools
TYPE-POOLS:SLIS.
*--internal tables for alv
DATA:
W_EBELN TYPE EKKO-EBELN,
W_PROG TYPE SY-REPID,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
T_EVENTCAT TYPE SLIS_T_EVENT,
W_EVENTCAT LIKE LINE OF T_EVENTCAT.

DATA:
T_EKKO LIKE STANDARD TABLE OF EKKO,
FS_EKKO LIKE LINE OF T_EKKO.

DATA:T_EKPO LIKE STANDARD TABLE OF EKPO,
FS_EKPO LIKE LINE OF T_EKPO.

*---- SELECT-OPTIONS DECLARATION
SELECT-OPTIONS:S_EBELN FOR W_EBELN.

*----- START-OF-SELECTION
START-OF-SELECTION.
SELECT *
FROM EKKO
INTO TABLE T_EKKO
WHERE EBELN IN S_EBELN.

W_PROG = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
I_CALLBACK_USER_COMMAND = 'PICK'
I_STRUCTURE_NAME = 'EKKO'
TABLES
T_OUTTAB = T_EKKO .

*&--------------------------------------------------------------------*
*& Form pick
*---------------------------------------------------------------------*
FORM PICK USING COMMAND LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
READ TABLE T_EKKO INTO FS_EKKO INDEX SELFIELD-TABINDEX.

CASE COMMAND.
WHEN '&IC1'.
SELECT *
FROM EKPO
INTO TABLE T_EKPO
WHERE EBELN EQ FS_EKKO-EBELN.

W_PROG = SY-REPID.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'EKPO'
CHANGING
CT_FIELDCAT = T_FIELDCAT .


DELETE T_FIELDCAT WHERE FIELDNAME EQ 'EBELN'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'BUKRS'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'LGORT'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'WERKS'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
IT_FIELDCAT = T_FIELDCAT
IT_EVENTS = T_EVENTCAT
TABLES
T_OUTTAB = T_EKPO .

ENDCASE. " CASE COMMAND
ENDFORM. " FORM PICK

FORM T_EVENTCAT.
W_EVENTCAT-NAME = 'TOP_OF_PAGE'.
W_EVENTCAT-FORM = 'TOP'.
APPEND W_EVENTCAT TO T_EVENTCAT.
ENDFORM.

FORM TOP.
READ TABLE T_EKPO INTO FS_EKPO INDEX 1.
WRITE:/ 'Purchase Document Number'(001),30 FS_EKPO-EBELN,
/ 'Company Code'(002), 30 FS_EKPO-BUKRS,
/ 'Plant'(003), 30 FS_EKPO-WERKS,
/ 'Storage Location'(004),30 FS_EKPO-LGORT.
ENDFORM.


ALSO READ:

- Simple ALV Grid/List With Save Layout.

- Checkbox In ALV Program.

- ALV Header With Logo.

- Including Line After Subtotal In ALV Display.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.

ABAP - Displaying Icon's In ALV Display.

*&---------------------------------------------------------------------*
*& Report ZALV_ICON *
*& *
*&---------------------------------------------------------------------*

REPORT ZALV_ICON .
************************************************************************
* Include Programs
************************************************************************
INCLUDE .

************************************************************************
* Database Tables
************************************************************************
TABLES: kna1. "Customer Master

************************************************************************
* Types
************************************************************************
TYPE-POOLS: kkblo.

************************************************************************
* Structures
************************************************************************
* Structure to hold the Color Information
DATA: BEGIN OF st_color,
color(3) TYPE c,
END OF st_color.

* Structure to hold the Icon Information
DATA: BEGIN OF st_icon,
icon(4) TYPE c,
END OF st_icon.

* ALV Field Catalog Structure
DATA: st_fieldcat TYPE slis_fieldcat_alv.

* ALV Layout Structure
DATA: st_layout TYPE slis_layout_alv.

************************************************************************
* Internal Tables
************************************************************************
* Output Table
DATA: BEGIN OF tbl_kna1 OCCURS 0.
INCLUDE STRUCTURE st_icon. "Icon Structure
INCLUDE STRUCTURE kna1. "Customer Master Structure
INCLUDE STRUCTURE st_color. "Color Structure
DATA: END OF tbl_kna1.

* ALV Field Catalog Table
DATA: tbl_fieldcat TYPE slis_t_fieldcat_alv.

************************************************************************
* Variables
************************************************************************
DATA: fieldname(30) TYPE c,
g_repid LIKE sy-repid.

************************************************************************
* Start of Selection
************************************************************************
START-OF-SELECTION.

g_repid = sy-repid.

PERFORM get_data.

************************************************************************
* End of Selection
************************************************************************
END-OF-SELECTION.

PERFORM do_fancy_stuff.
PERFORM get_layout.
PERFORM get_fieldcat.
PERFORM create_report.


*&---------------------------------------------------------------------*
*& Form CREATE_REPORT
*&---------------------------------------------------------------------*
* Learn to read the subroutine name!
*----------------------------------------------------------------------*
FORM create_report.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_interface_check = ' '
i_callback_program = g_repid
i_callback_user_command = 'PROCESS_USER_COMMANDS'
it_fieldcat = tbl_fieldcat
i_default = 'X'
i_save = ' '
is_layout = st_layout
TABLES
t_outtab = tbl_kna1
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " CREATE_REPORT

*&---------------------------------------------------------------------*
*& Form GET_FIELDCAT
*&---------------------------------------------------------------------*
* Build the Field Catalog
*----------------------------------------------------------------------*
FORM get_fieldcat.
* Here the field catalog is created. To display more fields simply
* 'uncomment' the additional lines and add the field name. Also note
* that the field catalog is much more powerful than this. You can
* intensify fields, change the colour, assign reference fields, etc.
* Look at type slis_fieldcat_alv for more options.
PERFORM write_fieldcat USING 'ICON' 'TBL_KNA1' ' ' 'X' 1 '2' 'X'
' '.
PERFORM write_fieldcat USING 'KUNNR' 'TBL_KNA1' 'KNA1' 'X' 2 ' ' ' '
' '.
PERFORM write_fieldcat USING 'NAME1' 'TBL_KNA1' 'KNA1' ' ' 3 '10' ' '
'X'.
PERFORM write_fieldcat USING 'STRAS' 'TBL_KNA1' 'KNA1' ' ' 4 ' ' ' '
' '.
PERFORM write_fieldcat USING 'TELF1' 'TBL_KNA1' 'KNA1' ' ' 5 ' ' ' '
' '.
PERFORM write_fieldcat USING 'ORT01' 'TBL_KNA1' 'KNA1' ' ' 6 ' ' ' '
' '.
PERFORM write_fieldcat USING 'PSTLZ' 'TBL_KNA1' 'KNA1' ' ' 7 ' ' ' '
' '.
PERFORM write_fieldcat USING 'SORTL' 'TBL_KNA1' 'KNA1' ' ' 8 ' ' ' '
' '.
PERFORM write_fieldcat USING 'ERNAM' 'TBL_KNA1' 'KNA1' ' ' 9 ' ' ' '
' '.
PERFORM write_fieldcat USING 'SPRAS' 'TBL_KNA1' 'KNA1' ' ' 10 ' ' ' '
' '.
* perform write_fieldcat using ' ' 'TBL_KNA1' 'KNA1' ' ' 10 ' '.
* perform write_fieldcat using ' ' 'TBL_KNA1' 'KNA1' ' ' 11 ' '.
* perform write_fieldcat using ' ' 'TBL_KNA1' 'KNA1' ' ' 12 ' '.

ENDFORM. " GET_FIELDCAT

*&---------------------------------------------------------------------*
*& Form WRITE_FIELDCAT
*&---------------------------------------------------------------------*
* Write the Field Catalog data to the Field Catalog Table
*----------------------------------------------------------------------*
* -->name Field name
* -->tab Table name
* -->st Structure Name
* -->key Is this field a Key?
* -->pos Position Number
* -->length Field Length
* -->icon Display as Icon
* -->hot Hotspot
*----------------------------------------------------------------------*
FORM write_fieldcat USING name tab st key pos length icon hot.

st_fieldcat-fieldname = name.
st_fieldcat-tabname = tab.
st_fieldcat-ref_tabname = st.
st_fieldcat-key = key.
st_fieldcat-col_pos = pos.
st_fieldcat-outputlen = length.
st_fieldcat-icon = icon.
st_fieldcat-hotspot = hot.
APPEND st_fieldcat TO tbl_fieldcat.
CLEAR st_fieldcat.

ENDFORM. " WRITE_FIELDCAT

*&---------------------------------------------------------------------*
*& Form PROCESS_USER_COMMANDS
*&---------------------------------------------------------------------*
* Interactive Reporting Commands
*----------------------------------------------------------------------*
FORM process_user_commands USING syst-ucomm LIKE syst-ucomm
selfield TYPE slis_selfield.

* This subroutine is called when there is user interaction in the output
* In this case if the user double clicks the Customer Number then the
* program will call transaction XD03 and display the Customer Master
* Data

CASE syst-ucomm.
WHEN '&IC1'.
* get cursor field fieldname.
READ TABLE tbl_kna1 INDEX selfield-tabindex.
SET PARAMETER ID 'KUN' FIELD tbl_kna1-kunnr.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
ENDCASE.

ENDFORM. " PROCESS_USER_COMMANDS

*&---------------------------------------------------------------------*
*& Form GET_LAYOUT
*&---------------------------------------------------------------------*
* set the layout of the ALV.
* add color to the row?
*----------------------------------------------------------------------*
FORM get_layout.

st_layout-info_fieldname = 'COLOR'.
st_layout-colwidth_optimize = 'X'.
st_layout-get_selinfos = 'X'.

ENDFORM. " GET_LAYOUT
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* Get some data to play with
*----------------------------------------------------------------------*
FORM get_data.

SELECT * FROM kna1 INTO CORRESPONDING FIELDS OF TABLE tbl_kna1
UP TO 30 ROWS.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form do_fancy_stuff
*&---------------------------------------------------------------------*
* Do some fancy pants stuff for example changing the color of
* lines and adding icons
*----------------------------------------------------------------------*
FORM do_fancy_stuff.

* Here we will demonstrate changing the color of ALV Record lines as
* well as displaying Icons
LOOP AT tbl_kna1.
* All records where NAME1 begins with 'M', will be displayed in Bluish
* Green
IF tbl_kna1-name1(1) EQ 'M'.
tbl_kna1-color = 'C41'. "Bluish Green
MODIFY tbl_kna1 TRANSPORTING color.
ENDIF.

* All records with no TELF1 will be displayed in White and have a
* Warning Icon
IF tbl_kna1-telf1 IS INITIAL.
tbl_kna1-color = 'C00'. "White
tbl_kna1-icon = '@AH@'. "Warning Icon
MODIFY tbl_kna1 TRANSPORTING icon color.
ENDIF.
ENDLOOP.

ENDFORM. " do_fancy_stuff



ABAP - ALV Data In Different Languages.

REPORT ZTEST.

tables:mara,makt.

TYPE-POOLS:SLIS.

data:begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
end of it_mara.
data: begin of it_makt occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
SPRAS like makt-spras,
end of it_makt.

data:begin of it_final occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
maktx like makt-maktx,
end of it_final.

DATA:IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV.

select-options:s_matnr for mara-matnr.
parameters: p_lang like sy-langu.

parameters:p_rad1 radiobutton group g1 DEFAULT 'X',
p_rad2 radiobutton group g1,
p_rad3 radiobutton group g1.

AT SELECTION-SCREEN OUTPUT.

if p_rad1 = 'X'.
p_lang = 'EN'.
endif.

if p_rad2 = 'X'.
p_lang = 'DE'.
endif.

if p_rad3 = 'X'.
p_lang = 'FR'.
endif.

START-OF-SELECTION.

select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr.

select matnr
maktx
spras
from makt
into table it_makt
for all entries in it_mara
where matnr = it_mara-matnr
and spras = p_lang.

loop at it_mara.
it_final-matnr = it_mara-matnr.
it_final-meins = it_mara-meins.
it_final-mtart = it_mara-mtart.
read table it_makt with key matnr = it_mara-matnr.
it_final-maktx = it_makt-maktx.
append it_final.
clear it_final.
endloop.


WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MATNR'.
WA_FIELDCAT-REF_TABNAME = 'MARA'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MEINS'.
WA_FIELDCAT-REF_TABNAME = 'MARA'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MTART'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MTART'.
WA_FIELDCAT-REF_TABNAME = 'MARA'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MAKTX'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MATKX'.
WA_FIELDCAT-REF_TABNAME = 'MAKT'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.



CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = IT_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = IT_FINAL.



ALSO READ:

- ALV Hierarchical For Tables.

- Display ALV List/Grid Sub-Total & Total.

- Interactive ALV On T-Codes.

- Display EKPO Table Data In ALV Grid/List Display.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.

ABAP - Use Of Double Click On ALV Grid/List Display

REPORT ZPURCHASE_ORDER.

TYPE-POOLS:SLIS.
DATA:W_EBELN TYPE EKKO-EBELN,
W_PROG TYPE SY-REPID,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
T_EVENTCAT TYPE SLIS_T_EVENT,
W_EVENTCAT LIKE LINE OF T_EVENTCAT.

SELECT-OPTIONS:S_EBELN FOR W_EBELN.
DATA:T_EKKO LIKESTANDARD TABLEOF EKKO,FS_EKKO LIKE LINE OF T_EKKO.
DATA:T_EKPO LIKESTANDARD TABLEOF EKPO,FS_EKPO LIKE LINE OF T_EKPO.

START-OF-SELECTION.

SELECT *FROM
EKKO INTO TABLE T_EKKO
WHERE EBELN IN S_EBELN.

W_PROG = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
I_CALLBACK_USER_COMMAND = 'PICK'
I_STRUCTURE_NAME = 'EKKO'
TABLES
T_OUTTAB = T_EKKO
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&--------------------------------------------------------------------
**& Form pick
*&--------------------------------------------------------------------
** -->UCOMM text
* -->SELFIELD text
*---------------------------------------------------------------------*
FORM PICK USING COMMAND LIKE SY-UCOMMSELFIELD
TYPE SLIS_SELFIELD.

READ TABLE T_EKKO INTO FS_EKKO INDEX SELFIELD-TABINDEX.
CASE COMMAND.
WHEN '&IC1'.
SELECT *FROM
EKPOINTO TABLE T_EKPO
WHERE EBELN EQ FS_EKKO-EBELN.
W_PROG = SY-REPID.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'EKPO'
CHANGING
CT_FIELDCAT = T_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'EBELN'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'BUKRS'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'LGORT'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'WERKS'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
IT_FIELDCAT = T_FIELDCAT
IT_EVENTS = T_EVENTCAT
TABLES
T_OUTTAB = T_EKPO
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDCASE. " CASE COMMAND
ENDFORM. " FORM PICK

FORM T_EVENTCAT.
W_EVENTCAT-NAME = 'TOP_OF_PAGE'.
W_EVENTCAT-FORM = 'TOP'.
APPEND W_EVENTCAT TO T_EVENTCAT.
ENDFORM.

FORM TOP.
READ TABLE T_EKPO INTO FS_EKPO INDEX 1.
WRITE:/ 'Purchase Document Number'(001),
30 FS_EKPO-EBELN,
/ 'Company Code'(002),
30 FS_EKPO-BUKRS,
/ 'Plant'(003),
30 FS_EKPO-WERKS,
/ 'Storage Location'(004),
30 FS_EKPO-LGORT.
ENDFORM.


..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.