ALV Report heading
Hi,
When I am display data using ALV I am not able to display some fields data in the output it's like this if I have f1,f2,f3,f4,f5 i am able to see the data only for f4 and f5 but not able to see the data of f1,f2 ,f3 even then I have data for that fields
these fields(f1,f2,f3) are sorted and subtotal fields can any body tell me what's the wrong here.
Thanks&Regards
Mahesh
Hi Mahesh,
U have to give all the field names of field catalog in capitals within quotes.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'RECORD'.
line_fieldcat-tabname = 'I_MSG_LOG'.
line_fieldcat-seltext_l = 'Record'.
line_fieldcat-outputlen = '60'.
APPEND line_fieldcat TO i_fieldcat.
Hope it helps.
Similar Messages
-
Printing an ALV Report: Header to be printed on first page only
Hi All,
I was just wondering if there's a way such that the header of an ALV report appears on the first page only when the report is printed out?
Thanks for your replies.
Edited by: Chris Estanislao on Sep 21, 2010 4:22 AMHi Chris,
Which ALV technique will you use to print out?? (LIST, GRID or something else...).
Please give us more information.
Thanks, -
Hi to all
I am preparing a ALV report.
In which I want to display the values which are entered on selection screen.
On the selection screen these are the fields :
s_werks for pa0001-werks
s_orgeh for pa0001-orgeh
I am successful to capture one value (s_orgeh-low) but if multiple values are selected then how to display.
Plz guide me...Hi,
try like this..in the belwo code first FM captures the selection screen fields and the second function mdoule dispalys them in the output.
DATA :
Internal table for Selection screen parameters
i_seltable TYPE STANDARD TABLE OF rsparams.
*& Form get_selection_screen
Subroutine to get the user selection on selection screen
FORM get_selection_screen .
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = sy-repid
TABLES
selection_table = i_seltable
EXCEPTIONS
not_found = 01
no_report = 02.
IF sy-subrc NE 0.
REFRESH i_seltable.
ENDIF.
ENDFORM. " get_selection_screen
*& Form display_selection_criteria
Subroutine to display the selction criteria in the output
FORM display_selection_criteria .
CALL FUNCTION 'RS_LIST_SELECTION_TABLE'
EXPORTING
report = sy-repid
seltext = c_x
newpage = space
TABLES
sel_tab = i_seltable
EXCEPTIONS
sel_tab_empty = 1
OTHERS = 2.
IF sy-subrc <> 0.
REFRESH i_seltable.
ENDIF.
ENDFORM. " display_selection_criteria
Regards,
Nagaraj -
Problem in displaying Total No.of Lines in ALV report header.
Hi guys,
my field symbol internal table is having records in which "Compliance" field is having YES or NO values. now requirement is to display
Total No. of Compliances which are having YES.
lets say, internal table is having 10 lines. in which compliance field is having 6 YES and 4 No respective values .
now i want to display header as No. of Compliances : 6
following is my code to display Total no.of lines in internal tables.
* total no. of records selected
DESCRIBE TABLE <table> LINES ld_lines.
ld_linesc = ld_lines.
CONCATENATE text-004 ld_linesc
INTO t_line SEPARATED BY space.
wa_header-typ = 'A'.
wa_header-info = t_line.
APPEND wa_header TO t_header.
CLEAR: wa_header, t_line,ld_lines, ld_linesc .
My data is there in Field-Symbol table.
Now i want to display No.of compliances . could anybody please help me out in this.
Thanks in Advance.
Regards
satishHI,
You can use another option like below,
<Table>[] = <Table1>[]
delete table1 where compliance = 'NO'.
DESCRIBE TABLE <Table1> LINES ld_lines. .. follow your logic as above.
Hope this will helps you,
Thanks & Regards,
Suresh M -
Hi,
How to increase the field width of a field in ALV report.
I mean, in a ALV report, the field description of a field is not showing correctly. IF i try to extend the field width by the mouse/coursor, it displays the correct description.
IS there any way where for displaying the field description correctly?
Thanks,
KumarHi,
Go through the sample code,
*& Report ZDEMO_ALVLIST *
*& Example of a simple ALV List Report *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
REPORT zdemo_alvlist .
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-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_LIST_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
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
i_logo = 'Z_LOGO'.
endform.
Regards,
Raj. -
*& Report ZALV11 *
REPORT zalv11 LINE-SIZE 1023 MESSAGE-ID zz.
TYPE-POOLS : slis.
* T A B L E S D E C L A R A T I O N S *
TABLES : ce1eg01,
makt,
kna1,
t9zfprct,
tvkmt.
* I N T E R N A L T A B L E D E C L A R A T I O N S *
DATA : BEGIN OF itab OCCURS 0,
paledger TYPE ce1eg01-paledger, "Currency type for an operating concern
vrgar TYPE ce1eg01-vrgar, "Record Type
versi TYPE ce1eg01-versi, "Plan version (CO-PA)
perio TYPE ce1eg01-perio, "Period/year
paobjnr TYPE ce1eg01-paobjnr, "Profitability Segment no
pasubnr TYPE ce1eg01-pasubnr, "Profitability Segment changes
belnr TYPE ce1eg01-belnr, "Doc no of line item in profit
posnr TYPE ce1eg01-posnr, "Item no in CO-PA line item
hzdat TYPE ce1eg01-hzdat, "Date on which record was created
usnam TYPE ce1eg01-usnam, "Created by
gjahr TYPE ce1eg01-gjahr, "Fiscal year
perde TYPE ce1eg01-perde, "Period
kunnr LIKE ce1eg01-kndnr, "Customer
artnr TYPE ce1eg01-artnr, "Product Number
frwae TYPE ce1eg01-frwae, "Foreign currency key
kaufn TYPE ce1eg01-kaufn, "Sales order number
kdpos TYPE ce1eg01-kdpos, "Item no in Sales order
bzirk TYPE ce1eg01-bzirk, "Sales district
vkbur TYPE ce1eg01-vkbur, "Sales office
wwsap TYPE ce1eg01-wwsap, "Sales Person
ktgrm TYPE tvkmt-ktgrm, "AAG
land1 TYPE ce1eg01-land1, "Country Key
auart TYPE ce1eg01-auart, "Sales document type
kunwe TYPE ce1eg01-kunwe, "Ship-to-party
erlos TYPE ce1eg01-erlos, "Revenue
absmg TYPE ce1eg01-absmg, "Sales qty
kwfrgr TYPE ce1eg01-kwfrgr, "Freight
vvdis TYPE ce1eg01-vvdis, "Discounts
zprdgrp TYPE t9zfprct-zprdgrp, "Product group
name1 TYPE kna1-name1, "Customer Name
maktx TYPE makt-maktx, "Material Description
vtext TYPE tvkmt-vtext, "Description
name2 TYPE kna1-name1, "Sales Person Name
END OF itab.
DATA : BEGIN OF itab1 OCCURS 0,
perio TYPE ce1eg01-perio, "Period/year5
kunnr TYPE ce1eg01-kndnr, "Customer
artnr TYPE ce1eg01-artnr, "Product Number 21
kaufn TYPE ce1eg01-kaufn, "Sales order number28
kdpos TYPE ce1eg01-kdpos, "Item no in Sales order29
bzirk TYPE ce1eg01-bzirk, "Sales district58
vkbur TYPE ce1eg01-vkbur, "Sales office59
ktgrm TYPE tvkmt-ktgrm, "AAG 61
land1 TYPE ce1eg01-land1, "Country Key 63
auart TYPE ce1eg01-auart, "Sales document type68
kunwe TYPE ce1eg01-kunwe, "Ship-to-party71
zprdgrp TYPE t9zfprct-zprdgrp, "Product group
paledger TYPE ce1eg01-paledger, "Currency type for an operating concern
versi TYPE ce1eg01-versi, "Plan version (CO-PA)4
paobjnr TYPE ce1eg01-paobjnr, "Profitability Segment no6
pasubnr TYPE ce1eg01-pasubnr, "Profitability Segment changes7
belnr TYPE ce1eg01-belnr, "Doc no of line item in profit 8
posnr TYPE ce1eg01-posnr, "Item no in CO-PA line item 9
hzdat TYPE ce1eg01-hzdat, "Date on which record was created10
usnam TYPE ce1eg01-usnam, "Created by11
gjahr TYPE ce1eg01-gjahr, "Fiscal year12
perde TYPE ce1eg01-perde, "Period13
frwae TYPE ce1eg01-frwae, "Foreign currency key23
wwsap TYPE ce1eg01-wwsap, "Sales Person 60
erlos TYPE ce1eg01-erlos, "Revenue76
absmg TYPE ce1eg01-absmg, "Sales qty85
kwfrgr TYPE ce1eg01-kwfrgr, "Freight97
vvdis TYPE ce1eg01-vvdis, "Discounts98
name1 TYPE kna1-name1, "Customer Name
maktx TYPE makt-maktx, "Material Description
vtext TYPE tvkmt-vtext, "Description
name2 TYPE kna1-name1, "Sales Person Name
END OF itab1.
DATA : BEGIN OF itab2 OCCURS 0,
perio TYPE ce1eg01-perio, "Period/year
hzdat TYPE ce1eg01-hzdat, "Date on which record was created
usnam TYPE ce1eg01-usnam, "Created by
gjahr TYPE ce1eg01-gjahr, "Fiscal year
perde TYPE ce1eg01-perde, "Period
kunnr LIKE ce1eg01-kndnr, "Customer
artnr TYPE ce1eg01-artnr, "Product Number
frwae TYPE ce1eg01-frwae, "Foreign currency key
kaufn TYPE ce1eg01-kaufn, "Sales order number
kdpos TYPE ce1eg01-kdpos, "Item no in Sales order
bzirk TYPE ce1eg01-bzirk, "Sales district
vkbur TYPE ce1eg01-vkbur, "Sales office
wwsap TYPE ce1eg01-wwsap, "Sales Person
ktgrm TYPE tvkmt-ktgrm, "AAG
land1 TYPE ce1eg01-land1, "Country Key
auart TYPE ce1eg01-auart, "Sales document type
kunwe TYPE ce1eg01-kunwe, "Ship-to-party
erlos TYPE ce1eg01-erlos, "Revenue
absmg TYPE ce1eg01-absmg, "Sales qty
kwfrgr TYPE ce1eg01-kwfrgr, "Freight
vvdis TYPE ce1eg01-vvdis, "Discounts
zprdgrp TYPE t9zfprct-zprdgrp, "Product group
name1 TYPE kna1-name1, "Customer Name
maktx TYPE makt-maktx, "Material Description
vtext TYPE tvkmt-vtext, "Description
name2 TYPE kna1-name1, "Sales Person Name
END OF itab2.
DATA : BEGIN OF i_kna1 OCCURS 0,
kunnr LIKE kna1-kunnr,
name1 LIKE kna1-name1,
END OF i_kna1.
DATA : BEGIN OF i_kna2 OCCURS 0,
kunnr LIKE kna1-kunnr,
name1 LIKE kna1-name1,
END OF i_kna2.
DATA : BEGIN OF i_makt OCCURS 0,
matnr LIKE makt-matnr,
maktx LIKE makt-maktx,
END OF i_makt.
DATA : wa_t9zfprct TYPE t9zfprct,
i_t9zfprct LIKE STANDARD TABLE OF wa_t9zfprct WITH HEADER LINE.
DATA : wa_tvkmt TYPE tvkmt,
i_tvkmt LIKE STANDARD TABLE OF wa_tvkmt WITH HEADER LINE.
DATA: wa_itab like itab.
DATA: wa_itab2 like itab2.
* D A T A D E C L A R A T I O N F O R A L V *
TYPE-POOLS: slis. "ALV Declarations
DATA: t_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
tt_fieldcat TYPE slis_t_fieldcat_alv,
x_fieldcat TYPE slis_fieldcat_alv.
DATA : mycat TYPE slis_t_fieldcat_alv ,
scat TYPE slis_fieldcat_alv,
gt_events TYPE slis_t_event.
DATA: g_repid LIKE sy-repid,
gd_layout TYPE slis_layout_alv,
gt_sort TYPE slis_t_sortinfo_alv,
gd_prntparams TYPE slis_print_alv,
rs_variant LIKE disvariant.
data: p_file TYPE rlgrap-filename value 'TEST3.txt'.
data: wa_tab2 like tab2.
* D A T A D E C L A R A T I O N *
DATA : t_lineno LIKE sy-tabix,
ld_linesc(10) TYPE c.
DATA : w_erlos TYPE ce1eg01-erlos,
w_absmg TYPE ce1eg01-absmg,
w_kwfrgr TYPE ce1eg01-kwfrgr,
w_vvdis TYPE ce1eg01-vvdis.
* S E L E C T I O N S C R E E N *
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_curr FOR ce1eg01-paledger ,
s_vrgar FOR ce1eg01-vrgar,
s_perio FOR ce1eg01-perio,
s_spras FOR makt-spras NO INTERVALS,
s_auart FOR ce1eg01-auart,
s_kaufn FOR ce1eg01-kaufn.
PARAMETERS: p_layout TYPE slis_vari.
SELECTION-SCREEN END OF BLOCK blk1.
* A T S E L E C T I O N S C R E E N *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
PERFORM alv_variant_f4 CHANGING p_layout.
* S T A R T O F S E L E C T I O N
START-OF-SELECTION.
PERFORM data_select.
DESCRIBE TABLE itab LINES t_lineno.
IF t_lineno = 0.
MESSAGE i000 WITH 'NO RECORD FOUND'.
ELSE.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM build_events.
PERFORM build_print_params.
* PERFORM calculate.
PERFORM call_alv.
PERFORM dataset.
ENDIF.
*& Form DATA_SELECT
FORM data_select.
SELECT paledger vrgar versi perio paobjnr pasubnr belnr posnr hzdat usnam gjahr perde kndnr artnr frwae kaufn kdpos bzirk
vkbur wwsap ktgrm land1 auart kunwe erlos absmg kwfrgr vvdis
FROM ce1eg01 INTO TABLE itab
WHERE paledger IN s_curr
AND vrgar IN s_vrgar
AND perio IN s_perio
AND kaufn IN s_kaufn
AND auart IN s_auart.
IF sy-subrc = 0.
SELECT matnr maktx FROM makt INTO TABLE i_makt
FOR ALL ENTRIES IN itab
WHERE matnr = itab-artnr
AND spras IN s_spras.
* Reading sales person
SELECT kunnr name1 FROM kna1 INTO TABLE i_kna1
FOR ALL ENTRIES IN itab
WHERE kunnr = itab-kunnr.
* Reading ship to party
SELECT kunnr name1 FROM kna1 INTO TABLE i_kna2
FOR ALL ENTRIES IN itab
WHERE kunnr = itab-wwsap. "kunwe.
SELECT * FROM t9zfprct INTO TABLE i_t9zfprct
FOR ALL ENTRIES IN itab
WHERE ktgrm = itab-ktgrm.
SELECT * FROM tvkmt INTO TABLE i_tvkmt
FOR ALL ENTRIES IN itab
WHERE ktgrm = itab-ktgrm.
SORT i_kna1 BY kunnr.
SORT i_kna2 BY kunnr.
SORT i_t9zfprct BY ktgrm.
SORT i_tvkmt BY ktgrm.
LOOP AT itab.
MOVE-CORRESPONDING itab TO itab1.
READ TABLE i_kna1 WITH KEY kunnr = itab-kunnr BINARY SEARCH.
IF sy-subrc = 0.
itab1-name1 = i_kna1-name1.
ENDIF.
READ TABLE i_kna2 WITH KEY kunnr = itab-wwsap BINARY SEARCH.
IF sy-subrc = 0.
itab1-name2 = i_kna2-name1.
ENDIF.
READ TABLE i_t9zfprct WITH KEY ktgrm = itab-ktgrm BINARY SEARCH.
IF sy-subrc = 0.
itab1-zprdgrp = i_t9zfprct-zprdgrp.
ENDIF.
READ TABLE i_tvkmt WITH KEY ktgrm = itab-ktgrm BINARY SEARCH.
IF sy-subrc = 0.
itab1-ktgrm = i_tvkmt-ktgrm.
itab1-vtext = i_tvkmt-vtext.
ENDIF.
READ TABLE i_makt WITH KEY matnr = itab-artnr.
IF sy-subrc = 0.
itab1-maktx = i_makt-maktx.
ENDIF.
APPEND itab1.
CLEAR itab1.
ENDLOOP.
REFRESH itab.
SORT itab1 BY perio kunnr artnr kaufn kdpos bzirk vkbur ktgrm land1 auart kunwe zprdgrp paledger.
CLEAR : w_erlos ,w_absmg ,w_kwfrgr ,w_vvdis.
LOOP AT itab1.
MOVE-CORRESPONDING itab1 TO itab.
SHIFT itab-wwsap LEFT DELETING LEADING '0'.
SHIFT itab-kunnr LEFT DELETING LEADING '0'.
SHIFT itab-kaufn LEFT DELETING LEADING '0'.
SHIFT itab-kunwe LEFT DELETING LEADING '0'.
SHIFT itab-belnr LEFT DELETING LEADING '0'.
w_erlos = w_erlos + itab1-erlos.
w_absmg = w_absmg + itab1-absmg.
w_kwfrgr = w_kwfrgr + itab1-kwfrgr.
w_vvdis = w_vvdis + itab1-vvdis.
AT END OF paledger.
MOVE : w_erlos TO itab-erlos,
w_absmg TO itab-absmg,
w_kwfrgr TO itab-kwfrgr,
w_vvdis TO itab-vvdis.
APPEND itab.
CLEAR itab.
CLEAR : w_erlos ,w_absmg ,w_kwfrgr ,w_vvdis.
ENDAT.
ENDLOOP.
ENDIF.
clear itab.
loop at itab.
move-corresponding itab to itab2.
append itab2.
endloop.
ENDFORM. "data_select
*& Form build_fieldcatalog
* Fill field catalog and sort catelog with output fields
FORM build_fieldcatalog.
* PERFORM append_fldcat USING 'PALEDGER' 'ITAB' 'Currency type' 01 .
PERFORM append_fldcat USING 'ZPRDGRP' 'ITAB' 'Product group' 01 .
PERFORM append_fldcat USING 'KUNNR' 'ITAB' 'Customer' 02 .
PERFORM append_fldcat USING 'NAME1' 'ITAB' 'Customer Name' 03 .
PERFORM append_fldcat USING 'ARTNR' 'ITAB' 'Product Number' 04 .
PERFORM append_fldcat USING 'MAKTX' 'ITAB' 'Material Description' 05 .
PERFORM append_fldcat USING 'KTGRM' 'ITAB' 'AAG' 06 .
PERFORM append_fldcat USING 'VTEXT' 'ITAB' 'Description' 07 .
PERFORM append_fldcat USING 'WWSAP' 'ITAB' 'Sales Person' 08 .
PERFORM append_fldcat USING 'NAME2' 'ITAB' 'Sales Person Name' 09 .
PERFORM append_fldcat USING 'VKBUR' 'ITAB' 'Sales office' 10 .
PERFORM append_fldcat USING 'LAND1' 'ITAB' 'Country Key' 11 .
PERFORM append_fldcat USING 'KAUFN' 'ITAB' 'Sales order number' 12 .
PERFORM append_fldcat USING 'KDPOS' 'ITAB' 'Item no in Sales order' 13 .
PERFORM append_fldcat USING 'PERIO' 'ITAB' 'Period/year' 14 .
PERFORM append_fldcat USING 'HZDAT' 'ITAB' 'Date on which record was created' 15 .
PERFORM append_fldcat USING 'ABSMG' 'ITAB' 'Sales qty' 16 .
PERFORM append_fldcat USING 'ERLOS' 'ITAB' 'Revenue' 17 .
PERFORM append_fldcat USING 'VVDIS' 'ITAB' 'Discounts' 18 .
PERFORM append_fldcat USING 'KWFRGR' 'ITAB' 'Freight' 19 .
PERFORM append_fldcat USING 'FRWAE' 'ITAB' 'Foreign currency key' 20 .
PERFORM append_fldcat USING 'AUART' 'ITAB' 'Sales document type' 21 .
PERFORM append_fldcat USING 'KUNWE' 'ITAB' 'Ship-to-party' 22 .
PERFORM append_fldcat USING 'BZIRK' 'ITAB' 'Sales district' 23 .
* PERFORM append_fldcat USING 'BELNR' 'ITAB' 'Doc no of line item in profit' 24 .
* PERFORM append_fldcat USING 'VERSI' 'ITAB' 'Plan version (CO-PA)' 25 .
* PERFORM append_fldcat USING 'PAOBJNR' 'ITAB' 'Profitability Segment no' 26 .
* PERFORM append_fldcat USING 'PASUBNR' 'ITAB' 'Profitability Segment changes' 27 .
* PERFORM append_fldcat USING 'POSNR' 'ITAB' 'Item no in CO-PA line item' 28 .
PERFORM append_fldcat USING 'USNAM' 'ITAB' 'Created by' 29 .
PERFORM append_fldcat USING 'GJAHR' 'ITAB' 'Fiscal year' 30 .
PERFORM append_fldcat USING 'PERDE' 'ITAB' 'Period' 31 .
ENDFORM. "build_T_FIELDCAT
*& Form build_layout
FORM build_layout .
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
ENDFORM. " build_layout
*& Form build_events
FORM build_events .
DATA: ls_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_events[].
READ TABLE gt_events WITH KEY name = slis_ev_end_of_page
INTO ls_event.
IF sy-subrc = 0.
MOVE 'END_OF_PAGE' TO ls_event-form.
APPEND ls_event TO gt_events.
ENDIF.
READ TABLE gt_events WITH KEY name = slis_ev_end_of_list
INTO ls_event.
IF sy-subrc = 0.
MOVE 'END_OF_LIST' TO ls_event-form.
APPEND ls_event TO gt_events.
ENDIF.
READ TABLE gt_events
WITH KEY name = slis_ev_user_command INTO ls_event.
IF sy-subrc = 0.
ls_event-name = 'USER_COMMAND'.
ls_event-form = 'USER_COMMAND'.
APPEND ls_event TO gt_events.
ENDIF.
ENDFORM. " build_events
*& Form BUILD_PRINT_PARAMS
* Setup print parameters
FORM build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
ENDFORM. " BUILD_PRINT_PARAMS
*& Form call_alv
* text
* --> p1 text
* <-- p2 text
FORM call_alv .
g_repid = sy-repid.
rs_variant-variant = p_layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
is_layout = gd_layout
it_fieldcat = t_fieldcat[]
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
is_variant = rs_variant
TABLES
t_outtab = itab2
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " call_alv
* Form TOP-OF-PAGE *
* ALV Report Header *
FORM top-of-page.
*ALV Header declarations
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
t_line LIKE wa_header-info.
* Title
wa_header-typ = 'H'.
wa_header-info = 'PA Sales Book Summary report'.
APPEND wa_header TO t_header.
CLEAR wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
APPEND wa_header TO t_header.
CLEAR: wa_header.
* Total No. of Records Selected
DESCRIBE TABLE itab LINES t_lineno.
ld_linesc = t_lineno.
CONCATENATE 'Total No. of Records Selected: ' ld_linesc
INTO t_line SEPARATED BY space.
wa_header-typ = 'A'.
wa_header-info = t_line.
APPEND wa_header TO t_header.
CLEAR: wa_header, t_line.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
ENDFORM. "top-of-page
*& Form END_OF_PAGE
FORM end_of_page.
DATA: listwidth TYPE i,
ld_pagepos(10) TYPE c,
ld_page(10) TYPE c.
WRITE: sy-uline(50).
SKIP.
WRITE:/40 'Page:', sy-pagno .
ENDFORM. "END_OF_PAGE
*& Form END_OF_LIST
FORM end_of_list.
DATA: listwidth TYPE i,
ld_pagepos(10) TYPE c,
ld_page(10) TYPE c.
SKIP.
WRITE:/40 'Page:', sy-pagno .
ENDFORM. "END_OF_LIST
*& Form user_command
* text
* -->R_UCOMM text
* -->RS_SELFIELDtext
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
IF r_ucomm = '&IC1'.
CASE rs_selfield-fieldname.
WHEN 'KUNNR'.
SET PARAMETER ID 'KUN' FIELD rs_selfield-value.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDIF.
ENDFORM. "user_command
*& Form append_fldcat
* text
FORM append_fldcat USING par_fldname par_tabname par_seltext pos.
t_fieldcat-tabname = par_tabname.
t_fieldcat-fieldname = par_fldname .
* t_fieldcat-seltext_s = par_seltext.
* t_fieldcat-seltext_m = par_seltext.
t_fieldcat-seltext_l = par_seltext.
t_fieldcat-reptext_ddic = par_seltext.
t_fieldcat-col_pos = pos.
* t_fieldcat-just = 'R'.
t_fieldcat-lzero = ' '.
APPEND t_fieldcat.
ENDFORM. " append_fldcat
*& Form ALV_VARIANT_F4
* text
* -->PA_VARI text
FORM alv_variant_f4 CHANGING p_layout.
DATA nof4 TYPE c.
CLEAR nof4.
LOOP AT SCREEN.
IF screen-name = 'P_LAYOUT'.
IF screen-input = 0.
nof4 = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
rs_variant-report = sy-repid.
rs_variant-username = sy-uname.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = rs_variant
i_save = 'A'
IMPORTING
es_variant = rs_variant
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0 AND nof4 EQ space.
p_layout = rs_variant-variant.
ENDIF.
ENDFORM.
*& Form dataset
* text
* --> p1 text
* <-- p2 text
form dataset .
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*--- Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT itab2.
TRANSFER itab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
endform. " dataset
When I execute this code and move back it shows the following error.I want to move the output to p_file in application server.Plz suggest what to do.
Only character-type data objects are supported at the argument
position "f" for the statement
"TRANSFER f TO ...".
In this case, the operand "f" has the non-character-type "u". The
current program is flagged as a Unicode program. In the Unicode context,
type X fields are seen as non-character-type, as are structures that
contain non-character-type components.Some of the fields in TAB2 may not be text. Open the dataset in binary mode and see if that resolves the issue.
If you must have the file in text mode, then copy the header line to a structure containing just text fields and then transfer to the dataset. -
Classical Report on clicking button on ALV Report
I have a requirement where I have to display a classical report based on the user-click on a "custom button" on my ALV. I am unable to display the classical report. Please help with code example..
Hi,
See the example.Change the code according to your requirement.
*& Report ZDEMO_ALVGRID *
*& Example of a simple ALV Grid Report *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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'.
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_events
is_print = gd_prntparams
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
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
i_logo = 'Z_LOGO'.
endform.
FORM USER_COMMAND *
--> R_UCOMM *
--> RS_SELFIELD *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
Check function code
CASE r_ucomm.
WHEN '&IC1'.
Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'EBELN'.
Read data table, using index of row user clicked on
READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
Set parameter ID for transaction screen field
SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
*& Form BUILD_EVENTS
Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*& Form BUILD_PRINT_PARAMS
Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*& Form END_OF_PAGE
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*& Form END_OF_LIST
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
Pls. reward if useful... -
How to read complete line displayed thru ALV report on double click? urgent
Hi guys,
An ALV report is displayed using 'REUSE_ALV_LIST_DISPLAY' and i have a requirement such that i have to read the line item on which double click is done.
I have to fetch the line item, field by field and not by characters. I have attached the function code and all using PF status.
Please tell me an approach as how to fetch the line item on which double click is done.
Points will be rewarded.
Regards
RahulHi ..
i did report with belnr , bukrs , Gjahr . which will call the transcation code FB03 displaing thedocument ...
please cut and paste the report it will work ..
REPORT zdemo_alvgrid .
TABLES: bkpf . " ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
BUKRS like bkpf-BUKRS,
BELNR like bkpf-BELNR,
GJAHR like bkpf-GJAHR,
BLART like bkpf-BLART,
BLDAT like bkpf-BLDAT,
BUDAT like bkpf-BUDAT,
MONAT like bkpf-MONAT,
XBLNR like bkpf-XBLNR ,
* 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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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 = 'BUKRS'.
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 = 'BELNR'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'GJAHR'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BLART'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BLDAT'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BUDAT'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MONAT'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XBLNR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
* fieldcatalog-do_sum = 'X'.
* 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_events
is_print = gd_prntparams
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 BUKRS
BELNR
GJAHR
BLART
BLDAT
BUDAT
MONAT
XBLNR up to 10 rows
from bkpf
into table it_ekko.
*select ebeln ebelp statu aedat matnr menge meins netpr peinh
* up to 10 rows
* from ekpo
* into table it_ekko.
endform. " DATA_RETRIEVAL
* Form TOP-OF-PAGE *
* ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform.
* FORM USER_COMMAND *
* --> R_UCOMM *
* --> RS_SELFIELD *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* Check function code
CASE r_ucomm.
WHEN '&IC1'.
* Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'BELNR'.
* Read data table, using index of row user clicked on
READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
* Set parameter ID for transaction screen field
SET PARAMETER ID 'BES' FIELD wa_ekko-bELNR .
SET PARAMETER ID 'MES' FIELD wa_ekko-bUKRS .
SET PARAMETER ID 'DES' FIELD wa_ekko-GJAHR .
* Sxecute transaction ME23N, and skip initial data entry screen
* CALL TRANSACTION 'FB03' AND SKIP first screen.
SUBMIT RFBUEB00
* WITH ALCUR ...
* WITH ARCHOBJ ...
* WITH ARCH_SEL ...
* WITH ARUSETYP ...
* WITH AUTBEXNO ...
* WITH AUTH_BUK ...
* WITH AUTH_LDR ...
* WITH BR_AWKEY ...
* WITH BR_AWSYS ...
* WITH BR_AWTYP ...
WITH BR_BELNR = wa_ekko-bELNR
* WITH BR_BLART ...
* WITH BR_BLDAT ...
* WITH BR_BUDAT ...
WITH BR_BUKRS = wa_ekko-bUKRS
* WITH BR_CPUDT ...
WITH BR_GJAHR = wa_ekko-GJAHR
* WITH BR_RLDNR ...
* WITH BR_SEQ ...
* WITH BR_USNAM ...
* WITH BR_XBLNR ...
* WITH EXCDT ...
* WITH P_STATS ...
* WITH STATISTK ...
* WITH STATUSD ...
* WITH STATUSL ...
* WITH STATUSM ...
* WITH STATUSS ...
* WITH STATUSV ...
* WITH TCODE ...
* WITH UNAME ...
* WITH XEMUCNV ...
* WITH XUSEAR ...
* WITH XUSEAS ...
* WITH XUSEDB
AND RETURN .
ENDIF.
ENDCASE.
ENDFORM.
*& Form BUILD_EVENTS
* Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*& Form BUILD_PRINT_PARAMS
* Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*& Form END_OF_PAGE
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*& Form END_OF_LIST
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
reward points if it is usefull ...
Girish -
hi
can anyone send me a simple and easily understandable ALV report.
points will be rewarded....Hi,
I think this will help u a lot...Plz reward if helpful to u...
REPORT ZSDR_SOSA NO STANDARD PAGE HEADING
LINE-COUNT 65 LINE-SIZE 100.
--Tables--
tables: vbap, vbak, vbpa, vbkd, makt,konv.
--Data Fetching--
TYPE-POOLS: slis.
data:begin of i_vbap occurs 0,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
matnr like vbap-matnr,
arktx like vbap-arktx,
kdmat like vbap-kdmat,
taxm1 like vbap-taxm1,
end of i_vbap.
data:begin of i_vbak occurs 0,
vbeln like vbak-vbeln,
audat like vbak-audat,
vbtyp like vbak-vbtyp,
vkorg like vbak-vkorg,
knumv like vbak-knumv,
kunnr like vbak-kunnr,
end of i_vbak.
data:begin of i_vbpa occurs 0,
vbeln like vbpa-vbeln,
posnr like vbpa-posnr,
parvw like vbpa-parvw,
kunnr like vbpa-kunnr, "SH
kunnr1 like vbpa-kunnr, "SP
end of i_vbpa.
data:begin of i_konv occurs 0,
knumv like konv-knumv,
kschl like konv-kschl,
kbetr like konv-kbetr,
mwsk1 like konv-mwsk1,
end of i_konv.
data:begin of i_vbkd occurs 0,
vbeln like vbkd-vbeln,
posnr like vbkd-posnr,
bstkd like vbkd-bstkd,
bstdk like vbkd-bstdk,
end of i_vbkd.
data:begin of i_makt occurs 0,
matnr like makt-matnr,
spras like makt-spras,
maktx like makt-maktx, "MAt. Desc
maktx1 like makt-maktx, "Cust mat. no.
end of i_makt.
data:wa_makt like makt.
DATA:BEGIN OF itab OCCURS 0,
vbeln like vbap-vbeln, "SD no.
audat like vbak-audat, "Order date
kunnr like vbpa-kunnr, "sold to party
kunnr1 like vbpa-kunnr, "ship to party
matnr like vbap-matnr, "Mat. No.
maktx like makt-maktx, "Material Desc.
kdmat like vbap-kdmat, "Cust. Mat.no.
maktx1 like makt-maktx, "Customer Mat. desc.
bstkd like vbkd-bstkd, "PO number
bstdk like vbkd-bstdk, "PO date
kbetr like konv-kbetr, "Basic Price
knumv like vbak-knumv,
vkorg like vbak-vkorg,
vbtyp like vbak-vbtyp,
parvw like vbpa-parvw,
kschl like konv-kschl,
mwsk1 like konv-mwsk1,
posnr like vbap-posnr,
arktx like vbap-arktx,
taxm1 like vbap-taxm1,
END OF itab.
--ALV DECLARATION--
DATA :v_pgm LIKE sy-repid.
DATA :col_pos TYPE i.
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,
gt_events TYPE slis_t_event,
gd_prntparams TYPE slis_print_alv.
DATA:fcat TYPE slis_t_fieldcat_alv,
fcat1 TYPE slis_t_fieldcat_alv,
fcat2 TYPE slis_t_fieldcat_alv,
eve TYPE slis_t_event,
eve1 TYPE slis_t_event,
subtot TYPE slis_t_sortinfo_alv,
g_subtot LIKE LINE OF subtot.
--SELECTION SCREEN--
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_audat FOR vbak-audat,
s_vkorg for vbak-vkorg,
s_kunnr for vbak-kunnr.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS:p_sorder RADIOBUTTON GROUP rad1,
p_agree RADIOBUTTON GROUP rad1,
p_order radiobutton group rad1.
SELECTION-SCREEN END OF BLOCK b2.
--Initialization--
INITIALIZATION.
v_pgm = sy-repid.
--Start-of-selection--
Start-of-selection.
if p_sorder = 'X'.
perform get_sorder_data.
perform process_data.
perform display_data1.
elseif p_agree = 'X'.
perform get_agree_data.
perform process_data.
perform display_data1.
elseif p_order = 'X'.
perform get_order_data.
perform process_data.
perform display_data1.
endif.
*& Form get_sorder_data
text
--> p1 text
<-- p2 text
FORM get_sorder_data .
*Get from VBAK table.
select vbeln audat vbtyp vkorg knumv kunnr
from vbak into table i_vbak
where audat in s_audat
and vkorg in s_vkorg
and kunnr in s_kunnr
and vbtyp in ('C','E').
*Get from VBAP table.
if not i_vbak[] is initial.
clear:i_vbap. refresh:i_vbap.
select vbeln posnr matnr arktx kdmat taxm1
from vbap into table i_vbap
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
*Get from VBPA table.
if not i_vbap[] is initial.
clear:i_vbpa. refresh:i_vbpa.
select vbeln posnr parvw kunnr
from vbpa into table i_vbpa
for all entries in i_vbap
where vbeln = i_vbap-vbeln
and parvw in ('AG','KB','RE','RG','VE','WE','ZM').
endif.
*Get from KONV table.
if not i_vbak[] is initial.
clear:i_konv. refresh:i_konv.
select knumv kschl kbetr mwsk1
from konv into table i_konv
for all entries in i_vbak
where knumv = i_vbak-knumv
and kschl = 'PR00'.
endif.
*Get from VBKD table.
if not i_vbak[] is initial.
clear:i_vbkd. refresh:i_vbkd.
select vbeln posnr bstkd bstdk
from vbkd into table i_vbkd
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
**Get from MAKT table.
if not i_vbap[] is initial.
clear:i_makt. refresh:i_makt.
select single maktx
from makt into i_makt
for all entries in i_vbap
where matnr = i_vbap-matnr
and spras = sy-langu.
endif.
ENDFORM. " get_sorder_data
*& Form process_data
text
--> p1 text
<-- p2 text
FORM process_data .
Loop at i_vbap.
itab-vbeln = i_vbap-vbeln.
itab-posnr = i_vbap-posnr.
itab-matnr = i_vbap-matnr.
itab-arktx = i_vbap-arktx.
itab-kdmat = i_vbap-kdmat.
itab-taxm1 = i_vbap-taxm1.
*Get from MAKT table.
select single maktx from makt
into wa_makt-maktx
where matnr = itab-matnr
and spras = sy-langu.
if sy-subrc = 0.
itab-maktx = wa_makt-maktx.
itab-maktx1 = wa_makt-maktx.
endif.
read table i_vbak with key vbeln = itab-vbeln.
if sy-subrc = 0.
itab-audat = i_vbak-audat.
itab-knumv = i_vbak-knumv.
itab-vkorg = i_vbak-vkorg.
itab-vbtyp = i_vbak-vbtyp.
endif.
read table i_vbpa with key vbeln = itab-vbeln.
if sy-subrc = 0.
itab-parvw = i_vbpa-parvw.
itab-kunnr = i_vbpa-kunnr.
itab-kunnr1 = i_vbpa-kunnr.
endif.
read table i_konv with key knumv = itab-knumv.
if sy-subrc = 0.
itab-kschl = i_konv-kschl.
itab-kbetr = i_konv-kbetr.
itab-mwsk1 = i_konv-mwsk1.
endif.
read table i_vbkd with key vbeln = itab-vbeln.
if sy-subrc = 0.
itab-bstkd = i_vbkd-bstkd.
itab-bstdk = i_vbkd-bstdk.
endif.
read table i_makt with key matnr = itab-matnr.
if sy-subrc = 0.
itab-maktx = i_makt-maktx.
itab-maktx1 = i_makt-maktx1.
endif.
append itab.
clear itab.
endloop.
delete itab where not audat in s_audat.
delete itab where not vkorg in s_vkorg.
delete itab where not kunnr in s_kunnr.
ENDFORM. " process_data
*& Form display_data1
text
--> p1 text
<-- p2 text
FORM display_data1 .
PERFORM get_buildfieldcat1.
PERFORM display_alv.
ENDFORM. " display_data1
*& Form display_alv
text
--> p1 text
<-- p2 text
FORM display_alv .
IF itab[] IS INITIAL.
MESSAGE 'No Data Exist' TYPE 'E'.
ENDIF.
DATA: title TYPE lvc_title
, datelow(10) TYPE c
, datehigh(10) TYPE c
DATA: gd_repid LIKE sy-repid
, gd_layout TYPE slis_layout_alv
***************Layout Formatting***************
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-zebra = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
***************Layout Formatting***************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_pgm
i_callback_top_of_page = 'ALV_TOP_OF_PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND' "'ALV_USER_COMMAND'
i_grid_title = title
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
it_sort = subtot
is_variant = z_template
TABLES
t_outtab = itab
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
*& Form ALV_TOP_OF_PAGE
ALV Report Header *
--> p1 text
<-- p2 text
FORM alv_top_of_page .
*ALV Header declarations
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
t_line LIKE wa_header-info,
ld_lines TYPE i,
ld_linesc(10) TYPE c.
FORM alv_top_of_page1 .
DATA: i_header TYPE slis_t_listheader,
wa1_header TYPE slis_listheader,
i_line LIKE wa1_header-info,
lld_lines TYPE i,
lld_linesc(10) TYPE c.
Title
wa1_header-typ = 'H'.
wa1_header-info = 'Schedule Line-Basic Price Details'.
APPEND wa1_header TO t_header.
CLEAR wa1_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
APPEND wa_header TO t_header.
CLEAR: wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Time: '.
CONCATENATE
sy-uzeit(2) ':'
sy-uzeit+2(2) ':'
sy-uzeit+4(2) INTO wa_header-info. "time
APPEND wa_header TO t_header.
CLEAR: wa_header.
wa_header-typ = 'A'.
wa_header-info = t_line.
APPEND wa_header TO t_header.
CLEAR: wa_header, t_line.
Total No. of Rows Displayed
DESCRIBE TABLE itab LINES ld_lines.
ld_linesc = ld_lines.
CONCATENATE 'Total No. of Rows: ' ld_linesc
INTO t_line SEPARATED BY space.
wa_header-typ = 'A'.
wa_header-info = t_line.
APPEND wa_header TO t_header.
CLEAR: wa_header, t_line.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header
i_logo = 'Z_LOGO'
ENDFORM. "alv_top_of_page
*& Form get_buildfieldcat1
text
--> p1 text
<-- p2 text
FORM get_buildfieldcat1 .
DATA position TYPE i.
position = -1.
position = position + 1.
fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'Sales Order No.'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'AUDAT'.
fieldcatalog-seltext_m = 'Order Date'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 15.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'KUNNR'.
fieldcatalog-seltext_m = 'Sold to Party'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'KUNAG'.
fieldcatalog-seltext_m = 'Ship to Party'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material No.'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'MAKTX'.
fieldcatalog-seltext_m = 'Material Desc.'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'KDMAT'.
fieldcatalog-seltext_m = 'Customer Material No.'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'MAKTX1'.
fieldcatalog-seltext_m = 'Customer Material Desc'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'BSTKD'.
fieldcatalog-seltext_m = 'Purchase Order No.'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'BSTDK'.
fieldcatalog-seltext_m = 'Purchase Order Date'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
position = position + 1.
fieldcatalog-fieldname = 'KBETR'.
fieldcatalog-seltext_m = 'Basic Price'.
fieldcatalog-col_pos = position.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " get_buildfieldcat1
*& Form get_agree_data
text
--> p1 text
<-- p2 text
FORM get_agree_data .
*Get from VBAK table.
select vbeln audat vbtyp vkorg knumv kunnr
from vbak into table i_vbak
where audat in s_audat
and vkorg in s_vkorg
and kunnr in s_kunnr
and vbtyp in ('C','E').
*Get from VBAP table.
if not i_vbak[] is initial.
clear:i_vbap. refresh:i_vbap.
select vbeln posnr matnr arktx kdmat taxm1
from vbap into table i_vbap
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
*Get from VBPA table.
if not i_vbap[] is initial.
clear:i_vbpa. refresh:i_vbpa.
select vbeln posnr parvw kunnr
from vbpa into table i_vbpa
for all entries in i_vbap
where vbeln = i_vbap-vbeln
and parvw in ('AG','KB','RE','RG','VE','WE','ZM').
endif.
*Get from KONV table.
if not i_vbak[] is initial.
clear:i_konv. refresh:i_konv.
select knumv kschl kbetr mwsk1
from konv into table i_konv
for all entries in i_vbak
where knumv = i_vbak-knumv
and kschl = 'PR00'.
endif.
*Get from VBKD table.
if not i_vbak[] is initial.
clear:i_vbkd. refresh:i_vbkd.
select vbeln posnr bstkd bstdk
from vbkd into table i_vbkd
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
ENDFORM. " get_agree_data
*& Form get_order_data
text
--> p1 text
<-- p2 text
FORM get_order_data .
*Get from VBAK table.
select vbeln audat vbtyp vkorg knumv kunnr
from vbak into table i_vbak
where audat in s_audat
and vkorg in s_vkorg
and kunnr in s_kunnr
and vbtyp in ('C','E').
*Get from VBAP table.
if not i_vbak[] is initial.
clear:i_vbap. refresh:i_vbap.
select vbeln posnr matnr arktx kdmat taxm1
from vbap into table i_vbap
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
*Get from VBPA table.
if not i_vbap[] is initial.
clear:i_vbpa. refresh:i_vbpa.
select vbeln posnr parvw kunnr
from vbpa into table i_vbpa
for all entries in i_vbap
where vbeln = i_vbap-vbeln
and parvw in ('AG','KB','RE','RG','VE','WE','ZM').
endif.
*Get from KONV table.
if not i_vbak[] is initial.
clear:i_konv. refresh:i_konv.
select knumv kschl kbetr mwsk1
from konv into table i_konv
for all entries in i_vbak
where knumv = i_vbak-knumv
and kschl = 'PR00'.
endif.
*Get from VBKD table.
if not i_vbak[] is initial.
clear:i_vbkd. refresh:i_vbkd.
select vbeln posnr bstkd bstdk
from vbkd into table i_vbkd
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
ENDFORM. " get_order_data
With Regards,
Seevangi -
Hi all,
I have data in fianal internal table like
287 10 A 1 $
287 10 B 2 #
287 10 C 3 @
287 10 D 4 !
500 20 X Y Z
500 20 1 2 3
Now I want to display this data an ALV like
287 10 A 1 $ B 2 # C 3 @ D 4 !
500 20 X Y Z 1 2 3
This means the HEADER containig all its ITEM details should be displayed in it's row by column by column
I have been trying this from past few days, but I didn't
Can anybody send replies with logic or sample programs
last time group people sent progrms related to OBJECT ORIENTED CONCEPT but Iam very poor in this concept.
Reward points for every answer
Thanks & Regards
RKHi
I'm not so far clear about your query?? What problem you are facing know???
Do u want to display details on header data then
Check this report
*& Report ZALV *
Report ZALV .
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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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-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_events
is_print = gd_prntparams
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
* Form TOP-OF-PAGE *
* ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform.
* FORM USER_COMMAND *
* --> R_UCOMM *
* --> RS_SELFIELD *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* Check function code
CASE r_ucomm.
WHEN '&IC1'.
* Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'EBELN'.
* Read data table, using index of row user clicked on
READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
* Set parameter ID for transaction screen field
SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
* Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
*& Form BUILD_EVENTS
* Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*& Form BUILD_PRINT_PARAMS
* Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*& Form END_OF_PAGE
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*& Form END_OF_LIST
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
If not provide me more info
Reward all helpfull answers
Regards
Pavan -
Hi,
Need help on ALV ..am a newbie on this...I have created the source code but i cant proceed with the below requirement
The report will be generated in ALV ,
1. executed in a background job
2. spool to be converted in a PDF
3. PDF to be save in SAP directory
4. PDF file to be sent other server ( outside SAP)
I have completed the coding for the alv report but put to stop coz of the 4 requirements above..
Need your expertise advise here.. Many thanks in advance.
========================
REPORT ZSD_REPORT.
TABLES: VBAK,
KNA1,
VBPA,
PA0001,
T001.
DATA: T_VBELN LIKE VBAK-VBELN.
DATA: T_VGBEL LIKE VBAK-VGBEL.
DATA: IT_VBAK1 LIKE VBAK OCCURS 0 WITH HEADER LINE.
DATA: IT_VBAK2 LIKE VBAK OCCURS 0 WITH HEADER LINE,
IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE,
IT_VBPA LIKE VBPA OCCURS 0 WITH HEADER LINE,
IT_VBPA1 LIKE VBPA OCCURS 0 WITH HEADER LINE,
IT_PA0001 LIKE PA0001 OCCURS 0 WITH HEADER LINE,
IT_PA00011 LIKE PA0001 OCCURS 0 WITH HEADER LINE.
type-pools: slis. "ALV Declarations
TYPES: BEGIN OF IT_VBAK,
VBELN TYPE VBAK-VBELN,
VGBEL TYPE VBAK-VGBEL,
ZZ_PROBEZ TYPE VBAK-ZZ_PROBEZ,
ZK_PERNR TYPE VBPA-PERNR,
ZT_PERNR TYPE VBPA-PERNR,
VDATU TYPE VBAK-VDATU,
ZZ_PROJ_LOC TYPE VBAK-ZZ_PROJ_LOC,
NAME1 TYPE KNA1-NAME1,
GV_PC TYPE PA0001-ENAME,
GV_PM TYPE PA0001-ENAME,
ZZ_COMP_02 TYPE VBAK-ZZ_COMP_02,
END OF IT_VBAK.
DATA: IT_VBAK TYPE STANDARD TABLE OF IT_VBAK WITH HEADER LINE.
DATA: IS_VBAK TYPE STANDARD TABLE OF IT_VBAK WITH HEADER LINE.
DATA: WA_VBAK TYPE STANDARD TABLE OF IT_VBAK WITH HEADER LINE.
*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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
*Start-of-selection.
START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK PSP WITH FRAME TITLE TEXT-001.
PARAMETERS P_AUART LIKE VBAK-AUART DEFAULT 'ZSSO'.
PARAMETERS P_VKORG LIKE VBAK-VKORG DEFAULT '2700'.
PARAMETERS P_STATUS LIKE VBAK-ZZ_COMP_02.
*SELECT-OPTIONS SO_ERDAT LIKE VBAK-ERDAT DEFAULT SY-DATUM.
SELECTION-SCREEN END OF BLOCK PSP.
SELECT * INTO TABLE IT_VBAK1 FROM VBAK
WHERE AUART EQ P_AUART
AND VKORG EQ P_VKORG
AND ZZ_COMP_02 EQ P_STATUS.
IF NOT IT_VBAK1[] IS INITIAL.
SORT IT_VBAK1 BY VBELN.
LOOP AT IT_VBAK1.
SELECT SINGLE * FROM KNA1
INTO IT_KNA1
WHERE KUNNR = IT_VBAK1-KUNNR.
SELECT SINGLE * FROM VBPA
INTO IT_VBPA
WHERE VBELN = IT_VBAK1-VBELN
AND PARVW = 'ZK'.
SELECT SINGLE * FROM PA0001
INTO IT_PA0001
WHERE PERNR = IT_VBPA-PERNR.
SELECT SINGLE * FROM VBPA
INTO IT_VBPA1
WHERE VBELN = IT_VBAK1-VBELN
AND PARVW = 'ZT'.
SELECT SINGLE * FROM PA0001
INTO IT_PA00011
WHERE PERNR = IT_VBPA1-PERNR.
T_VBELN = IT_VBAK1-VBELN.
T_VGBEL = IT_VBAK1-VGBEL.
SHIFT T_VBELN LEFT DELETING LEADING '0'.
SHIFT T_VGBEL LEFT DELETING LEADING '0'.
MOVE T_VBELN TO IT_VBAK-VBELN.
MOVE T_VGBEL TO IT_VBAK-VGBEL.
MOVE IT_VBAK1-ZZ_PROBEZ TO IT_VBAK-ZZ_PROBEZ.
MOVE IT_VBPA-PERNR TO IT_VBAK-ZK_PERNR.
MOVE IT_VBPA1-PERNR TO IT_VBAK-ZT_PERNR.
APPEND IT_VBAK.
ENDLOOP.
ELSE.
WRITE: /'No Record Exists'.
ENDIF.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
form build_fieldcatalog.
fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'Order No.'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'VGBEZ'.
fieldcatalog-seltext_m = 'Quotation Ref.'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NAME1'.
fieldcatalog-seltext_m = 'Customer'.
fieldcatalog-col_pos = 2.
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).
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_events
is_print = gd_prntparams
i_save = 'X'
is_variant = z_template
tables
t_outtab = IT_VBAK
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
endif.
endform. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM DATA_RETRIEVAL.
ENDFORM.
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
ld_title(100) type c,
ld_title2(200) type c,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c,
it_logo(10) type c.
LD_TITLE = 'SD REPORT'.
wa_header-typ = 'H'.
wa_header-info = ld_title.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
endform.
FORM USER_COMMAND *
--> R_UCOMM *
--> RS_SELFIELD *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
Check function code
CASE r_ucomm.
WHEN '&IC1'.
Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'VBELN'.
Read data table, using index of row user clicked on
READ TABLE IT_VBAK INTO WA_VBAK INDEX rs_selfield-tabindex.
Set parameter ID for transaction screen field
SET PARAMETER ID 'AUN' FIELD WA_VBAK-VBELN.
Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
*& Form BUILD_EVENTS
Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*& Form BUILD_PRINT_PARAMS
Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*& Form END_OF_PAGE
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*& Form END_OF_LIST
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
=============================
SheHi SHE,
Check the attached sample code for more details. Hope this helps.#
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT 'she @company.com',
p_sender LIKE somlreci1-receiver
DEFAULT 'she @company.com',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
* Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname type btcjob,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
*** Alternative way could be to submit another program and store spool
*** id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
* to sap-spool
* spool parameters %_print
* archive parameters %_print
* without spool dynpro
* and return.
* Get spool id from program called above
* IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
* FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
* FORM get_job_details *
FORM get_job_details.
* Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
* FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
* Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
* FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
* perform send_email using p_email2.
ENDFORM.
* FORM send_email *
* --> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
* Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
* CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
* If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
* FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
* Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM. -
How to add link in the ALV report?
Hi ,
Now, I want to turn to a t-code (e.x. Va03) after double click column for order of ALV report.
Is it possible? what i should do?
Thanl you all~Yes , it is Possible in ALV .
From the Sales order Field (VBLEN) in the Basic List to Sales Order Display TrascationCode : (VA03).
Here is the Sample code for Purchase Order Display .
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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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'.
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_events
is_print = gd_prntparams
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
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
i_logo = 'Z_LOGO'.
endform.
FORM USER_COMMAND *
--> R_UCOMM *
--> RS_SELFIELD *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
Check function code
CASE r_ucomm.
WHEN '&IC1'.
Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'EBELN'.
Read data table, using index of row user clicked on
READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
Set parameter ID for transaction screen field
SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
*& Form BUILD_EVENTS
Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*& Form BUILD_PRINT_PARAMS
Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*& Form END_OF_PAGE
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*& Form END_OF_LIST
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
Reward Points if it is usefull,,,
Girish -
ALV Grid Header Problem.
Hi All,
I want to display the header of the ALV Grid as:
Material 111/11823
Plant/Usage/Alt 2845/3/5
Description ABI CAB
Base Qty. 23.000
The values are to be taken from variables
Please suggest how to do this.
Thanks*& Report ZDEMO_ALVGRID *
*& Example of a simple ALV Grid Report with grand total *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
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.
perform top-of-page.
*& 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
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
i_logo = 'ideas'.
endform. -
In ALV Report output heading is printing twice.
Hi Experts,
Im working on ALV Reports.
Im printing header text by using listheader and commentary write function module.
the problem is when i sort any column in ALV ouput the heading is printing twice.
Again if i sort the column the heading is printed is 4 times.
so if anybody knows the solution how we can avoid repetition of heading ,
Please reply me as soon as possible.
regards
Imrangs.Hi Noorie,
Thanks a lot.
Your answer is perfect.
Bye.
Regards,
Imran -
Column Heading are not displayed in ALV Report using CL_SALV_DISPLAY?
Hi,
I am using CL_SALV_DISPLAY class to display data. I Created an Internal Table Dynamically based fieldcatalog which was prepared based data at run time. When i displayed data using CL_SALC_DISPALY data is display in output but column headings are not displayed.
can anyone suggest me how to display heading in ALV using CL_SALV_DISPLAY class, My code is
CLASS lcl_report DEFINITION
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
METHODS:
display IMPORTING l_table TYPE string
l_fcat TYPE string.
ENDCLASS. "lcl_report DEFINITION
CLASS lcl_report IMPLEMENTATION
CLASS lcl_report IMPLEMENTATION.
METHOD display.
DATA: gr_table TYPE REF TO cl_salv_table.
DATA: gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
ls_fcat TYPE slis_fieldcat_alv.
DATA: gr_display TYPE REF TO cl_salv_display_settings.
DATA: l_o_functions TYPE REF TO cl_salv_functions_list,
l_field TYPE string.
FIELD-SYMBOLS : <fs_table> TYPE STANDARD TABLE,
<ft_fcat> TYPE STANDARD TABLE.
Get the ALV object refering to the output table
ASSIGN (l_table) TO <fs_table>.
ASSIGN (l_fcat) TO <ft_fcat>.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = <fs_table> ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
Add basic default functionality in the ALV report
Functions
l_o_functions = gr_table->get_functions( ).
l_o_functions->set_all( abap_true ).
gr_columns = gr_table->get_columns( ).
gr_columns->set_headers_visible( abap_true ).
Display the list
gr_table->display( ).
ENDMETHOD. "extract
ENDCLASS. "lcl_report IMPLEMENTATION
*& start-of-selection declaration
START-OF-SELECTION.
PERFORM :
get store codes
get_storecodes USING p_stfile
CHANGING it_t001w,
fetching mard data
read_mard_data,
preparing fieldcatalog for Final Data
create_filedcat USING it_t001w
it_site
CHANGING it_fieldcat,
preparing structure & internal table for Final Data
create_final_table_structure USING it_fieldcat,
prepare output data
prepare_final_data.
*& end-of-selection declaration
END-OF-SELECTION.
PERFORM :
display data
display_data USING l_table
l_fcat.
*& Form get_storecodes
FORM get_storecodes USING p_p_stfile
CHANGING p_it_t001w LIKE it_t001w[].
DATA :
internal table for RAW
lt_raw TYPE truxs_t_text_data,
rs_site LIKE LINE OF rt_site,
l_index LIKE sy-tabix.
FIELD-SYMBOLS :
field symbol for it_t001w
<fs_t001w> LIKE LINE OF p_it_t001w.
calling function module to get Stores Data from File
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = 'X'
i_tab_raw_data = lt_raw
i_filename = p_p_stfile
TABLES
i_tab_converted_data = p_it_t001w[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
SORT p_it_t001w BY werks.
CLEAR rs_site.
rs_site-sign = 'I'.
rs_site-option = 'EQ'.
rs_site-low = p_dccode.
APPEND rs_site TO rt_site.
IF it_t001w[] IS NOT INITIAL.
LOOP AT p_it_t001w ASSIGNING <fs_t001w>.
l_index = sy-tabix.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_t001w>-werks
IMPORTING
output = <fs_t001w>-werks.
MODIFY p_it_t001w FROM <fs_t001w> INDEX l_index.
IF <fs_t001w>-werks GE s_site-low AND <fs_t001w>-werks LE s_site-high.
append site to ranges
CLEAR rs_site.
rs_site-sign = 'I'.
rs_site-option = 'EQ'.
rs_site-low = <fs_t001w>-werks.
APPEND rs_site TO rt_site.
CONTINUE.
ENDIF.
ENDLOOP.
SORT p_it_t001w BY werks.
SORT rt_site.
ENDIF.
ENDFORM. " get_storecodes
*& Form create_final_table_structure
FORM create_filedcat USING p_it_t001w LIKE it_t001w[]
p_it_site LIKE it_site[]
CHANGING p_it_fieldcat LIKE it_fieldcat[].
FIELD-SYMBOLS :
field symbol for p_it_t001w
<fs_t001w> LIKE LINE OF p_it_t001w,
field symbol for p_it_site
<fs_site> LIKE LINE OF p_it_site.
DATA :
fieldname
l_fieldname TYPE slis_fieldname,
workarea for site ranges
rs_site LIKE LINE OF rt_site.
CLEAR : l_fieldname, rs_site.
l_fieldname = p_dccode.
PERFORM
prepare fieldcatalog
build_fieldcatalog USING : 'MTART' 'CHAR' '5' ,
'MTBEZ' 'CHAR' '25' ,
'MATKL' 'CHAR' '6' ,
'WGBEZ' 'CHAR' '20' ,
'MATNR' 'CHAR' '18' ,
'MAKTX' 'CHAR' '30' ,
l_fieldname 'CHAR' '17' .
create header for excel
PERFORM create_excel_header USING : 'Division',
'Divsion Description',
'MC Code',
'MC Description',
'Article',
'Article Description',
l_fieldname.
loop for creating fieldcatalog
LOOP AT it_site ASSIGNING <fs_site>.
READ TABLE it_t001w ASSIGNING <fs_t001w> WITH KEY werks = <fs_site>-werks
BINARY SEARCH.
IF sy-subrc = 0 AND <fs_t001w> IS ASSIGNED AND
<fs_site> IS ASSIGNED AND <fs_site>-stock GT 0.
CLEAR : l_fieldname, rs_site.
l_fieldname = <fs_site>-werks.
prepare fieldcatalog
PERFORM build_fieldcatalog USING : l_fieldname 'CHAR' '17'.
create header for excel
PERFORM create_excel_header USING l_fieldname .
CONTINUE.
ENDIF.
ENDLOOP.
l_fcat = 'it_fieldcat[]'.
ENDFORM. " create_final_table_structure
*& Form build_fieldcatalog
FORM build_fieldcatalog USING p_fieldname TYPE slis_fieldname
p_datatype TYPE datatype_d
p_length TYPE intlen.
DATA : ls_fieldcat LIKE LINE OF it_fieldcat.
CLEAR : ls_fieldcat.
ls_fieldcat-fieldname = p_fieldname.
ls_fieldcat-datatype = p_datatype.
ls_fieldcat-intlen = p_length.
APPEND ls_fieldcat TO it_fieldcat.
ENDFORM. " build_fieldcatalog
*& Form create_final_table_structure
FORM create_final_table_structure USING p_it_fieldcat.
Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = t_table.
ASSIGN t_table->* TO <ft_final>.
ENDFORM. " create_final_table_structure
*& Form create_excel_header
FORM create_excel_header USING p_p_fieldname.
DATA : ls_header LIKE LINE OF it_header.
CLEAR ls_header.
ls_header-col_name = p_p_fieldname.
APPEND ls_header TO it_header.
ENDFORM. " create_excel_header
*& Form prepare_final_data
FORM prepare_final_data .
DATA : l_matnr LIKE g_matnr,
l_werks LIKE g_werks,
l_index LIKE sy-tabix.
FIELD-SYMBOLS : <fs_mard> LIKE LINE OF it_mard.
Getting No. of Lines in IT_MARD internal table
DESCRIBE TABLE it_mard LINES g_lines.
LOOP AT it_mard ASSIGNING <fs_mard>.
l_index = sy-tabix.
IF l_matnr IS INITIAL.
l_matnr = <fs_mard>-matnr.
CLEAR : l_werks.
l_werks = <fs_mard>-werks.
UNASSIGN : <fs_value>, <fs_final>.
Create dynamic work area and assign to FS
CREATE DATA t_line LIKE LINE OF <ft_final>.
ASSIGN t_line->* TO <fs_final>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_mard>-matnr.
ASSIGN COMPONENT l_werks OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_value> + <fs_mard>-labst.
getting Article Type,MC & its Descriptions
PERFORM get_other_data USING l_matnr
l_werks.
ELSEIF l_matnr <> <fs_mard>-matnr.
APPEND <fs_final> TO <ft_final>.
CLEAR l_matnr.
l_matnr = <fs_mard>-matnr.
CLEAR : l_werks.
l_werks = <fs_mard>-werks.
UNASSIGN : <fs_value>, <fs_final>.
Create dynamic work area and assign to FS
CREATE DATA t_line LIKE LINE OF <ft_final>.
ASSIGN t_line->* TO <fs_final>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_mard>-matnr.
ASSIGN COMPONENT l_werks OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_value> + <fs_mard>-labst.
getting Article Type,MC & its Descriptions
PERFORM get_other_data USING l_matnr
l_werks.
ELSE.
CLEAR : l_werks.
l_werks = <fs_mard>-werks.
ASSIGN COMPONENT l_werks OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_value> + <fs_mard>-labst.
ENDIF.
IF l_index = g_lines.
APPEND <fs_final> TO <ft_final>.
ENDIF.
ENDLOOP.
l_table = '<ft_final>[]'.
ENDFORM. " prepare_final_data
*& Form get_other_data
FORM get_other_data USING p_l_matnr
p_l_werks.
FIELD-SYMBOLS : <fs_mara> LIKE LINE OF it_mara,
<fs_t023t> LIKE LINE OF it_t023t,
<fs_t134t> LIKE LINE OF it_t134t,
<fs_makt> LIKE LINE OF it_makt.
READ TABLE it_mara ASSIGNING <fs_mara> WITH KEY matnr = p_l_matnr. " BINARY SEARCH.
IF sy-subrc = 0 AND <fs_mara> IS ASSIGNED.
ASSIGN COMPONENT 'MTART' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_mara>-mtart.
ASSIGN COMPONENT 'MATKL' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_mara>-matkl.
READ TABLE it_makt ASSIGNING <fs_makt> WITH KEY matnr = <fs_mara>-matnr BINARY SEARCH.
IF sy-subrc = 0 AND <fs_makt> IS ASSIGNED.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_makt>-maktx.
ENDIF.
READ TABLE it_t023t ASSIGNING <fs_t023t> WITH KEY matkl = <fs_mara>-matkl BINARY SEARCH.
IF sy-subrc = 0 AND <fs_t023t> IS ASSIGNED.
ASSIGN COMPONENT 'WGBEZ' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_t023t>-wgbez.
ENDIF.
READ TABLE it_t134t ASSIGNING <fs_t134t> WITH KEY mtart = <fs_mara>-mtart BINARY SEARCH.
IF sy-subrc = 0 AND <fs_t134t> IS ASSIGNED.
ASSIGN COMPONENT 'MTBEZ' OF STRUCTURE <fs_final> TO <fs_value>.
<fs_value> = <fs_t134t>-mtbez.
ENDIF.
ENDIF.
ENDFORM. " get_other_data
*& Form display_data
text
FORM display_data USING p_l_table
p_l_fcat.
DATA:
Variable for Object Creation
o_report TYPE REF TO lcl_report.
CREATE OBJECT o_report.
o_report->display( EXPORTING l_table = p_l_table
l_fcat = p_l_fcat ).
ENDFORM. " display_dataI don't know how to read the code you pasted or I would have checked this myself.
Do your fields in the internal table reference dictionary objects or elementary types? If not using dictionary types, the column names will be blank by default. If you can't change your fields to be dictionary types, you can try this to change the column names:
I made a method inside my local class to add the names:
call method set_colname
EXPORTING iv_tab = alv_tab
iv_colid = 'xxxx' "fieldname from the table
iv_stxt = text-t54
iv_mtxt = text-t55
iv_ltxt = text-t55.
METHOD set_colname .
data:
alv_cols type REF TO cl_salv_columns_table,
alv_col type REF TO cl_salv_column.
TRY .
*... Change fieldnames
call METHOD iv_tab->get_columns RECEIVING value = alv_cols.
call method alv_cols->get_column EXPORTING columnname = iv_colid RECEIVING value = alv_col.
IF iv_stxt <> ''.
CALL METHOD alv_col->set_short_text EXPORTING value = iv_stxt.
ENDIF.
IF iv_mtxt <> ''.
CALL METHOD alv_col->set_medium_text EXPORTING value = iv_mtxt.
ENDIF.
IF iv_ltxt <> ''.
CALL METHOD alv_col->set_long_text EXPORTING value = iv_ltxt.
ENDIF.
CATCH cx_salv_not_found.
ENDTRY.
ENDMETHOD. "set_colname
Maybe you are looking for
-
Media Encoder CC stürzt seit Update beim Programmstart ab
Hallo! Hat jemand das gleiche PRoblem? Seit gestern stürzt bei mir der MEdiaEncoder CC bei jedem PRogrammstart bei der Übergabe der Renderaufträge von Premiere ab. Und zwar auf zwei unterschiedlichen Rechnern das gleiche Spiel. Laptop und Desktop gle
-
How do you make in "urchin" in illustrator
Hi everyone, So, I'm new to these boards; if there is a problem in how I ask this, please let me know I am making figures for research I am doing that involves sticking molecules on nanoparticles. In illustrator, what I've done so far was making a se
-
Syncing removes purchased apps from iPhone
Can anyone tell me how to stop purchased apps just disappearing from my iPhone when I sync with my laptop? Thanks!
-
Hi I executed the following code. NODES: spfli, sflight. FIELD-GROUPS: header, flight_info, flight_date. INSERT: spfli-carrid spfli-connid sflight-fldate INTO header, spfli-cityfrom spfli-cityto INTO flight_info. START-OF-SELE
-
Hey all, I just upgraded to CS6 and all of a sudden when I'm saving files as PDFs they save as grayscale (no colour). Any idea what's causing this? Please let m know! Thanks in advance. Cheers Jon