2007 Jan 04 3:01 PM
I have to create a report program the required output of which is following.
1)
Vendors Company codes Fiscal year/period1 Fiscal year/period2 Total
1000000 0010
0020
0030
0040
Subtotal
1000001 0010
0020
0030
0040
Subtotal
Total
The number of fiscal periods change depending on the number of entries on the selection screen. For example following dynamic table will be created for two fiscal periods
VENDOR USERID CO_CODE 2005/05 2005/06 TOTAL
Now I have to enter the number of documents created in these fiscal periods based on a query of BKPF and BSEG. I have created another internal table ITAB that contains info from these tables. The structure of ITAB is as follows
BELNR BUKRS GJAHR MONAT USNAM LIFNR BLART TCODE
How do I select the information from this table and populate the dynamic table?
I have to create a report program the required output of which is following.
1)
Vendors Company codes Fiscal year/period1 Fiscal year/period2 Total
1000000 0010
0020
0030
0040
Subtotal
1000001 0010
0020
0030
0040
Subtotal
Total
The number of fiscal periods change depending on the number of entries on the selection screen. For example following dynamic table will be created for two fiscal periods
VENDOR USERID CO_CODE 2005/05 2005/06 TOTAL
Now I have to enter the number of documents created in these fiscal periods based on a query of BKPF and BSEG. I have created another internal table ITAB that contains info from these tables. The structure of ITAB is as follows
BELNR BUKRS GJAHR MONAT USNAM LIFNR BLART TCODE
How do I select the information from this table and populate the dynamic table?
2007 Jan 04 4:23 PM
Hi.
First thought.
Will the output be ALV?
If so, then you may not need a dynamic table.
You could have a table that allows for a maximum number of periods (60 say), and use however many of these columns that you need.
Then you simply do not include the unused columns in your field catalog.
OK, you may have some tricky work to do figuring out which period column to assign to, doing these assignments (use field-symbols), and creating the column headings in the field catalog, but it would not be too bad.
The limitation to 60 periods (or however many) is not elegant, I agree.
John
2007 Jan 04 9:27 PM
Do you mean I cannot use ALV with a dynamic table?
Can you please tell me how to use the field symbols? I dont know exactly how I can do it. Here is my code......Please see FORM process_data.
REPORT Z_FIR_NO_INV_USER_IDS_VENDORS.
TABLES: BSEG, BKPF, SKAT, CEPCT, CSKT.
******selection screen************************************************
SELECT-OPTIONS: co_code FOR BKPF-BUKRS OBLIGATORY,
vendor FOR BSEG-lifnr,
fis_year FOR BKPF-GJAHR NO-DISPLAY,
period for BKPF-MONAT NO-DISPLAY,
tran_cod for BKPF-TCODE NO-DISPLAY,
doc_type for BKPF-blart NO-DISPLAY.
************************************************************************
*******data and internal table declarations***************************
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
DATA: BEGIN OF IBKPF OCCURS 10,
BELNR LIKE BKPF-BELNR, " Accounting document number
BUKRS LIKE BKPF-BUKRS, " Company code
GJAHR LIKE BKPF-GJAHR, " Fiscal Year Range
monat like BKPF-MONAT, " Period
usnam like BKPF-USNAM, " Username
blart like BKPF-blart, " document type
tcode like bkpf-tcode, " transaction code
END OF IBKPF.
DATA: BEGIN OF IBSEG OCCURS 10,
BELNR LIKE BSEG-BELNR, "Document #
LIFNR LIKE BSEG-LIFNR, "Vendor
END OF IBSEG.
DATA: BEGIN OF ITAB OCCURS 10,
BELNR LIKE BKPF-BELNR, " Accounting document number
BUKRS LIKE BKPF-BUKRS, " Company code
GJAHR LIKE BKPF-GJAHR, " Fiscal Year Range
MONAT LIKE BKPF-MONAT, " Period
USNAM LIKE BKPF-USNAM, " Username
LIFNR LIKE BSEG-LIFNR, " Vendor
blart like BKPF-blart, " document type
tcode like bkpf-tcode, " transaction code
END OF ITAB.
FOR number of periods in fiscal periods determination.
data: t_spbup type spbup.
data: begin of ispbup occurs 0,
spbup type spbup,
ind type i,
end of ispbup.
data: year(4) type c,
year_beg(4) type c,
year_end(4) type c,
per(2) type n.
data: tot_periods type i.
select-options: s_spbup for t_spbup.
FOR alv (LIST VIEWER)
type-pools: slis.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
DATA per_mon(6) type c.
**********************************************************
FOR SORT OPTIONS OF REPORT
PARAMETERS: sort_ven RADIOBUTTON GROUP rad1, "sort by vendors
sort_usr RADIOBUTTON GROUP rad1. " sort by users
DATA ind(2) type c.
***********************************************************************
INITIALIZATION.
********************************************************************
tran_cod-sign = 'I'.
tran_cod-option = 'EQ'.
tran_cod-low = 'MIRO'.
append tran_cod.
tran_cod-sign = 'I'.
tran_cod-option = 'EQ'.
tran_cod-low = 'MR8M'.
append tran_cod.
doc_type-sign = 'I'.
doc_type-option = 'EQ'.
doc_type-low = 'RE'.
append doc_type.
doc_type-sign = 'I'.
doc_type-option = 'EQ'.
doc_type-low = 'KR'.
append doc_type.
doc_type-sign = 'I'.
doc_type-option = 'EQ'.
doc_type-low = 'KG'.
append doc_type.
doc_type-sign = 'I'.
doc_type-option = 'EQ'.
doc_type-low = 'KA'.
append doc_type.
************************************************************************
START-OF-SELECTION.
************************************************************************
PERFORM DETERMINE_FISCAL_PERIODS.
PERFORM build_dyn_itab.
PERFORM transfer_data_into_int_table.
PERFORM process_data.
PERFORM ALV_OUTPUT.
************************************************************************
END-OF-SELECTION.
************************************************************************
PERFORM write_data.
&----
*& Form TRANSFER_DATA_INTO_INTERNAL_TA
&----
text
----
--> p1 text
<-- p2 text
----
FORM transfer_data_into_int_table.
SELECT BELNR
BUKRS
GJAHR
MONAT
USNAM
BLART
TCODE
INTO TABLE IBKPF
FROM BKPF
WHERE BUKRS IN co_code
AND GJAHR IN fis_year
AND MONAT IN period
AND TCODE IN tra n_cod
and blart in doc_type.
Check NOT ibkpf[] is initial.
loop at IBKPF.
concatenate IBKPF-GJAHR IBKPF-MONAT into per_mon.
if NOT per_mon in s_spbup.
delete IBKPF.
endif.
endloop.
sort ibkpf by belnr.
SELECT BELNR
lifnr
FROM BSEG
INTO TABLE IBSEG
FOR ALL entries in IBKPF
WHERE BUKRS = IBKPF-BUKRS
AND BELNR = IBKPF-BELNR
AND GJAHR = IBKPF-GJAHR
AND lifnr in vendor.
sort ibseg by belnr.
ENDFORM.
&----
*& Form process_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM process_data.
loop at ibseg.
loop at ibkpf where belnr = ibseg-belnr.
ITAB-BELNR = iBKPF-BELNR. "Accounting document number
ITAB-BUKRS = iBKPF-BUKRS. "Company code
ITAB-GJAHR = iBKPF-GJAHR. "Fiscal Year
ITAB-MONAT = iBKPF-MONAT. "Period
ITAB-USNAM = iBKPF-USNAM. "Username
ITAB-LIFNR = IBSEG-LIFNR. "Vendor
ITAB-BLART = IBKPF-BLART. "DOC TYPE
ITAB-TCODE = IBKPF-TCODE. "TRAN. CODE
append itab.
CLEAR IBKPF.
endloop.
CLEAR ibseg.
endloop .
field-symbols.
if sort_ven = 'X'.
sort itab by lifnr descending bukrs.
LOOP AT ITAB.
ENDLOOP.
endif.
if sort_usr = 'X'.
sort itab by usnam bukrs.
LOOP AT ITAB.
ENDLOOP.
endif.
ENDFORM. " process_data
&----
*& Form ALV_OUTPUT
&----
text
----
--> p1 text
<-- p2 text
----
FORM ALV_OUTPUT.
-
" still need to put the output here.
ENDFORM. " ALV_OUTPUT
&----
*& Form build_dyn_itab
&----
text
----
--> p1 text
<-- p2 text
----
FORM build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'VENDOR'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
wa_it_fldcat-outputlen = 10.
append wa_it_fldcat to it_fldcat .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'USERID'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
wa_it_fldcat-outputlen = 10.
append wa_it_fldcat to it_fldcat .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'CO_CODE'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
wa_it_fldcat-OUTPUTLEN = 5.
append wa_it_fldcat to it_fldcat .
sort ispbup by spbup ascending.
LOOP AT ispbup.
clear wa_it_fldcat.
ind = sy-tabix.
wa_it_fldcat-fieldname = ispbup-spbup.
concatenate 'PERIOD' ind into wa_it_fldcat-fieldname.
wa_it_fldcat-fieldname = ispbup-spbup.
condense wa_it_fldcat-fieldname no-gaps.
wa_it_fldcat-REPTEXT = ispbup-spbup.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-outputlen = 6.
wa_it_fldcat-intlen = 6.
append wa_it_fldcat to it_fldcat .
endloop.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'TOTAL'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-outputlen = 5.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
ENDFORM. " build_dyn_itab
&----
*& Form DETERMINE_FISCAL_PERIODS
&----
text
----
--> p1 text
<-- p2 text
----
FORM DETERMINE_FISCAL_PERIODS.
year_beg = sy-datum+0(4).
year_beg = year_beg - 10.
year_end = year_beg + 20.
concatenate year_beg '00' into ispbup-spbup.
ispbup-spbup = '198000'.
append ispbup.
per = ispbup-spbup+4(2).
year = ispbup-spbup+0(4).
append ispbup.
do .
per = per + 1.
if per = 13.
per = 1.
year = year + 1.
endif.
if year gt year_end.
exit.
endif.
concatenate year per into ispbup-spbup.
append ispbup.
enddo.
loop at ispbup.
if not ispbup-spbup in s_spbup.
delete ispbup.
CONTINUE.
endif.
endloop.
describe table ispbup lines tot_periods.
loop at ispbup.
fis_year-sign = 'I'.
fis_year-option = 'EQ'.
fis_year-low = ispbup+0(4).
append fis_year.
clear fis_year.
period-sign = 'I'.
period-option = 'EQ'.
period-low = ispbup+4(2).
append period.
clear period.
endloop.
SORT FIS_YEAR BY LOW.
SORT PERIOD BY LOW.
DELETE ADJACENT DUPLICATES FROM fis_year.
DELETE ADJACENT DUPLICATES FROM period .
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |