Collect statement error
Hi all,
i have the fallowing problem.
I'm trying to do a collect statement as fallow:
SORT i_tran BY cuenta ASCENDING.
LOOP AT i_tran.
AT NEW cuenta.
COLLECT i_tran INTO i_tran2.
APPEND i_tran2.
CLEAR i_tran.
CLEAR i_tran2.
ENDAT.
endloop.
where i_tran is a collect internal table and i_tran2 is another internal table.
when I execute the collect statement all the fields are fill with asterics and the field that Im interested in is set to zero.
another problem is that is not doing the collect per cuenta. (is doing it per record, ex. if cuenta 123 has three records it executes at the collect statement for each one of them.
this is the structure of i_tran:
* Registro de Transacciones
TYPES: BEGIN OF E_TRAN,
RECTYPE TYPE C, "Tipo Registro N
CCODE(15) TYPE C, "Id Empresa (RNC)
SEQNR(7) TYPE C, "Secuencia Header
SECTR(7) TYPE C, "Secuencia Transaccion
CUENTA(20) TYPE C, "Cuenta Suplidor
MONTRN TYPE I, "Montro Transaccion (13)
TIPCTA TYPE C, "Tipo de Cuenta
WAERS(3) TYPE C, "Moneda
CODBAN(8) TYPE C, "Banco Destino (No. Cuenta Banco)
DIGVER TYPE C, "Digito Verificacion
CODOPR(2) TYPE C, "Codigo Operacion
TIPIDN(2) TYPE C, "Tipo de Identificacion
IDENTF(15) TYPE C, "Identificacion
NOMBRE(35) TYPE C, "Nombre Beneficiario
REFERN(12) TYPE C, "Referencia
DESCRED(40) TYPE C, "Descripcion Estado Destino
FECVEN(4) TYPE C, "Fecha Vencimiento
FCONTC TYPE C, "Forma de Contacto
EMAIL(40) TYPE C, "E-mail Beneficiario
NUMFAX(12) TYPE C, "Numero de Fax
RESERV(2) TYPE C, "Reservado para uso futuro
NUMAUT(15) TYPE C, "Numero Autorizacion
CODRET(3) TYPE C, "Codigo Retorno Remoto
CODRZR(3) TYPE C, "Codigo Razon Remoto
CODRZI(3) TYPE C, "Codigo Razon Interno
PROCTR TYPE C, "Procesador Transaccion
STATS(2) TYPE C, "Status Transaccion
FILLER(52), "En blanco
END OF E_TRAN.
DATA: IT_TRAN TYPE E_TRAN.
DATA: I_TRAN TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE,
I_TRAN2 TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE.
if anyone can help me I'll appreciated.
thanks in advanced,
Gregorio.
Hi Gergorio,
1. I think that the way you have used COLLECT
is incorrect.
(There is no need to use AT NEW for collect)
(only Loop, Collect will do the work)
2. U have said that :
tran is a collect internal table and i_tran2 is
another internal table.
3. Meaning, that,
i_trans2 has many records
tran is the SUMMARY table (to gather totals)
4. Now, on what base,
do u want to do summary ?
ie. What will be the key/main/criteria fields?
(all char fields of your internal table,
or some of them)
(If only some are required, then your logic won't work)
5. Moreover, we should have numeric/integer
fields in our internal table so that
summation is done automatically.
6. The simple logic is like this.
LOOP AT DETAILITAB.
COLLECT DETAILTAB INTO SUMMARYTAB.
ENDLOOP.
7. The above will take care of
all summations
(with respect to DISTINCT COMBAINATION
of ALL CHAR FIELDS)
8. If your criteria for summation is
less fields then some little more work
is required. If this is so, let me know.
I hope it helps.
Regards,
Amit M.
Similar Messages
-
Error in collect statement(non-key fields must be numeric)...
Error in collect statement(non-key fields must be numeric)...
Hello Experts,
I created an internal table based from a ztable. The structure of the ztable is
as follows:
1. MANDT -> PRIMARY KEY
2. BUKRS -> PRIMARY KEY
3. TXK50 -> PRIMARY KEY
4. ANLKL -> PRIMARY KEY
5. KTANSW -> PRIMARY KEY
6. KOSTL -> PRIMARY KEY
Then the remainder of the fields(around 8 fields) are currency data types(ANBTR).
An error is showing saying 'You can only use the collect command in a table if all of its non-key
fields are numeric(type I,P or F).
I searched the forum and it said that non-keys must be numeric in order for the
collect command to work. But all of my primary keys are non-numeric.
Below is my declaration:
CLASS-DATA: gt_output_acq TYPE hashed TABLE OF zsd_output_acq
WITH UNIQUE KEY bukrs txk50 anlkl
ktansw kostl,
gt_output_ret LIKE gt_output_acq,
wa_output_gen LIKE LINE OF gt_output_acq,
gt_output_net TYPE HASHED TABLE OF zsd_output_net
WITH UNIQUE KEY bukrs txk50 anlkl
ktansw kostl,
wa_output_net LIKE LINE OF gt_output_net,
gt_sort_crit TYPE SORTED TABLE OF t_sort_crit
WITH NON-UNIQUE KEY bukrs kostl,
wa_sort_crit LIKE LINE OF gt_sort_crit.
FIELD-SYMBOLS: <fs_output_acq> LIKE LINE OF gt_output_acq,
<fs_output_ret> LIKE LINE OF gt_output_ret,
<fs_output_net> LIKE LINE OF gt_output_net.
COLLECT <fs_output_acq> INTO gt_output_acq. "Here is the errorHi Vijay,
Here it is:
CLASS-DATA: gt_output_acq TYPE hashed TABLE OF zsd_output_acq
WITH unique KEY bukrs txk50 anlkl
ktansw kostl,
gt_output_ret LIKE gt_output_acq,
wa_output_gen LIKE LINE OF gt_output_acq,
gt_output_net TYPE hashed TABLE OF zsd_output_net
WITH unique KEY bukrs txk50 anlkl
ktansw kostl,
wa_output_net LIKE LINE OF gt_output_net,
gt_sort_crit TYPE SORTED TABLE OF t_sort_crit
WITH NON-UNIQUE KEY bukrs kostl,
wa_sort_crit LIKE LINE OF gt_sort_crit. -
Report in which collect statement .
report in which collect statement is used and also its purpose.
COLLECT
Basic form
COLLECT [wa INTO] itab.
Addition
... SORTED BY f
Effect
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .
If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.
If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.
If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.
If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .
After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.
Notes
COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.
If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that
the internal table will actually be unique or compressed, as described above and
COLLECT will run very efficiently.
If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.
Example
Compressed sales figures for each company
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
The table COMPANIES now has the following appearance:
NAME SALES
Duck 40
Tiger 20
Addition
... SORTED BY f
Effect
COLLECT ... SORTED BY f is obsolete and should no longer be used. Use APPEND ... SORTED BY f which has the same meaning.
Note
Performance
The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.
If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.
A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).
Note
Runtime errors
COLLECT_OVERFLOW : Overflow in integer field when calculating totals.
COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals. -
Invalid cursor state error while executing the prepared statement
hai friends,
following code showing the invalid cursor state error while executing the second prepared statement.
pls anyone help me
String query = "select * from order_particulars where order_no=" + orderno + " order by sno"; psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs1 = psmt1.executeQuery(); rs1.last(); intRowCount = rs1.getRow(); particularsdata = new Object[intRowCount][6]; rs1.beforeFirst(); if (intRowCount >= 1) { for (int i = 0; rs1.next(); i++) { particularsdata[0] = i + 1;
particularsdata[i][1] = rs1.getString(3);
particularsdata[i][2] = Double.parseDouble(rs1.getString(4));
rs1.close();
psmt1.close();
query = "SELECT sum(delqty) FROM billdetails,billparticulars WHERE order_no= " + orderno + " and " +
"billdetails.bill_no = billparticulars.bill_no GROUP BY particulars ORDER BY sno";
psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs1 = psmt1.executeQuery(); //error showing while executing this lineAlso .. Why using arrays instead of collections? Shifting the cursor all the way forth and back to get the count is fairly terrible.
With regard to the problem: either there's a nasty bug in the JDBC driver used, or you actually aren't running the compiled class version of the posted code. -
About Collect Statement.
hi experts,
i am genereating a report in FICO module. i have to fetch teh data from the field DMBTR (AMOUNT). it has both credits anddebits. i have to do calculations and should display the final balance in the report. each GL account number has different credits and debits. i have to display each account with the balance. if i am using collect statement it only making sum of eitehr debits or credits. i want both to be sum up. is tehre any other way to do the same..thnx in advance,
santosh.Syntax Diagram
COLLECT
Syntax
COLLECT wa INTO itab [result].
Effect
This statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key. As of Release 6.10, you can use result to set a reference to the inserted or changed row in the form of a field symbol or data reference.
Prerequisite for the use of this statement is that wa is compatible with the row type of itab and all components that are not part of the table key must have a numeric data type (i, p, f).
In standard tables that are only filled using COLLECT, the entry is determined by a temporarily created hash administration. The workload is independent of the number of entries in the table. The hash administration is temporary and is generally invalidated when the table is accessed for changing. If further COLLECT statements are entered after an invalidation, a linear search of all table rows is performed. The workload for this search increases in a linear fashion in relation to the number of entries.
In sorted tables, the entry is determined using a binary search. The workload has a logarithmic relationship to the number of entries in the table.
In hashed tables, the entry is determined using the hash administration of the table and is always independent of the number of table entries.
If no line is found with an identical key, a row is inserted as described below, and filled with the content of wa:
In standard tables the line is appended.
In sorted tables, the new line is inserted in the sort sequence of the internal table according to its key values, and the table index of subsequent rows is increased by 1.
In hashed tables, the new row is inserted into the internal table by the hash administration, according to its key values.
If the internal table already contains one or more rows with an identical key, those values of the components of work area wa that are not part of the key, are added to the corresponding components of the uppermost existing row (in the case of index tables, this is the row with the lowest table index).
The COLLECT statement sets sy-tabix to the table index of the inserted or existing row, in the case of standard tables and sorted tables, and to the value 0 in the case of hashed tables.
Outside of classes, you can omit wa INTO if the internal table has an identically-named header line itab. The statement then implicitly uses the header line as the work area.
COLLECT should only be used if you want to create an internal table that is genuinely unique or compressed. In this case, COLLECT can greatly benefit performance. If uniqueness or compression are not required, or the uniqueness is guaranteed for other reasons, the INSERT statement should be used instead.
The use of COLLECT for standard tables is obsolete. COLLECT should primarily be used for hashed tables, as these have a unique table key and a stable hash administration.
If a standard table is filled using COLLECT, it should not be edited using any other statement with the exception of MODIFY. If the latter is used with the addition TRANSPORTING, you must ensure that no key fields are changed. This is the only way to guarantee that the table entries are always unique and compressed, and that the COLLECT statement functions correctly and benefits performance. The function module ABL_TABLE_HASH_STATE can be used to check whether a standard table is suitable for editing using COLLECT.
Example
Compressed insertion of data from the database table sflight into the internal table seats_tab. The rows in which the key components carrid and connid are identical are compressed by adding the number of occupied seats to the numeric component seatsocc.
DATA: BEGIN OF seats,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
seatsocc TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE HASHED TABLE OF seats
WITH UNIQUE KEY carrid connid.
SELECT carrid connid seatsocc
FROM sflight
INTO seats.
COLLECT seats INTO seats_tab.
ENDSELECT.
Exceptions
Catchable Exceptions
CX_SY_ARITHMETIC_OVERFLOW
Cause: Overflow in integer field during totals formation
Runtime Error: COLLECT_OVERFLOW
Cause: Overflow in type p field during totals formation
Runtime Error: COLLECT_OVERFLOW_TYPE_P
Non-Catchable Exceptions
Cause: COLLECT used for non-numeric fields
Runtime Error: TABLE_COLLECT_CHAR_IN_FUNCTION -
Hi
I am trying to set up an Azure RemoteApp Hybrid solution.
I have created RemoteApp net and uploaded a custom image and all that is fine.
When I link my template to my Collection it fails after provisioning for about an hour.
I recive the following message: Could not provision the RemoteApp collection. Error: Could not join the domain. Unable to reach the domain.
The join domin works fine and I have tryed with account with different lvl of access to my AD.
Any suggestion how to solve this?Hello Eric,
I am landing into the same Problem and i read your guidance on this issue. Let me answer it point by point.
1. Check the VPN state to ensure it is active or connected state:
Sundesh:My Azure RemoteApp Virtual Network after successfull S2S configuration shows as Ready. Is that what you mean by Connected State? Earlier to S2S, it was just under connecting state.
2. Verify your VNET configurations have proper IP address ranges
Sundesh: The VNET address range, the Local address range and DNS has already been verified twice. In fact the same address ranges(with exception to VNET) are working fine on a VENT config on Azure VM instance. Verified.
3. Verify your DNS IP configurations are valid, (often this is the problem)
Sundesh: Yes its done and verified
4. Verify the credentials entered for domain join are valid.
Sundesh: Tested these credentials by joining a regular Azure VM to domain and it works there.
5. Make sure your VPN endpoint that Azure RemoteApp service is connecting to is not blocking traffic.
Sundesh: Can you please let us know the specific port numbers that we need to consider and i can have it checked with the Network team
Thanks
SUndesh -
Hi i have some problem with collect statement.
hi when i am using collect statement and whn ever any field is modified it is getting doubled and showing doubled value. may i knoe what would be problem.
Hai Kumar
Go through the following Collect Syntax
COLLECT
Basic form
COLLECT [wa INTO] itab.
Addition
... SORTED BY f
Effect
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .
If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.
If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.
If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.
If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .
After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.
Notes
COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.
If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that
the internal table will actually be unique or compressed, as described above and
COLLECT will run very efficiently.
If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.
Example
Compressed sales figures for each company
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
The table COMPANIES now has the following appearance:
NAME SALES
Duck 40
Tiger 20
Addition
... SORTED BY f
Effect
COLLECT ... SORTED BY f is obsolete and should no longer be used. Use APPEND ... SORTED BY f which has the same meaning.
Note
Performance
The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.
If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.
A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).
Note
Runtime errors
COLLECT_OVERFLOW : Overflow in integer field when calculating totals.
COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals.
Thanks & regards
Sreenivasulu P -
TABLE ILLEGAL STATEMENT error with MODIFY command
Hi gurus,
i want you to inform me about table illegal statement error. The error occurs when i use modify as below.
loop at itab.
select .......
where xxx eq itab-xxxx.
MODIFY itab.
endselect.
endloop.
i know that i have to give the sy-tabix as INDEX parameter to the modify command. but i want to know why i have to do this?
cause when i debug, i follow the sy-tabix field and it have not a change in select endselect.
may the reason of the error about cursor in select and cursor effects modify command?
or why?
Thx,Hello,
I guess this is because your MODIFY statement is inside the SELECT ... ENDSELECT & not inside the LOOP ... ENDLOOP.
SAP documentation says:
Within a LOOP loop, the INDEX addition can be ommitted. In this case the current table line of the LOOP loop is changed.
You have to change the coding:
DATA: v_index TYPE i.
loop at itab.
v_index = sy-index.
select .......
where xxx eq itab-xxxx.
MODIFY itab INDEX v_index.
endselect.
endloop.
BR,
Suhas
PS: The coding practice followed is not very performance oriented as well. May be you should have a look around in some blogs, wikis in SCN & change the code accordingly.
Edited by: Suhas Saha on Nov 19, 2009 9:41 AM -
How to use collect statement properly
In PBID table , i will get 4 rows for a material . I will get the corresponding values of bdzei from the same table . Now i will pass this bdzei into pbhi table. then i will get some 200 rows of data. I have to sum up the field plnmg , by grouping the laeda field of pbhi. In short, i need to know the sum of pbhi-plnmg for a particular pbhi-laeda . I know a way to do it. But i want to know how to use the COLLECT statement for this purpose. My output should contain oly 1 line for 1 material ..
PBID table
Matnr BDZEI
p4471 457
1002
2309
2493
PBHI table
BDZEI LAEDA PLNMG
1002 06.08.2004 0.000
1002 06.08.2004 83.000
457 07.08.2004 12.000
457 07.08.2004 24.000
Reqd O/p
MATNR LAEDA PLNMG
p4471 06.08.2004 83
p4471 07.08.2004 36
Hope u understood my situation .please help me out ...
Thanking you in advance ..
ShankarREPORT zppr_zpipr NO STANDARD PAGE HEADING LINE-SIZE 150 LINE-COUNT 63.
TABLES: pbid,
pbhi,
makt,
mseg,
mkpf.
DATA: BEGIN OF it_pbid OCCURS 0,
matnr LIKE pbid-matnr, " Material
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
bdzei LIKE pbid-bdzei,
laeda LIKE pbhi-laeda,
end of it_pbid.
DATA: BEGIN OF it_pbim OCCURS 0,
matnr LIKE pbid-matnr, " Material
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
bdzei LIKE pbim-bdzei,
laeda LIKE pbhi-laeda,
end of it_pbim.
DATA: BEGIN OF it_pbid_pbim OCCURS 0,
matnr LIKE pbid-matnr, " Material
laeda LIKE pbhi-laeda, " Reduction Date
dbmng LIKE pbhi-dbmng, " Planned quantity in the data base
plnmg LIKE pbhi-plnmg, " Planned quantity
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
mblnr LIKE mseg-mblnr, " Material Doc Number
pbfnr LIKE pbid-pbdnr, " Plan Number
maktx LIKE makt-maktx, " Matl Desc
aenam LIKE pbhi-aenam, " User Changed
erfmg LIKE mseg-erfmg, " Qty Invoiced
budat LIKE mkpf-budat, " Invoice date
bdzei LIKE pbid-bdzei, " Independent requirements pointer
werks LIKE pbid-werks, " plant
pirrednqty TYPE i, " PIR Reduction Quantity = pbih-plnmg - pbih-dbmng
diff TYPE i, " Difference
slno TYPE i, " Sl No
END OF it_pbid_pbim.
DATA: BEGIN OF it_allrows OCCURS 0.
INCLUDE STRUCTURE it_pbid_pbim.
DATA: END OF it_allrows.
*DATA: BEGIN OF it_final OCCURS 0.
INCLUDE STRUCTURE it_pbid_pbim.
*DATA: END OF it_final.
DATA: BEGIN OF line,
matnr LIKE pbid-matnr, " Material
laeda LIKE pbhi-laeda, " Reduction Date
plnmg LIKE pbhi-plnmg, " Planned quantity
maktx LIKE makt-maktx, " Matl Desc
dbmng LIKE pbhi-dbmng, " Planned quantity in the data base
mblnr LIKE mseg-mblnr, " Material Doc Number
pbfnr LIKE pbid-pbdnr, " Plan Number
aenam LIKE pbhi-aenam, " User Changed
erfmg LIKE mseg-erfmg, " Qty Invoiced
budat LIKE mkpf-budat, " Invoice date
bdzei LIKE pbid-bdzei, " Independent requirements pointer
werks LIKE pbid-werks, " plant
pirrednqty TYPE i, " PIR Reduction Quantity = pbih-plnmg - pbih-dbmng
diff TYPE i, " Difference
slno TYPE i, " Sl No
status TYPE c LENGTH 4, " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
END OF line.
DATA Itfinal1 LIKE STANDARD TABLE
OF LINE
WITH DEFAULT KEY.
DATA ITfinal LIKE ITfinal1.
DATA: BEGIN OF it_dates OCCURS 0,
date TYPE sy-datum,
END OF it_dates.
DATA: l_slno TYPE i.
DATA: l_zebra TYPE c.
SELECT-OPTIONS:
s_werks FOR pbid-werks obligatory.
SELECT-OPTIONS:
s_matnr FOR pbid-matnr.
SELECT-OPTIONS:
s_pbdnr FOR pbid-pbdnr.
SELECT-OPTIONS:
s_laeda FOR pbhi-laeda obligatory.
parameter:
c_print type checkbox.
SELECT matnr bdzei FROM pbid INTO (it_pbid-matnr, it_pbid-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
it_pbid-status = 'PBID'.
APPEND it_pbid.
move-corresponding it_pbid to it_pbid_pbim.
Append it_pbid_pbim.
ENDSELECT.
SELECT matnr bdzei FROM pbim INTO (it_pbim-matnr,it_pbim-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
APPEND it_pbim.
Append it_pbid_pbim.
ENDSELECT.
*break-point.
START-OF-SELECTION.
LOOP AT s_laeda.
it_dates-date = s_laeda-low.
APPEND it_dates.
ENDLOOP.
DATA: l_startdate LIKE sy-datum.
IF s_laeda-high EQ space.
ELSE.
l_startdate = s_laeda-low + 1.
DO.
IF l_startdate <= s_laeda-high.
it_dates-date = l_startdate.
APPEND it_dates.
ELSE.
it_dates-date = sy-datum.
EXIT.
ENDIF.
l_startdate = l_startdate + 1.
ENDDO.
ENDIF.
*break-point.
LOOP AT it_pbim.
LOOP AT it_dates.
it_pbim-laeda = it_dates-date.
it_pbim-status = 'PBIM'.
MODIFY it_pbim TRANSPORTING laeda status.
MOVE-CORRESPONDING it_pbim TO it_pbid_pbim.
APPEND it_pbid_pbim.
ENDLOOP.
ENDLOOP.
break-point.
l_zebra = 'X'.
DATA: l_toterfmg LIKE mseg-erfmg.
DATA: l_erfmg LIKE mseg-erfmg.
data: l_totpir type i.
**************************************PBID*************************************
LOOP AT it_pbid.
move-corresponding it_pbid to it_pbid_pbim.
append it_pbid_pbim.
SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbid-matnr.
MODIFY table it_pbid_pbim TRANSPORTING maktx.
SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-'.
MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
select single sum( dbmng ) sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
endselect.
it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
append it_allrows.
ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
delete it_pbid_pbim index sy-tabix. " debug here
ENDIF.
ENDSELECT.
ENDLOOP.
**************************************PBIM*************************************
LOOP AT it_pbim.
move-corresponding it_pbim to it_pbid_pbim.
append it_pbid_pbim.
SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbim-matnr.
MODIFY table it_pbid_pbim TRANSPORTING maktx.
SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-'.
MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
select single sum( dbmng ) sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
append it_allrows.
ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
delete it_pbid_pbim index sy-tabix. " debug here
ENDIF.
ENDSELECT.
ENDLOOP.
sort it_allrows by matnr laeda status.
**********************************ALL ROWS************************
loop at it_allrows.
line-matnr = it_allrows-matnr.
line-laeda = it_allrows-laeda.
line-plnmg = it_allrows-plnmg.
line-dbmng = it_allrows-dbmng.
line-mblnr = it_allrows-mblnr.
line-pbfnr = it_allrows-pbfnr.
line-maktx = it_allrows-maktx.
line-aenam = it_allrows-aenam.
line-erfmg = it_allrows-erfmg.
line-budat = it_allrows-budat.
line-bdzei = it_allrows-bdzei.
line-werks = it_allrows-werks.
line-pirrednqty = it_allrows-pirrednqty.
line-diff = it_allrows-diff.
line-slno = it_allrows-slno.
line-status = it_allrows-status.
collect line into itfinal1.
endloop.
loop at itfinal1 into line.
collect line into itfinal.
write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
endloop.
skip 4.
loop at itfinal into line.
write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
endloop.
break-point. -
I am getting "ORA-00900: invalid SQL statement" error.?
I did installed oracle 11gR2. and used "DBMS_METADATA_DIFF.COMPARE_ALTER('TABLE','TBL_A','TBL_A','USER1','USER2')" to see the result like below, but I am getting "ORA-00900: invalid SQL statement" error. Any idea?
I am using:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> desc user1.tbl_a
Name Null? Type
FIELD_A1 NOT NULL NUMBER
FIELD_A2 VARCHAR2(20)
FIELD_A4 NOT NULL NUMBER(5,2)
FIELD_A5 VARCHAR2(10)
FIELD_A6 NOT NULL NUMBER(2)
SQL> desc user2.tbl_a
Name Null? Type
FIELD_A1 NOT NULL NUMBER
FIELD_A2 VARCHAR2(50)
FIELD_A3 DATE
FIELD_A4 NUMBER(5,2)
FIELD_A5 NOT NULL VARCHAR2(10)
SQL> select dbms_metadata_diff.compare_alter('TABLE','TBL_A','TBL_A','USER1','USER2') from dual
expected result:
DBMS_METADATA_DIFF.COMPARE_ALTER('TABLE','TBL_A','TBL_A','U1','U2')
ALTER TABLE "U1"."TBL_A" ADD ("FIELD_A3" DATE)
ALTER TABLE "U1"."TBL_A" DROP ("FIELD_A6")
ALTER TABLE "U1"."TBL_A" MODIFY ("FIELD_A2" VARCHAR2(50))
ALTER TABLE "U1"."TBL_A" MODIFY ("FIELD_A4" NUMBER(5,2) DEFAULT 0)
ALTER TABLE "U1"."TBL_A" MODIFY ("FIELD_A4" NULL)
ALTER TABLE "U1"."TBL_A" MODIFY ("FIELD_A5" NOT NULL ENABLE)Thanks for reply rp,
I got result using "select dbms_metadata_diff.compare_alter('TABLE','TBL_A','TBL_A','USER1','USER2') from dual" -
ORA-00900: invalid SQL statement Error while Executing Procedure
Hi:
I am trying to execute following procedure through java code, but i am getting ORA-00900: invalid SQL statement error.
Procedure is :
<code>
(vResult out int)
as
vCardId varchar2(16);
vForacid varchar2(16);
vApp_Entry_No varchar2(10);
vSrNo number(6);
vCardStatus char(1);
vCardStat char(2);
vExpiryDate date;
Cursor cardCur1 is
select u.card_number,trim(u.ACCOUNT_NUMBER),u.CARD_STATUS,to_char(u.EXPIRY_DATE,'dd-MM-yyyy')
FROM DailyCardData u
where default_indicator='1'
and isprocessed = 'N'
order by expiry_date;
begin
vSrNo := 0;
vResult := 0;
open cardCur1;
Loop
fetch cardCur1 into vCardId,vForacid,vCardStat,vExpiryDate;
if cardCur1%NOTFOUND then
exit;
end if;
if (vCardStat != null) then
vCardStatus := 'H';
elsif (vExpiryDate <= sysdate) then
vCardStatus := 'E';
else
vCardStatus := null;
end if;
select a.app_entry_no into vApp_Entry_No from Application a,ApplicationLinkedAccounts l
where l.foracid = vForacid and l.AcSrNo = '1'
and a.app_entry_no = l.app_entry_no
and a.cardid is null
and a.DOWNLOADFILECREATIONFLAG = 'Y';
update Application set CardId = vCardId,
Card_Status = vCardStatus,APPLICATIONPROCESSEDFLAG = 'Y',
APPLICATIONPROCESSEDdate = DOWNLOADFILECREATIONdate
where App_Entry_No = vApp_Entry_No;
commit;
update DailyCardData set isprocessed = 'Y',app_entry_no = vApp_Entry_No
where card_number = vCardId;
commit;
end Loop;
close cardCur1;
vResult := 1;
end;
</code>
Can any body help me in that?
Thank You,
AnupFirst of all I don't see a procedure header.
Secondly I see you commit inside your procedure. This is a bug.
Thirdly I see you also commit inside a loop. This is also a bug, and needs to be removed asap.
The error indicates a statement doesn't parse. As you don't post the error stack, nor a table definition no one can reproduce the problem.
You need to isolate the statements, one by one, and run them through sql*plus to see what happens.
Sybrand Bakker
Senior Oracle DBA -
Issue while using Collect statement in program
Hi friend's,
i have some issue regarding Collect statement..
Issue is somthing like this,i have created a structure and internal table and work area with same type,
u can look in below code..i wann to collect 'enmng' f'ield value whose matnr,charg,mvt type ,aufnr,rsnum are same but rspos and lgort are differnt for this i need to collect 'ENMNG' field value can any one tel me what to do...it not collectng value instead of this it append entire row...
types: begin of ty_resb,
rsnum type resb-rsnum, "Resrvation Number
rspos type resb-rspos, "item position
xloek type resb-xloek, "Item Deleted if = 'X'
matnr type resb-matnr, "Material Number
lgort type resb-lgort, "Storage location 'REJT'
charg type resb-charg, "Batch No
enmng type resb-enmng, "Quantity withdrawn should be greater then '0'
enwrt type resb-enwrt, "Value Withdrawn
aufnr type resb-aufnr, "Order
bwart type resb-bwart, "Movement type
end of ty_resb.
data:tt_resb type table of ty_resb ,
tt_resb1 type table of ty_resb ,
tt_resb2 type standard table of ty_resb ,
**workarea.
ts_resb type ty_resb,
ts_resb2 type ty_resb,
ts_resb1 type ty_resb.
**move data to another internal table
tt_resb1[] = tt_resb[].
sort tt_resb by rsnum rspos matnr charg bwart lgort aufnr .
sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
DELETE adjacent duplicates from tt_resb comparing rsnum rspos matnr charg bwart lgort aufnr .
DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
loop at tt_resb into ts_resb .
clear:ts_resb1,ts_resb2.
read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
if ts_resb1-bwart = '261' .
move ts_resb1-aufnr to ts_resb2-aufnr.
move ts_resb1-matnr to ts_resb2-matnr.
move ts_resb1-charg to ts_resb2-charg.
move ts_resb1-bwart to ts_resb2-bwart.
move ts_resb1-enwrt to ts_resb2-enwrt.
move ts_resb1-lgort to ts_resb2-lgort.
move ts_resb1-enmng to ts_resb2-enmng.
collect ts_resb2 into tt_resb2.
endif.
clear ts_resb.
endloop.
Regard's,
shaikh khalid.Hi Shaikh,
I have added new declarations as highlighted below and new lines within your loop:
Execute your program in debug mode and see what happens to the internal tt_collect I added. The collect will sum the fields enmng for all entries that have same value on the fields matnr,charg,mvt type ,aufnr,rsnum.
Question from me: what do you want to do with the collected/Summed up entries?
types: begin of ty_resb,
rsnum type resb-rsnum, "Resrvation Number
rspos type resb-rspos, "item position
xloek type resb-xloek, "Item Deleted if = 'X'
matnr type resb-matnr, "Material Number
lgort type resb-lgort, "Storage location 'REJT'
charg type resb-charg, "Batch No
enmng type resb-enmng, "Quantity withdrawn should be greater then '0'
enwrt type resb-enwrt, "Value Withdrawn
aufnr type resb-aufnr, "Order
bwart type resb-bwart, "Movement type
end of ty_resb.
data:tt_resb type table of ty_resb ,
tt_resb1 type table of ty_resb ,
tt_resb2 type standard table of ty_resb ,
types: begin of ty_collect,
rsnum type resb-rsnum,
matnr type resb-matnr,
charg type resb-charg,
bwart type resb-bwart,
aufnr type resb-aufnr,
enmng type resb-enmng,
end of ty_collect.
data: tt_collect type table of ty_collect,
ts_collect type ty_collect.
**workarea.
ts_resb type ty_resb,
ts_resb2 type ty_resb,
ts_resb1 type ty_resb.
**move data to another internal table
tt_resb1[] = tt_resb[].
sort tt_resb by rsnum rspos matnr charg bwart lgort aufnr .
sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
DELETE adjacent duplicates from tt_resb comparing rsnum rspos matnr charg bwart lgort aufnr .
DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
loop at tt_resb into ts_resb .
clear:ts_resb1,ts_resb2.
read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
if ts_resb1-bwart = '261' .
move ts_resb1-aufnr to ts_resb2-aufnr.
move ts_resb1-matnr to ts_resb2-matnr.
move ts_resb1-charg to ts_resb2-charg.
move ts_resb1-bwart to ts_resb2-bwart.
move ts_resb1-enwrt to ts_resb2-enwrt.
move ts_resb1-lgort to ts_resb2-lgort.
move ts_resb1-enmng to ts_resb2-enmng.
collect ts_resb2 into tt_resb2.
move-corresponding ts_resb1 to ts_collect.
collect ts_collect into tt_collect
endif.
clear ts_resb.
clear ts_collect.
endloop. -
Hi,
i have requirement to get all unique entries from table .if i am getting duplicate record then i need to add qunatity field which i have define like rlbes-anfme.
my internal table is :
11 name1 23.00
22 name2 1,324.00
11 name1 10.00
I want output in this way
11 name1 33.00
22 name2 1,324.00
i tried to use collect statement but the problem is its not working on character type field.
if i use packed field then i am not able to upload my file because i am getting quantity filed 1,2344.00 this way.( instead of 1325.00)
please give me any solution.
thanks,
jackHi,
Try this..
Create another internal table which has the same structure of your internal table.
DATA: LT_COLLECT LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: V_QUANTITY TYPE MENGE_D.
Sort the internal table.
SORT ITAB BY field1 field2. " Give the appropriate field names.
<b>* process the internal table which has the records.</b>
LOOP AT ITAB.
Sum up the quantity.
V_MENGE = V_MENGE + ITAB-ANFME. " Quantity field.
Move the first two fields.
LT_COLLECT-FIELD1 = ITAB-FIELD1.
LT_COLLECT-FIELD2 = ITAB-FIELD2.
At the end of the record..append the record.
AT END OF FIELD2. " Give the corresponding field name.
LT_COLLECT-ANFME = V_MENGE.
APPEND LT_COLLECT.
CLEAR: V_MENGE.
ENDAT.
ENDLOOP.
Thanks,
Naren -
Reg: Collect statement in internal table
Hi,
Can any one tell me wether we can use the collect statement in an internal table which has no header line
if it can be used can anyone please send me a sample snippet
Thanks In ADVANCE
Guhapriyan SubrahmanyamHi Guhapriyan,
I have used the collect statement in the way as shown..
DATA : BEGIN of I_ALLOCATIONS OCCURS 0,
PSPNR LIKE PRPS-PSPNR,
PSPID LIKE PROJ-PSPID,
PSPHI LIKE PRPS-PSPHI,
POST1 LIKE PROJ-POST1,
ZZLOB LIKE PROJ-ZZLOB,
WERKS LIKE PROJ-WERKS,
SOBID LIKE HRP1001-SOBID,
OBJID LIKE HRP1001-OBJID,
BEGDA LIKE HRP1001-BEGDA,
ENDDA LIKE HRP1001-ENDDA,
PROZT LIKE HRP1001-PROZT,
LOB LIKE HRP1000-STEXT,
TEMP TYPE P decimals 2,
TYPE(3),
ZROLE LIKE PA0001-ZROLE,
HOLID TYPE P decimals 2,
LEAVE TYPE P decimals 2,
DAYS TYPE P decimals 2,
END of I_ALLOCATIONS.
DATA: I_ALLOCATION LIKE I_ALLOCATIONS OCCURS 0 WITH HEADER LINE.
************Populate I_ALLOCATIONS **************
LOOP AT I_ALLOCATIONS.
COLLECT I_ALLOCATIONS INTO I_ALLOCATION.
ENDLOOP.
Actually i had requirement like u, but this one is rather simple...
Get the required data in an I_Table which dont require Header line..
Later on collect this particular I_Table in other I_Table1 with the Header Line...
Regards,
Abhishek -
Two collect statement from internal table
Dear Experts,
I want populate values to two internal tables from a internal table.
can i use two collect statement for different internal table from a single internal table.
advise please.
Thanks in advance.
R.Rajendranhi there....
well u can very well use this thing.....
use the two colect statements inside the loop which u will use to read the records of the input table.
hope it helps.
do reward if it does.
Maybe you are looking for
-
All devices are using updated software and here's the issue: Mom & Dad each have an ipod 3gs. Two teen kids each have an ipod touch 4. All 4 devices use the same Apple ID, share free and purchased apps. The kids are receiving Mom and Dad's text mes
-
I have a 4Gs on IOS6 that wont sent MMS to a 3Gs using IOS4 something or other. I spoke to 02 today and they say there is an Apple fix on the way but there is something that can be tweaked in the meantime but she doesnt know what it is. Anyone having
-
When I attempt to open a Docx type file Thunderbird is attempting to open the document with an old version of Office (2003). I have upgraded to (2013). I have followed the suggestions of going to Tools, Options and Attachments to assign which program
-
Updation agent information in table
Hi , I have created one custom module pool program which is used for request for resource. Now in that i create new entries with request no , date (i.e sydatum) , person responsible (for creating request) all this values are stored in the custom tabl
-
Hi all, can any one tell me that ,Is it possible to install the oracle 10g rel2 on the windows 7 ultimate 32bit. I saw on the oracle download page but it is only available for vista. Reading a article about windows 7 ,it says that many of the vista o