Sum of one column of an internal table
Hi All,
I have an internal table with two columns.
First column is having standard taxt "ZSSS" (for all rows).
The second column is having Amount value.
Internal table might have multiple lines with this structure.
Now i would like to sum the second column which is having Amount value.
How to code to get the sum in such scenario?
Your help will be appreciated.....
Regards
Pavan
Hi
This is possible with COntrol Break Stamnts\Check below Code for example..
DATA: BEGIN OF line,
carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
fldate TYPE sbook-fldate,
custtype TYPE sbook-custtype,
class TYPE sbook-class,
bookid TYPE sbook-bookid,
END OF line.
DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY table_line.
SELECT carrid connid fldate custtype class bookid
FROM sbook INTO CORRESPONDING FIELDS OF TABLE itab.
LOOP AT itab INTO line.
AT FIRST.
WRITE / 'List of Bookings'.
ULINE.
ENDAT.
AT NEW carrid.
WRITE: / 'Carrid:', line-carrid.
ENDAT.
AT NEW connid.
WRITE: / 'Connid:', line-connid.
ENDAT.
AT NEW fldate.
WRITE: / 'Fldate:', line-fldate.
ENDAT.
AT NEW custtype.
WRITE: / 'Custtype:', line-custtype.
ENDAT.
WRITE: / line-bookid, line-class.
AT END OF class.
ULINE.
ENDAT.
ENDLOOP.
Hope it helps.
Praveen
Similar Messages
-
Introduction
In SQL Server Reporting Services, we can define a mapping between the fields that are returned in the query to specific delivery options and to report parameters in a data-driven subscription.
For a report with a parameter (such as YEAR) that allow multiple values, when creating a data-driven subscription, how can we pass a record like below to show correct data (data for year 2012, 2013 and 2014).
EmailAddress Parameter
Comment
[email protected] 2012,2013,2014 NULL
In this article, I will demonstrate how to configure a Data Driven Subscription which get multi-value parameters from one column of a database table
Workaround
Generally, if we pass the “Parameter” column to report directly in the step 5 when creating data-driven subscription.
The value “2012,2013,2014” will be regarded as a single value, Reporting Services will use “2012,2013,2014” to filter data. However, there are no any records that YEAR filed equal to “2012,2013,2014”, and we will get an error when the subscription executed
on the log. (C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\LogFiles)
Microsoft.ReportingServices.Diagnostics.Utilities.InvalidReportParameterException: Default value or value provided for the report parameter 'Name' is not a valid value.
This means that there is no such a value on parameter’s available value list, this is an invalid parameter value. If we change the parameter records like below.
EmailAddress Parameter Comment
[email protected] 2012 NULL
[email protected] 2013 NULL
[email protected] 2014 NULL
In this case, Reporting Services will generate 3 reports for one data-driven subscription. Each report for only one year which cannot fit the requirement obviously.
Currently, there is no a solution to solve this issue. The workaround for it is that create two report, one is used for view report for end users, another one is used for create data-driven subscription.
On the report that used create data-driven subscription, uncheck “Allow multiple values” option for the parameter, do not specify and available values and default values for this parameter. Then change the Filter
From
Expression:[ParameterName]
Operator :In
Value :[@ParameterName]
To
Expression:[ParameterName]
Operator :In
Value :Split(Parameters!ParameterName.Value,",")
In this case, we can specify a value like "2012,2013,2014" from database to the data-driven subscription.
Applies to
Microsoft SQL Server 2005
Microsoft SQL Server 2008
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2012
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.For every Auftrag, there are multiple Position entries.
Rest of the blocks don't seems to have any relation.
So you can check this code to see how internal table lt_str is built whose first 3 fields have data contained in Auftrag, and next 3 fields have Position data. The structure is flat, assuming that every Position record is related to preceding Auftrag.
Try out this snippet.
DATA lt_data TYPE TABLE OF string.
DATA lv_data TYPE string.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = 'C:\temp\test.txt'
CHANGING
data_tab = lt_data
EXCEPTIONS
OTHERS = 19.
CHECK sy-subrc EQ 0.
TYPES:
BEGIN OF ty_str,
a1 TYPE string,
a2 TYPE string,
a3 TYPE string,
p1 TYPE string,
p2 TYPE string,
p3 TYPE string,
END OF ty_str.
DATA: lt_str TYPE TABLE OF ty_str,
ls_str TYPE ty_str,
lv_block TYPE string,
lv_flag TYPE boolean.
LOOP AT lt_data INTO lv_data.
CASE lv_data.
WHEN '[Version]' OR '[StdSatz]' OR '[Arbeitstag]' OR '[Pecunia]'
OR '[Mita]' OR '[Kunde]' OR '[Auftrag]' OR '[Position]'.
lv_block = lv_data.
lv_flag = abap_false.
WHEN OTHERS.
lv_flag = abap_true.
ENDCASE.
CHECK lv_flag EQ abap_true.
CASE lv_block.
WHEN '[Auftrag]'.
SPLIT lv_data AT ';' INTO ls_str-a1 ls_str-a2 ls_str-a3.
WHEN '[Position]'.
SPLIT lv_data AT ';' INTO ls_str-p1 ls_str-p2 ls_str-p3.
APPEND ls_str TO lt_str.
ENDCASE.
ENDLOOP. -
Adding a column in an internal table
Hi,
I want to know how to add different rows of a column in an internal table.
My code :
Declaration Part-----
types : begin of imchb,
clabs like mchb-clabs,
cumlm like mchb-cumlm,
cinsm like mchb-cinsm,
tot_val_stock type p decimals 3,
pm_percent type p decimals 6,
end of imchb.
data : int_inv type standard table of imchb with header line,
wa_inv like line of int_inv.
Then I do few calculations and display it in the column pm_percent.
Now I want to sum this column.
Summation---
loop
at int_inv into wa_inv.
at end of pm_percent.
sum.
endat.
endloop.
write :/ wa_inv-pm_percent.
However , wa_inv-pm_percent only gives me the value of the last row of the column.
Kindly suggest .Hi,
Please try this code:
loop at int_inv into wa_inv.
lv_count = lv_count + 1.
AT END OF posnr. <------- The field you want to sum..
gs_total-posnr = wa_inv-posnr.
gs_total-cov_total = lv_count.
APPEND gs_total TO gt_total.
CLEAR : gs_total,
lv_count,
wa_inv.
ENDAT.
ENDLOOP. -
Copy columns of an internal table
hi,
i want to copy columns of an internal table into another internal table, now i loop the original table to one workarea and then get the field i need, and then append to destination table.
is there any more effective way ?hi,
use move corresponding statement.
Example:
MOVE-CORRESPONDING ADDRESS TO NAME.
and also use
<itab2> = <itab1>.
*if useful reward with points.* -
How to find the number of columns in an internal table DYNAMICALLY ?
Hi,
How to find the number of columns in an internal table DYNAMICALLY ?
Thanks and Regards,
saleem.Hi,
you can find the number of columns and their order using
the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif
now describe your fieldcat . and find no of columns.
and their order also..
regards
vijay -
Moving columns of an internal table to rows of an another internal table.
Hi
i have an internal table with 20 fields for single record .Now i need to move the 20 fields
(of similar length) of single record into internal table with those 20 fields as 20 records i.e i need to make rows of first internal table into columns of second internal table.
hope iam clear.HI Deepthi,
Try with this Logic...
IF NOT ITAB[] IS INITIAL.
LOOP AT ITAB FROM 7.
ITAB2-FIELD1 = ITAB-FIELD1.
ITAB2-FIELD2 = ITAB-FIELD2.
APPEND : ITAB2.
CLEAR : ITAB2.
ENDLOOP.
DO 27 TIMES.
CASE CNT.
WHEN '1'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD6.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD6.
WHEN '2'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD7.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD7.
WHEN '3'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD8.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD8.
WHEN '4'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD9.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD9.
WHEN '5'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD10.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD10.
WHEN '6'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD11.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD11.
WHEN '7'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD12.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD12.
WHEN '8'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD13.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD13.
WHEN '9'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD14.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD14.
WHEN '10'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD15.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD15.
WHEN '11'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD16.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD16.
WHEN '12'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD17.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD17.
WHEN '13'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD18.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD18.
WHEN '14'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD19.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD19.
WHEN '15'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD20.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD20.
WHEN '16'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD21.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD21.
WHEN '17'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD22.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD22.
WHEN '18'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD23.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD23.
WHEN '19'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD24.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD24.
WHEN '20'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD25.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD25.
WHEN '21'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD26.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD26.
WHEN '22'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD27.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD27.
WHEN '23'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD28.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD28.
WHEN '24'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD29.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD29.
WHEN '25'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD30.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD30.
WHEN '26'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD31.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD31.
WHEN '27'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD32.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD32.
WHEN '28'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD33.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD33.
WHEN '29'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD34.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD34.
WHEN '30'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD35.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD35.
WHEN '31'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD36.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD36.
WHEN '32'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD37.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD37.
WHEN '33'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD38.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD38.
WHEN '34'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD39.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD39.
WHEN '35'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD40.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD40.
WHEN '36'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD41.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD41.
WHEN '37'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD42.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD42.
WHEN '38'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD43.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD43.
WHEN '39'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD44.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD44.
WHEN '40'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD45.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD45.
WHEN '41'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD46.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD46.
WHEN '42'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD47.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD47.
WHEN '43'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD48.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD48.
WHEN '44'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD49.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD49.
WHEN '45'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD50.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD50.
WHEN '46'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD51.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD51.
WHEN '47'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD52.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD52.
WHEN '48'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD53.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD53.
WHEN '49'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD54.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD54.
WHEN '50'.
READ TABLE ITAB INDEX 4.
ITAB3-FIELD1 = ITAB-FIELD55.
READ TABLE ITAB INDEX 5.
ITAB3-FIELD2 = ITAB-FIELD55.
ENDCASE.
APPEND ITAB3.
CLEAR ITAB3.
CNT = CNT + 1.
ENDDO.
ENDIF.
ENDIF.
Regards,
Santosh -
Sum two different columns from two different tables
Can you select and sum two different columns, from two different tables in the same sql statement?
i.e.
table1
Item----OnHand_Qty
A--------10
A--------15
B--------10
B--------10
C--------20
table2
Item----Trx_Qty
A--------2
A--------4
A--------6
B--------1
B--------1
C--------4
I'm looking for the following results from a query
Item----Sum(Onhand_Qty)---Sum(Trx_Qty)
A--------25Like this?
SQL> create table table1 (item,onhand_qty)
2 as
3 select 'A', 10 from dual union all
4 select 'A', 15 from dual union all
5 select 'B', 10 from dual union all
6 select 'B', 10 from dual union all
7 select 'C', 20 from dual union all
8 select 'D', 30 from dual
9 /
Tabel is aangemaakt.
SQL> create table table2 (item, trx_qty)
2 as
3 select 'A', 2 from dual union all
4 select 'A', 4 from dual union all
5 select 'A', 6 from dual union all
6 select 'B', 1 from dual union all
7 select 'B', 1 from dual union all
8 select 'C', 4 from dual union all
9 select 'E', 3 from dual
10 /
Tabel is aangemaakt.
SQL> select nvl(t1.item,t2.item) item
2 , t1.sum_onhand_qty
3 , t2.sum_trx_qty
4 from ( select item, sum(onhand_qty) sum_onhand_qty
5 from table1
6 group by item
7 ) t1
8 full outer join
9 ( select item, sum(trx_qty) sum_trx_qty
10 from table2
11 group by item
12 ) t2
13 on (t1.item = t2.item)
14 /
I SUM_ONHAND_QTY SUM_TRX_QTY
A 25 12
B 20 2
C 20 4
E 3
D 30
5 rijen zijn geselecteerd.Regards,
Rob. -
Change the Value of column of the internal table at run time
Hello Experts,
With the below code i am able to determine the value hold
by internal table at run time for a sepcific column but i am not getting the way
of how to update the internal if one of the value is changed,
lr_desc_table ?= cl_abap_typedescr=>describe_by_data( itab ).
lr_desc_struc ?= lr_desc_table->get_table_line_type( ).
loop at itab assigning <fs_data>.
loop at lr_desc_struc->components ASSIGNING <fs_comp_wa>.
assign component <fs_comp_wa>-name of structure <fs_data> to <fs_field>.
lv_excel_row = <fs_field>.
CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
EXPORTING
INTEXT = lv_excel_row
IMPORTING
OUTTEXT = lv_excel_row.
assign lv_excel_row to <fs_field>. "this is not changing the value actually hold in internal table
endloop.
endloop.Hi,
Resolved this issue with the code mentioned below.
Code:
loop at lt_export_items assigning <fs_data>.
ls_data = <fs_data>.
loop at lr_desc_struc->components ASSIGNING <fs_comp_wa>.
assign component <fs_comp_wa>-name of structure <fs_data> to <fs_field>.
lv_excel_row = <fs_field>.
CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
EXPORTING
INTEXT = lv_excel_row
IMPORTING
OUTTEXT = lv_excel_row.
concatenate 'ls_data-' <fs_comp_wa>-name into lv_var.
assign (lv_var) to <fs_var>.
<fs_var> = lv_excel_row.
endloop.
modify lt_export_items from ls_data .
clear:ls_data.
endloop.
Take care,
Sanju -
Key column in an internal table?
Hi all,
Can somebody tell me, if it is possible to create an internal table with a key-column?
I think it is, but I do not know how? So, How can I make it? Does this keys work exactly like DB table keys?
Thanks,
MPMI'm not sure if it is correct that sorted tables can only have unique keys.
The table keys are important for access:
1. Every table with character fields have got a key by (SAP) definition. An unsorted standard table's key consists of all non-numeric fields. In this case the access will be sequential except for a binary search.
2. Sorted tables may have one unique or non-unique key consisting odf one or more fields. If the key is not unique, the entry with the lowest index is accessed.
3. Only Hash tables require a unique key
4. Only one key per internal table is allowed (no secondary keys as in other programming languages or database definitions).
5. See also:
http://help.sap.com/saphelp_47x200/helpdata/en/90/8d7325b1af11d194f600a0c929b3c3/frameset.htm
regards,
Clemens -
Adding Specific columns of dynamic internal table row into another column
Hi Gurus,
I need to add few columns of a dynamic internal table row into another column:
Article description hy01 hy02 total
101 panza 10 12 22
102 masht 12 12 24
dynamic internal table is created and columns hy01 hy02.... can increase
How to add the the values in hy01 hy 02... into total.
Regards,
DepHi,
If you really want to have a dynamic table, then you will have to find a way to generate a whole new table, and then copy the data from the old table to the new one. There is no way to modify a type during runtime in ABAP.
Here an example how to generate a dynamic table based on another internal table, hope this will help you.
TYPE-POOLS: slis.
PARAMETERS: p_nb_hy TYPE i DEFAULT 2. "Number of new HY columns to be added
* Type ZST_T:
* matnr TYPE matnr
* maktx TYPE maktx
* hy01 TYPE i
* total TYPE i
TYPES: ty_t TYPE STANDARD TABLE OF zst_s.
PERFORM main.
*& Form main
* text
FORM main.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_t TYPE ty_t,
lr_new_t TYPE REF TO data.
FIELD-SYMBOLS: <lt_new_t> TYPE STANDARD TABLE.
"Add some lines to LT_T just to have something to display on screen
DO 10 TIMES.
APPEND INITIAL LINE TO lt_t.
ENDDO.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZST_S'
CHANGING
ct_fieldcat = lt_fieldcat.
"Copy LT_T to LR_NEW_T
PERFORM extend_and_copy_table USING lt_t p_nb_hy CHANGING lr_new_t lt_fieldcat.
CLEAR lt_t. "Not needed anymore...
ASSIGN lr_new_t->* TO <lt_new_t>.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = lt_fieldcat
TABLES
t_outtab = <lt_new_t>.
ENDFORM. "main
*& Form extend_and_copy_table
FORM extend_and_copy_table USING ut_t TYPE STANDARD TABLE
uv_nb_hy TYPE i
CHANGING cr_t TYPE REF TO data
ct_fieldcat TYPE slis_t_fieldcat_alv
RAISING cx_sy_struct_creation cx_sy_table_creation.
DATA: lo_tabledescr TYPE REF TO cl_abap_tabledescr,
lo_structdescr TYPE REF TO cl_abap_structdescr,
lo_new_structdescr TYPE REF TO cl_abap_structdescr,
lo_new_tabledescr TYPE REF TO cl_abap_tabledescr,
lt_components TYPE cl_abap_structdescr=>component_table,
ls_component TYPE cl_abap_structdescr=>component,
lv_field_cnt TYPE numc2,
ls_fieldcat TYPE slis_fieldcat_alv,
lr_fieldcat TYPE REF TO slis_fieldcat_alv.
FIELD-SYMBOLS: <ls_old_s> TYPE ANY,
<lt_new_t> TYPE STANDARD TABLE,
<ls_new_s> TYPE ANY.
"Get the list of all components from UT_T line structure
lo_tabledescr ?= cl_abap_tabledescr=>describe_by_data( ut_t ).
lo_structdescr ?= lo_tabledescr->get_table_line_type( ).
lt_components = lo_structdescr->get_components( ).
"The new columns will be from type of column HY01
ls_component-type = lo_structdescr->get_component_type( 'HY01' ).
"The new columns will have the same fieldcat info as column HY01
READ TABLE ct_fieldcat INTO ls_fieldcat WITH KEY fieldname = 'HY01'.
"HY<lv_field_cnt> = new field name
lv_field_cnt = uv_nb_hy + 1.
"For each new column...
DO uv_nb_hy TIMES.
"Generate the new column field name
CONCATENATE 'HY' lv_field_cnt INTO ls_component-name.
ls_fieldcat-fieldname = ls_component-name.
"Add the new field to the components of the new structure
INSERT ls_component INTO lt_components INDEX 4.
"Add the new field's fieldcat info to the fieldcat
INSERT ls_fieldcat INTO ct_fieldcat INDEX 4.
lv_field_cnt = lv_field_cnt - 1.
ENDDO.
"Adjust the COL_POS from fieldcat
LOOP AT ct_fieldcat REFERENCE INTO lr_fieldcat.
lr_fieldcat->col_pos = sy-tabix.
ENDLOOP.
"Create the new table
lo_new_structdescr = cl_abap_structdescr=>create( p_components = lt_components ).
lo_new_tabledescr = cl_abap_tabledescr=>create( p_line_type = lo_new_structdescr ).
CREATE DATA cr_t TYPE HANDLE lo_new_tabledescr.
ASSIGN cr_t->* TO <lt_new_t>.
"Copy all data from old to new table
LOOP AT ut_t ASSIGNING <ls_old_s>.
APPEND INITIAL LINE TO <lt_new_t> ASSIGNING <ls_new_s>.
MOVE-CORRESPONDING <ls_old_s> TO <ls_new_s>.
ENDLOOP.
ENDFORM. "main -
Hide or Delete Empty columns in dynamic internal table
Hi,
I am having an dynamic internal table which contains more than 100 columns.
I need to delete empty column from that table, can any one help this.Hello,
If you are talking about ALV then you can just the the table for empty columns before populating fieldcataloge and hide the columns.
If your query is still not answered please provide a detail requirement. -
Shortcut object in Sunopsis- Adding one column in multiple aggregate tables
Hello,
We have a situation where we have existing aggregate tables. Now i need to add one column in common to all the aggregate tables(more than 10 aggregate tables). Is there some way out to do all at the same e.g. making some shortcut object or something else.Hi,
have you tried requesting the focus on your newly selected internal frame ? -
Subtract sum of two columns in two different tables and display balance for each row
Hello Friends,
I have the below 5 tables
1. STUDENT (STUDENT_ID, NAME)
2. DEPARTMENT (DEPT_ID, NAME, CONTACT_PERSON, PHONE)
3. SECTION (SECTION_ID,SNAME,DEPT_ID,Acad_LEVEL,SHIFT,TIME,ROOM)
4. TUITION_BILL (Seq_No, STUDENT_ID, DEPT_ID, Acad_Level, SECTION_ID, SEMESTER, Acad_Year, BILL_DATE, GROSS_AMT_DUE)
5. TUITION_PAYMENT (Seq_No,RECEIPT_NO,STUDENT_ID,DEPT_ID,Acad_Level,SECTION_ID,SEMESTER,Acad_Year,SCHOLARSHIP,PAYMENT_DATE,PAYMENT_AMT,REFERENCE,REMARKS)
I wrote the following query
SELECT T.Seq_No,T.STUDENT_ID,S.NAME As STUDENT_NAME,d.name As DEPT,T.Acad_Level,c.SNAME As SECTION,
T.SEMESTER,T.[Acad_Year],BILL_DATE,GROSS_AMT_DUE,
COALESCE(SUM(T.GROSS_AMT_DUE),0)-COALESCE(SUM(PAY.PAYMENT_AMT),0)- COALESCE(SUM(PAY.SCHOLARSHIP),0) As BALANCE
FROM TUITION_BILL T JOIN STUDENT S ON S.STUDENT_ID=T.STUDENT_ID join DEPARTMENT d on d.DEPT_ID=T.DEPT_ID
join SECTION c on c.SECTION_ID=T.SECTION_ID LEFT JOIN (SELECT DISTINCT STUDENT_ID,COALESCE(SUM(p.PAYMENT_AMT),0) As PAYMENT_AMT,
COALESCE(SUM(P.SCHOLARSHIP),0) As SCHOLARSHIP FROM TUITION_PAYMENT p GROUP BY p.STUDENT_ID) As PAY ON PAY.STUDENT_ID=T.STUDENT_ID
WHERE s.STUDENT_ID='138218' GROUP BY T.Seq_No,T.STUDENT_ID,S.NAME,d.NAME,T.[Acad_Level],c.SNAME,T.SEMESTER,
T.[Acad_Year],BILL_DATE,GROSS_AMT_DUE,PAYMENT_AMT,SCHOLARSHIP
The above query shows the below output
Seq_No
STUDENT_ID
STUDENT_NAME
DEPT
Acad_Level
SECTION
SEMESTER
Acad_Year
BILL_DATE
GROSS_AMT_DUE
BALANCE
1
138218
Abdirahman Dhuh Gamadid
Agriculture and Veterinary
Year 2
2A
One
2014-2015
1/10/2014
200
0
5638
138218
Abdirahman Dhuh Gamadid
Agriculture and Veterinary
Year 2
2A
Two
2014-2015
3/20/2015
200
0
There are two records in the TUITION_BILL table with different Semesters and bill dates for the specified student_id and there is only one record in the TUITION_PAYMENT table which is the semester one payment record. Semester two payment record
is not recorded yet and I want to display the balance like the following output instead of the above output.
Seq_No
STUDENT_ID
STUDENT_NAME
DEPT
Acad_Level
SECTION
SEMESTER
Acad_Year
BILL_DATE
GROSS_AMT_DUE
BALANCE
1
138218
Abdirahman Dhuh Gamadid
Agriculture and Veterinary
Year 2
2A
One
2014-2015
1/10/2014
200
0
5638
138218
Abdirahman Dhuh Gamadid
Agriculture and Veterinary
Year 2
2A
Two
2014-2015
3/20/2015
200
200
The above query is working fine but I'm facing only one problem with it which its showing 0 balance for both records instead of different balances like the above desired output.
Please help me in getting the desired result.
Any help would be appreciated.
Thanks in advance,
MohamoudThanks a lot Pituach for your reply; below I posted the script for the database and table creation and inserting sample data into the tables.
CREATE
DATABASE TESTdb
GO
USE TESTdb
CREATE
TABLE [dbo].[STUDENT](
[STUDENT_ID] [int]
NOT NULL,
[NAME] [varchar](40)
NULL,
PRIMARY
KEY CLUSTERED
[STUDENT_ID]
ASC
)WITH
(PAD_INDEX
= OFF,
STATISTICS_NORECOMPUTE
= OFF,
IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS
= ON,
ALLOW_PAGE_LOCKS =
ON)
ON [PRIMARY]
ON [PRIMARY]
GO
SET
ANSI_PADDING OFF
GO
CREATE
TABLE [dbo].[DEPARTMENT](
[DEPT_ID] [int]
IDENTITY(1,1)
NOT NULL,
[NAME] [varchar](30)
NULL,
[CONTACT_PERSON] [varchar](40)
NULL,
[PHONE] [int]
NULL,
CONSTRAINT [PK__DEPARTME__512A59AC03317E3D]
PRIMARY KEY
CLUSTERED
[DEPT_ID]
ASC
)WITH
(PAD_INDEX
= OFF,
STATISTICS_NORECOMPUTE
= OFF,
IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS
= ON,
ALLOW_PAGE_LOCKS =
ON)
ON [PRIMARY]
ON [PRIMARY]
GO
SET
ANSI_PADDING OFF
GO
CREATE
TABLE [dbo].[SECTION](
[SECTION_ID] [int]
IDENTITY(1,1)
NOT NULL,
[SNAME] [varchar](40)
NOT NULL,
[DEPT_ID] [int]
NOT NULL,
[Acad_Level] [varchar](30)
NULL,
[SHIFT] [varchar](20)
NULL,
[TIME] [varchar](20)
NULL,
[ROOM] [varchar](20)
NULL,
CONSTRAINT [PK__SECTION__92F8069507020F21]
PRIMARY KEY
CLUSTERED
[SECTION_ID]
ASC,
[DEPT_ID]
ASC
)WITH
(PAD_INDEX
= OFF,
STATISTICS_NORECOMPUTE
= OFF,
IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS
= ON,
ALLOW_PAGE_LOCKS =
ON)
ON [PRIMARY]
ON [PRIMARY]
GO
SET
ANSI_PADDING OFF
GO
CREATE
TABLE [dbo].[TUITION_BILL](
[Seq_No] [int]
IDENTITY(1,1)
NOT NULL,
[STUDENT_ID] [int]
NOT NULL,
[DEPT_ID] [int]
NOT NULL,
[Acad_Level] [varchar](50)
NOT NULL,
[SECTION_ID] [int]
NOT NULL,
[SEMESTER] [varchar](50)
NOT NULL,
[Acad_Year] [varchar](50)
NOT NULL,
[BILL_DATE] [date]
NULL,
[GROSS_AMT_DUE] [decimal](18, 2)
NULL,
CONSTRAINT [PK_TUITION_BILL]
PRIMARY KEY
CLUSTERED
[STUDENT_ID]
ASC,
[DEPT_ID]
ASC,
[Acad_Level]
ASC,
[SEMESTER]
ASC,
[Acad_Year]
ASC
)WITH
(PAD_INDEX
= OFF,
STATISTICS_NORECOMPUTE
= OFF,
IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS
= ON,
ALLOW_PAGE_LOCKS =
ON)
ON [PRIMARY]
ON [PRIMARY]
GO
SET
ANSI_PADDING OFF
GO
CREATE
TABLE [dbo].[TUITION_PAYMENT](
[Seq_No] [int]
IDENTITY(1,1)
NOT NULL,
[RECEIPT_NO] [int]
NOT NULL,
[STUDENT_ID] [int]
NOT NULL,
[DEPT_ID] [int]
NOT NULL,
[Acad_Level] [varchar](50)
NOT NULL,
[SECTION_ID] [int]
NOT NULL,
[SEMESTER] [varchar](50)
NOT NULL,
[Acad_Year] [varchar](50)
NOT NULL,
[SCHOLARSHIP] [decimal](18, 2)
NULL,
[PAYMENT_DATE] [date]
NULL,
[PAYMENT_AMT] [decimal](18, 2)
NULL,
[REFERENCE] [varchar](50)
NULL,
[REMARKS] [varchar](max)
NULL,
CONSTRAINT [PK_TUITION_PAYMENT]
PRIMARY KEY
CLUSTERED
[Seq_No]
ASC
)WITH
(PAD_INDEX
= OFF,
STATISTICS_NORECOMPUTE
= OFF,
IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS
= ON,
ALLOW_PAGE_LOCKS =
ON)
ON [PRIMARY]
ON [PRIMARY]
GO
SET
ANSI_PADDING OFF
GO
USE TESTdb
INSERT
INTO STUDENT(STUDENT_ID,NAME)VALUES(138218,'Abdirahman
Dhuh Gamadid')
INSERT
INTO DEPARTMENT(NAME,CONTACT_PERSON,PHONE)VALUES('Agriculture
and Veterinary','Mohamoud Abdilahi','065')
INSERT
INTO SECTION(SNAME,DEPT_ID,Acad_Level,SHIFT,[TIME],ROOM)VALUES('2A',1,'Year
2','Morning','8:00-10:00','Room 1')
INSERT
INTO TUITION_BILL(STUDENT_ID,DEPT_ID,Acad_Level,SECTION_ID,SEMESTER,Acad_Year,BILL_DATE,GROSS_AMT_DUE)
VALUES(138218,1,'Year
2',1,'One','2014-2015','2014-09-10',200.00)
INSERT
INTO TUITION_BILL(STUDENT_ID,DEPT_ID,Acad_Level,SECTION_ID,SEMESTER,Acad_Year,BILL_DATE,GROSS_AMT_DUE)
VALUES(138218,1,'Year
2',1,'Two','2014-2015','2015-01-10',200.00)
INSERT
INTO TUITION_PAYMENT(RECEIPT_NO,STUDENT_ID,DEPT_ID,Acad_Level,SECTION_ID,SEMESTER,Acad_Year,SCHOLARSHIP,
PAYMENT_DATE,PAYMENT_AMT,REFERENCE,REMARKS)VALUES(1,138218,1,'Year
2',1,'One','2014-2015',0.00,'2014-10-10',200.00,'N','N') -
How to convert rows of internal table to columns of another internal table?
Hi,
Experts,
test_data.xls:
one two three four five
one two three four
one two three
one two
one
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = 'c:/test_data.xls'
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '10'
I_END_ROW = '10'
TABLES
INTERN = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
output:
0001 0001 one
0001 0002 two
0001 0003 three
0001 0004 four
0001 0005 five
0002 0001 one
0002 0002 two
0002 0003 three
0002 0004 four
0003 0001 one
0003 0002 two
0003 0003 three
0004 0001 one
0004 0002 two
0005 0001 one
but i want this format:
one two three four five
one two three four
one two three
one two
one
i don't want this type of output display i want to display in ABAP report as in file format how can i achieve this post some ideas on it.
Thank U,
Shabeer ahmed.Hi,
Use this piece of code :
parameters: p_flname type rlgrap-filename.
data:
li_filecontent type standard table of alsmex_tabline ,
lwa_filecontent type alsmex_tabline ,
lv_begin_col type i value 1,
lv_begin_row type i value 1,
lv_end_col type i value 17,
lv_end_row type i value 65000,
li_fieldlist type lvc_t_fcat,
li_data type ref to data,
dy_line type ref to data.
field-symbols:<dyntable> type standard table,
<fs_data> type ref to data,
<fs_1>,
<dyn_wa>,
<dyn_field>.
*Transfer excel file contents to internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_flname
i_begin_col = lv_begin_col
i_begin_row = lv_begin_row
i_end_col = lv_end_col
i_end_row = lv_end_row
tables
intern = li_filecontent
exceptions
inconsistent_parameters = 1
upload_ole = 2
error_message = 3
others = 4.
if sy-subrc = 0.
*Creating the list of fields in the table
perform f_create_tab_field tables li_fieldlist using 'BUKRS' 4 .
perform f_create_tab_field tables li_fieldlist using 'ZPOC_KUNNR' 10 .
perform f_create_tab_field tables li_fieldlist using 'RANL' 13.
perform f_create_tab_field tables li_fieldlist using 'ZPEDAT' 10 .
perform f_create_tab_field tables li_fieldlist using 'KWERT' 15 .
perform f_create_tab_field tables li_fieldlist using 'BONUS' 2 .
perform f_create_tab_field tables li_fieldlist using 'WAERS' 5 .
perform f_create_tab_field tables li_fieldlist using 'ZVAL' 15 .
perform f_create_tab_field tables li_fieldlist using 'ZQTY' 15 .
perform f_create_tab_field tables li_fieldlist using 'KMEIN' 3 .
assign li_data to <fs_data>.
*CREATING INTERNAL TABLE TO store data
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = li_fieldlist
importing
ep_table = <fs_data>
exceptions
generate_subpool_dir_full = 1
others = 2.
if sy-subrc = 0.
assign <fs_data>->* to <fs_1>.
assign <fs_1> to <dyntable>.
Create dynamic work area and assign to FS
create data dy_line like line of <dyntable>. " creating a line type of the table just created above
assign dy_line->* to <dyn_wa>. " creating the work area with reference to the line type
loop at li_filecontent into lwa_filecontent.
assign component lwa_filecontent-col "accessing corresponding field in the field catalog
of structure <dyn_wa> to <dyn_field>. "and assigning this field to a field symbol
if sy-subrc = 0.
<dyn_field> = lwa_filecontent-value. " filling value for this field
endif.
at end of row.
append <dyn_wa> to <dyntable>.
clear <dyn_wa>.
endat.
clear lwa_filecontent.
endloop.
i_input_file[] = <dyntable>.
endif.
elseif sy-subrc <> 0.
message s027 display like c_error with text-001.
stop.
endif.
form f_create_tab_field tables p_li_fieldlist structure lvc_s_fcat
using p_fname
p_lenght.
data:lwa_fieldlist type lvc_s_fcat.
lwa_fieldlist-fieldname = p_fname.
lwa_fieldlist-intlen = p_lenght.
append lwa_fieldlist to p_li_fieldlist.
clear lwa_fieldlist.
endform. " F_CREATE_TAB_FIELD
Regards,
Dev. -
Moving columns in an internal table
Hi Gurus,
I have this ALV program which displays the cost element and its corresponding groups (up to 10th level only).
My problem is on how to display the report where the first column is the cost element and the succeeding columns the cost element groups starting from the top level.
Below is example of a hierarchy of a given cost element ( 50030000 ).
EMPSTOTAL <---Top level
ESSPENDING
ES5003
ES5003P
50030000 <---Cost Element
Now, since the selection of data is from the cost element up to to the top level group.
The internal table would look like this:
Cost Element Group 1 Group 2 Group 3 Group 4 Group 5 Group 6 .......
50030000 ES5003P ES5003 ESSPENDING EMPSTOTAL (blank) (blank)......
But this output is wrong, what I really want is like this:
Cost Element Group 1 Group 2 Group 3 Group 4 Group 5 Group 6 .......
50030000 EMPSTOTAL ESSPENDING ES5003 ES5003P (blank) (blank)......
As you can see, what is placed next to the cost element is the Top level Group and the last is the group directly linked to the cost element.
Can you please teach me on how to do just that?
Thank you so much for your help.
Regards,
OnyxHi,
As my analysis you are passing the values to the wrong fields of the internal table. Please check the structure of your internal table . Is this in the order which you want?
Other wise please look into how this internal table is getting filled?
This is the sturucture mismatch probelm.
Also look in to the fieldcatalog.
With Regards,
Sumodh.P
Maybe you are looking for
-
External display on 2011 21" iMac won't sleep
I have a Samsung SyncMaster 213T attached to my iMac12,1 through a MiniDP->DVI Adapter attached to the Thunderbolt Port on the back of the mac. Now I have the problem that the display won't get to sleep together with the iMac's one. This feature work
-
Loading documents and attaching them to business objects
Hi, I am trying to load documents (Word and PDF files) into a content management server linked to a SAP CRM system. The documents need to be attached to business objects such as interaction records (BUS2000126) and service tickets (BUS2000116). I hav
-
Note of credit (return) with MIRO during use of two currencies (changeover)
Hello: We have a problem with the MIRO when we do a second partial note of credit with the new currency VEF (the purchase is in VEB) Now provisionally we work with two currencys: VEB (local currency) and VEF (transaction currency). When there is real
-
Adobe Captivate Help | Record video demonstrations
This question was posted in response to the following article: http://helpx.adobe.com/captivate/using/record-video-demonstrations.html
-
Book appears on shelf but does not open
I downloaded a book and it appears on my iBooks shelf, but it does not open. I'm using the iPhone 4s. I have about 11.7 GBs available. Help?