Previous record in internal table
HI,
suppose i have two records in my internal table
Prince 3 12/12/1999
menon 4 12/12/2000
When i loop at this and when my record comes to menon i need the date of prince to be stored... how do i proceed.
i.e going on record back.
Any help will be appreciated.
Prince
Try something like this.
data: index type i.
data: wa like line of itab.
Loop at itab.
index = sy-tabix - 1.
read table itab into wa index index.
if sy-subrc = 0.
* Now WA contains the previous row of ITAB
endif.
endloop.
Regards,
Rich Heilman
Similar Messages
-
How to fetch previous record from internal table?
Hi,
My final internal table (it_final) has all the data month wise year wise.(opening and closing qty)
but if
Material Batch Month Year opening_qty closing_qty
FC5431 abc 08 2008 100 50
FC5431 ABC 09 2009 0 100
Suppose I want to take PREVIOUS record(closing_qty = 50 in my 09/2009 openin_qty = 50) how will Ido this?
Any solution????????? BTW i m using S033 for opening an closing qt monthwise.
Plz reply soon if anyone knows.
Thanks and Regards,
ArchanaHi,
Test the following Sample code hope will solve out your problem,
TYPES: BEGIN OF ty_test,
m(3),
open_qty TYPE i,
close_qty TYPE i,
END OF ty_test.
DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE,
wa_test LIKE LINE OF it_test,
ctabix LIKE sy-tabix,
ptabix LIKE sy-tabix.
it_test-m = 'AAA'. it_test-open_qty = 100. it_test-close_qty = 50. append it_test.
it_test-m = 'AAA'. it_test-open_qty = 0. it_test-close_qty = 100. append it_test.
LOOP AT it_test.
ctabix = sy-tabix.
IF sy-tabix > 1.
ptabix = sy-tabix - 1.
READ TABLE it_test into wa_test INDEX ptabix.
IF sy-subrc = 0.
it_test-open_qty = wa_test-close_qty.
ENDIF.
MODIFY it_test INDEX ctabix.
ENDIF.
ENDLOOP.
LOOP AT it_test.
WRITE: it_test-m, it_test-open_qty, it_test-close_qty, /.
ENDLOOP.
Regards,
Faisal -
To get recent timestamp records from internal table
hi all,
i have one requirment
i'm storing error messages in one table while creating a sales order basing on timestamp
which is of this format yyyy-mm-dd hh:mm:ss (random Number)
if i want to see the error messages left i'm getting all the error messages displayed
for example i have created a sales order
i got 10 errors displayed
i have rectified 5 errors ... if i again display error messages the 10 errors + the 5 errors is getting displayed
i want to display the 5 error messages only not the previous messages from internal table
basing on timestamp current one has to displayed remaining has to deleted from internal table.I thought we used Sales Order Incompletion process for this.... but, if you're recreating the errors list every time you save with a create or change transaction then, at save, delete all rows in your error table for this document. Then get your errors and update your db table from your current errors table. From this viewpoint, the timestamp is not relevant.
-
How to update Records from Internal table to u2018Zu2019 table?
Hi Friends,
How to update Records from Internal table to u2018Zu2019 table.
I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
( my internal table & u2018 Zu2019 table structures are same.)
Thanking you.
Regards,
SubashHi,
loop at internal table.
modify <Z- table > from values < internal table Workarea>.
if sy-subrc = 0.
COMMIT work.
else.
ROLLBACK waork.
endif.
endloop.
or
UPDATE <Z- table > from table < internal table Workarea>.
if sy-subrc = 0.
COMMIT work.
else.
ROLLBACK waork.
endif.
Prabhudas -
Inserting records from internal table to database table
Hi all,
i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
1) insert one by one record from internal table
loop at itab.
insert ztable from wa.
endloop.
2) insert total records at a time
INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or let me know if any other statement is there with high performance.
i internal table contains nearly 40000 records.
thanks.Hi,
Insert the entire table at atime rather than a record so as to increase the performance.
you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or
MODIFY ZPRODUCT FROM TABLE GI_AFPO.
Regards,
Raj. -
To delete duplicate records from internal table
hi friends,
i have to delete records from internal table based on following criterion.
total fields are 7.
out of which if 4 fields are same and 5th field is different,then both records must be deleted.
in case all five fields are same,the program should do nothing.
for example.
if there are 3 records as follows
a1 b1 c1 d1 e1 f g
a1 b1 c1 d1 e2 w r
a1 b1 c1 d1 e1 j l
then first two records should be deleted as four fields are same but fifth(e) field differs.
but third record should remain as it is evenif first five fields are same for first and third record.
values of last two fields need not to be consider for deleting the records.LOOP AT ITAB.
V_FILED5 = ITAB-F5. "to compare later
V_TABIX = SY-TABIX. "used to delete if condition not matches
READ TABLE ITAB WITH KEY F1 = ITAB-F1
F2 = ITAB-F2
F3 = ITAB-F3
F4 = ITAB-F4.
IF SY-SUBRC = 0.
IF ITAB-F5 <> V_FIELD5.
*--both the records to be deleted,as Field5 is different.
DELETE ITAB INDEX SY-TABIX. "deletes that record
DELETE ITAB INDEX V_TABIX. "deletes the current record
ENDIF.
ENDIF.
ENDLOOP.
Message was edited by: Srikanth Kidambi
added comments
Message was edited by: Srikanth Kidambi -
How to get multiple records from internal table through BDC
PERFORM DYNPRO USING:
'X' 'SAPMM61L' '0500',
' ' 'BDC_OKCODE' '=NEWC',
'X' 'SAPMM61L' '0500',
' ' 'BDC_CURSOR' 'PLPTU-PLWRK(01)',
' ' 'BDC_OKCODE' '=TAKE',
' ' 'PLPTU-PLWRK(01)' '2531'. (2531 is a plant)
This is the recording used to get plant via BDC of MS31.
Using this code i can get only single plant...
If i want to get multiple plants from an internal table,how i can change this code?
Since it is a recording i cant put this code in LOOP..ENDLOOP.
Suggest any method for doing this....
Awaiting for ur reply...Hi,
While recording also record the scroll down button.
The you can place different plant in the BDC using loop and endloop
Regards
Arun -
Regarding how to delete the record in internal table
Hi experts ,
how to delete the record in intarnal table after validating the data,
if record contains invalid fields?
i am giving my code see this and give me the answer?
loop at it_data into wa_data .
Validate Cost Center
READ TABLE it_kostl INTO wa_kostl WITH KEY kostl = wa_data-kostl BINARY SEARCH.
IF sy-subrc NE 0.
PERFORM update_error_log USING wa_data
text-004.
ENDIF.
Validate source file material ( material number )
loop at it_mara into wa_mara .
read table it_ausp into wa_ausp with key atwrt = wa_data-i_matnr .
if sy-subrc NE 0 .
PERFORM update_error_log USING wa_data
text-002.
delete it_data-objek .
else.
read table it_mara into wa_mara with key matnr = wa_ausp-objek .
if sy-subrc EQ 0 .
wa_data-objek = wa_mara-matnr.
wa_data-matkl = wa_mara-matkl.
ENDIF.
Modify it_data from wa_data .
endif.
*endloop.
Validate unit of measure (unit)
READ TABLE it_t006 INTO wa_t006 WITH KEY msehi = wa_data-unit .
IF sy-subrc NE 0.
PERFORM update_error_log USING wa_data
text-003.
endif.
Validate delivery location ( storage location )
READ TABLE it_lgort INTO wa_lgort WITH KEY del_loc = wa_data-del_loc.
IF sy-subrc NE 0.
PERFORM update_error_log USING wa_data
text-001.
if wa_data-flag ='x' .
delete it_data from wa_data .
endif.
ENDIF.
endloop.Hi Naren,
First get the index number of the IT_data table and store it in one variable whose declaration like this.
data: tabix type sy-tabix.
while reading the internal table it_data set the tabix variable.
tabix = sy-tabix.
Instead of the above use below one.
Delete it_data-objek
Use the Below statement it will delete the row from the internal table.
Delete it_data-objek index tabix
Thanks,
Chidanand -
Unable to delete double records from internal table
Hi all,
The internal table is like this
begin of ta_itab1 occurs 0,
mark type c,
cnt_hedg type c,
kunnr like vbak-kunnr,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
matnr like vbap-matnr,
kwmeng like vbap-kwmeng,
h_kwmeng like vbap-kwmeng,
spart like vbap-spart,
werks like vbap-werks,
component like bom_item_api01-component,
comp_qty like bom_item_api01-comp_qty,
comp_qty1 like bom_item_api01-comp_qty,
base_quan like stko_api02-base_quan,
comp_unit like bom_item_api01-comp_unit,
base_unit like bom_item_api01-comp_unit,
bukrs_vf like vbak-bukrs_vf,
end of ta_itab1.
and used the sytax:
sort ta_itab6 by kunnr vbeln.
DELETE ADJACENT DUPLICATES FROM ta_itab6 comparing COMP_QTY COMP_QTY1.
but Im unable to delete duplicate record .
Thank You.
anuHi ,
You need to use the fields in sort statement on whichyiu wnat to perform Delete Adjacent duplicates..
sort ta_itab6 by kunnr vbeln COMP_QTY COMP_QTY1.
DELETE ADJACENT DUPLICATES FROM ta_itab6 comparing COMP_QTY COMP_QTY1. -
Delete records in internal table
Hi,
I have two internal tables itab1 and itab2.
I need to delete records from itab1 comparing the data from itab2. I tried to use the read statement within the main table.
My problem is itab2 and itab1 has multiple records and all the records need to be checked from itab2 with itab1 before deleting the records from itab1.
itab1 and itab2 have a common field 'runid' between them.
How can this be accomplished?
Thanks,
VG>
Venkat.O wrote:
> Hi VG,
> Try this way.
>
> data: tabix type sy-tabix.
> loop at itab1.
> tabix = sy-tabix.
> _LOOP at itab2 where runid = itab1-runid._
_> if sy-subrc NE 0._
> delete itab1 index tabix.
> endif.
> endloop.
>
> Thanks
> Venkat.O
Venkat, inside a loop a IF SY-SUBRC NE 0 doesn't make sense because you are in the loop only after the condition in WHERE clause is satisfied (which means SY-SUBRC is always 0). Also you are missing another ENDLOOP. -
Delete records from internal table
hi all,
i want to delete records from intenal table which are starting with a particular starting number .
eg internal table
10000
20000
90000
91000
92000
88880
i want delete the records starting with 9 i.e. 90000 91000 92000.
Thanks in Adv
RAJYou can test this piece of code.
DATA:
i_tab TYPE STANDARD TABLE OF mara,
wa_tab TYPE mara.
wa_tab-matnr = '1000'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '1001'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '1002'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '1003'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '2001'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '3001'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '4010'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM -
To find the duplicate record in internal table
Hi,
i have a requirement to fine the duplicate record with 3 fields.
i am getting a flat file with 15 fields .
i need to check the duplaicate records of 3 fields . if i get any 2nd same record of 3 fields , the records will go to other internal table.
for ex :
1. aaa bbb ccc ddd eee fff ggg hhh
2. aaa bbb ccf dde edd ffg ggh hhj
3. aaa bbb cce ddd ees ffh ggu hhk
in that 1st record and 3rd record are same (aaa bbb ddd)
i need to find 3rd record
please help me
regrards
srinivasuhi,
itab2[] = itab1[].
sort itab1 by f1 f2 f3.
sort itab2 by f1 f2 f3.
delete itab2 index 1. "to delete the first record in itab2.
loop at itab1 into ws_itab1.
loop at itab2 into ws_itab2.
if ws_itab1-f1 = ws_itab2-f1 and
ws_itab1-f2 = ws_itab2-f2 and
ws_itab1-f3 = ws_itab2-f3.
ws_itab3 = ws_itab2.
append ws_itab3 into itab3. "Third internal table.
endif.
endloop.
delete itab2 index 1.
endloop.
ITAB3 will have all the duplicate records.
Regards,
Subramanian -
Question reg. modifying latest record in internal table
Can you tell me if it is possible to modify the last appended record to the internal table?
I just want to modify the record in the internal table which is appended at the latest. Please tell me the logic for this.
Thanks a lot,
KrishenHi try with this:
DATA line TYPE I.
DATA wa_itab TYPE LINE OF it_itab.
DESCRIBE TABLE IT_TABLE LINE line.
READ TABLE IT_TABLE INTO wa_itab INDEX line.
WA_TABLE-FIELD = 'new value'.
MODIFY TABLE IT_TABLE FROM wa_itab
TRANSPORTING field.
Best regards. -
Only first record in internal table in output
Hi,
I have a requirement.
I loop at an internal table and that tabl (list_selected_records) records.
Loop at list_of_selected_nodes into wa_selected_nodes.
node = wa_selected_nodes-node_id.
node_level = wa_selected_nodes-node_level.
read table ex_list_of_texts
into wa_list_of_texts
with key node_id = node
binary search.
IF sy-subrc eq 0.
node_text = wa_list_of_texts-text.
ENDIF.
node_level = node_level - 1.
Selecting Text for Node selected (Business Scenario)
READ TABLE list_of_all_nodes into wa_all_nodes WITH KEY NODE_LEVEL = node_level
BINARY SEARCH.
if sy-subrc = 0.
SELECT SINGLE TEXT FROM TTREET into texts WHERE ID EQ wa_all_nodes-tree_id
AND SPRAS EQ 'EN '.
IF NOT TEXTS IS INITIAL.
wa_final-texts = texts.
append wa_final to it_final.
CLEAR WA_FINAL.
endif.
endif.
endloop.
This is my code.
Now from the select single stmt i fetch a text and add it to be internal table . Once i fetch a one record the loop should be ended and a new iteration for for a second guid should start.
Once one record , first record is fetched for texts, only that shd appear in alv output but not other. but the loop should contnue for other fields. Please help
Thanks in Advance.
SSHi Swarna,
Use control event AT-NEW inside the loop. This event will triger only once for every new node_id.
Loop at list_of_selected_nodes into wa_selected_nodes.
AT-NEW node_id.
node = wa_selected_nodes-node_id.
node_level = wa_selected_nodes-node_level.
read table ex_list_of_texts
into wa_list_of_texts
with key node_id = node
binary search.
IF sy-subrc eq 0.
node_text = wa_list_of_texts-text.
ENDIF.
node_level = node_level - 1.
Selecting Text for Node selected (Business Scenario)
READ TABLE list_of_all_nodes into wa_all_nodes WITH KEY NODE_LEVEL = node_level
BINARY SEARCH.
if sy-subrc = 0.
SELECT SINGLE TEXT FROM TTREET into texts WHERE ID EQ wa_all_nodes-tree_id
AND SPRAS EQ 'EN '.
IF NOT TEXTS IS INITIAL.
wa_final-texts = texts.
append wa_final to it_final.
CLEAR WA_FINAL.
endif.
endif.
ENDAT.
endloop.
Thanks & Regards,
Parameswaran.K -
Calling record in internal table
Hi,
I have an internal table itab of this type:
types: begin of tdat
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of tdat.
All I want to do is assign the second field of the second record of the internal table to a variable. How do I do so?
thanks!Not sure what you requirement is......but you can do this too.
report zrich_0001.
data: begin of itab occurs 0,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of itab.
field-symbols: <fs>.
data: some_variable(10).
itab-fld1 = '1'.
itab-fld2 = '2'.
itab-fld3 = '3'.
append itab.
itab-fld1 = '4'.
itab-fld2 = '5'.
itab-fld3 = '6'.
append itab.
itab-fld1 = '7'.
itab-fld2 = '8'.
itab-fld3 = '9'.
append itab.
assign itab-fld2 to <fs>.
read table itab index 2.
check sy-subrc = 0.
some_variable = <fs>.
Regards,
Rich Heilman
Maybe you are looking for
-
I can't publish to an ftp server. can you help?
G'day everyone, I've made a lovely iWeb site, but am having problems getting it online. I click publish and iWeb is busy for about 2 - 3 hours, eventually ending with this "PUBLISH ERROR" message: "There was an error communicating with the FTP server
-
Hello everyone, I would like to know the differences between the different exchange rate types, particularly EURO, EURX and M. From what I've read: EURO is the fixed currency between old EMU-participating currencies and the Euro (DEM<->EUR, ...). EUR
-
"Please Wait For The User Profile Service" message when logging on to TS 2008
I have a Windows 2008 AD Domain with 2 Windows 2008 Terminal Servers. Both are configured identically. I have the TS Roaming profiles stored on a 3rd server and a GPO pointing all users to the roaming profiles. On one of the servers everything wor
-
Text size, better to use px or em?
For text sizing, is it better to use px or em? And what are the advantages to one/both? thanks james
-
Code to display error msg if duplicate entry
I have an upload program to upload csv file to itab, and i need a sample code for the employee id to give me an error message if a duplicate employee id is found during execution.