Skip to Content
0
Former Member
Jul 25, 2012 at 04:46 AM

ALV query and data structure issue

28 Views

Hi,

I need to do subtotal in between ALV so please tell me how to do this, in the meantime kindly let me know how to get data from two tables, I have done but not getting desired result,

Firstly i get data from one table through query then from second table through query, Now i want to move data from second table to first internal table so i can populate it from a location to ALV,

Below is my program kindly tell me where to add second internal table in structure or data i think i am making mistake in making data or structure

My First Database table is "afvc" it_proj

My secod database tbale is "proj" mess up what to do here

after getting data io want to merge them in a single internal table

*&---------------------------------------------------------------------*

*& 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,

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,

END OF p_proj.

TYPES: BEGIN OF pl_proj,

SNO TYPE int4,

sakto TYPE afvc-sakto,

END OF p_proj.

*DATA: IT_PRPS TYPE TABLE OF PRPS.

DATA: it_proj TYPE STANDARD TABLE OF p_proj,

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 = 10.

fieldcatalog-emphasize = 'C170'.

fieldcatalog-key = 'X'.

fieldcatalog-do_sum = 'X'.

fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'PSPID'.

fieldcatalog-seltext_m = 'Description'.

fieldcatalog-col_pos = 2.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'C170'.

fieldcatalog-key = 'X'.

fieldcatalog-do_sum = 'X'.

fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'ERNAM'.

fieldcatalog-seltext_m = 'Quantity'.

fieldcatalog-col_pos = 3.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'STSPR'.

fieldcatalog-seltext_m = 'Ex-Factory'.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'PWHIE'.

fieldcatalog-seltext_m = 'Delivery'.

fieldcatalog-col_pos = 5.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'BESTA'.

fieldcatalog-seltext_m = 'Erection'.

fieldcatalog-col_pos = 6.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'SCOPE'.

fieldcatalog-seltext_m = 'Crane'.

fieldcatalog-col_pos = 7.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'XSTAT'.

fieldcatalog-seltext_m = 'Total'.

fieldcatalog-col_pos = 8.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'POSTU'.

fieldcatalog-seltext_m = 'Ex-Factory'.

fieldcatalog-col_pos = 9.

* fieldcatalog-outputlen = 15.

* fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'SMPRF'.

fieldcatalog-seltext_m = 'Delivery'.

fieldcatalog-col_pos = 10.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'ERDAT'.

fieldcatalog-seltext_m = 'Erection'.

fieldcatalog-col_pos = 11.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'POST1'.

fieldcatalog-seltext_m = 'Erection1'.

fieldcatalog-col_pos = 12.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'SAKTO'.

fieldcatalog-seltext_m = 'Cost Element'.

fieldcatalog-col_pos = 13.

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'.

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

*&---------------------------------------------------------------------*

*& 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 * from afvc into corresponding fields of table it_proj.

MOVE GTab-bukrs TO GLTab-bukrs.

MOVE GTab-gjahr TO GLTab-gjahr.

MOVE GTab-BELNR TO GLTab-BELNR.

MOVE GTab-BLART TO GLTab-BLART.

MOVE GTab-LTEXT TO GLTab-LTEXT.

MOVE GTab-BLDAT TO GLTab-BLDAT.

MOVE GTab-BUDAT TO GLTab-BUDAT.

MOVE GTab-XBLNR TO GLTab-XBLNR.

MOVE GTab-BKTXT TO GLTab-BKTXT.

MOVE GTab-USNAM TO GLTab-USNAM.

MOVE GTab-CPUDT TO GLTab-CPUDT.

MOVE GTab-STBLG TO GLTab-STBLG.

* SELECT ERDAT INTO proj-erdat "Cost Center Id and Description

* FROM PRPS. "AND SPRAS = 'E'.

*ENDSELECT.

LOOP AT it_proj INTO wa_proj .

wa_proj-sno = sy-tabix.

MODIFY it_proj FROM wa_proj TRANSPORTING SNO .

CLEAR wa_proj.

ENDLOOP.

*select ERDAT from prps into corresponding fields of table it_proj.

*select * from prps into corresponding fields of table it_PRPS.

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.

Attachments

Untitled.jpg (46.6 kB)