Sort field in ALV report
Hi Expert,
IN ALV report using RESUE_ALV_GRID_DISPLAY . I want to sort the second field of ALV output . In this function module RESUE_ALV_GRID_DISPLAY using event PF_STATUS . so can u tell me how sort the second field .
Regards
Bhabani
Hi,
check the fallowing code
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_SORT TYPE slis_sortinfo_alv,
****SORT LABELS AT RUN TIME
WA_SORT-TABNAME = 'IT_FINAL1'.
WA_SORT-FIELDNAME = 'BUDAT'.
WA_SORT-UP = 'X'.
WA_SORT-GROUP = 'X'.
WA_SORT-subtot = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
WA_SORT-TABNAME = 'IT_FINAL1'.
WA_SORT-FIELDNAME = 'MATNR'.
WA_SORT-UP = 'X'.
WA_SORT-GROUP = 'X'.
WA_SORT-subtot = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
IS_LAYOUT = LAYOUT
IT_FIELDCAT = IT_FIELDCAT
IT_SORT = IT_SORT
I_DEFAULT = 'X'
I_SAVE = 'U'
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_FINAL1
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.
Regards
Nandan.N
Similar Messages
-
Regd: Calculation of TOTAL field in ALV report
Hi All,
We have a scenario that we are not getting the total value for numeric fields in ALV report.
Below i have given the code used for it.
G_KEY = 'X'.
G_NOKEY = SPACE.
G_SUM = 'X'.
G_NOSUM = SPACE.
PERFORM BUILD_FIELDCAT USING 'VBELN' G_KEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'BLDAT' G_NOKEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'VGBEL' G_KEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'POSNR' G_KEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'MATNR' G_KEY G_NOSUM..
PERFORM BUILD_FIELDCAT USING 'LFIMG' G_NOKEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'VRKME' G_NOKEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'NETPR' G_NOKEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'BRTWR' G_NOKEY G_NOSUM.
PERFORM BUILD_FIELDCAT USING 'VALUE_INR' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'B_DUTY' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'S_TOTAL1' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'CV_DUTY' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'C_CVD' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'S_TOTAL2' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'C_DUTY' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'S_TOTAL3' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'A_DUTY' G_NOKEY G_SUM.
PERFORM BUILD_FIELDCAT USING 'T_DUTY' G_NOKEY G_SUM.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_DISPLAY.
*& Form DISPLAY
text
FORM BUILD_DISPLAY.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ' '
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE = TEXT-000
I_GRID_SETTINGS =
IS_LAYOUT = IG_LAYOUT
IT_FIELDCAT = IG_FIELDCAT
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'A'
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IG_INBOUND
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. "DISPLAY
*& Form BUILD_FIELDCAT
text
-->G_FIELDNAME text
-->L_KEY text
-->L_SUM text
FORM BUILD_FIELDCAT USING L_FIELDNAME LIKE DD03L-FIELDNAME L_KEY TYPE C L_SUM TYPE C.
CLEAR WG_FIELDCAT_LN.
ADD 1 TO G_COL_POS.
WG_FIELDCAT_LN-REF_TABNAME = 'IG_INBOUND'.
WG_FIELDCAT_LN-FIELDNAME = L_FIELDNAME.
WG_FIELDCAT_LN-KEY = L_KEY.
WG_FIELDCAT_LN-DO_SUM = L_SUM.
WG_FIELDCAT_LN-COL_POS = G_COL_POS.
WG_FIELDCAT_LN-NO_OUT = SPACE.
WG_FIELDCAT_LN-QFIELDNAME = SPACE.
WG_FIELDCAT_LN-HOTSPOT = SPACE.
APPEND WG_FIELDCAT_LN TO IG_FIELDCAT.
ENDFORM. "BUILD_FIELDCAT
*& Form BUILD_LAYOUT
text
FORM BUILD_LAYOUT.
IG_LAYOUT-TOTALS_TEXT = 'Total Amount'.
*IG_LAYOUT-SUBTOTALS_TEXT = 'A'.
IG_LAYOUT-ZEBRA = 'X'.
ENDFORM.
Help and Sugesstions will be much appreciated.
Thanks & Regds.
Ramesh.This is sample program for the same
REPORT Z_50657_ALV_EX2
NO STANDARD PAGE HEADING
LINE-COUNT 65(3)
LINE-SIZE 220
MESSAGE-ID ZZ.
* Type Pools *
TYPE-POOLS: SLIS, ICON.
* Tables *
TABLES: VBAK. "Sales Document Data
* Internal Tables *
* TABLE TO HOLD DATA OF SALES DOCUMENT
DATA: BEGIN OF IT_VBAK OCCURS 0,
VBELN LIKE VBAK-VBELN, "Sales Document
VBTYP LIKE VBAK-VBTYP, "SD document category
AUDAT LIKE VBAK-AUDAT, "Document date (date received/sent)
AUGRU LIKE VBAK-AUGRU, "Order reason (reason for the business)
AUART LIKE VBAK-AUART, "Sales Document Type
NETWR LIKE VBAK-NETWR, "Net Sales Order in Doc. Currency
WAERK LIKE VBAK-WAERK, "SD document currency
ICON TYPE ICON-ID, "traffic lights
END OF IT_VBAK.
* Work Areas *
*WORK AREAS DEFINED FOR ALV'S
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "field catalog
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "field catalog ITAB
WA_SORT TYPE SLIS_SORTINFO_ALV, "SORT work area
IT_SORT TYPE SLIS_T_SORTINFO_ALV, "SORT ITAB
LAYOUT TYPE SLIS_LAYOUT_ALV, "LAYOUT
WA_FCODE TYPE SLIS_EXTAB, "FUN CODE
I_FCODE_EXTAB TYPE SLIS_T_EXTAB,
WA_EVENTS TYPE SLIS_ALV_EVENT,
IT_EVENTS TYPE SLIS_T_EVENT.
* Selection-Screen *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
PARAMETERS: P_VBTYP LIKE VBAK-VBTYP DEFAULT 'C'.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS: LIST RADIOBUTTON GROUP G1,
GRID RADIOBUTTON GROUP G1.
SELECTION-SCREEN END OF BLOCK B2.
* At Selection-Screen *
*VALIDATION
* Start of Selection *
START-OF-SELECTION.
*POPULATION OF DATA INTO INTERNAL TABLE ITAB
PERFORM GET_DATA.
*DEFINE USER DEFINED FIELDCATALOG
PERFORM DEFINE_FIELDCATALOG.
*SUBTOTALS AND TOTALS DISPLAY USING SORT
PERFORM SORT_LIST.
*CHANGE FCODE OF STATUS
PERFORM CHANGE_FCODE.
*CHECK RADIOBUTTON OPTION AND ACCORDINGLY FINAL DISPLAY
PERFORM CHECK_OPTION.
*& Form GET_DATA
* text
FORM GET_DATA.
SELECT VBELN
VBTYP
AUDAT
AUGRU
AUART
NETWR
WAERK FROM VBAK INTO TABLE IT_VBAK
WHERE VBELN IN S_VBELN AND VBTYP = P_VBTYP
AND ERDAT > '01.01.2004' AND NETWR > 0.
LOOP AT IT_VBAK.
IF IT_VBAK-NETWR < 10000.
IT_VBAK-ICON = '@08@'.
ELSEIF IT_VBAK-NETWR > 100000.
IT_VBAK-ICON = '@0A@'.
ELSE.
IT_VBAK-ICON = '@09@'.
ENDIF.
MODIFY IT_VBAK INDEX SY-TABIX.
ENDLOOP.
ENDFORM. "GET_DATA
*& Form CHECK_OPTION
* text
FORM CHECK_OPTION.
WA_EVENTS-NAME = 'TOP_OF_PAGE'.
WA_EVENTS-FORM = 'TOP'.
APPEND WA_EVENTS TO IT_EVENTS.
CLEAR WA_EVENTS.
WA_EVENTS-NAME = 'END_OF_LIST'.
WA_EVENTS-FORM = 'END_LIST'.
APPEND WA_EVENTS TO IT_EVENTS.
CLEAR WA_EVENTS.
IF LIST = 'X'.
PERFORM LIST_DISP.
ENDIF.
IF GRID = 'X'.
PERFORM GRID_DISP.
ENDIF.
ENDFORM. "CHECK_OPTION
*& Form DEFINE_FIELDCATALOG
* text
FORM DEFINE_FIELDCATALOG.
WA_FIELDCAT-COL_POS = 1.
WA_FIELDCAT-FIELDNAME = 'ICON'.
WA_FIELDCAT-SELTEXT_L = 'ICON'.
WA_FIELDCAT-ICON = 'X'.
WA_FIELDCAT-OUTPUTLEN = 8.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 2.
WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-SELTEXT_L = 'SALES DOC NO.'.
WA_FIELDCAT-OUTPUTLEN = 10.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 3.
WA_FIELDCAT-FIELDNAME = 'AUDAT'.
WA_FIELDCAT-SELTEXT_L = 'CREATED ON'.
WA_FIELDCAT-OUTPUTLEN = 10.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 4.
WA_FIELDCAT-FIELDNAME = 'VBTYP'.
WA_FIELDCAT-SELTEXT_L = 'CATEGORY'.
WA_FIELDCAT-OUTPUTLEN = 1.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 6.
WA_FIELDCAT-FIELDNAME = 'AUGRU'.
WA_FIELDCAT-SELTEXT_L = 'REASON'.
WA_FIELDCAT-OUTPUTLEN = 3.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 5.
WA_FIELDCAT-FIELDNAME = 'AUART'.
WA_FIELDCAT-SELTEXT_L = 'DOC TYPE'.
WA_FIELDCAT-OUTPUTLEN = 4.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 7.
WA_FIELDCAT-FIELDNAME = 'NETWR'.
WA_FIELDCAT-SELTEXT_L = 'NET VALUE'.
WA_FIELDCAT-OUTPUTLEN = 17.
WA_FIELDCAT-DECIMALS_OUT = 2.
* WA_FIELDCAT-DO_SUM = 'X'.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = 8.
WA_FIELDCAT-FIELDNAME = 'WAERK'.
WA_FIELDCAT-SELTEXT_L = 'UNIT'.
WA_FIELDCAT-OUTPUTLEN = 50.
WA_FIELDCAT-TABNAME = 'IT_VBAK'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "DEFINE_FIELDCATALOG
*& Form DEFINE_LAYOUT
* text
FORM DEFINE_LAYOUT.
LAYOUT-ZEBRA = 'X'.
LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL SUM'.
LAYOUT-WINDOW_TITLEBAR = 'EXERCISE 2'.
LAYOUT-TOTALS_TEXT = 'TOTAL'.
ENDFORM. "DEFINE_LAYOUT
*& Form SORT_LIST
* text
FORM SORT_LIST.
WA_SORT-FIELDNAME = 'VBELN'.
WA_SORT-TABNAME = 'IT_VBAK'.
WA_SORT-SPOS = 1.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
WA_SORT-FIELDNAME = 'NETWR'.
WA_SORT-TABNAME = 'IT_VBAK'.
WA_SORT-UP = 'X'.
WA_SORT-SPOS = 2.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
ENDFORM. "SORT_LIST
*& Form LIST_DISP
* text
FORM LIST_DISP.
PERFORM DEFINE_LAYOUT.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FIELDCAT
IS_LAYOUT = LAYOUT
IT_SORT = IT_SORT
I_CALLBACK_PF_STATUS_SET = 'STATUS'
IT_EXCLUDING = I_FCODE_EXTAB
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_EVENTS = IT_EVENTS[]
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_VBAK
* 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. "LIST_DISP
*& Form GRID_DISP
* text
FORM GRID_DISP.
PERFORM DEFINE_LAYOUT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = LAYOUT
IT_FIELDCAT = IT_FIELDCAT
IT_SORT = IT_SORT
I_CALLBACK_PF_STATUS_SET = 'STATUS'
IT_EXCLUDING = I_FCODE_EXTAB
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_EVENTS = IT_EVENTS[]
TABLES
T_OUTTAB = IT_VBAK.
* 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. "GRID_DISP
*& Form STATUS
* text
* -->P_EXTAB text
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STATUS' EXCLUDING P_EXTAB.
ENDFORM. "STATUS
*& Form USER_COMMAND
* text
* -->R_UCOMM text
* -->RS_SELFIELD text
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'BACK' OR 'CANC' OR 'EXIT'.
LEAVE TO SCREEN 0.
WHEN '&IC1'.
SET PARAMETER ID 'AUN' FIELD RS_SELFIELD-VALUE.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDFORM. "USER_COMMAND
*& Form CHANGE_FCODE
* text
FORM CHANGE_FCODE.
WA_FCODE = 'PRNT'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&OAD'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&AVE'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&EB9'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&SUM'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&UMC'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&XPA'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
WA_FCODE = '&OMP'.
APPEND WA_FCODE TO I_FCODE_EXTAB.
ENDFORM. "CHANGE_FCODE
*& Form TOP
* text
FORM TOP.
IF LIST = 'X'.
WRITE:/ SY-ULINE.
WRITE:/ 'DATE:', SY-DATUM,55 'INTELLIGROUP ASIA PVT LTD'.
WRITE:/ 'TIME:', SY-UZEIT.
WRITE:/ 'USER NAME:', SY-UNAME,60 SY-TITLE.
WRITE:/ 'PAGE', SY-PAGNO.
WRITE:/ SY-ULINE.
ENDIF.
IF GRID = 'X'.
DATA: LS_LINE TYPE SLIS_LISTHEADER,
E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
* Listenüberschrift: Typ H
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
* LS_LINE-KEY: not used for this type
LS_LINE-INFO = 'Summary'.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
* Kopfinfo: Typ S
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'Intelligroup'.
LS_LINE-INFO = ''.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
LS_LINE-KEY = 'ASIA'.
LS_LINE-INFO = 'PVT LTD'.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
* Aktionsinfo: Typ A
CLEAR LS_LINE.
LS_LINE-TYP = 'A'.
* LS_LINE-KEY: not used for this type
LS_LINE-INFO = 'truman'.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = E04_LT_TOP_OF_PAGE
I_LOGO = 'ENJOY_SAP_LOGO'.
ENDIF.
ENDFORM. "TOP
*& Form END_LIST
* text
FORM END_LIST.
IF LIST = 'X'.
SKIP 2.
WRITE:/60 'END OF PAGE'.
ENDIF.
IF GRID = 'X'.
DATA: LS_LINE TYPE SLIS_LISTHEADER,
E04_LT_END_OF_LIST TYPE SLIS_T_LISTHEADER.
* Listenüberschrift: Typ H
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
* LS_LINE-KEY: not used for this type
LS_LINE-INFO = 'Summary'.
APPEND LS_LINE TO E04_LT_END_OF_LIST.
* Kopfinfo: Typ S
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'Intelligroup'.
LS_LINE-INFO = ''.
APPEND LS_LINE TO E04_LT_END_OF_LIST.
LS_LINE-KEY = 'ASIA'.
LS_LINE-INFO = 'PVT LTD'.
APPEND LS_LINE TO E04_LT_END_OF_LIST.
* Aktionsinfo: Typ A
CLEAR LS_LINE.
LS_LINE-TYP = 'A'.
* LS_LINE-KEY: not used for this type
LS_LINE-INFO = TEXT-105.
APPEND LS_LINE TO E04_LT_END_OF_LIST.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = E04_LT_END_OF_LIST.
ENDIF.
ENDFORM. "END_LIST -
Hi Experts,
Can i achieve sorting in Blocked ALV report as we can do in ALV Grid Display.???
If so, how can this be achieved????
For example, if there are 3 records with the same value for a field.....say thfreee rows with name 'Gaurav'.
I want to show 'Gaurav' only in the first row and the other two rows must be empty.
Gaurav 1 2 3
Gaurav 4 5 6
Gaurav 7 8 9
Should be seen as
Gaurav 1 2 3
4 5 6
7 8 9
Thanks and regards
Gaurav raghavHere is the code.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = 'ZCRM_ACTIVITY_REPORT'
CHANGING
ct_fieldcat = gt_fieldcatalog[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
CLEAR gs_sort.
gs_sort-fieldname = 'ORG'.
gs_sort-tabname = 'GT_ITAB'.
gs_sort-spos = '1'.
gs_sort-up = 'X'.
APPEND gs_sort TO gt_sort.
CLEAR gs_sort.
gs_sort-fieldname = 'EMPLOYEE'.
gs_sort-tabname = 'GT_ITAB'.
gs_sort-spos = '2'.
gs_sort-up = 'X'.
APPEND gs_sort TO gt_sort.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = gt_layout
it_fieldcat = gt_fieldcatalog
i_tabname = 'GT_ITAB'
it_events = gt_events
it_sort = gt_sort
i_text = 'Report 1 '
TABLES
t_outtab = gt_itab
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'. -
Hide grand total field on ALV report, But keep the sub total fields
Dear Experts,
1) How to hide grand total field on ALV report, But keep the sub total fields.
2) How to populate rate per ton & calculate total price according to the qty in delivering document.Dear Experts,
1) How to hide grand total field on ALV report, But keep the sub total fields.
2) How to populate rate per ton & calculate total price according to the qty in delivering document. -
Hi all,
i have to develop a ALV report.
In that report i have to put a open quantity column , so that the user can enter values in that, and that value should get updated in the database.
So please suggest me how to develop such report with open field.
Thanks in advance,
Regards,
PawanHi,
Try executing the below code
REPORT YMS_EDITBLOCKALV.
TABLES : rmmg1,MCHB, mkpf.
DATA: BEGIN OF t_mseg OCCURS 0,
zeile LIKE mseg-zeile,
menge LIKE mseg-menge,
meins LIKE mseg-meins,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
charg LIKE mseg-charg,
bwart LIKE mseg-bwart,
END OF t_mseg.
DATA:BEGIN OF t_mchb OCCURS 0.
INCLUDE STRUCTURE mchb.
data flag type c.
matnr LIKE mchb-matnr,
charg LIKE mchb-charg,
werks LIKE mchb-werks,
clabs LIKE mchb-clabs,
DATA END OF t_mchb.
TYPE-POOLS slis.
data: progname like sy-repid,
fieldcattab TYPE slis_t_fieldcat_alv WITH HEADER LINE.
data tabindex type i.
data wa_matnr LIKE mchb-matnr.
progname = sy-repid.
SELECTION-SCREEN BEGIN OF BLOCK b_b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_docno FOR mkpf-mblnr. " OBLIGATORY.
PARAMETERS p_docyr LIKE mkpf-mjahr. " OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b_b1.
START-OF-SELECTION.
SELECT zeile
menge
meins
matnr
werks
charg
bwart
FROM mseg
INTO TABLE t_mseg
WHERE mblnr IN s_docno AND mjahr = p_docyr.
CLEAR fieldcattab.
fieldcattab-col_pos = 1.
fieldcattab-fieldname = 'ZEILE'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-fix_column = 'X'.
fieldcattab-seltext_l = 'Item'.
APPEND fieldcattab.
CLEAR fieldcattab.
fieldcattab-col_pos = 2.
fieldcattab-fieldname = 'MENGE'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-seltext_l = 'Quantity'.
APPEND fieldcattab.
CLEAR fieldcattab.
fieldcattab-col_pos = 3.
fieldcattab-fieldname = 'MEINS'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-seltext_l = 'Unit'.
APPEND fieldcattab.
CLEAR fieldcattab.
fieldcattab-col_pos = 4.
fieldcattab-fieldname = 'MATNR'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-seltext_l = 'Material'.
APPEND fieldcattab.
CLEAR fieldcattab.
fieldcattab-col_pos = 5.
fieldcattab-fieldname = 'WERKS'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-seltext_l = 'Plant'.
APPEND fieldcattab.
CLEAR fieldcattab.
fieldcattab-col_pos = 6.
fieldcattab-fieldname = 'CHARG'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-seltext_l = 'Batch No'.
APPEND fieldcattab.
CLEAR fieldcattab.
fieldcattab-col_pos = 7.
fieldcattab-fieldname = 'BWART'.
fieldcattab-tabname = 'T_MSEG'.
fieldcattab-seltext_l = 'Inventory'.
fieldcattab-hotspot = 'X'.
APPEND fieldcattab.
end-of-selection.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = PROGNAME
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USERCOMMAND1'
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT =
IT_FIELDCAT = fieldcattab[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_ADD_FIELDCAT = fieldcattab
IT_HYPERLINK =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = t_mseg
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 usercommand1 USING r_ucomm LIKE sy-ucomm rs_selfield TYPE
slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
tabindex = rs_selfield-tabindex.
read table t_mseg INDEX tabindex.
select * from mchb into table t_mchb where matnr = t_mseg-matnr.
clear fieldcattab.
CLEAR fieldcattab[].
fieldcattab-col_pos = 1.
fieldcattab-fieldname = 'FLAG'.
fieldcattab-tabname = 'T_MCHB'.
fieldcattab-fix_column = 'X'.
fieldcattab-seltext_l = 'Check Box'.
fieldcattab-input = 'X'.
fieldcattab-edit = 'X'.
fieldcattab-checkbox = 'X'.
APPEND fieldcattab.
clear fieldcattab.
fieldcattab-col_pos = 2.
fieldcattab-fieldname = 'MATNR'.
fieldcattab-tabname = 'T_MCHB'.
fieldcattab-fix_column = 'X'.
fieldcattab-seltext_l = 'Material'.
fieldcattab-emphasize = 'C1'.
fieldcattab-input = 'X'.
fieldcattab-edit = 'X'.
fieldcattab-checkbox = 'X'.
APPEND fieldcattab.
clear fieldcattab.
fieldcattab-col_pos = 3.
fieldcattab-fieldname = 'CHARG'.
fieldcattab-tabname = 'T_MCHB'.
fieldcattab-seltext_l = 'Batch No'.
fieldcattab-emphasize = 'C2'.
fieldcattab-input = 'X'.
fieldcattab-edit = 'X'.
APPEND fieldcattab.
clear fieldcattab.
fieldcattab-col_pos = 4.
fieldcattab-fieldname = 'WERKS'.
fieldcattab-tabname = 'T_MCHB'.
fieldcattab-seltext_l = 'Plant'.
fieldcattab-emphasize = 'C30'.
fieldcattab-input = 'X'.
fieldcattab-edit = 'X'.
APPEND fieldcattab.
clear fieldcattab.
fieldcattab-col_pos = 5.
fieldcattab-fieldname = 'CLABS'.
fieldcattab-tabname = 'T_MCHB'.
fieldcattab-seltext_l = 'Stock'.
fieldcattab-emphasize = 'C601'.
fieldcattab-input = 'X'.
fieldcattab-edit = 'X'.
APPEND fieldcattab.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = PROGNAME
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USERCOMMAND2'
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT =
IT_FIELDCAT = FIELDCATTAB[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_ADD_FIELDCAT =
IT_HYPERLINK =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = t_mchb
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.
endform.
FORM usercommand2 USING r_ucomm LIKE sy-ucomm rs_selfield TYPE
slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
IF rs_selfield-sel_tab_field = 'T_MCHB-MATNR'.
CALL FUNCTION 'ZALV2'
EXPORTING
CTU = 'X'
MODE = 'E'
UPDATE = 'A'
GROUP =
USER =
KEEP =
HOLDDATE =
NODATA = '/'
MATNR_001 = '200-200'
KZSEL_01_002 = 'X'
IMPORTING
SUBRC =
TABLES
MESSTAB =
SET PARAMETER ID 'RID' FIELD RMMG1-MATNR.
CALL TRANSACTION 'MM03' and skip first screen.
ENDIF.
ENDCASE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = progname
i_callback_user_command = 'USERCOMMAND3'
it_fieldcat = fieldcattab[]
TABLES
t_outtab = t_mchb
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.
ENDFORM.
Regards,
chandru -
Hi all
In ALV Report .The user must be able to adapt the result list (add hidden fields, remove columns) and save the layout as layout. The user must be able to select this layout when executing the selection.
the user must hide the fields and can diplay when ever he needs in ALV reportU have to use no_out = 'X'.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-no_out = 'X'.
fieldcatalog-key = 'X'.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
<b> i_save = 'X'</b>
is_variant = z_template
tables
t_outtab = it_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.
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_enhanced.htm -
Regarding Selection Screen field making display field in ALV report
Hi All,
In ALV Report, at runtime how can i make the field as Display Field in selection screen .
Thks & Regds
Shaileshhii,
Go to se38 and give the below progra name execute.... check the source code it is very easy to understand.
1.demo_dynpro_modify_simple
2.demo_dynpro_modify_screen
if tou are using grid,u can refer to foll link
sequencing / choosing fields in report screen at runtime,
Display the Columns in the grid at run time
rgrds,
Shweta -
Summation of a field in ALV report
Hi,
I hv created an ALV Report. But i m not getting the summation sign in the Application Toolbar. What can be the problem? I am trying to find out the sum of the the field NETWR in table VBAK.
Thanks,
Mohit.See the ALV function module used by you and me ... the below program gives the summation icon in the alv bar .
*& Report ZDEMO_ALVGRID *
*& Example of a simple ALV Grid Report *
REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*& Form BUILD_FIELDCATALOG
* Build Fieldcatalog for ALV Report
form build_fieldcatalog.
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = 'X'. "Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
* Build layout for ALV grid report
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
* gd_layout-zebra = 'X'.
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
* Display report using ALV grid
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_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.
endform. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
* Retrieve data form EKPO table and populate itab it_ekko
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
endform. " DATA_RETRIEVAL
reward points if it is usefull
Girish -
Insert extra field in ALV report
Hi All,
Ive requirement like need to add Vendors Country Code very next to Tax code field in standard SAP standard ALV report S_ALR_87012357 .
Ive copied program (RFUMSV00) into z-program.
But Im not getting any idea how can I add extra field in field catalogue and corresponding value in internal table.
Any ideas please ..
Full points will be rewarded for useful answersI didn´t understand the question very well, but if i am in certain, you will have to modify the internal table to add the field. If the table which shows the alv is like a data base type, you will have to modify this in this way:
data: begin of gt_table occurs 0,
include structure ,
new_field type XXXX.
data: end of gt_table.
Then, you will have to add this new field to the field catalogue, in this form:
ls_catalogue-fialdname = 'NEW_FIELD'.
ls_catalogue-tabname = 'GT_TABLE'.
etc...
Luck in your requeriment.
ls_catalogue-tabname = 'GT_TABLE'.
etc...
Luck in your travel. -
Merge field label of two fields in ALV report
Hi,
Greetings of the day !!
I have a requirement to create a ALV report and the alv report has three fields(say F1, F2, F3). Where F1 and F2 fall under same category and i need to have single field label for both these fields.
How can I merge the field label of the fields F1 and F2?
Pl. share your knowledge regarding this.
Thanking you.
Regards,
RaghuHi Jodeswara Rao,
I need to display a ALV report with fields F1, F2 and F3. But F1 and F2 should have same field Label.
Header 1
Header 3
F1
F2
F3 -
Hotspot on more than one fields in ALV Report
I want to add Hotspot on more than one field in ALV,
one field is Vbeln , one is BSTNK, one is matnr and so on.
i have used form user_command.and have written coding for Vbeln (on vbeln i am showing transaction VA02)
i want to pass an eror mesaage when user clicks on bstnk or matnr.
ThanksHi Lovleen,
*Global definitions *
Data Types
type-pools: slis.
types: begin of tp_data,
ebeln like ekko-ebeln,
*matnr like ekko-matnr,
*meins like ekko-meins,
lifnr like lfa1-lifnr,
chk1,
end of tp_data,
tp_tbl_data type standard table of tp_data.
Constants
Data objects (variable declarations and definitions)
Report data to be shown.
data: it_data type standard table of tp_data.
Heading of the report.
data: t_heading type slis_t_listheader.
======================= Selection Screen ==========================
selection-screen: begin of block b1 with frame title text-t01.
DATA: w_aux_ebeln like ekko-ebeln.
SELECT-OPTIONS s_ebeln for w_aux_ebeln
DEFAULT 1000 .
DATA: w_aux_lifnr like lfa1-lifnr.
SELECT-OPTIONS s_lifnr for w_aux_lifnr
DEFAULT 00000001000 .
selection-screen: end of block b1.
======================== Event Blocks =============================
at selection-screen.
start-of-selection.
perform get_data using it_data.
end-of-selection.
perform build_alv using it_data t_heading.
======================== Subroutines ==============================
*& Form get_data
Gets the information to be shown in the report.
form get_data using t_data type tp_tbl_data.
SELECT e~ebeln
*e~matnr
*e~meins
l~lifnr
INTO CORRESPONDING FIELDS OF TABLE t_data
FROM ekko as e
inner join lfa1 as l on elifnr = llifnr
WHERE e~ebeln in s_ebeln
AND l~lifnr in s_lifnr
endform. " get_data
*& Form build_alv
Builds and display the ALV Grid.
form build_alv using t_data type tp_tbl_data
t_heading type slis_t_listheader.
ALV required data objects.
data: w_title type lvc_title,
w_repid type syrepid,
w_comm type slis_formname,
w_status type slis_formname,
x_layout type slis_layout_alv,
t_event type slis_t_event,
t_fieldcat type slis_t_fieldcat_alv,
t_sort type slis_t_sortinfo_alv.
refresh t_fieldcat.
refresh t_event.
refresh t_sort.
clear x_layout.
clear w_title.
Field Catalog
perform set_fieldcat2 using:
1 'CHK1' 'XFELD' space space space 'Select' 'Select this row' 'Sel'
'Select this row' space space space 'X' 'X' space t_fieldcat,
2 'EBELN' 'EBELN' 'EKKO' space space space space space space space
space space space space space t_fieldcat ,
3 'MATNR' 'MATNR' 'EKKO' space space space space space space space
space space space space space t_fieldcat ,
4 'MEINS' 'MEINS' 'EKKO' space space space space space space space
space space space space space t_fieldcat ,
5 'LIFNR' 'LIFNR' 'LFA1' space space space space space space space
space space space space space t_fieldcat .
Layout
x_layout-zebra = 'X'.
Top of page heading
perform set_top_page_heading using t_heading t_event.
Events
perform set_events using t_event.
GUI Status
w_status = ''.
w_repid = sy-repid.
Title
w_title = <<If you want to set a title for
the ALV, please, uncomment and edit this line>>.
User commands
w_comm = 'USER_COMMAND'.
Order
Example
PERFORM set_order USING '<field>' 'IT_DATA' 'X' space space t_sort.
Displays the ALV grid
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
it_fieldcat = t_fieldcat
is_layout = x_layout
it_sort = t_sort
i_callback_pf_status_set = w_status
i_callback_user_command = w_comm
i_save = 'X'
it_events = t_event
i_grid_title = w_title
tables
t_outtab = t_data
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. " build_alv.
*& Form set_top_page_heading
Creates the report headings.
form set_top_page_heading using t_heading type slis_t_listheader
t_events type slis_t_event.
data: x_heading type slis_listheader,
x_event type line of slis_t_event.
Report title
clear t_heading[].
clear x_heading.
x_heading-typ = 'H'.
x_heading-info = ''(001).
append x_heading to t_heading.
Program name
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Program: '.
x_heading-info = sy-repid.
append x_heading to t_heading.
User who is running the report
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'User: '.
x_heading-info = sy-uname.
append x_heading to t_heading.
Date of execution
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Date: '.
write sy-datum to x_heading-info.
append x_heading to t_heading.
Time of execution
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Time: '.
write sy-uzeit to x_heading-info.
append x_heading to t_heading.
Top of page event
x_event-name = slis_ev_top_of_page.
x_event-form = 'TOP_OF_PAGE'.
append x_event to t_events.
endform.
*& Form set_events
Sets the events for ALV.
The TOP_OF_PAGE event is alredy being registered in
the set_top_page_heading subroutine.
form set_events using t_events type slis_t_event.
data: x_event type line of slis_t_event.
Example
clear x_event.
x_event-name = .
x_event-form = .
append x_event to t_event.
endform.
*& Form set_order
Adds an entry to the order table.
FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot
t_sort TYPE slis_t_sortinfo_alv.
DATA: x_sort TYPE slis_sortinfo_alv.
CLEAR x_sort.
x_sort-fieldname = p_fieldname.
x_sort-tabname = p_tabname.
x_sort-up = p_up.
x_sort-down = p_down.
x_sort-subtot = p_subtot.
APPEND x_sort TO t_sort.
ENDFORM. "set_order
*& Form set_fieldcat2
Adds an entry to the field catalog.
p_colpos: Column position.
p_fieldname: Field of internal table which is being described by
* this record of the field catalog.
p_ref_fieldname: (Optional) Table field / data element which
* describes the properties of the field.
* If this field is not given, it is copied from
* the fieldname.
p_ref_tabname: (Optional) Table which holds the field referenced
* by <<p_ref_fieldname>>.
If this is not given, the parameter
<<p_ref_fieldname>> references a data element.
p_outputlen: (Optional) Column width.
p_noout: (Optional) If set to 'X', states that the field is not
* showed initially. If so, the field has to be
included in the report at runtime using the display
options.
p_seltext_m: (Optional) Medium label to be used as column header.
p_seltext_l: (Optional) Long label to be used as column header.
p_seltext_s: (Optional) Small label to be used as column header.
p_reptext_ddic: (Optional) Extra small (heading) label to be
* used as column header.
p_ddictxt: (Optional) Set to 'L', 'M', 'S' or 'R' to select
whether to use SELTEXT_L, SELTEXT_M, SELTEXT_S,
or REPTEXT_DDIC as text for column header.
p_hotspot: (Optional) If set to 'X', this field will be used
* as a hotspot area for cursor, alolowing the user
* to click on the field.
p_showasicon: (Optional) If set to 'X', this field will be shown
as an icon and the contents of the field will set
* which icon to show.
p_checkbox: (Optional) If set to 'X', this field will be shown
as a checkbox.
p_edit: (Optional) If set to 'X', this field will be editable.
p_dosum: (Optional) If set to 'X', this field will be summed
(aggregation function) according to the grouping set
by the order functions.
t_fieldcat: Table which contains the whole fieldcat.
FORM set_fieldcat2 USING
p_colpos p_fieldname p_ref_fieldname p_ref_tabname
p_outputlen p_noout
p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
p_hotspot p_showasicon p_checkbox p_edit
p_dosum
t_fieldcat TYPE slis_t_fieldcat_alv.
DATA: wa_fieldcat TYPE slis_fieldcat_alv.
CLEAR wa_fieldcat.
General settings
wa_fieldcat-fieldname = p_fieldname.
wa_fieldcat-col_pos = p_colpos.
wa_fieldcat-no_out = p_noout.
wa_fieldcat-hotspot = p_hotspot.
wa_fieldcat-checkbox = p_checkbox.
wa_fieldcat-icon = p_showasicon.
wa_fieldcat-do_sum = p_dosum.
Set reference fieldname, tablenam and rollname.
If p_ref_tabname is not given, the ref_fieldname given
is a data element.
If p_ref_tabname is given, the ref_fieldname given is a
field of a table.
In case ref_fieldname is not given,
it is copied from the fieldname.
IF p_ref_tabname IS INITIAL.
wa_fieldcat-rollname = p_ref_fieldname.
ELSE.
wa_fieldcat-ref_tabname = p_ref_tabname.
IF p_ref_fieldname EQ space.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
ELSE.
wa_fieldcat-ref_fieldname = p_ref_fieldname.
ENDIF.
ENDIF.
Set output length.
IF NOT p_outputlen IS INITIAL.
wa_fieldcat-outputlen = p_outputlen.
ENDIF.
Set text headers.
IF NOT p_seltext_m IS INITIAL.
wa_fieldcat-seltext_m = p_seltext_m.
ENDIF.
IF NOT p_seltext_l IS INITIAL.
wa_fieldcat-seltext_l = p_seltext_l.
ENDIF.
IF NOT p_seltext_s IS INITIAL.
wa_fieldcat-seltext_s = p_seltext_s.
ENDIF.
IF NOT p_reptext_ddic IS INITIAL.
wa_fieldcat-reptext_ddic = p_reptext_ddic.
ENDIF.
IF NOT p_ddictxt IS INITIAL.
wa_fieldcat-ddictxt = p_ddictxt.
ENDIF.
Set as editable or not.
IF NOT p_edit IS INITIAL.
wa_fieldcat-input = 'X'.
wa_fieldcat-edit = 'X'.
ENDIF.
APPEND wa_fieldcat TO t_fieldcat.
ENDFORM. "set_fieldcat2
======================== Subroutines called by ALV ================
*& Form top_of_page
Called on top_of_page ALV event.
Prints the heading.
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
i_logo = <<If you want to set a logo, please,
uncomment and edit this line>>
it_list_commentary = t_heading.
endform. " alv_top_of_page
*& Form user_command
Called on user_command ALV event.
Executes custom commands.
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
Example Code
Executes a command considering the sy-ucomm.
CASE r_ucomm.
WHEN '&IC1'.
Set your "double click action" response here.
Example code: Create and display a status message.
DATA: w_msg TYPE string,
w_row(4) TYPE n.
w_row = rs_selfield-tabindex.
CONCATENATE 'You have clicked row' w_row
'field' rs_selfield-fieldname
'with value' rs_selfield-value
INTO w_msg SEPARATED BY space.
MESSAGE w_msg TYPE 'S'.
ENDCASE.
End of example code.
endform. "user_command
Reward Points if useful.
Regards,
Manoj Kumar -
Deleting Zeros at the end of fields in ALV report
I want to make an ALV report that include both integer and decimals in same column.
for example :
1 - 1234.0000
2 - 0.0027
i dont want to see zeros at the end of value.
But the type will be decimal and integer values will be shown with zeros at the end.
For Ex.
I want to take report like this ;
1 - 1234
2 - 0.0027
How can i make this?
Thanks.
Edited by: aydnbk on May 14, 2010 3:22 PMHello aydnbk.
As far as i know, there is no way to do what you want using standard ALV-Functions. There is a field 'DECIMALS' in structure LVC_S_FCAT, but using this field you could only define ONE setting, that would affect ANY value.
Furthermore i am asking myself, if this feature is really sensible - when numbers are right-justified, a global setting for the number of decimals makes it much easier to compare the values - at least this is my personal opinion...
If i had to do this trick, i would simply add some character fields to the output-structure and write the values to the charater-fields to enforce this quite special layout.
Additionally i would set the fields 'NO_OUT' and 'TECH' for the fields of type 'P', that are holding the values - 'NO_OUT' hides the column and 'TECH' ensures, that the field can not be selected in a user-defined layout.
Hope this helps.
Regards, Jörg -
How to make optional fields in alv report
Hello Experts,
Can anyone tell me how to do fields as optional in ALV report Output. My requirement is I want to display only few fields as default in my output and remaining fields will be added if needed by clicking the layout button.For clear example i have totally 10 fields in that fields i want to display only 5 fields and remaining 5 fields will be optional and when i click on layout button then i can add those 5 fields also. Can anyone tell me how to do this.
Thanks,
Vinod.Hi Vinod,
As suggested by Eitan, kindly use the attribute NO_OUT = 'X' in field catalog for the appropriate column. Based on that we can hide the fields.
L_FIELDCAT-NO_OUT = 'X'.
Also we can group the hidden fields in layout using SP_GROUP attribute in Field catalog as shown below. Based on that, we can separate the fields based on category/group.
L_FIELDCAT-SP_GROUP = 'A'.
Regards
Rajkumar Narasimman -
Hiding some fields from ALV report
Hi All,
I want to know if there is way to hide certain fields in ALV for some users only and not for others?
If I use the option NO_OUT = 'X' it will not be displayed in the list but the user can see the in the Layout option fields but if use NO_OUT = 'X' and TECH = 'X' the field will not be in the list and in the layout also but other users will miss that field.
If I create user specific variant, but once the user is in the report he can change the layout so certain fields cannot be hidden.
So, is there any way to hide some fields for certain users and not for others without hard coding user ids in program and restricting the fields from display??
Thanks in Advance.
Sonali.Thank You Vijay for the reply.
I knew that Authorization object was the final solution but before using it I wanted to find out if there was a way in the ALV report to restrict certain fields.
Sonali. -
Add $ and % to fields in ALV report
Hi,
How to add $ and % sybmbols to field values in ALV report. I cannot use a Char as I need to do totals and subtotals for those fields.
Best Regards
SureshHi,
You cannot use % or $ or any special characters if you want to use the standard SAP totaling ans subtotaling.. you need to create another field adjacent to that field and show the currency or %.
Otherwise you need to do the totaling logic yourself and then you can use $ or %
Cheers:)
Kothand
Maybe you are looking for
-
Problem with Photoshop CS6 Extended upgrade
I have been using CS6 on both my desktop MacPro and my laptop Macbbok Pro. In the last few days, whenever I open photoshop on my desktop, it is the EXTENDED version and indicates that I am in a trial period for the next 30 days. I never purchased or
-
ITunes launching error?! xO
Whenever i double click my itunes, it shows the loading sign then a few seconds later nothing happens. I would really appreciate it if someone could tell me what's going on and how I could fix this problem!! xd Dell dimension 2400 Windows XP
-
How to use US date format on schedule?
When schedule a recurring instance and I'm prompted for the Start and End dates, they are formatted in the European date format. How can I have it default to and always use the US date format?
-
Linear trend line in ssrs 2008
Hello, I am looking to add a linear trend line in my report. I am trying to replicate the linear trend line from excel. The calculated field option like running total, etc isnt getting what we need. Any thoughts?
-
Ar_transaction_pub
Hi all, Please tell me documentation for this procedure, AR_TRANSACTION_PUB.CREATE_TRANSACTION , I think if I want to create credit memo or debit memo then I put entry in this procedure to create automatic credit memo. However need verification and d