To find sum in an internal table - Bit urgent
Hi SAP experts,
I have an internal table with the following fields and data :
Emp_number Section Days
1 A 10
1 B 20
3 A 20
3 B 10
2 A 20
2 B 10
Now I want to calculate the total days for each employee which is a sum of days of section A and days of section B.
I want the data as below into another internal table
Emp_number Total_days
1 30
2 30
3 30
Could any one tell the code for the same.
Useful answers wud be rewarded.
Vishnu.
Hi Vishwanath,
In this case you have to use CONTROL BREAK STATEMENTS.
1.At first
2.At new
3.At end
4.At last
1.At first is going to trigger at the 1st loop of the internal table.From the 2nd loop it is not going to trigger.
It is mainly used for sub headings.
2.At new is going to trigger at the new value of the internal table.
3. At end is going to trigger at the end of the new value of a particular field.
It is mainly use for subtotals.
4.At last is going to trigger at the last loop of the internal table.
It is mainly use for grand totals.
So you gothrough the above 4 statements.
In your case you have to use the third statement i.e., At end.
At end
ur logic
endat.
Similar Messages
-
Sum function for internal table column
Dear Experts,
how can I sum a complete internal table column.
Regards
ertasHi,
Use SUM in AT END of event in the loop of an internal table.
Example
Loop at ITAB into wa_itab.
at end of wa_itab-field.
sum. " Here all numric fields will be summed and stored in that filed(wa_itab-field)
endat.
Endloop.
Regards
Krishna -
How to find out structure of internal table?
Hi
is there any way how to find out name of structure upon which internal
table was created?
i got internal table passed to function module by any table
type. There can be different types of table passed in. Inside of
module a need to find out the structure of table.
I've found a tricky way how to find this information using following
command 'DESCRIBE FIELD dobj INTO td.', but its probably not a correct
way because using this command is not recommended in application
programs.
Is there any function module, or something i can use for getting this information?
ThanksThanks very much
This has solved my problem:
DATA descr_ref TYPE ref to cl_abap_typedescr.
DATA tabname TYPE string.
descr_ref = cl_abap_typedescr=>describe_by_data( itab ).
tabname = descr_ref->absolute_name. -
ALV - need to sum values of internal table and display in ALV
I have data in internal table as:
Material date sum1 sum2
Mat_A 19990101 4 4
Mat_A 20080501 3 0
Mat_A 20080601 2 0
Mat_B 19990101 2 0
Mat_B 20080601 5 5
Required output is :
Material qty1 qty2 19990101 20080501 20080601
Mat_A 432 4 4 3 2
Mat_B 2+5 5 2 5
Thinking of using ALV to pass the internal table and display as classical report (and also to save as excel spreadsheet).
Counting your help on the following questions:
1) How to accomplish the sum in ALV report? Can ALV FM do that or one has to use ABAP to compute the sum from the given internal table?
2) Mat_A can have more date values. Here it got 3 distinct date values 19990101, 20080601, 20080501. If it has say 5 date values, how to create the ALV date columns (from 3 to 5 date columns) dynamically?
Thanks for the help.for the sum inalv we use generally..
it_fieldcat-do_sum = 1.
check this examples...
http://www.****************/Tutorials/ALV/Subtotals/text.htm
*& Report ZTEST_ALV_PERC_13317
REPORT ztest_alv_perc_13317.
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_events TYPE slis_t_event,
wa_events TYPE slis_alv_event,
it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
l_layout TYPE slis_layout_alv.
TYPES: BEGIN OF ty_itab,
field1(10),
qty1 TYPE i,
qty2 TYPE i,
qty3 TYPE i,
dummy TYPE c,
END OF ty_itab.
DATA: itab TYPE STANDARD TABLE OF ty_itab WITH HEADER LINE,
itab1 TYPE ty_itab.
START-OF-SELECTION.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'FIELD1'.
wa_fieldcat-tabname = 'ITAB'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'QTY1'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'QTY2'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'QTY3'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'DUMMY'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
wa_fieldcat-no_out = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = it_events
EXCEPTIONS
list_type_wrong = 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.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF. -
Function module to find the columns in Internal table
Hi Group,
Is there any function module which displays the columns of the internal table. I guess there is one cos when we debug any program and select the "Tables" button while debugging and enter an internal table and then do a "Find" the pop up which comes up shows the internal table columns. As this functionality is in the debugger which I cannot debug hence was wondering if some one has come across any such function module. Thanks in advance.
Regards,
Ankur Bhandari
[email protected]Hi again,
1. In the above FM
Pass Program as SY-REPID (U cann pass other prg name also)
in FieldName Pass the name of the internal table
eg. 'ITAB'
2. This FM will give u the details of the
internal table.
The u can display the COMPONENTS table
using ALV or anyother method u like.
Regards,
Amit M. -
Sample code to find duplicated entries in internal table and mark them?
We have one internal table called itab1 which contains the following fields:
f1 (key field)
f2 (non-key field)
f3 (non-key field)
The business scenario is f1, f2, and f3 are one to one relationship to each other, or in other word, f2 or f3 can't be duplicated with the the same values for different f1 (key field) records. We will move the check result of the duplication into another internal table itab2 which contains f1, f2, f3, f4, and f5 where f1, f2, and f3 are the same ones as in itab1, f4 will get the value "Yes" to mark duplicated for f2 (or "No" to mark non-duplicated), and f5 will get the value "Yes" to mark duplicated for f3 (or "No" to mark non-duplicated).
We know that through the loop of itab1, the above logic can be done to fill in f4 and f5 value for each row with either "Yes" or "No".
Just give an example of how itab2 will look like after the coding:
f1----f2--f3--f4(f2 duplicated?)---f5(f3 duplicated?)
A----01-X0YesNo--
B----01-X1YesYes--
C----02-X1NoYes--
Could any ABAP expert here show us the sample code to generate itab2 in loop of itab1 to find the duplicated entries of f2 and f3 and then populated the corresponding row values for f4 and f5 with "Yes" or "No"? We will give you reward points!TYPES: BEGIN OF ty_1,
f1,
f2(2),
f3(2),
f4,
f5,
END OF ty_1.
TYPES: BEGIN OF ty_2,
type(2),
value(2),
END OF ty_2.
DATA: itab1 TYPE STANDARD TABLE OF ty_1 WITH HEADER LINE,
itab2 TYPE TABLE OF ty_2 WITH HEADER LINE.
DATA: f2_c TYPE sy-tabix VALUE 0,
f3_c TYPE sy-tabix VALUE 0,
curr_f2 LIKE itab1-f2,
curr_f3 LIKE itab1-f3.
itab1-f1 = 'A'.
itab1-f2 = '01'.
itab1-f3 = 'X0'.
APPEND itab1.
itab1-f1 = 'B'.
itab1-f2 = '01'.
itab1-f3 = 'X1'.
APPEND itab1.
itab1-f1 = 'C'.
itab1-f2 = '02'.
itab1-f3 = 'X1'.
APPEND itab1.
SORT itab1 BY f1 f2 f3 AS TEXT.
LOOP AT itab1.
IF sy-tabix EQ 1.
curr_f2 = itab1-f2.
curr_f3 = itab1-f3.
ENDIF.
IF itab1-f2 NE curr_f2.
f2_c = 0.
curr_f2 = itab1-f2.
ENDIF.
IF itab1-f3 NE curr_f3.
f3_c = 0.
curr_f3 = itab1-f3.
ENDIF.
f2_c = f2_c + 1.
f3_c = f3_c + 1.
IF f2_c > 1.
itab1-f4 = 'X'.
MODIFY itab1.
itab2-type = 'f2'.
itab2-value = itab1-f2.
APPEND itab2.
ENDIF.
IF f3_c > 1.
itab1-f5 = 'X'.
MODIFY itab1.
itab2-type = 'f3'.
itab2-value = itab1-f3.
APPEND itab2.
ENDIF.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM itab2.
LOOP AT itab2.
IF itab2-type = 'f2'.
LOOP AT itab1 WHERE f2 = itab2-value AND f4 NE 'X'.
itab1-f4 = 'X'.
MODIFY itab1.
ENDLOOP.
ELSE.
LOOP AT itab1 WHERE f3 = itab2-value AND f5 NE 'X'.
itab1-f5 = 'X'.
MODIFY itab1.
ENDLOOP.
ENDIF.
ENDLOOP.
Edited by: Ramiro Escamilla on Apr 5, 2008 1:45 AM
changed the code, now should work -
Hi All,
I have internal table like this.
Field1 Field2 Field3
a 1 5.000
b 1 5.000
b 1 3.000
b 1 10.000
b 1 10.000
b 2 15.000
c 1 10.000
c 2 10.000
Now i have to sum field3 based on field1 and field2 i.e My Output will be like this.
Field1 Field2 Field3
a 1 5.000
b 1 28.000
b 2 15.000
c 1 10.000
c 2 10.000.
Please suggest some solution as I guess this output is not possible thru At end of or at new.
We can get the desired output using on change of but the summation is not possible thru on change of.
Thanks and regards
Nazmul AzadHi,
Please refer the below program:
data : var(20) type c,
var1(20) type c,
var2(20) type c.
data : begin of itab occurs 0,
f1 type c,
f2 type i,
f3 type i,
end of itab.
itab-f1 = 'a'.
itab-f2 = '1'.
itab-f3 = '5'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '1'.
itab-f3 = '5'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '1'.
itab-f3 = '3'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '1'.
itab-f3 = '10'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '2'.
itab-f3 = '15'.
append itab.
clear itab.
itab-f1 = 'c'.
itab-f2 = '1'.
itab-f3 = '10'.
append itab.
clear itab.
itab-f1 = 'c'.
itab-f2 = '2'.
itab-f3 = '10'.
append itab.
clear itab.
//Sorted based on field1 and field2 and used At new
sort itab by f1 f2.
loop at itab.
at new f2.
sum.
endat.
endloop.
Best Regards,
Sumana -
Hi Gurus,
I want to print sum of a particular coloumn in dynamic internal table,
But in Field symbold use char type so i cant able to print sum.
help me to solve this problem.
Regards,
Bhuvana.Hi
Herwith i attach my code.
*& Report ZFR133_TELECAST_REVENUE *
REPORT zfr133_telecast_revenue .
MODULE xxxxxxxx. *
Objective :.......................................... *
Program : Updates Tables ( ) Downloads data ( ) *
Outputs List ( ) *
Technical Spec No ............... *
Date Created 17/09/2008 *
Author J.Bhuvaneswari *
Location SUN TV / Chennai *
LDB ..... *
External Dependencies *
Amendment History *
Who Change ID Reason *
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ *
XXXXXXXXX AADDMMYYYY Where XXXX = Developers Name................. *
AA- Developers Initial ................................ *
Includes *
*INCLUDE : *
Tables *
TABLES : t001, bkpf, csks, bseg, cskt.
Types Begin with TY_ *
TYPES : BEGIN OF ty_bkpf,
bukrs LIKE bkpf-bukrs,
belnr LIKE bkpf-belnr,
gjahr LIKE bkpf-gjahr,
monat LIKE bkpf-monat,
stblg LIKE bkpf-stblg,
END OF ty_bkpf,
BEGIN OF ty_bseg,
bukrs LIKE bseg-bukrs,
gjahr LIKE bseg-gjahr,
belnr LIKE bseg-belnr,
shkzg LIKE bseg-shkzg,
dmbtr LIKE bseg-dmbtr,
kostl LIKE bseg-kostl,
hkont LIKE bseg-hkont,
END OF ty_bseg,
BEGIN OF ty_cskt,
kostl LIKE cskt-kostl,
ltext LIKE cskt-ltext,
END OF ty_cskt,
BEGIN OF ty_temp,
belnr LIKE bseg-belnr,
monat LIKE bkpf-monat,
kostl LIKE cskt-kostl,
ltext LIKE cskt-ltext,
shkzg LIKE bseg-shkzg,
dmbtr LIKE bseg-dmbtr,
END OF ty_temp.
DATA: BEGIN OF ty_stru OCCURS 0,
kostl LIKE cskt-kostl,
monat LIKE bkpf-monat,
dmbtr LIKE bseg-dmbtr,
END OF ty_stru.
Constants Begin with C_ *
*CONSTANTS: *
Data Begin with W_ *
DATA : w_amt LIKE bseg-dmbtr,
w_var TYPE string,
w_text TYPE string,
w_value TYPE i,
w_cnt TYPE i VALUE 1,
w_mon TYPE month,
okcode TYPE sy-ucomm.
Infotypes ( HR Module Specific) *
*INFOTYPES : *
Internal tables Begin with IT_ *
DATA : it_bkpf TYPE TABLE OF ty_bkpf,
it_bseg TYPE TABLE OF ty_bseg,
it_cskt TYPE TABLE OF ty_cskt,
it_temp TYPE TABLE OF ty_temp,
it_tmp1 TYPE TABLE OF ty_temp,
it_tmp2 TYPE TABLE OF ty_temp,
it_ccen TYPE TABLE OF ty_temp,
it_monat TYPE TABLE OF ty_temp.
DATA : xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat,
ty_lay TYPE lvc_s_layo,
dy_table TYPE REF TO data,
dy_line TYPE REF TO data.
DATA : cl TYPE REF TO cl_gui_custom_container,
cl_alv TYPE REF TO cl_gui_alv_grid.
DATA : wa_bkpf TYPE ty_bkpf,
wa_bseg TYPE ty_bseg,
wa_cskt TYPE ty_cskt,
wa_temp TYPE ty_temp,
wa_tmp1 TYPE ty_temp,
wa_tmp2 TYPE ty_temp,
wa_ccen TYPE ty_temp,
wa_monat TYPE ty_temp,
wa_month TYPE t247.
Field Symbols Begin with FS_ *
*FIELD-SYMBOLS: *
FIELD-SYMBOLS: .
Insert *
*INSERT : *
Select Options Begin with SO_ *
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS : pr_bukrs LIKE t001-bukrs OBLIGATORY,
pr_gjahr LIKE bkpf-gjahr OBLIGATORY.
SELECT-OPTIONS : so_monat FOR bkpf-monat OBLIGATORY,
so_kostl FOR bseg-kostl OBLIGATORY,
so_hkont FOR bseg-hkont OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.
Parameters Begin with PR_ *
*PARAMETERS : *
Initialisation *
*INITIALIZATION.
At selection-screen *
*AT SELECTION-SCREEN.
S T A R T O F S E L E C T I O N *
START-OF-SELECTION.
******Select data from Header Table.
SELECT bukrs gjahr belnr monat stblg
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
WHERE bukrs = pr_bukrs AND
gjahr = pr_gjahr AND
monat IN so_monat AND
stblg = ' '.
******Select data from Item Table
IF it_bkpf IS NOT INITIAL.
SELECT bukrs gjahr belnr shkzg dmbtr kostl hkont
FROM bseg INTO CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs AND
gjahr = it_bkpf-gjahr AND
belnr = it_bkpf-belnr AND
kostl IN so_kostl AND
hkont IN so_hkont.
ENDIF.
******Select Cost center text
SELECT kostl ltext
FROM cskt INTO CORRESPONDING FIELDS OF TABLE it_cskt
WHERE spras = 'EN' AND
kokrs = 'SUN1' AND
kostl IN so_kostl.
******Append data in temporary table.
LOOP AT it_bseg INTO wa_bseg.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY belnr = wa_bseg-belnr.
IF sy-subrc = 0.
wa_temp-belnr = wa_bkpf-belnr.
wa_temp-monat = wa_bkpf-monat.
wa_temp-kostl = wa_bseg-kostl.
READ TABLE it_cskt INTO wa_cskt WITH KEY kostl = wa_bseg-kostl.
IF sy-subrc = 0.
wa_temp-ltext = wa_cskt-ltext.
ENDIF.
IF wa_bseg-shkzg = 'H'.
wa_temp-dmbtr = wa_bseg-dmbtr * -1.
ELSE.
wa_temp-dmbtr = wa_bseg-dmbtr.
ENDIF.
APPEND wa_temp TO it_temp.
ENDIF.
ENDLOOP.
SORT it_temp BY kostl monat.
******Internal Table of cost center without duplications.
it_ccen = it_temp.
DELETE ADJACENT DUPLICATES FROM it_ccen COMPARING kostl.
******Internal Table of fiscal period without duplications.
it_monat = it_temp.
SORT it_monat BY monat.
DELETE ADJACENT DUPLICATES FROM it_monat COMPARING monat.
PERFORM dynamic_table.
PERFORM data_upload_dynamic_table.
SET SCREEN 3000.
IF cl IS INITIAL.
CREATE OBJECT cl EXPORTING container_name = 'TC'.
CREATE OBJECT cl_alv EXPORTING i_parent = cl.
ENDIF.
CALL METHOD cl_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'ZALIKP'
is_layout = ty_lay
CHANGING
it_outtab =
it_fieldcatalog = ifc.
*GET XX.
*END-OF-SELECTION.
E N D O F S E L E C T I O N *
At line selection *
*AT LINE-SELECTION.
User Command Processing *
*AT USER-COMMAND.
Top Of Page *
*TOP-OF-PAGE.
End Of Page *
*END-OF-PAGE.
*& Form DYNAMIC_TABLE
FORM dynamic_table .
PERFORM design_fieldcat USING 'KOSTL' 'BSEG' text-002 '10'.
PERFORM design_fieldcat USING 'LTEXT' 'CSKT' text-003 '30'.
LOOP AT it_monat INTO wa_monat.
CONCATENATE 'PE' wa_monat-monat INTO w_text.
w_mon = wa_monat-monat.
CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
EXPORTING
langu = sy-langu
month = w_mon
IMPORTING
t247 = wa_month.
w_var = wa_monat-monat.
w_text = wa_month-ltx.
PERFORM design_fieldcat USING w_var 'BKPF' w_text '10'.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO .
ENDFORM. " DYNAMIC_TABLE
*& Form DESIGN_FIELDCAT
FORM design_fieldcat USING value TYPE string
tab TYPE string
text TYPE string
length TYPE string.
xfc-fieldname = value.
xfc-tabname = tab.
xfc-reptext = text.
xfc-outputlen = length.
APPEND xfc TO ifc.
w_cnt = w_cnt + 1.
CLEAR xfc.
ENDFORM. " DESIGN_FIELDCAT
*& Form DATA_UPLOAD_DYNAMIC_TABLE
FORM data_upload_dynamic_table .
DATA : w_c(2) TYPE c,
w_c1(5) TYPE c,
w_c2(5) TYPE c.
CREATE DATA dy_line LIKE LINE OF .
CLEAR: wa_tmp2,w_amt.
ENDON.
ENDLOOP.
ENDLOOP.
ENDFORM. " DATA_UPLOAD_DYNAMIC_TABLE
*& Module STATUS_3000 OUTPUT
MODULE status_3000 OUTPUT.
SET PF-STATUS 'MENU'.
SET TITLEBAR 'TIT'.
ENDMODULE. " STATUS_3000 OUTPUT
*& Module USER_COMMAND_3000 INPUT
MODULE user_command_3000 INPUT.
CASE okcode.
WHEN 'BACK'." OR 'RW' OR '%EX'.
LEAVE PROGRAM.
CLEAR okcode.
ENDCASE.
ENDMODULE. " USER_COMMAND_3000 INPUT -
Hi All,
I have an internal table as follows.
Now if the KUNNR, PRCTR and VERNA field are similar, i have to sum up the QTY columns accordingly.
I mean to say, in this case, the rows 1, 2 and 3 have same kunnr, prctr and verna fields. Henc ei should sum up the corresponding columns (qty1, qty2, qty3 and SUM) and make it as one row.
kunnr | prctr | verna | qty1 | qty2 | qty3 | sum
11 | 100 | Raj | 10.0 | 5.0 | 0.0 | 15.0
11 | 100 | Raj | 8.0 | 1.0 | 2.0 | 11.0
11 | 100 | Raj | 0.0 | 0.0 | 6.5 | 6.5
12 | 200 | Ram | 2.0 | 0.0 | 0.0 | 2.0
How to carry out this calculation....???
Regards
PavanHi Friend,
Use the Control Break Statement for this, Go through the following steps
1. Sort the Internal Table
2. Loop the Internal Table
3. Use the Control Break Statement
4. Sum
5. Write Statement
6. Endloop.
Ex.
sort itab.
loop at itab.
at end of kunnr.
sum.
write: 'mara-kunnr'.
endat.
endloop.
Hope the answer of your question.
Regards,
Md Ziauddin.
Edited by: MD ZIAUDDIN on Dec 31, 2008 7:40 PM -
Regarding Uploading of internal Table - Its Urgent.
Hi All,
I want to upload the data from an Excel File into Interna Table.
GUI_UPLOAD is used for Flat File but for Excel Which FM should I use?
Can Any One give me the sample code for this ?
Points will be rewarded.
Thanks in Advance.
Regards
Jitendra Gujarathihi
REPORT zupload_excel_to_it NO STANDARD PAGE HEADING.
TYPES: BEGIN OF t_datatab ,
col1(25) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
col4(30) TYPE c,
col5(30) TYPE c,
col6(30) TYPE c,
col7(30) TYPE c,
col8(30) TYPE c,
col9(30) TYPE c,
col10(30) TYPE c,
col11(30) TYPE c,
END OF t_datatab.
DATA: it_datatab TYPE STANDARD TABLE OF t_datatab INITIAL SIZE 0,
wa_datatab TYPE t_datatab.
DATA : gd_scol TYPE i VALUE '1',
gd_srow TYPE i VALUE '1',
gd_ecol TYPE i VALUE '256',
gd_erow TYPE i VALUE '65536'.
DATA: it_tab TYPE filetable,
gd_subrc TYPE i.
*Selection screen definition
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file LIKE rlgrap-filename
DEFAULT 'c:\test.xls' OBLIGATORY. " File Name
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
REFRESH: it_tab.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select File'
default_filename = '*.xls'
multiselection = ' '
CHANGING
file_table = it_tab
rc = gd_subrc.
LOOP AT it_tab INTO p_file.
so_fpath-sign = 'I'.
so_fpath-option = 'EQ'.
append so_fpath.
ENDLOOP.
START-OF-SELECTION.
START-OF-SELECTION.
PERFORM upload_excel_file TABLES it_datatab
USING p_file
gd_scol
gd_srow
gd_ecol
gd_erow.
END-OF-SELECTION.
END-OF-SELECTION.
LOOP AT it_datatab INTO wa_datatab.
WRITE:/ wa_datatab-col1,
wa_datatab-col2,
wa_datatab-col3,
wa_datatab-col4,
wa_datatab-col5,
wa_datatab-col6,
wa_datatab-col7,
wa_datatab-col8,
wa_datatab-col9,
wa_datatab-col10,
wa_datatab-col11.
ENDLOOP.
*& Form UPLOAD_EXCEL_FILE
upload excel spreadsheet into internal table
-->P_TABLE Table to return excel data into
-->P_FILE file name and path
-->P_SCOL start column
-->P_SROW start row
-->P_ECOL end column
-->P_EROW end row
FORM upload_excel_file TABLES p_table
USING p_file
p_scol
p_srow
p_ecol
p_erow.
DATA : lt_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.
Has the following format:
Row number | Colum Number | Value
i.e. 1 1 Name1
2 1 Joe
DATA : ld_index TYPE i.
FIELD-SYMBOLS : .
Note: Alternative function module - 'ALSM_EXCEL_TO_INTERNAL_TABLE'
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
filename = p_file
i_begin_col = p_scol
i_begin_row = p_srow
i_end_col = p_ecol
i_end_row = p_erow
TABLES
intern = lt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'Error Uploading file'.
EXIT.
ENDIF.
IF lt_intern[] IS INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'No Data Uploaded'.
EXIT.
ELSE.
SORT lt_intern BY row col.
LOOP AT lt_intern.
MOVE lt_intern-col TO ld_index.
ASSIGN COMPONENT ld_index OF STRUCTURE p_table TO <fs>.
MOVE lt_intern-value TO .
AT END OF row.
APPEND p_table.
CLEAR p_table.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. "UPLOAD_EXCEL_FILE
plz reward points!
rgds -
Delete duplicate entriess from the internal table its urgent pls help.
Hi friends,
Hope everybody is doing good,Here is m query on delete duplicate data from the intenal table.
I have an internal table which contain data in the following format.
Doc No Comp Cod Vendor Assignment
1500000009 JM11 00000000
1500000008 JM11 20070212(Repeating)
1500000007 JM11 20070212
1500000006 JM11 00000000
1500000005 JM11 00000000
1500000004 JM11 00000000(Repeating)
1500000003 JM11 00000000 (Repeating)
1500000002 JM11 00000000
1500000001 JM11 20050302
1500000000 JM11 00000000
1500000003 JM11 10000088
1500000001 JM11 10000088
1500000030 JM11 10006260
1500000010 JM11 10006269
1500000008 JM11 10006269
1500000006 JM11 10006269
1500000004 JM11 10006269
if you see the document numbers,there are some document number which are repeating here,there are some document numer which contain vendor number but not the assignments,some of the document numbers contain the assignments but not the vendors.
If my internal table contain this kind of data with repeted document numbers than i want the document number which contains only the vendor number.
Pls help me with the appropriate logic,its urgent.
Thanks a lot
mrutyun^Hi,
<u><b>Deleting Adjacent Duplicate Entries</b></u>
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f2> ...
|ALL FIELDS].
The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are
duplicate if they fulfill one of the following compare criteria:
Without the COMPARING addition, the contents of the key fields of the table must be
identical in both lines.
If you use the addition COMPARING <f1> <f2> ... the contents of the specified fields <f1>
<f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as
the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is
executed, it is ignored. You can restrict the search to partial fields by
specifying offset and length.
If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines
must be identical.
You can use this statement to delete all duplicate entries from an internal table if the table is
sorted by the specified compare criterion.
If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
Examples
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 1.
DELETE TABLE ITAB: FROM LINE,
WITH TABLE KEY COL1 = 3.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2.
ENDLOOP.
The output is:
2 4
4 16
The program fills a hashed table with a list of square numbers. The DELETE
statement delete the lines from the table where the key field COL1 has the contents 1 or 3.
Regards,
Bhaskar -
Finding Sum of grouped lines / Tables EKKO, EKPO
Hi, am using the following tables:
TABLES: ekko,ekpo.
with Inner Join
select ekkobukrs ekkoebeln ekkoaedat ekkobsart ekkoekgrp ekkolifnr ekkowaers ekkowkurs ekkoernam ekpobrtwr
into CORRESPONDING FIELDS OF TABLE itab from ekko
inner join EKPO on ekPOEBELN = ekkoebeln.
end-OF-SELECTION.
Basically i want to group the result of this SQL statement by Purchasing Doc (ekko~ebeln) and display the
sum of Gross value (ekpo~brtwr) for the line items of each Purchasing Doc.
Note: i want the Purchasing Doc to appear one time only in the report
i have tried the following :
select ekkobukrs ekkoebeln ekkoaedat ekkobsart ekkoekgrp ekkolifnr ekkowaers ekkowkurs ekkoernam sum( ekpobrtwr )
into CORRESPONDING FIELDS OF TABLE itab from ekko
inner join EKPO on ekPOEBELN = ekkoebeln
WHERE ekkobukrs IN S_bukrs AND ekkobsart IN s_bsart
Group By ekkoebeln ekkobukrs ekkoaedat ekkobsart ekkoekgrp ekkolifnr ekkowaers ekkowkurs ekko~ernam.
then loop through the ITAB:
LOOP at itab.
write:/ itab-bukrs under 'Company Code',
itab-ebeln UNDER 'PO-Number',
itab-aedat UNDER 'Date' ,
itab-bsart UNDER 'Doc-Type' ,
itab-ekgrp UNDER 'Purchase-Grp' ,
itab-lifnr UNDER 'Vendor' ,
itab-waers UNDER 'Currency',
itab-wkurs UNDER 'Rate' ,
itab-brtwr under 'Gross Value',
itab-ernam UNDER 'Created By'.
ENDLOOP.
but it is not working with me, am not able to show the result of sum( ekpo~brtwr ) am getting 0 in all lines
thanks a lot for your help" My Full Code.
TABLES: ekko,ekpo,ekbe,rbkp.
data: BEGIN OF itab OCCURS 0, "EKKO TABLE"
inco1 like ekko-inco1,
inco2 like ekko-inco2,
bukrs like ekko-bukrs,
ebeln like ekko-ebeln,
aedat like ekko-aedat,
bsart like ekko-bsart,
ekgrp like ekko-ekgrp,
lifnr like ekko-lifnr,
waers like ekko-waers,
wkurs like ekko-wkurs,
ernam like ekko-ernam,
BRTWR LIKE ekpo-brtwr,
end of itab.
SELECT-OPTIONS : s_bukrs FOR itab-bukrs OBLIGATORY,
s_ebeln for itab-ebeln ,
s_aedat FOR itab-aedat ,
s_bsart for itab-bsart ,
s_ekgrp FOR itab-ekgrp ,
s_lifnr FOR itab-lifnr ,
s_budat FOR jtab-budat ,
s_bewtp for jtab-bewtp .
DATA ProceesITAB LIKE SORTED TABLE OF ITAB WITH UNIQUE KEY TABLE LINE.
AT SELECTION-SCREEN on s_bukrs.
START-OF-SELECTION.
select ekkobukrs ekkoebeln ekkoaedat ekkobsart ekkoekgrp ekkolifnr ekkowaers ekkowkurs ekkoernam ekpobrtwr
into CORRESPONDING FIELDS OF TABLE itab from ekko
inner join EKPO on ekPOEBELN = ekkoebeln.
end-OF-SELECTION.
LOOP at itab.
write:/ itab-bukrs under 'Company Code',
itab-ebeln UNDER 'PO-Number',
itab-aedat UNDER 'Date' ,
itab-bsart UNDER 'Doc-Type' ,
itab-ekgrp UNDER 'Purchase-Grp' ,
itab-lifnr UNDER 'Vendor' ,
itab-waers UNDER 'Currency',
itab-wkurs UNDER 'Rate' ,
itab-brtwr under 'Gross Value',
itab-ernam UNDER 'Created By'.
ENDLOOP.
TOP-OF-PAGE.
write:/70 'Company'.
uline.
skip.
write:/5 'Company Code',25 'PO-Number',40 'Date',55 'Doc-Type',70 'Purchase-Grp',85 'Vendor',100 'Currency',115 'Rate',125 'Created By',
140 'Gross Value'.
ULINE.
SKIP.
Edited by: YasinN on Mar 24, 2010 9:45 AM -
How to find value in internal table
Hi,
I'm trying to search a value in internal table by using the FIND TABLE syntax but there's an error message saying In CHAR MODE a character-like, or in BYTE MODE a byte-like field is expected as the row type for the table "ITABLE". The internal table already has character-like field.
Here's the code:
FIND ALL OCCURRENCES OF w_itable-ordno IN TABLE itable RESULTS results.
Wherein:
w_itable-ordno contains the value that I need to find
itable is the internal table that has data
Thanks.
KathHi Kathy,
I dont think you can use the given syntax in unicode envoirnment.
As i understand, you are trying to find a value in your internal table. Why dont you make use of LOOP or READ statements. That would be a better option.
Best Regards,
Ram. -
hi friends,
i want to find max ,min in internal table can any one help me on this..
thanks and regards,
shridevi.lHi,
Check the links
https://forums.sdn.sap.com/click.jspa?searchID=11972479&messageID=3541325
https://forums.sdn.sap.com/click.jspa?searchID=11972479&messageID=5320476
https://forums.sdn.sap.com/click.jspa?searchID=11972479&messageID=4297115
Reward for useful answers.
Regards,
Raj. -
How to use aggregate function on internal table
hi experts,
I am beginner in abap.I want to use sum function on internal table.
I have structure as follow:
types: begin of ty_ftab,
docno TYPE bkpf-belnr,
comcode TYPE bkpf-bukrs,
year TYPE bkpf-gjahr,
line_itm type bsad-buzei,
cust type bsad-kunnr,
amt type bsad-dmbtr,
end of ty_ftab.
data: it_ftab type table of ty_ftab,
wa_ftab type ty_ftab.
i fetched data successfully into it_ftab from bkpf and bsad table and displyed into alv.
now i want sum of amt using group by cust and want to display like
cust total_amt
in next screen...
displying part is not important but how can i do sum of amt according to cust value? Is there in way to query on internal table?Hi,
try this code,
data : i_sort TYPE TABLE OF slis_sortinfo_alv
w_sort like LINE OF i_sort.
sort it_ftab by cust.
w_sort-subtot = 'X'.
w_sort-fieldname = 'AMT'.
w_sort-tabname = 'it_ftab'.
APPEND w_sort to i_sort.
In fieldcatalog :
w_fcat-fieldname = 'AMT'.
w_fcat-tabname = 'it_ftab'.
w_fcat-do_sum = 'X'.
In REUSE_ALV_GRID_DISPLAY FUNCTION MODULE provide the it_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = i_sort
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab =
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Maybe you are looking for
-
My weather app is not working on cell data??
The weather app that came on my iPhone 4s doesnt work when im using 3g. It only works when im using wifi. Is anyone else having this problem? How can i fix it?
-
Check Printing on Custom Paper size
Hi All, I am using RTF template to print checks using XML publisher. I generated the PDF file and it prints fine on a regular 8.5 * 11 letter size paper. When I print on real check which is 8.5 * 7 size, it does not print correctly. I am using the HP
-
Referencing field in a query struct
About 5% of the time I get an error 'Element COMPANYSTATUS is undefined in Q.' from the code in SNIPPET 1. Can anyone tell me why I would ever get this error? If the query returns 0 results (which it may if the user is not logged in and SESSION.User.
-
Should library be on its own drive?
Quick question since I just bought a G-Tech G-Speed Q drive; I am thinking about putting all my media(video, photos, music, etc) in one place so I can stop hooking up 10 different hard drives in a mess of wires each time I have a project to do. Is
-
Same JMS queue in 2 differents processes
Hi, I have 2 processes which listen on the same JMS queue. the first one consumes a message on the queue. if the message contains some information the second process consumes another message (different format) in the queue. the problem is sometimes t