ā2012 Jul 30 8:15 AM
Hi,
I want to use multiple headers in my ALV report attach is what i want, and what is currently my ALV showing, below is my code too
How i want
This my report
I want a top header of my four columns
Unit Cost
Ex-factory
Delivery
Erection
Crane
Total
Amount
Ex-factory
Delivery
Erection
Crane
Total
here is my code
*&---------------------------------------------------------------------*
*& Report /BWN0/Z_PROJECT_SUMMERY
* created by sarosh durrani
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT /BWN0/Z_PROJECT_SUMMERY.
TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF p_proj,
SNO TYPE int4,
* v_sno(6) type c,
pspid TYPE proj-pspid,
pspnr TYPE proj-pspnr,
ernam TYPE proj-ernam,
stspr TYPE proj-stspr,
pwhie TYPE proj-pwhie,
besta TYPE proj-besta,
scope TYPE proj-scope,
xstat TYPE proj-xstat,
postu TYPE proj-postu,
smprf TYPE proj-smprf,
erdat TYPE proj-erdat,
post1 TYPE proj-post1,
sakto TYPE afvc-sakto,
a type i,
b type i,
c type i,
END OF p_proj.
TYPES: BEGIN OF pl_afvc,
* SNO TYPE int4,
sakto TYPE afvc-sakto,
projn TYPE afvc-projn,
psphi TYPE prps-psphi,
END OF pl_afvc.
*DATA: IT_PRPS TYPE TABLE OF PRPS.
DATA: it_proj TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,
it_afvc TYPE STANDARD TABLE OF pl_afvc WITH HEADER LINE,
wa_proj TYPE p_proj,
VSNO TYPE INT4.
*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.
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
************************************************************************
*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
*----------------------------------------------------------------------*
VSNO = VSNO + 1.
* it_proj-SNO = VSNO.
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 5.
* fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-just = 'L'.
* fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 50.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'A'.
fieldcatalog-seltext_m = 'A'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'B'.
fieldcatalog-seltext_m = 'B'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'C'.
fieldcatalog-seltext_m = ' C = Sum a + b'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_m = 'Quantity'.
fieldcatalog-col_pos = 6.
fieldcatalog-outputlen = 20.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STSPR'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PWHIE'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BESTA'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 9.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SCOPE'.
fieldcatalog-seltext_m = 'Crane'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XSTAT'.
fieldcatalog-seltext_m = 'Total'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PSPID'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 12.
* fieldcatalog-outputlen = 15.
* fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SMPRF'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 13.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 14.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POST1'.
fieldcatalog-seltext_m = 'Erection1'.
fieldcatalog-col_pos = 15.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SAKTO'.
fieldcatalog-seltext_m = 'Cost Element'.
fieldcatalog-col_pos = 16.
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-colwidth_optimize = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
* gd_layout-expand_fieldname = 'EXPAND'.
* gd_layout-window_titlebar = 'Hierarchical ALV list display'.*
* gd_layout-lights_tabname = 'IT_PROJ'.
* gd_layout-colwidth_optimize = 'X'.
endform. " BUILD_LAYOUT " 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_tab_group
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_proj
* t_outtabnew = it_prps
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 PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF ERDAT from proj into corresponding fields of table it_proj.
select * from proj into corresponding fields of table it_proj.
select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps
ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .
LOOP AT it_proj INTO wa_proj .
wa_proj-sno = sy-tabix.
wa_proj-a = sy-tabix.
wa_proj-b = sy-tabix * 3.
wa_proj-c = wa_proj-a + wa_proj-b.
READ TABLE it_afvc with key psphi = wa_proj-pspnr .
IF sy-SUBRC eq 0.
wa_proj-sakto = it_afvc-sakto.
ENDIF.
MODIFY it_proj FROM wa_proj TRANSPORTING SNO sakto a b c .
CLEAR wa_proj.
ENDLOOP.
endform. " DATA_RETRIEVAL
*up to 10 rows
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
*-------------------------------------------------------------------*
* 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_proj 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. "top_of_page
ā2012 Jul 30 11:36 AM
hi sarosh ,
try this and format accordingly the text in bold letters :
*&---------------------------------------------------------------------*
*& Report /BWN0/Z_PROJECT_SUMMERY
* created by sarosh durrani
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT /BWN0/Z_PROJECT_SUMMERY.
TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF p_proj,
SNO TYPE int4,
* v_sno(6) type c,
pspid TYPE proj-pspid,
pspnr TYPE proj-pspnr,
ernam TYPE proj-ernam,
stspr TYPE proj-stspr,
pwhie TYPE proj-pwhie,
besta TYPE proj-besta,
scope TYPE proj-scope,
xstat TYPE proj-xstat,
postu TYPE proj-postu,
smprf TYPE proj-smprf,
erdat TYPE proj-erdat,
post1 TYPE proj-post1,
sakto TYPE afvc-sakto,
a type i,
b type i,
c type i,
END OF p_proj.
TYPES: BEGIN OF pl_afvc,
* SNO TYPE int4,
sakto TYPE afvc-sakto,
projn TYPE afvc-projn,
psphi TYPE prps-psphi,
END OF pl_afvc.
*DATA: IT_PRPS TYPE TABLE OF PRPS.
DATA: it_proj TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,
it_afvc TYPE STANDARD TABLE OF pl_afvc WITH HEADER LINE,
wa_proj TYPE p_proj,
VSNO TYPE INT4.
*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.
data : it_event TYPE slis_t_event ,
* wa_fld TYPE slis_fieldcat_alv ,
heading TYPE slis_t_listheader,
wa_event TYPE slis_alv_event .
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
PERFORM eventtab_build USING it_event.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
VSNO = VSNO + 1.
* it_proj-SNO = VSNO.
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 5.
* fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-just = 'L'.
* fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 50.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'A'.
fieldcatalog-seltext_m = 'A'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'B'.
fieldcatalog-seltext_m = 'B'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'C'.
fieldcatalog-seltext_m = ' C = Sum a + b'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_m = 'Quantity'.
fieldcatalog-col_pos = 6.
fieldcatalog-outputlen = 20.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STSPR'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PWHIE'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BESTA'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 9.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SCOPE'.
fieldcatalog-seltext_m = 'Crane'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XSTAT'.
fieldcatalog-seltext_m = 'Total'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PSPID'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 12.
* fieldcatalog-outputlen = 15.
* fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SMPRF'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 13.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 14.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POST1'.
fieldcatalog-seltext_m = 'Erection1'.
fieldcatalog-col_pos = 15.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SAKTO'.
fieldcatalog-seltext_m = 'Cost Element'.
fieldcatalog-col_pos = 16.
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-colwidth_optimize = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
* gd_layout-expand_fieldname = 'EXPAND'.
* gd_layout-window_titlebar = 'Hierarchical ALV list display'.*
* gd_layout-lights_tabname = 'IT_PROJ'.
* gd_layout-colwidth_optimize = 'X'.
* gd_LAYOUT-no_colhead = 'X' .
endform. " BUILD_LAYOUT " 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_tab_group
IT_EVENTS = it_event[]
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_proj
* t_outtabnew = it_prps
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 PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF ERDAT from proj into corresponding fields of table it_proj.
select * from proj into corresponding fields of table it_proj.
select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps
ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .
LOOP AT it_proj INTO wa_proj .
wa_proj-sno = sy-tabix.
wa_proj-a = sy-tabix.
wa_proj-b = sy-tabix * 3.
wa_proj-c = wa_proj-a + wa_proj-b.
READ TABLE it_afvc with key psphi = wa_proj-pspnr .
IF sy-SUBRC eq 0.
wa_proj-sakto = it_afvc-sakto.
ENDIF.
MODIFY it_proj FROM wa_proj TRANSPORTING SNO sakto a b c .
CLEAR wa_proj.
ENDLOOP.
endform. " DATA_RETRIEVAL
*up to 10 rows
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
*&---------------------------------------------------------------------*
*& Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LT_EVENTS text
*----------------------------------------------------------------------*
FORM eventtab_build USING lt_events TYPE slis_t_event.
DATA : wa_event TYPE slis_alv_event .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
et_events = lt_events.
READ TABLE lt_events INTO wa_event
WITH KEY name = slis_ev_after_line_output .
wa_event-form = slis_ev_after_line_output .
MODIFY lt_events FROM wa_event INDEX sy-tabix .
READ TABLE lt_events INTO wa_event
WITH KEY name = slis_ev_top_of_page .
wa_event-form = slis_ev_top_of_page .
MODIFY lt_events FROM wa_event INDEX sy-tabix .
ENDFORM. "EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
"Uline for creating a horizontal line
ULINE AT 1(199) .
"Format color for header background
FORMAT COLOR 4 .
WRITE: / sy-vline ,
15 SY-VLINE, 47 SY-VLINE , 68 sy-vline ,69 'Quantity' , 77 sy-vline , 94 'Unit Cost', 121 sy-vline, 154 'Amount' , 199 sy-vline .
ENDFORM. "top_of_page
regards ,
yogendra bhaskar
ā2012 Jul 30 8:47 AM
Take a look at this blog and make your changes.
http://sample-code-abap.blogspot.in/2008/01/printing-multiple-line-header-and.html
Thanks,
Shambu
ā2012 Jul 30 9:27 AM
Nice blog Shambu. Even I got such requirement few days ago and when I asked someone, they said its only possible through OO ALV. So, I dropped that requiement.
ā2012 Jul 30 11:36 AM
hi sarosh ,
try this and format accordingly the text in bold letters :
*&---------------------------------------------------------------------*
*& Report /BWN0/Z_PROJECT_SUMMERY
* created by sarosh durrani
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT /BWN0/Z_PROJECT_SUMMERY.
TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF p_proj,
SNO TYPE int4,
* v_sno(6) type c,
pspid TYPE proj-pspid,
pspnr TYPE proj-pspnr,
ernam TYPE proj-ernam,
stspr TYPE proj-stspr,
pwhie TYPE proj-pwhie,
besta TYPE proj-besta,
scope TYPE proj-scope,
xstat TYPE proj-xstat,
postu TYPE proj-postu,
smprf TYPE proj-smprf,
erdat TYPE proj-erdat,
post1 TYPE proj-post1,
sakto TYPE afvc-sakto,
a type i,
b type i,
c type i,
END OF p_proj.
TYPES: BEGIN OF pl_afvc,
* SNO TYPE int4,
sakto TYPE afvc-sakto,
projn TYPE afvc-projn,
psphi TYPE prps-psphi,
END OF pl_afvc.
*DATA: IT_PRPS TYPE TABLE OF PRPS.
DATA: it_proj TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,
it_afvc TYPE STANDARD TABLE OF pl_afvc WITH HEADER LINE,
wa_proj TYPE p_proj,
VSNO TYPE INT4.
*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.
data : it_event TYPE slis_t_event ,
* wa_fld TYPE slis_fieldcat_alv ,
heading TYPE slis_t_listheader,
wa_event TYPE slis_alv_event .
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
PERFORM eventtab_build USING it_event.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
VSNO = VSNO + 1.
* it_proj-SNO = VSNO.
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 5.
* fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-just = 'L'.
* fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 50.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'A'.
fieldcatalog-seltext_m = 'A'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'B'.
fieldcatalog-seltext_m = 'B'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'C'.
fieldcatalog-seltext_m = ' C = Sum a + b'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_m = 'Quantity'.
fieldcatalog-col_pos = 6.
fieldcatalog-outputlen = 20.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STSPR'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PWHIE'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BESTA'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 9.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SCOPE'.
fieldcatalog-seltext_m = 'Crane'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XSTAT'.
fieldcatalog-seltext_m = 'Total'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PSPID'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 12.
* fieldcatalog-outputlen = 15.
* fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SMPRF'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 13.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 14.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POST1'.
fieldcatalog-seltext_m = 'Erection1'.
fieldcatalog-col_pos = 15.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SAKTO'.
fieldcatalog-seltext_m = 'Cost Element'.
fieldcatalog-col_pos = 16.
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-colwidth_optimize = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
* gd_layout-expand_fieldname = 'EXPAND'.
* gd_layout-window_titlebar = 'Hierarchical ALV list display'.*
* gd_layout-lights_tabname = 'IT_PROJ'.
* gd_layout-colwidth_optimize = 'X'.
* gd_LAYOUT-no_colhead = 'X' .
endform. " BUILD_LAYOUT " 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_tab_group
IT_EVENTS = it_event[]
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_proj
* t_outtabnew = it_prps
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 PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF ERDAT from proj into corresponding fields of table it_proj.
select * from proj into corresponding fields of table it_proj.
select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps
ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .
LOOP AT it_proj INTO wa_proj .
wa_proj-sno = sy-tabix.
wa_proj-a = sy-tabix.
wa_proj-b = sy-tabix * 3.
wa_proj-c = wa_proj-a + wa_proj-b.
READ TABLE it_afvc with key psphi = wa_proj-pspnr .
IF sy-SUBRC eq 0.
wa_proj-sakto = it_afvc-sakto.
ENDIF.
MODIFY it_proj FROM wa_proj TRANSPORTING SNO sakto a b c .
CLEAR wa_proj.
ENDLOOP.
endform. " DATA_RETRIEVAL
*up to 10 rows
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
*&---------------------------------------------------------------------*
*& Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LT_EVENTS text
*----------------------------------------------------------------------*
FORM eventtab_build USING lt_events TYPE slis_t_event.
DATA : wa_event TYPE slis_alv_event .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
et_events = lt_events.
READ TABLE lt_events INTO wa_event
WITH KEY name = slis_ev_after_line_output .
wa_event-form = slis_ev_after_line_output .
MODIFY lt_events FROM wa_event INDEX sy-tabix .
READ TABLE lt_events INTO wa_event
WITH KEY name = slis_ev_top_of_page .
wa_event-form = slis_ev_top_of_page .
MODIFY lt_events FROM wa_event INDEX sy-tabix .
ENDFORM. "EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
"Uline for creating a horizontal line
ULINE AT 1(199) .
"Format color for header background
FORMAT COLOR 4 .
WRITE: / sy-vline ,
15 SY-VLINE, 47 SY-VLINE , 68 sy-vline ,69 'Quantity' , 77 sy-vline , 94 'Unit Cost', 121 sy-vline, 154 'Amount' , 199 sy-vline .
ENDFORM. "top_of_page
regards ,
yogendra bhaskar
ā2012 Aug 01 7:21 AM
Hi,
Currently i have a query which is fetching data from two tables, now i want to fetch data form 3tables
Below is my query
select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps
ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .
New Field Name: usr05
new Table name from which field come: afvgd
Please guide me
Regards
ā2012 Aug 01 7:39 AM
hi sarosh ,
afvgd is a structure , i guess the field USR05 can be obtained from table AFVU .
regards ,
Yogendra Bhaskar
ā2012 Aug 01 7:47 AM
Yes that field can be obtained from there, Now please add this in my inner join query and let me know what will be the query for that?
Regards
ā2012 Aug 01 8:12 AM
hi sarosh ,
I suppose you require this ,
select afvc~sakto afvc~projn prps~psphi afvu~usr05
FROM ( ( afvc INNER JOIN prps ON AFVC~PROJN = PRPS~PSPNR )
INNER JOIN afvu on afvu~AUFPL = afvc~AUFPL and afvu~APLZL = afvc~APLZL )
into corresponding fields of table it_afvc
FOR ALL ENTRIES IN it_proj
WHERE PRPS~PSPHI = it_PROJ-PSPNR .
regards ,
Yogendra Bhaskar