ALV Grid Totals Issue
Hi,
We are using REUSE_ALV_GRID_DISPLAY for diaplying grid . we want the totals to be displayed for some fields.
but for percentage fields we want to calculate the values. How do we do this?
Hi Asharaghu,
FOR TOTAL:
there is a property of fieldcatalog, that is do_sum.
USE COED LIKE:
PERFORM fieldcat USING:
'1' 'KUNNR' 'I_MARD' 'CUSTOMER NO' ,
'2' 'DMBTR' 'I_MARD' 'CURRENCY' ,
FORM fieldcat USING value(p_0029)
value(p_0030)
value(p_0031)
value(p_0032)
wa_fieldcat-col_pos = p_0029.
wa_fieldcat-fieldname = p_0030.
wa_fieldcat-tabname = p_0031.
wa_fieldcat-reptext = p_0032.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO i_fieldcat.
ENDFORM. " FIELDCAT
Then pass i_fieldcat through REUSE_ALV_GRID_DISPLAY.
in final output you will get the total of currency field.
Hope this can solve your problems.
Regards,
Tutun
Similar Messages
-
ALV grid total or based on two key fields
Hello experts,
I have ALV grid with vendor, g/l account and amount field.
I want to have sum or total of each vendor, and if vendor having mutliple g/l accounts i want to have sum for each g/l account.
ex: vendor g/l account amount.
10 aa 100
10 bb 200
11 cc 300
olp : 10 aa 100
10 bb 200
11 cc 300
ex2 : vendor g/ account amount
10 aa 100
10 aa 200
11 cc 300
o/p 10 aa 300.
11 cc 300.
Could you please help me and any suggestions
<<Text removed>>
Thanks
reddy.
Edited by: Matt on Jul 27, 2011 9:21 AMHello Reddy,
Try using the sort functionality of ALV grid
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_save = 'A'
is_layout = lwa_layout
it_toolbar_excluding = i_excl_func
i_default = c_x
CHANGING
it_outtab = i_outtab[]
it_fieldcatalog = i_fieldcat[]
it_sort = li_sort[] "use this functionality as per your requirement
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
Hope this may be helpful.
Sharin -
ALV grid total line customizing
Dear Masters,
I need a solution for my problem. I need to modify sorting of subtotal and grand total based on currency which criteria i create myself. The standard alv output sort total by currency based on alpahabetical order, e.g: AUD, EUR, IDR, USD. I need to change the sorting into IDR, USD, AUD, EUR. How can i do it in alv grid?
I also like to add new line after grand total line, which is grand total in Local Currency, in this case, in IDR, which rate given. I can get the figure of subtotal, but i don't know how to append new line after grand total line output in alv standard.
Need your suggestion.
Many thanks,
TiaraHi,
I have used object oriented ALV. You can remove final total line and have sub total lines. Code below can help you.
1) Fieldcatalog you can do sum for currency values
2) Sort Build you can have sub totals.
3) layout_init you can remove final total line.
4) CALL METHOD grid->set_table_for_first_display you can pass above structure for excepted Result.
fieldcatalog_init
FORM fieldcatalog_init USING lt_fieldcatalog TYPE lvc_t_fcat
value(field_name) value(field_type) value(field_text) value(field_key).
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
CLEAR ls_fieldcatalog.
ls_fieldcatalog-fieldname = field_name.
ls_fieldcatalog-datatype = field_type.
ls_fieldcatalog-reptext = field_text.
ls_fieldcatalog-coltext = field_text.
ls_fieldcatalog-seltext = field_text.
ls_fieldcatalog-tooltip = field_text.
ls_fieldcatalog-key = field_key.
IF field_type = 'CURR'.
ls_fieldcatalog-do_sum = 'X'.
ENDIF.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ENDFORM. "fieldcatalog_init
sort_build
FORM sort_build USING lt_sort TYPE lvc_t_sort.
DATA: ls_sort TYPE lvc_s_sort.
ls_sort-fieldname = 'BUKRS'. "Fieldname on which to sort
ls_sort-subtot = 'X'.
ls_sort-up = 'X'. "Sort Ascending
APPEND ls_sort TO lt_sort.
IF p_comp <> 'X'.
ls_sort-fieldname = 'LIFNR'. "Fieldname on which to sort
ls_sort-subtot = 'X'.
ls_sort-up = 'X'. "Sort Ascending
APPEND ls_sort TO lt_sort.
ENDIF.
ls_sort-fieldname = 'WAERS'. "Fieldname on which to sort
ls_sort-subtot = 'X'.
ls_sort-up = 'X'. "Sort Ascending
APPEND ls_sort TO lt_sort.
ENDFORM. "sort_build
layout_init
FORM layout_init USING ls_layout TYPE lvc_s_layo.
DATA lv_date(10) TYPE c.
WRITE sy-datum TO lv_date.
IF p_line = 'X'.
CONCATENATE 'Line Item wise Report as on' lv_date INTO w_string2 SEPARATED BY space.
ELSEIF p_vend = 'X'.
CONCATENATE 'Vendor Summary Report as on' lv_date INTO w_string2 SEPARATED BY space.
ELSEIF p_comp = 'X'.
CONCATENATE 'Company Summary Report as on' lv_date INTO w_string2 SEPARATED BY space.
ENDIF.
ls_layout-zebra = 'X'.
ls_layout-grid_title = w_string2.
ls_layout-sel_mode = 'A'.
ls_layout-no_merging = 'X'.
ls_layout-cwidth_opt = 'X'.
ls_layout-no_totline = 'X'.
IF p_line = 'X'.
ls_layout-ctab_fname = 'COLINFO'.
ENDIF.
ENDFORM. "layout_init
CALL METHOD grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
is_variant = va_layout "&see below
i_save = 'A' "&see below
i_default = ''
CHANGING
it_outtab = it_apout[]
it_fieldcatalog = gt_fieldcatalog
it_sort = gt_sort.
Edited by: Himanshu Dave on May 11, 2009 2:33 PM -
hi all,
I have an overflow error in alv total field.
first i filled alv grid using et_table_for_first_display, again i changed itab data
and use refresh_table_display to refresh data.
the alv contains total fields in field catalog.... when i try to 'refresh_table_display '
it comes an over flow error is coming and it comes every sort of records.. how can i trap this error ..??
thanks and regards
JoseHi Anup,
While using ALV with OOP methodology, you can create an extra row for giving the sum of any field.
In the field catalog, there is a component named 'DO_SUM', if set, will give the total value for the field.
In the method where you fill the field catalog , just add this component.
eg:
form catalog_fill changing p_field_catalog.
data ls_fcat type lvc_s_fcat .
ls_fcat-fieldname = 'CARRID' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '20' .
ls_fcat-coltext = 'Carrier ID' .
ls_fcat-web_field = 'carrid_handle'.
ls_fcat-edit = 'X'.
*ls_fcat-emphasize = 'C310'. "needed for column coloring
append ls_fcat to field_catalog .
clear ls_fcat .
ls_fcat-fieldname = 'FLDATE' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_table = 'FLDATE' .
ls_fcat-outputlen = '20' .
<b>ls_fcat-do_sum = 'X'.</b>
ls_fcat-coltext = 'Flight Date' .
ls_fcat-web_field = 'fldate_handle'.
append ls_fcat to field_catalog .
clear ls_fcat .
ls_fcat-fieldname = 'PRICE' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_table = 'PRICE' .
ls_fcat-outputlen = '20' .
ls_fcat-coltext = 'Airfare' .
append ls_fcat to field_catalog .
endform.
In this way, you can get the total of any field in ALV.
Regards,
SP. -
ALV Grid Total Text (OOPS)
Hi All,
I have a simple ALV Grid Report(OOPS), I would like to give a Text for Total Row. In REUSE_ALV_GRID we have the option of giving this text, but i am not able to figure it out how to get the same in OOPS.
Regards
AnupHi Anup,
While using ALV with OOP methodology, you can create an extra row for giving the sum of any field.
In the field catalog, there is a component named 'DO_SUM', if set, will give the total value for the field.
In the method where you fill the field catalog , just add this component.
eg:
form catalog_fill changing p_field_catalog.
data ls_fcat type lvc_s_fcat .
ls_fcat-fieldname = 'CARRID' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '20' .
ls_fcat-coltext = 'Carrier ID' .
ls_fcat-web_field = 'carrid_handle'.
ls_fcat-edit = 'X'.
*ls_fcat-emphasize = 'C310'. "needed for column coloring
append ls_fcat to field_catalog .
clear ls_fcat .
ls_fcat-fieldname = 'FLDATE' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_table = 'FLDATE' .
ls_fcat-outputlen = '20' .
<b>ls_fcat-do_sum = 'X'.</b>
ls_fcat-coltext = 'Flight Date' .
ls_fcat-web_field = 'fldate_handle'.
append ls_fcat to field_catalog .
clear ls_fcat .
ls_fcat-fieldname = 'PRICE' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_table = 'PRICE' .
ls_fcat-outputlen = '20' .
ls_fcat-coltext = 'Airfare' .
append ls_fcat to field_catalog .
endform.
In this way, you can get the total of any field in ALV.
Regards,
SP. -
Hi,
I have created an application that uses a web dynpro alv grid. I want to display totals - is there a setting that can do this automatically - if so, can you please tell me how to do this? Thanks,Hi
You can take help of following code snippet to create totals for a particular column
Data: lr_function_settings TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_column TYPE REF TO cl_salv_wd_column,
lt_column type salv_wd_t_column_ref,
ls_column type salv_wd_s_column_ref.
Data: lr_field_amnt type REF TO CL_SALV_WD_FIELD.
* get reference of ALV component
lr_salv_wd_table = wd_this->wd_cpifc_OVERVIEW_EARNED_ALV( ).
wd_this->alv_config_table = lr_salv_wd_table->get_model( ).
* get function settings
lr_function_settings ?= wd_this->alv_config_table.
* display columns in correct order
lr_column_settings ?= wd_this->alv_config_table.
lt_column = lr_column_settings->get_columns( ).
loop at lt_column into ls_column.
CASE ls_column-id.
when 'AMOUNT'
* aggregate field
CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
EXPORTING
FIELDNAME = 'AMOUNT'
RECEIVING
VALUE = lr_field_amnt.
* create aggregate rule as total
CALL METHOD LR_FIELD_AMNT->IF_SALV_WD_AGGR~CREATE_AGGR_RULE
EXPORTING
AGGREGATION_TYPE = IF_SALV_WD_C_AGGREGATION=>AGGRTYPE_TOTAL
RECEIVING
VALUE = lv_aggr_rule.
endcase.
Regards
Manas DUa -
ALV Grid - Alignment Issues in TOP OF PAGE.
Hi,
We have a requirement to right align text in the report header.
We are using REUSE ALV GRID DISPLAY, but using TOP-OF-PAGE event - the whole text is left aligned.
I tried using Class CL_DD_DOCUMENT which solved the alignment issue, but I am not able to see the header while printing/downloading to excel.
I want the header to be available while downloading/printing the list. Any suggestions?
Thanks in advance,
Harveen.Hi
The ALV download only the grid into the file, so not the data you're writing in TOP_OF_PAGE event.
If you need to do that, you should create an your own buttom to download the file.
Max -
How to Expand ALV Grid Total Width
I have to display 1476 characters in an ALV grid and then the users will use what they need when creating a layout.
Problem is ALV stops after displaying 1375 (or so) characters) - any parm or action to do this (maybe in the catalog setup sent to the program? Thanks!Hi Scott
This may be a restriction ALV Grid puts. My recommendation will be that, split some fields and generate more than one rows with the same key (you should then add a new key field which will hold line numbers specific to one definite key). When you sort with ALV Grid's sort option the keys will vertically merged (if you do not turn off this feature via layout or field catalog settings). I know this is not so pretty but ALV is not intended to show that kind of stuff.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a> -
ALV grid display issue from radio buttons
Hello,
I have a radio button group in a selection screen. On select of the first radio button, I display an ALV grid below the radio button group.
On selecting the next one, I want the grid to disappear which isn't happening currently.
Please help.
Thanks and Regards,
AbhijnanPlease check if this is what you needed or something else
DATA: obj TYPE REF TO cl_gui_alv_grid,
repid TYPE sy-repid,
entered TYPE c,
lv_structure TYPE tabname,
dock TYPE REF TO cl_gui_docking_container,
i_mara TYPE TABLE OF mara,
i_marc TYPE TABLE OF marc.
FIELD-SYMBOLS:<fs_tab> TYPE table.
PARAMETERS: p_matnr TYPE matnr.
PARAMETERS: p_mara RADIOBUTTON GROUP a USER-COMMAND abc.
PARAMETERS: p_marc RADIOBUTTON GROUP a.
AT SELECTION-SCREEN OUTPUT.
CHECK NOT p_matnr IS INITIAL.
IMPORT entered from memory id 'E'.
CHECK NOT entered IS INITIAL.
CHECK dock IS INITIAL.
repid = sy-repid.
CREATE OBJECT dock
EXPORTING
repid = repid
dynnr = sy-dynnr
ratio = 80
side = cl_gui_docking_container=>dock_at_bottom
name = 'DOCK_CONT'.
CHECK obj IS INITIAL.
CREATE OBJECT obj
EXPORTING
i_parent = dock.
IF p_mara = 'X'.
IMPORT i_mara FROM MEMORY ID 'IMARA'.
FREE MEMORY ID 'IMARA'.
lv_structure = 'MARA'.
ASSIGN i_mara TO <fs_tab>.
ELSE.
IMPORT i_marc FROM MEMORY ID 'IMARC'.
FREE MEMORY ID 'IMARC'.
lv_structure = 'MARC'.
ASSIGN i_marc TO <fs_tab>.
ENDIF.
CALL METHOD obj->set_table_for_first_display
EXPORTING
i_structure_name = lv_structure
CHANGING
it_outtab = <fs_tab>.
START-OF-SELECTION.
entered = 'X'.
EXPORT entered TO memory ID 'E'.
IF p_mara = 'X'.
SELECT * FROM mara UP TO 100 ROWS INTO TABLE i_mara
WHERE matnr = p_matnr.
EXPORT i_mara TO MEMORY ID 'IMARA'.
ELSE.
SELECT * FROM marc UP TO 100 ROWS INTO TABLE i_marc
WHERE matnr = p_matnr.
EXPORT i_marc TO MEMORY ID 'IMARC'.
ENDIF. -
ALV Grid - Resource Issue?
Morning All
I have a situation where I have a standard selection screen displaying an ALV grid. The user can then double click a line to see a drill down ALV. My error occurs if the user executes the program multiple times i.e. displaying the grid time and time again. Eventually the session does not display the grid and on a subsequent attempt the session either crashes or locks.
I am currently destroying the 2 containers used every time the user exits the relevant screens using call method gr_alvgrid-> free but to no avail.
Has anyone else had similar problems? I am on a 46B machine running on NT4 (yes I know I'm in the dark ages!)
Cheers
IanHi,
Have you did something like that before creating event receiver?
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
* Create the event reciever
IF o_eventreceiver IS INITIAL.
CREATE OBJECT o_eventreceiver.
ENDIF.
ENDIF.
In PAI of the screen,just try this.
module USER_COMMAND_9001 input.
CASE sy-ucomm.
WHEN 'EXIT' or 'CANC'.
perform f9600_free_objects:
using o_Alvgrid 'ALV' text-E02,
using o_Dockingcontainer 'DOCKING'
TEXT-E01.
* leave program.
LEAVE PROGRAM.
when 'BACK'.
perform f9600_free_objects:
using o_Alvgrid 'ALV' text-E02,
using o_Dockingcontainer 'DOCKING'
TEXT-E01.
set screen '0'.
leave screen.
* This leaves the program but you may need to re-call the
* transaction to go back to the original screen
when others.
ENDCASE.
endmodule. " USER_COMMAND_9001 INPUT
FORM f9600_free_objects USING pobject
value(ptype)
value(ptext).
DATA: l_objectalv TYPE REF TO cl_gui_alv_grid.
* Need to type the field symbol or it does not work
CASE ptype.
WHEN 'ALV'.
l_objectalv = pobject.
IF NOT ( l_objectalv IS INITIAL ).
CALL METHOD l_objectalv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, l_objectalv.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'DOCKING'.
DATA: lobjectdock TYPE REF TO cl_gui_docking_container.
lobjectdock = pobject.
IF NOT ( lobjectdock IS INITIAL ).
CALL METHOD lobjectdock->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectdock.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'CONTAINER'.
DATA: lobjectcontainer TYPE REF TO cl_gui_container.
lobjectcontainer = pobject.
IF NOT ( lobjectcontainer IS INITIAL ).
CALL METHOD lobjectcontainer->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectcontainer.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN OTHERS.
sy-subrc = 1.
PERFORM f9700_error_handle USING
text-e04.
ENDCASE.
ENDFORM. " f9600_free_objects
FORM f9700_error_handle USING value(ptext).
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-e03
txt2 = sy-subrc
txt1 = ptext.
ENDIF.
ENDFORM. " f9700_error_handle
Message was edited by: Jayanthi Jayaraman -
Hi Experts,
i have issue were in i need to show sum of the amount. like example...
for Custmer 100 there are vendor number 10,20,30,40,50. so for all this vendor numbers..
vendor----- amount
10 -
100
20----
200
30----
300
40----
400
50-------500
so in the output i want it to be..
customer--vendornumber--
amount
1000--10--
1500
20---
30---
40---
50---
.hope u experts have undestood. so how can i add the it and show it in the output....
am forwarding my code also..
Corrects answers will be fully rewarded..
REPORT zrfi007 NO STANDARD PAGE HEADING LINE-SIZE 255 MESSAGE-ID z01.
TYPE-POOLS: slis, abap.
* TYPES Declaration
TYPES: BEGIN OF ty_lfa1,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF ty_lfa1.
TYPES: BEGIN OF ty_bsik,
bukrs TYPE bsik-bukrs,
lifnr TYPE bsik-lifnr,
belnr TYPE bsik-belnr,
bldat TYPE bsik-bldat,
waers TYPE bsik-waers,
dmbtr TYPE bsik-dmbtr,
wrbtr TYPE bsik-wrbtr,
zfbdt TYPE bsik-zfbdt,
zbd1t TYPE bsik-zbd1t,
zbd2t TYPE bsik-zbd2t,
zbd3t TYPE bsik-zbd3t,
END OF ty_bsik.
TYPES: BEGIN OF ty_lfb1,
lifnr TYPE lfb1-lifnr,
bukrs TYPE lfb1-bukrs,
END OF ty_lfb1.
TYPES: BEGIN OF ty_final,
bukrs TYPE bsik-bukrs,
lifnr TYPE bsik-lifnr,
belnr TYPE bsik-belnr,
bldat TYPE bsik-bldat,
days TYPE sy-datum,
waers TYPE bsik-waers,
dmbtr TYPE bsik-dmbtr,
* waers type bsik-waers,
wrbtr TYPE bsik-wrbtr,
zfbdt TYPE bsik-zfbdt,
zbd1t TYPE bsik-zbd1t,
zbd2t TYPE bsik-zbd2t,
zbd3t TYPE bsik-zbd3t,
name1 TYPE lfa1-name1,
current TYPE bsik-dmbtr,
d30 TYPE bsik-dmbtr,
d60 TYPE bsik-dmbtr,
d90 TYPE bsik-dmbtr,
d120 TYPE bsik-dmbtr,
d180 TYPE bsik-dmbtr,
d240 TYPE bsik-dmbtr,
d360 TYPE bsik-dmbtr,
da365 TYPE bsik-dmbtr,
* ct_date TYPE sy-datum,
* date TYPE datum,
* days TYPE char8,
END OF ty_final.
* Data Declaration.
DATA: gt_lfa1 TYPE STANDARD TABLE OF ty_lfa1,
wa_lfa1 TYPE ty_lfa1.
DATA: gt_final TYPE STANDARD TABLE OF ty_final,
wa_final TYPE ty_final.
DATA: gt_bsik TYPE STANDARD TABLE OF ty_bsik,
wa_bsik TYPE ty_bsik.
DATA: gt_lfb1 TYPE STANDARD TABLE OF ty_lfb1,
wa_lfb1 TYPE ty_lfb1.
DATA: days TYPE sy-datum.
* ALV Components
**** ALV Internal Table
DATA : i_layout TYPE slis_layout_alv OCCURS 0 WITH HEADER LINE,
i_events TYPE slis_t_event,
i_fieldcat TYPE slis_t_fieldcat_alv,
i_print TYPE slis_print_alv,
i_list_top TYPE slis_t_listheader,
i_list_end TYPE slis_t_listheader,
i_sort TYPE slis_t_sortinfo_alv.
DATA: wa_fieldcat LIKE LINE OF i_fieldcat.
* ALV Variable.
DATA: v_top TYPE slis_formname VALUE 'TOP_OF_PAGE',
v_eop TYPE slis_formname VALUE 'END_OF_PAGE',
v_eol TYPE slis_formname VALUE 'END_OF_LIST',
v_tol TYPE slis_formname VALUE 'TOP_OF_LIST'.
**** ALV Variants
DATA: i_variant LIKE disvariant.
* Selection screen
DATA: v_bukrs TYPE bukrs,
v_lifnr TYPE kunnr,
pa_bldat TYPE bldat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bukrs FOR v_bukrs NO INTERVALS NO-EXTENSION OBLIGATORY,
s_lifnr FOR v_lifnr.
* bldat FOR v_bldat no-extension.
PARAMETERS: p_bldat TYPE bsik-bldat.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_detail RADIOBUTTON GROUP r1 DEFAULT 'X',
p_sumry RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK b2.
* Top-Of-Page Declaration Header
DATA: lwa_list_top LIKE LINE OF i_list_top.
DATA: lv_header(70),
lv_text(50),
lv_text1(60),
lv_text2(50),
lv_text3(50) ,
lv_text4(50),
lv_date TYPE char10,
lv_time TYPE char10.
DATA: lv_butxt LIKE t001-butxt,
lv_butxt1 LIKE lfa1-name1,
lv_butxt2 LIKE lfb1-lifnr.
INITIALIZATION.
*TOP-OF-PAGE.
* Validations for Selection screen
AT SELECTION-SCREEN ON s_bukrs.
IF NOT s_bukrs[] IS INITIAL.
SELECT SINGLE bukrs FROM lfb1
INTO s_bukrs
WHERE bukrs IN s_bukrs.
ENDIF.
IF sy-subrc NE 0.
MESSAGE e003.
ENDIF.
AT SELECTION-SCREEN ON s_lifnr.
IF NOT s_lifnr[] IS INITIAL.
SELECT SINGLE lifnr FROM lfa1
INTO s_lifnr
WHERE lifnr IN s_lifnr.
IF sy-subrc NE 0.
MESSAGE e005.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON p_bldat.
IF NOT p_bldat IS INITIAL.
SELECT SINGLE bldat FROM bsid
INTO p_bldat
WHERE bldat = p_bldat.
IF sy-subrc NE 0 .
MESSAGE e004.
ENDIF.
ENDIF.
* Selection For Top-of-page.
** Get company code description
SELECT SINGLE butxt
FROM t001 INTO lv_butxt
WHERE bukrs IN s_bukrs.
* SELECT SINGLE lifnr FROM lfb1
* INTO lv_butxt2 WHERE bukrs IN s_bukrs.
* SELECT SINGLE name1 FROM lfa1
* INTO lv_butxt1 WHERE lifnr = lv_butxt2.
START-OF-SELECTION.
PERFORM data_retrival.
PERFORM f_layout_init.
PERFORM f_eventtab_build.
i_variant-report = sy-repid.
PERFORM f_print_control.
* PERFORM f_build_header_list.
* perform f_build_header_list1.
* PERFORM f_build_fieldcat.
IF p_detail = 'X'.
PERFORM f_build_sort.
PERFORM fill_fieldcat.
PERFORM f_build_header_list.
ELSE.
PERFORM f_build_sort1.
PERFORM fill_fieldcat_sum.
PERFORM f_build_header_list1.
ENDIF.
PERFORM f_list_display TABLES gt_final[].
END-OF-SELECTION.
*& Form data_retrival
* text
* --> p1 text
* <-- p2 text
FORM data_retrival .
SELECT bukrs
lifnr
belnr
bldat
waers
dmbtr
wrbtr
zfbdt
zbd1t
zbd2t
zbd3t
FROM bsik INTO TABLE gt_bsik
WHERE bukrs IN s_bukrs
AND lifnr IN s_lifnr.
SELECT lifnr
name1
FROM lfa1 INTO TABLE gt_lfa1
FOR ALL ENTRIES IN gt_bsik
WHERE lifnr = gt_bsik-lifnr.
LOOP AT gt_bsik INTO wa_bsik.
READ TABLE gt_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_bsik-lifnr.
MOVE-CORRESPONDING wa_bsik TO wa_final.
MOVE-CORRESPONDING wa_lfa1 TO wa_final.
DATA: days TYPE char2,
c4 TYPE char2.
DATA: days1 TYPE sy-datum.
DATA:duedate TYPE rfpos-faedt.
CALL FUNCTION 'NET_DUE_DATE_GET'
EXPORTING
i_zfbdt = wa_final-zfbdt
i_zbd1t = wa_final-zbd1t
i_zbd2t = wa_final-zbd2t
i_zbd3t = wa_final-zbd3t
i_shkzg = ' '
i_rebzg = ' '
* I_KOART = 'D'
IMPORTING
e_faedt = duedate.
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = duedate
i_datum_von = wa_final-bldat
* I_KZ_EXCL_VON = '0'
* I_KZ_INCL_BIS = '0'
* I_KZ_ULT_BIS = ' '
* I_KZ_ULT_VON = ' '
* I_STGMETH = '0'
* I_SZBMETH = '1'
IMPORTING
e_tage = days
EXCEPTIONS
days_method_not_defined = 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.
wa_final-days = duedate.
DATA : wf_char TYPE char10.
wf_char = days.
IF wf_char+0(1) EQ '*' .
SKIP.
ELSE.
IF days EQ 0.
wa_final-current = wa_bsik-wrbtr.
ELSEIF days LE 30 AND days GT 0.
wa_final-d30 = wa_bsik-wrbtr.
ELSEIF days LE 60 AND days GT 30 .
wa_final-d60 = wa_bsik-wrbtr.
ELSEIF days LE 90 AND days GT 60.
wa_final-d90 = wa_bsik-wrbtr.
ELSEIF days LE 120 AND days GT 90.
wa_final-d120 = wa_bsik-wrbtr.
ELSEIF days LE 180 AND days GT 120.
wa_final-d180 = wa_bsik-wrbtr.
ELSEIF days LE 240 AND days GT 180.
wa_final-d240 = wa_bsik-wrbtr.
ELSEIF days LE 360 AND days GT 240.
wa_final-d360 = wa_bsik-wrbtr.
ELSEIF days GT 365 .
wa_final-da365 = wa_bsik-wrbtr.
ENDIF.
ENDIF.
APPEND wa_final TO gt_final.
CLEAR: wa_final,
days,
duedate,days1.
ENDLOOP.
ENDFORM. " data_retrival
*& Form fill_fieldcat
* text
FORM fill_fieldcat.
PERFORM fill_fields USING: 'Vendor Number' 'LIFNR',
'Vendor Name' 'NAME1',
'Document Number' 'BELNR',
'Document Date' 'BLDAT',
'Due Date' 'DAYS',
'Total In Document Currency' 'WRBTR',
'Currency' 'WAERS',
'Total In Reporting Currency' 'DMBTR',
'Current' 'CURRENT',
'1-30 days' 'D30',
'31-60 days' 'D60',
'61-90 days' 'D90',
'91-120 days' 'D120',
'121-180 days' 'D180',
'181-240 days' 'D240',
'241-360 days' 'D360',
* '181-365 days' 'D365',
'Above 365 days' 'DA365'.
ENDFORM. "fill_fieldcat
*& Form fill_fieldcat_sum
* text
FORM fill_fieldcat_sum.
PERFORM fill_fields USING: 'Vendor Number' 'LIFNR',
'Vendor Name' 'NAME1',
'Total In Reporting Currency' 'DMBTR',
'Current' 'CURRENT',
'1-30 days' 'D30',
'31-60 days' 'D60',
'61-90 days' 'D90',
'91-120 days' 'D120',
'121-180 days' 'D180',
'181-240 days' 'D240',
'241-360 days' 'D360',
'Above 365 days' 'DA365'.
ENDFORM. "fill_fieldcat_sum
*& Form fill_fields
* text
* -->&01 text
* -->&02 text
FORM fill_fields USING &01 &02 .
wa_fieldcat-tabname = 'T_OUTPUT'. "t_output_provgr
wa_fieldcat-fieldname = &02.
wa_fieldcat-seltext_m = &01.
* wa_fieldcat-ref_fieldname = fieldname.
* wa_fieldcat-ref_tabname = 'SFLIGHT'.
* w_fieldcat-do_sum = &03.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. "fill_fields
*& Form f_layout_init
* Set the layout
FORM f_layout_init.
* P_layout-min_linesize = 170.
* p_layout-max_linesize = 170.
* P_layout-no_colhead = abap_true.
* p_layout-detail_popup = abap_true.
i_layout-colwidth_optimize = abap_true.
i_layout-zebra = abap_true.
* i_layout-subtotals_text = 'SubTotal'.
* i_layout-totals_text = 'Total'.
ENDFORM. " f_layout_init
*& Form f_eventtab_build
* Set the events
FORM f_eventtab_build.
DATA: ls_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_events.
READ TABLE i_events WITH KEY name = slis_ev_top_of_page
INTO ls_event.
IF sy-subrc = 0.
MOVE v_top TO: ls_event-form,
ls_event-name.
APPEND ls_event TO i_events.
ENDIF.
READ TABLE i_events WITH KEY name = slis_ev_end_of_page
INTO ls_event.
IF sy-subrc = 0.
MOVE v_eop TO: ls_event-form,
ls_event-name.
APPEND ls_event TO i_events.
ENDIF.
READ TABLE i_events WITH KEY name = slis_ev_end_of_list
INTO ls_event.
IF sy-subrc = 0.
MOVE v_eol TO: ls_event-form,
ls_event-name.
APPEND ls_event TO i_events.
ENDIF.
READ TABLE i_events WITH KEY name = slis_ev_top_of_list
INTO ls_event.
IF sy-subrc = 0.
MOVE v_tol TO: ls_event-form,
ls_event-name.
APPEND ls_event TO i_events.
ENDIF.
ENDFORM. " f_eventtab_build
*& Form f_print_control
* Set the print control
FORM f_print_control .
* i_print-no_print_listinfos = abap_true.
* i_print-no_print_selinfos = abap_true.
* i_print-reserve_lines = 2.
* i_print-no_change_print_params = abap_true.
ENDFORM. " f_print_control
*& Form f_build_header_list
* Build the header list (top of page)
FORM f_build_header_list .
lv_header = 'Vendor Open Item Analysis By Balance Of Overdue Items'(h01).
lv_text = 'Company Name:'(s01).
lv_text1 = 'Open Item As Key Date:'(s02).
lv_text2 = 'Company Code:'(s03).
lv_text3 = 'Vendor Number:'(s04).
lv_text4 = 'Vendor Name:'(s05).
* Header
CLEAR lwa_list_top.
lwa_list_top-typ = 'H'.
lwa_list_top-info = lv_header.
APPEND lwa_list_top TO i_list_top.
* Run date Display
lwa_list_top-typ = 'S'. " Item
WRITE: sy-datum TO lv_date MM/DD/YYYY.
lwa_list_top-key = 'Date :'(025).
lwa_list_top-info = lv_date.
APPEND lwa_list_top TO i_list_top.
CLEAR: lwa_list_top,
lv_date.
* Run time Display
lwa_list_top-typ = 'S'. " Item
WRITE: sy-uzeit TO lv_time USING EDIT MASK '__:__:__'.
lwa_list_top-key = 'Time :'(026).
lwa_list_top-info = lv_time.
APPEND lwa_list_top TO i_list_top.
CLEAR: lwa_list_top,
lv_time.
CLEAR lwa_list_top.
* Company Name
lwa_list_top-typ = 'S'.
lwa_list_top-key = lv_text.
lwa_list_top-info = lv_butxt.
APPEND lwa_list_top TO i_list_top.
CLEAR lwa_list_top.
*Open Item As Key Date
lwa_list_top-typ = 'S'.
lwa_list_top-key = lv_text1.
lwa_list_top-info = p_bldat.
APPEND lwa_list_top TO i_list_top.
CLEAR lwa_list_top.
* Company Code
lwa_list_top-typ = 'S'.
lwa_list_top-key = lv_text2.
lwa_list_top-info = s_bukrs-low.
APPEND lwa_list_top TO i_list_top.
CLEAR lwa_list_top.
** Vendor Number
* lwa_list_top-typ = 'S'.
* lwa_list_top-key = lv_text3.
* lwa_list_top-info = lv_butxt2.
* APPEND lwa_list_top TO i_list_top.
* CLEAR lwa_list_top.
**Vendor Name
* lwa_list_top-typ = 'S'.
* lwa_list_top-key = lv_text4.
* lwa_list_top-info = lv_butxt1.
* APPEND lwa_list_top TO i_list_top.
ENDFORM. " f_build_header_list
*& Form f_build_header_list1
* text
* --> p1 text
* <-- p2 text
FORM f_build_header_list1 .
lv_header = 'Vendor Open Item Analysis By Balance Of Overdue Items'(h01).
lv_text = 'Company Name:'(s01).
lv_text1 = 'Open Item As Key Date:'(s02).
lv_text2 = 'Company Code:'(s03).
lv_text3 = 'Vendor Number:'(s04).
lv_text4 = 'Vendor Name:'(s05).
lwa_list_top-typ = 'H'.
lwa_list_top-info = lv_header.
APPEND lwa_list_top TO i_list_top.
* Run date Display
lwa_list_top-typ = 'S'. " Item
WRITE: sy-datum TO lv_date MM/DD/YYYY.
lwa_list_top-key = 'Date :'(025).
lwa_list_top-info = lv_date.
APPEND lwa_list_top TO i_list_top.
CLEAR: lwa_list_top,
lv_date.
* Run time Display
lwa_list_top-typ = 'S'. " Item
WRITE: sy-uzeit TO lv_time USING EDIT MASK '__:__:__'.
lwa_list_top-key = 'Time :'(026).
lwa_list_top-info = lv_time.
APPEND lwa_list_top TO i_list_top.
CLEAR: lwa_list_top,
lv_time.
CLEAR lwa_list_top.
* Company Name
lwa_list_top-typ = 'S'.
lwa_list_top-key = lv_text.
lwa_list_top-info = lv_butxt.
APPEND lwa_list_top TO i_list_top.
CLEAR lwa_list_top.
*Open Item As Key Date
lwa_list_top-typ = 'S'.
lwa_list_top-key = lv_text1.
lwa_list_top-info = p_bldat.
APPEND lwa_list_top TO i_list_top.
CLEAR lwa_list_top.
ENDFORM. " f_build_header_list1
*& Form f_build_sort
* Set the sorting sequence
FORM f_build_sort .
DATA: l_sort TYPE slis_sortinfo_alv.
l_sort-spos = '1'.
l_sort-fieldname = 'LIFNR'.
l_sort-up = abap_true.
l_sort-group = '*'.
* l_sort-subtot = 'X'.
APPEND l_sort TO i_sort.
* l_sort-spos = '2'.
* l_sort-fieldname = 'NAME1'.
* l_sort-up = abap_true.
* l_sort-group = '*'.
** l_sort-subtot = 'X'.
* APPEND l_sort TO i_sort.
* l_sort-spos = '2'.
* l_sort-fieldname = 'LIFNR'.
* l_sort-up = abap_true.
* l_sort-subtot = abap_true.
* APPEND l_sort TO i_sort.
* l_sort-spos = '1'.
* l_sort-fieldname = 'VBELN'.
* l_sort-up = abap_true.
* l_sort-subtot = abap_true.
* APPEND l_sort TO i_sort.
* l_sort-spos = '2'.
* l_sort-fieldname = 'POSNR'.
* l_sort-up = abap_true.
* l_sort-subtot = abap_true.
* APPEND l_sort TO i_sort.
ENDFORM. " f_build_sort
*& Form f_list_display
* Display the ALV list report
* -->PT_DATA Internal table containing the data
FORM f_list_display TABLES pt_data.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_variant-report
is_layout = i_layout
it_fieldcat = i_fieldcat[]
it_sort = i_sort
i_default = 'X'
i_save = 'A'
is_variant = i_variant
it_events = i_events[]
is_print = i_print
TABLES
t_outtab = pt_data.
ENDFORM. "f_list_display
*& Form TOP_OF_PAGE
* TOP_OF_PAGE Event
FORM top_of_page. "#EC CALLED
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
* i_logo = 'ZLOGO_BAB'
it_list_commentary = i_list_top
i_alv_form = 'X'.
* PERFORM f_print_header USING SPACE SPACE SPACE.
ENDFORM. "TOP_OF_PAGE
*& Form END_OF_PAGE
* END_OF_PAGE Event
FORM end_of_page. "#EC CALLED
* DATA: l_pos(3) TYPE n VALUE 0,
* l_foot(30) VALUE '*** END OF PAGE ***'.
* l_pos = ( sy-linsz / 2 ) - ( STRLEN( l_foot ) / 2 ).
* ULINE.
* WRITE: /, AT l_pos l_foot.
ENDFORM. "END_OF_PAGE
*& Form END_OF_LIST
* END_OF_LIST Event
FORM end_of_list. "#EC CALLED
* DATA: l_pos(3) TYPE n VALUE 0,
* l_foot(30) VALUE '*** END OF REPORT ***'.
* l_pos = ( sy-linsz / 2 ) - ( STRLEN( l_foot ) / 2 ).
* ULINE.
* WRITE: /, AT l_pos l_foot.
ENDFORM. "END_OF_LIST
*& Form f_print_header
* Print the header (Top-Of-Page)
* -->P_P_TITLE1 Title text 1
* -->P_P_TITLE2 Title text 2
* -->P_P_TITLE3 Title text 3
FORM f_print_header USING p_title1 LIKE sy-title
p_title2 LIKE sy-title
p_title3 LIKE sy-title.
DATA: l_post1 TYPE i,
l_post2 TYPE i,
l_post3 TYPE i,
l_posin TYPE i.
l_post1 = ( sy-linsz / 2 ) - ( STRLEN( p_title1 ) / 2 ).
l_post2 = ( sy-linsz / 2 ) - ( STRLEN( p_title2 ) / 2 ).
l_post3 = ( sy-linsz / 2 ) - ( STRLEN( p_title3 ) / 2 ).
l_posin = sy-linsz - 17.
WRITE: / 'Report :', sy-cprog.
WRITE AT l_post1 p_title1.
WRITE AT l_posin 'Date :'.
WRITE sy-datum.
WRITE: / 'Cli/Sys :', sy-mandt, '/', sy-sysid.
WRITE AT l_post2 p_title2.
WRITE AT: l_posin 'Time :'.
WRITE sy-uzeit.
WRITE: / 'UserID :', sy-uname.
WRITE AT l_post3 p_title3.
WRITE AT l_posin 'Page :'.
WRITE sy-pagno NO-ZERO.
ENDFORM. " f_print_header
*& Form f_build_sort1
* text
* --> p1 text
* <-- p2 text
form f_build_sort1 .
DATA: l_sort TYPE slis_sortinfo_alv.
l_sort-spos = '1'.
l_sort-fieldname = 'LIFNR'.
l_sort-up = abap_true.
l_sort-group = '*'.
* l_sort-subtot = 'X'.
APPEND l_sort TO i_sort.
l_sort-spos = '2'.
l_sort-fieldname = 'NAME1'.
l_sort-up = abap_true.
l_sort-group = '*'.
* l_sort-subtot = 'X'.
APPEND l_sort TO i_sort.
* l_sort-spos = '3'.
* l_sort-fieldname = 'DMBTR'.
* l_sort-up = abap_true.
* l_sort-group = '*'.
* l_sort-subtot = 'X'.
* APPEND l_sort TO i_sort.
endform. " f_build_sort1
Regards
Sunita.Hey,
U can try out "SORTING THE VENDORS AND DO THE SUM in the NETWR"... try it out....see u sort the customers...rit?...keep it as usual and little mentoned above...
hope dis help u out...
Thanks. -
ALV grid output issue to excel
Hi Experts
I have an ALV report which I want to Download to Excel( I am using excel 2003).
When I veiw the report it apperars ok. Their are around 90 columns in the Report
But when I export the alv I found that some columns are on the next line. Is there any way to resolve this issue
I want to export in excel without creating new rows of columns .
Thanks
VikrantHi,
please tell your abaper to move 90 fields to intenal table & have a look below code.
Here my internal table is i_downfinal.
DATA: FULLPATH TYPE STRING,
FILENAME TYPE STRING,
PATH TYPE STRING,
USER_ACTION TYPE I.
encoding TYPE ABAP_ENCODING.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'File Download'
DEFAULT_FILE_NAME = 'C:\TEMP\zpmcs.xls'
WITH_ENCODING = 'X'
CHANGING
FILENAME = FILENAME
PATH = PATH
FULLPATH = FULLPATH
USER_ACTION = USER_ACTION
FILE_ENCODING = encoding
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF USER_ACTION <> CL_GUI_FRONTEND_SERVICES=>ACTION_OK.
EXIT.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = FULLPATH
FILETYPE = 'DAT'
TABLES
DATA_TAB = I_DOWNFINAL
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
hi there...I know there´s a lot of posts about this subject but i didn't find what i´m looking for...
I want to know if there´s some way to give a total and a sub-total of a field, but instead of the total and subtotal sums I just want a count of the number of rows for the field that I've sorted.
FIELDCATALOG-FIELDNAME = 'BUKRS'.
FIELDCATALOG-SELTEXT_M = 'BUKRS'.
FIELDCATALOG-COL_POS = 0.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'BUTXT'.
FIELDCATALOG-SELTEXT_M = 'BUTXT'.
FIELDCATALOG-COL_POS = 1.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'LIFNR'.
FIELDCATALOG-SELTEXT_M = 'LIFNR'.
FIELDCATALOG-COL_POS = 2.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'NAME1'.
FIELDCATALOG-SELTEXT_M = 'NAME1'.
FIELDCATALOG-COL_POS = 3.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MBLNR'.
FIELDCATALOG-SELTEXT_M = 'MBLNR'.
FIELDCATALOG-COL_POS = 4.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MJAHR'.
FIELDCATALOG-SELTEXT_M = 'MJAHR'.
FIELDCATALOG-COL_POS = 5.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'CPUDT'.
FIELDCATALOG-SELTEXT_M = 'CPUDT'.
FIELDCATALOG-COL_POS = 6.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'BUDAT'.
FIELDCATALOG-SELTEXT_M = 'BUDAT'.
FIELDCATALOG-COL_POS = 7.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'USNAM'.
FIELDCATALOG-SELTEXT_M = 'BUDAT'.
FIELDCATALOG-COL_POS = 8.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MENGE'.
FIELDCATALOG-SELTEXT_M = 'MENGE'.
FIELDCATALOG-COL_POS = 9.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'DMBTR'.
FIELDCATALOG-SELTEXT_M = 'DMBTR'.
FIELDCATALOG-COL_POS = 10.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
* SORT
WA_SORT-SPOS = 1.
WA_SORT-FIELDNAME = 'BUKRS'.
WA_SORT-TABNAME = 'ITAB'.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
WA_SORT-SPOS = 2.
WA_SORT-FIELDNAME = 'LIFNR'.
WA_SORT-TABNAME = 'ITAB'.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
in the alv i want to know the number of rows for each value of lifnr (sub-total) and in the end the total of the all values of lifnr
thanksHi,
It is better to obtain this information not in ALV but working on the table. Using control level processing it is easy to achieve.
data: begin of it_overview occurs 0
lifnr type ..
tot_item type i, "number of lifnr withing subtotal
end of it_overwiev.
data: pos type i. "to remember the position.
"your output table
Loop at it_ouptut.
at new lifnr.
pos = sy-tabix. "remember first position of new LIFNR
endat.
at end of lifnr.
it_overview-lifnr = it_output-lifnr.
it_overview-tot_item = sy-tabix - pos. "calculate how many within one LIFNR
append it_overview. "store it in the table
clear pos.
endat.
endloop.
this way table IT_OVERVIEW stores LIFNRs and number of items forming their subtotals.
To get total use:
DESCRIEBE TABLE it_output.
it_output-lifnr = 'TOTAL_ITEMS'. "total items within all LIFNRs
it_output-tot_item = sy-tfill. "is equal to total lines in the table
append it_output.
Regards
Marcin -
Hi,
I've to display a list in a Grid using FM'S, So that it should fullfill 3 requirements given below.
1)Positive values should be in green color and negative values should be in red color. Similarly how to maintain various columns in various colors.
2)For the first 2 values in the grid scroll bar shouldn't be enabled. That means we con't scroll through those 2 values.
3)How to calculate subtotals.
Thanks,
G Sandeepexample:
REPORT Z_ALV_CELL_COLOR.
Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY. "#EC *
SELECTION-SCREEN END OF LINE.
TYPES :
BEGIN OF ty_data,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
END OF ty_data,
Data displayed
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
tabcolor TYPE lvc_t_scol, " Cell Color
END OF ty_vbak.
DATA:
gt_data TYPE TABLE OF ty_data,
Data displayed
gt_vbak TYPE TABLE OF ty_vbak.
INITIALIZATION.
v_1 = 'Maximum of records to read'. "#EC NOTEXT
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_fill_color.
PERFORM f_display_data.
Form f_read_data_vbak
FORM f_read_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM vbak UP TO p_max ROWS.
ENDFORM. " F_READ_DATA
Form f_fill_color
FORM f_fill_color.
DATA :
ls_data TYPE ty_data,
ls_vbak TYPE ty_vbak.
LOOP AT gt_data INTO ls_data.
CLEAR ls_vbak.
MOVE-CORRESPONDING ls_data TO ls_vbak.
PERFORM f_modify_color USING 'NETWR' CHANGING ls_vbak.
PERFORM f_modify_color USING 'VBELN' CHANGING ls_vbak.
Fill gt_vbak
APPEND ls_vbak TO gt_vbak.
ENDLOOP.
ENDFORM. " F_FILL_COLOR
Form F_modify_color
FORM f_modify_color USING u_fieldname TYPE lvc_fname
CHANGING us_vbak TYPE ty_vbak.
DATA :
l_rnd_value TYPE integer2,
ls_tabcolor TYPE lvc_s_scol.
Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.
CLEAR ls_tabcolor.
ls_tabcolor-fname = u_fieldname.
CASE l_rnd_value.
WHEN 0.
ls_tabcolor-color-col = 1. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 1.
ls_tabcolor-color-col = 3. " Yellow.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 2.
ls_tabcolor-color-col = 5. " Green.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 3.
ls_tabcolor-color-col = 6. " Red.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
ENDCASE.
INSERT ls_tabcolor INTO TABLE us_vbak-tabcolor.
ENDFORM. " F_MODIFY_COLOR
Form f_display_data
FORM f_display_data.
DATA:
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
Fill Layout
ls_layout-coltab_fieldname = 'TABCOLOR'.
Display the list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA -
Hellow Experts,
i got the some code to genrate auto genrated column based on date my out put is as follow
StudentID Day00 Day01 Day02 ......Day31
178 20 30 40 50
My Code for genrate day is
LOOP AT gt_cols INTO gs_col.
TRY.
CONCATENATE 'DATE' gs_col-date INTO g_col. "Define Column name
gr_column ?= gr_columns->get_column( g_col ). "Get column
CONCATENATE 'Day' gs_col-date+6(2) INTO g_txt. "Define new label (Day01, .., Day31)
gr_column->set_long_text( g_txt ). "Set label long text
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
ENDLOOP.
My requirment is i dont need 'Day00' like follow
StudentID Day01 Day02 ......Day31
178 30 40 50
PLz help me and Ammend my above code to remove Day00.ThanksLOOP AT gt_cols INTO gs_col.
TRY.
IF gs_col-date+6(2) NE '00'. "Add this IF statement and see if it solves the problem
CONCATENATE 'DATE' gs_col-date INTO g_col. "Define Column name
gr_column ?= gr_columns->get_column( g_col ). "Get column
CONCATENATE 'Day' gs_col-date+6(2) INTO g_txt. "Define new label (Day01, .., Day31)
gr_column->set_long_text( g_txt ). "Set label long text
ENDIF.
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
ENDLOOP.
-- Aniruddha
Maybe you are looking for
-
Unable to get Windows 7 partition to connect to the internet.
Hey all, I have come here in my last ditch effort of desperation. I purchased a new 21.5' iMac yesterday and have been trying all day to get Win7 installed via bootcamp. The drive is partitioned, I can early boot in and out of Windows. However, I am
-
Question - Trying to use Icloud on a PC - I get a server error after I put in my e-mail and password. Why? I can sync up all my devices from Itunes with my MaC, Iphone and IPad but I can't do it with my PC
-
When trying to reset my iCal sync preferences, I lost my Mail sync capability
iPhone 4s, version 8 - Mac 10.6.8. Mac's too old for iCloud, so I have to sync via a cable and iTunes 11.4. Even before upgrading my phone to version 8, I have been unable to sync iCal from my Mac to my phone. Last time I could was 11 days ago. In th
-
ObjectInputStream returns a wrong boolean value of a object
ObjectOutputStream.writeObject once, then change the boolean value of the Contact object, ObjectOutputStream.writeObject again, but when ObjectInputStream.readObject, it returns SAME boolean values which should be different. can somebody explain me t
-
Earlier today I tried to open up AIM on my Mac Mini and it refused to work. I restarted my computer and tried again. Again, it didnt open so I uninstalled it and attempted to reinstall it. When I tried to reinstall it, the installer wouldn't open. So