Regarding logic in manipulation of internal table
Hi All,
I have one internal table as below:
<b>I_TAB</b>.
<b>VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
QTY LIKE VBAP-KWMENG,
SUM LIKE VBAP-KWMENG,
</b>
Now i have filled in this internal table from select statement
Data is:
100, 10, 100
100, 10, 200
100, 10, 300
100, 20, 50
100, 30, 100
100, 30, 200
etc.
Now what i want is i want t calculate SUM field in above internal table based on VBELN & POSNR
Finally data should come as
100, 10, QTY, 600
100, 20, QTY, 50
100, 30, QTY, 300
(or)
we can update QTY with SUM of all VBELN/POSNR.
Can anybody tell me what is the logiic!
Thanks,
Deep.
Hi,
Declare on more table as ITAB, say JTAB.
Loop at ITAB.
JTAB-VBELN = ITAB-VBELN.
JTAB-POSNR = ITAB-POSNR.
JTAB-SUM = ITAB-QTY.
COLLECT JTAB
endloop.
JTAB will have ur required output, But u cant put QTY in between since, the Qunattity is Integer field u cant place 'QTY', since it is a char.
Sreedhar
Message was edited by:
Sreedhar Kanchanapalli
Similar Messages
-
Logic issues for manipulation of internal table data
Hi,
I am having a issue with logic of one program.
In the <b>XVBAP</b> internal table of <b>SO</b> User Exit.
We will have fields like
<b>UPDKZ, POSNR, UEPOS, ZZECD[Z-Field] etc.</b>
Above fields are related to logic.
1. Now my first point is:
<b>We need to capture Records where UPDKZ='D' and ZZECD[Z-Field] is populated.</b>
For this we will write code as below:
<b>LOOP AT XVBAP WHERE UPDKZ EQ C_D AND
ZZECD NE SPACE.
Here we will store all fields in I_XVBAP I.Table
ENDLOOP.</b>
Supoose we have retrieved records as below:
<b>VBELN, UPDKZ, POSNR, UEPOS, ZZECD
100 D 000040 000030 Text1
100 D 000050 000020 Text2
100 D 000060 000000 Text3</b>
2. My second point here is:
<b>For Every Item[POSNR] we need to get the Higher level item from UEPOS field, If the Higher level Item also has UPDKZ = D, then move the base unit and all its components into an internal table. continue this process till UEPOS for POSNR is 000000 but High item should have UPDKZ = 'D', not only this all items in this chain should have UPDKZ = 'D'.</b>
Ex:
<b>Suppose for item 000050 UEPOS is 000020 then goto XVBAP with POSNR = UEPOS[000020] and UPDKZ = 'D' if yes and then pick up UEPOS for 000020 item and continue this process till UEPOS becomes 000000 and UPDKZ = 'D'.
Here from Low level to High level all the chain items should have UPDKZ = 'D'. Then only write all items into Final Internal table.</b>
<b>Need to do this process for all above rec's [40,50,60 - POSNR].</b>
Can anybody provide me the logic for the above scenario.
Thanks in advance.
Thanks and Regards,
DeepHi Anurag,
Your assumption is wrong.
See first when we get into our logic we will get <b>XVBAP</b> data as below:
<b>VBELN, POSNR, UEPOS, UPDKZ, ZZECD
100, 10, 00, D, Text1
100, 20, 00, , Text2
100, 30, 20, D, Text3
100, 40, 30, D, Text4
100, 50, 00, , Text5
100, 60, 00, D, Text6
100, 70, 60, D, Text7</b>
After we run first point we will get data as:
Here logic is pick up data where <b>UPDKZ = D</b> and <b>ZZECD NE SPACE</b>.
<b>VBELN, POSNR, UEPOS, UPDKZ, ZZECD
100, 10, 00, D, Text1
100, 30, 20, D, Text3
100, 40, 30, D, Text4
100, 60, 00, D, Text6
100, 70, 60, D, Text7</b>
Then we will goto second point:
Here we need to look into <b>3</b> things totally in 2nd point:
1. In loop Select the record which has <b>UEPOS EQ space</b>, <b>UPDKZ = D</b> and <b>POSNR</b> should not be <b>UEPOS</b> for any other record from above data from 1st point.
<b>100, 10, 00, D, Text1</b>
will be selected into final internal table as per this point.
2. If for a POSNR value UEPOS NE SPACE, UPDKZ = D then goto UEPOS's POSNR in high level check there if UPDKZ = D and then wether UEPOS is ZERO (or) contains any value.
If any value is there repeat the process till UEPOS become ZERO. Then for that final higher level item check UPDKZ value if it has value as 'D', If has then write all those records from low item to high item into final internal table.
<b>100, 60, 00, D, Text6
100, 70, 60, D, Text7</b>
In above for Item 70[POSNR] we have UEPOS as 60 and UPDKZ as D. then we will goto UEPOS's POSNR, Now POSNR is 60 then check it's UEPOS it is ZERO so check UPDKZ because it is D write both items 60, 70 into final internal table.
2. If for a POSNR value UEPOS NE SPACE, UPDKZ = D then goto UEPOS's POSNR in high level check there if UPDKZ = D and then wether UEPOS is ZERO (or) contains any value.
If any value is there repeat the process till UEPOS become ZERO. Then for that final higher level item check UPDKZ value if it has value as 'D', If it does not have UPDKZ as 'D' then don't write any item from low to high into final internal table.
If we take the scenario of below rows:
<b>100, 20, 00, , Text2
100, 30, 20, D, Text3
100, 40, 30, D, Text4</b>
POSNR-40 has UEPOS-30 & UPDKZ = D then UEPOS's POSNR-30 has UEPOS-20 and UPDKZ-D then UEPOS POSNR-20 has UEPOS as 00 then stop here and see UPDKZ which is ZERO so don't consider items 20,30,40 into final i.table.
In the above chain in any record UPDKZ is not 'D' then skip the process anddon't write the records into final internal table.
Final output will come as:
<b>100, 10, 00, D, Text1</b>
<b>100, 60, 00, D, Text6
100, 70, 60, D, Text7</b>
Thanks for all your efforts.
Thanks,
Deep -
Logic required for a Internal table issue
Hi All,
I have 2 internal table. I need STLNR value to another internal table. Both having same field. But while reading from one internal table to another internal table using IDNRK key, One idnrk having 2 different stlnr value. But its taking only one. How to take both the values?
The internal table value like below.
it_stpo--> This is first table, Here one Idnrk having different stlnr value. I need the same in to next table. Here i read with idnrk field but its taking one stlnr value only into next table.
How to change the logic ?
Below is it_stpo table and next one is it_mbew_1
it_stpo
STLNR IDNRK MENGE
17224 00439RM1 2.3
17225 00439RM1 4.2
172333 00849RM2 5.6
172158 00432TM3 7.2
152164 00583RM4 8.4
176123 00583RM4 2.3
it_mbew_1
STLNR IDNRK STPRS
00439RM1 111.22
00439RM1 126.45
00849RM2 3.3364
00432TM3 15.5888
00583RM4 0
00583RM4 0.235
My logic like below,
SORT it_stpo BY idnrk.
SORT it_mbew_1 BY matnr.
LOOP AT it_mbew_1 INTO wa_mbew_1.
READ TABLE it_stpo INTO wa_stpo WITH KEY idnrk = wa_mbew_1-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_mbew_1-stlnr = wa_stpo-stlnr.
MODIFY it_mbew_1 FROM wa_mbew_1 TRANSPORTING stlnr WHERE matnr = wa_mbew_1-matnr.
ENDIF.
ENDLOOP.
Kindly help us.
MohanaTry below logic.
add one more field to it_stpo flag type char01.
update the field with value 'X'.
SORT it_stpo BY idnrk.
SORT it_mbew_1 BY matnr.
LOOP AT it_mbew_1 INTO wa_mbew_1.
CLEAR WA_STPO.
READ TABLE it_stpo INTO wa_stpo WITH KEY idnrk = wa_mbew_1-matnr
flag = 'X'.
if sy-subrc eq 0.
move ' ' to wa_stpo-flag.
modify it_stpo from wa_stpo index sy-tabix.
wa_mbew_1-stlnr = wa_stpo-stlnr.
MODIFY it_mbew_1 FROM wa_mbew_1 TRANSPORTING stlnr WHERE matnr = wa_mbew_1-matnr.
endif.
ENDLOOP.
Regards
Vinod -
Regarding read and compare of internal table.
HI,
i want to read internal table based on key pernr.
suppose if we load the dec month data we want the last record of that month.
if we load march 2008 data we want todays record.
for this there are two fields datefrom and dateto.
how to compare thesse two fields in read statement.
regards,
swami.Hi,
Check this code
loop at itab.
endloop.
if month = december
read table itab with key sy-tabix = sy-dbcnt.
"above stmt will fetch the last record
elseif month = march
read table itab with key sy-tabix = 1.
"above stmt will fetch the first record.
endif.
Reward if helpful.
Regards. -
Logic in updating a internal table...
Hello,
I have a internal table having values as follows:
I_TAB[]:
Doc-num..........Item-num.........amount........Doc-type
456..............01................4.26.................................
456..............02...............345.89..............................
456..............03..............-45.39................................
763...........and so on
After I loop at I_TAB[] is the sum of total amount > 0, the value in doc-type should get updated with 'PX' and if negative the, Doc-type should get updated with 'NX' for all the three records in internal table for whose amount were used in calculating net amount.
How can I achieve this ?
Regards,
Rajesh.Hello,
When you populate the internal table, also populate another internal table with fields document number and amount. Use collect statement to populate the new internal table. i.e by using collect statement you will have only 1 record for the document number and the amount will have summation of all the line items for that document number.
When you loop at itab, just read the new internal table based on the document number. That way you will know whether the total amount is greater than 0 or negative.
Based on this you can update the document type.
Hope this helps.
Thanks,
Sushil Joshi -
Regarding Delete duplicates adjacent in internal table
hey
In my report i tried to delete the adjacent datas as
below from table itab_rbusa.but it is not deleting. why
code------
append lines of itab_glt0[] to itab_rbusa.
delete adjacent duplicates from itab_rbusa comparing all fields.
endof code----
if internal table has below values
011F
316A
789B
789B
131B
132B
302B
i get the same values as output after using the delete statement why?(789B-Business Area is not deleting)
could you please guide me.
ambichan.Hi,
You can use the addition FOR ALL ENTRIES rather than issuing SELECT in a loop. Try something like:
SELECT [DISTINCT] rbusa
FROM glt0
INTO TABLE itab_glt0
FOR ALL ENTRIES IN TABLE itab_t001
WHERE bukrs EQ itab_t001-bukrs
AND <other fields>...
APPEND LINES OF itab_t001[] TO itab_rbusa....
If DISTINCT does not serve the purpose, then you will need:
SORT itab_rbusa.
DELETE ADJACENT DUPLICATES FROM...
Regards
Message was edited by: Shehryar Khan -
Regarding passing blank characters to internal table field
Hi All,
I have small issue.
Actual issue is
I am having one internal table field as <b>oper_table-arbid</b> in the program i will actually pass first 4 characters of that field into another internal table <b>i_download_operation-arbid.</b>
Then if <b>oper_table-arbid</b> is blank i need to pass
4 blank characters into <b>i_download_operation-arbid.</b>
Can anybody tell me how can i do it.
Code is like this
IF oper_table-arbid NE space.
MOVE oper_table-arbid+0(4) TO i_download_operation-arbid.
ELSE.
I need to pass 4 blank char's to i_download_operation-arbid
ENDIF.
oper_table-arbid is of 8 char length & i_download_operation-arbid is of 4 char length.
Can any body tell me what i need to do here.
Thanks in advance.
Thanks & Regards,
Rayeez.hi ,
shaik.
data: var(8) type c value 'abcdefgh'.
write var.
data: bar(8) type c value 'ijkl',
p1(8) .
move bar to p1.
write:/ p1 right-justified.
just execute the program and see the o/p.
if u r trying to pass character then default position is left-justfied .
so u need to explicitly say right-justified so it will take positions 5,6,7,8.
so here u need append blank spaces .
after seeing the o/p u will hav a clear picture .
vijay. -
Regarding the sorting of the internal table
hi,
this is my requirement
iam having an internal table itab and it consists of the date field s_date.
i have to sort the internal table in the descending order of the s_date.
please provide me the code for this.
thanks in advanceHi Surya,
U can use this code
SORT ITAB BY S_DATE DESCENDING.
itab----internal table
S_date--Field name
By default the sorting is done ascending you dont have to specify.
Thanks
Mohinder Singh Chauhan -
Hi All,
I have one logical issue related to internal table manipulation.
I have one internal table :
I_DAT - This is related to Loading/Unloading of Goods.
for example with 3 fields
VSTEL, KUNNA, KMMANG.
Now suppose my data looks like this after sorting:
VSTEL KUNNA KMMANG
100 - -
200 - -
300 - -
400 - -
- 500 X
- 600 X
- 700 X
- 800 X
Here 100,200,300,400 are Loading points.
ANd 500,600,700,800 are unloading points.
Now what i want is For loading & Unloading points i need to pick up Address and print one after other.
But how they need to print is:
FOR INITIAL LOADING OF
ADDRESS- For 100
FIRST STOP: FOR LOADING OF
ADDRESS- For 200
SECOND STOP: FOR LOADING OF
ADDRESS- For 300
Etc .....
Then
FOR UNLOADING OF:
ADDRESS- For 400
FIRST STOP: FOR UNLOADING OF
etc.
FINAL STOP: FOR FINAL UNLOADING OF
We might get as many records :
Can any body give me the logic:
Printing Address is not a problem:
But Above every address we need to print FIRST STOP, SECOND etc like that.
For this i need logic.
Can anybody give the solution!
Thanks in advance.
Thanks & Regards,
Prasad.Try this.I think you want output like this......
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.
This is also helpful......
LOOP AT <itab>.
AT FIRST. ... ENDAT.
AT NEW <f1>. ...... ENDAT.
AT NEW <f2 >. ...... ENDAT.
<single line processing>
AT END OF <f2>. ... ENDAT.
AT END OF <f1>. ... ENDAT.
AT LAST. .... ENDAT.
ENDLOOP.
Regards
Abhishek -
hi experts , i need a logic
i have a internal table itab_equi in that i am getting 11 values when i pass this internal table to another table using for all entries i will get 4 values in int_bmgkobj . i need logic for how to get the deleted values i.e 9 values deleted . i need that value 9 values ..
SELECT matnr
sernr
kunde
objnr FROM equi
INTO TABLE itab_equi " i am getting 11 values here
WHERE kunde = kunde .
IF itab_equi[] IS NOT INITIAL.
SELECT j_objnr
gwldt
gwlen FROM bgmkobj
INTO TABLE itab_bgmkobj " i am getting 4 values here
FOR ALL ENTRIES IN itab_equi
WHERE j_objnr = itab_equi-objnr .
i need the deleted 9 values in a seperate internal table ..
plz help me for this logic
regards
chinnaiya PHI,
Check this ..
SELECT matnr
sernr
kunde
objnr FROM equi
INTO TABLE itab_equi " i am getting 11 values here
WHERE kunde = kunde .
IF itab_equi[] IS NOT INITIAL.
SELECT j_objnr
gwldt
gwlen FROM bgmkobj
INTO TABLE itab_bgmkobj " i am getting 4 values here
FOR ALL ENTRIES IN itab_equi
WHERE j_objnr NE itab_equi-objnr . "--> Check here
Or
Select all the data from bgmkobj into internal table itab_bgmkobj.
Loop the itab_bgmkobj and check the entry using entries in internal table itab_equi..if found delete ..the left entries are what you required -
Hi all,
I have a requirement regarding data processing in a internal table,
internal table consists of filelds Vendor,Material and Scheduling Dates and Total Qty.
Here i need to fill the field Total Quantity, individual addition of quanties of that material for a particular vendor .
Let us consider intitially my internal table consists of data like this with these fields.
Vendor , Material , qty(individual), Total qty , Schedule dates
v1 , m1 , 10
v1 , m1 , 10
v1 , m1 , 20
v1 , m2 , 5
v1 , m2 , 10
v2 , m2 , 20
v2 , m2 , 15
v2 , m3 , 20
v2 , m3 , 10
Initiall the total qty field is empty i need to fill tht field for the last item for a particular material Like M1
for vendor v1 and total qty of m2 for vendor v1, total qty of m1 for v2, total qty of m2 for v2 and so on.
Requied output should be like this.
Vendor , Material , qty(individual) Total qty Schedule dates
v1 , m1 , 10 , 0
v1 , m1 , 10 , 0
v1 , m1 , 20 , 40(101020)
v1 , m2 , 5 , 0
v1 , m2 , 10 , 15(5+10)
v2 , m2 , 20 , 0
v2 , m2 , 15 , 35(20+15)
v2 , m3 , 20 , 0
v2 , m3 , 10 , 30(20+10)
Here i made one thing , i calculated the total qty of material for particular vendor.
Like
Vendor Material Total Qty
v1 , m1 , 40
v1 , m2 , 15
v2 , m2 , 35
v2 , m3 , 30
Finally i need the logic by using Control Events(At New , At End of ) to adjust that total qty of a material for a particular vendor by Modifying the internal table.
i hope my problem is clear , pls let me know if any clarifications needed. and
code for the same .
Thannks in advance,
Niranjan.Hi,
Solution is here.
sort itab by vendor material.
field-symbols: <itab> like line of itab.
loop at itab assigning <itab>.
on change of vendor.
clear flag.
endon.
add <itab>-quanity to lw_quantiy.
*--here pdate internal table end of each similar kind of record
at end of.
flag = 'x'.
<itab>-totalqty = lw_quantiy.
clear lw_quantiy
endat.
*--rest of record update zero by checking flag
if flag is initial.
<itab>-totalqty = 0.
endif.
endloop.
close this thread if you got solution.
Regards,
Peranandam -
Hi All,
I have defined an internal table 'with occurs 0'.
While debuggining, i am observing that only 50,000 lines are getting populated in that internal table.
How to increase the capacity of the internal table, so that it can hold more number of lines?
Regards
PavanI would like to explaing you all about this issue.
I have defined an internal table as follows...
data: IT_CATSDB TYPE BAPICATS2 OCCURS 0 WITH HEADER LINE.
I have used a BAPI called "BAPI_CATIMESHEETRECORD_GETLIST" which will retirieve the Timesheet details of all employees within a given date range.
Now, the number of entries that we got from this BAPI are stored in the internal table it_catsdb.
I have observed that this internal table is holding max of 50k lines.
If i check the database table (CATSDB) for the same conditions in SE11, i am able to get around 1L lines.
Hence my report is showing incorrect output.
Kindly help me out with some logic, so that this internal table can hold as much as data possible without any restriction.....
Regards
Pavan -
Pick Common records from 2 internal tables
Hi,
I have 2 similar internal tables it_bseg1 (contain records based on the Posting Date BUDAT of document) & it_bseg2 (contain records based on the Customer Code KUNNR). Both these tables contains some common records. And I want these common records only. So please tell me to get the common records in the easiest way.
Regards,
VishalHi,
There must be atleast one common field for these two internal tables to get the common records.
If you identify the common field then you can use this logic.
Loop at it_bseg1 into wa_bseg1.
Read table bseg2 into wa_bseg2 with key <commonfield > = wa_itab1-<commonfield>.
If sy-subrc eq 0.
Append wa_bseg1 to it_bseg3.
Endif.
Endloop.
Now it_bseg3 contains the common records.
If there is no use of it_bseg1 in your further development then you can do teh logic without declaring third internal table it_bseg3.
Loop at it_bseg1 into wa_bseg1.
Read table bseg2 into wa_bseg2 with key <commonfield > = wa_itab1-<commonfield>.
If sy-subrc ne 0.
delete it_bseg1 where <commonfield> = wa_itab1-<commonfield>.
Endif.
Endloop.
Now it_bseg1 contains teh common records of it_bseg1 and it_bseg2.
Hope this will help.
Regards,
Swarna Munukoti.
Edited by: Swarna Munukoti on Sep 3, 2008 2:05 PM -
Problem in changing the internal table contents of a standard program
Dear All,
I am making changes to internal table LT_PPDIT of standard program SAPLHRPT in the user exit EXIT_SAPLACC4_001 while payroll posting to accounting with tcode PC00_M99_CIPE. But though the changed value of LT_PPDIT is visible within the exit still the value of LT_PPDIT when we come outside exit is the same as what was before entering exit.
Please suggest is there any way of modifying internal table of a standard program in the user exit.
Regards,
KanupriyaHi,
I think the internal table is getting refreshed or something like that after the user exit.
Try debugging after the user exit and put breakpoints at clear and modify statements.
Then you ll find out where its regaining the oringinal value after getting changes.
After locating that point try finding some enhancmenent point there and including your code so that your value of internal able gets modified.
Regards,
Subhashini -
Steps for: Internal table - convert to PDF - Sotre PDF files on UNIX Server
Hi Experts,
My requirement is to Split an internal table into multiple tables and generate a PDF for each of them.Then I have to place these files on a unix server directory. How can I achieve this?
This seems like a very high level requirement description .Please let me know if the solution needs some more details.
Thanks In Advance
Abhishek
Edited by: Yatin Vishwas Parab on Oct 23, 2009 1:53 PMHi,
1) The logic for splitting a internal table into multiple tables should lie with you .
2) write each of the split internal table to spool and convert them to PDF using the FM 'CONVERT_ABAPSPOOLJOB_2_PDF'. This has been discussed many times and you can find relevant threads by searching.
3) For storing the PDF in application server, use OPEN DATASET statement in binary mode and transfer the data. Even this has been discussed quite a few times before and you can search for relevant threads
Vikranth
Maybe you are looking for
-
Frozen appple on LCD and not recognized by windows (Device Malfunction)
All songs totally erased from my Ipod a few weeks back. When I tried to syncronize my computer now says that the device is malfunctioned and windows does not recognize it. Now the Ipod has a frozen apple on the LCD that I cannot turn off or anything.
-
Mac Mini won't start and constantly makes disc ejecting noise
My Mac Mini won't start. It was working fine, then just locked up and won't start again. When I push the start button it just makes this repeated disc ejecting noise from the DVD drive. It doesn't make the chime noise or display anything on the monit
-
I wonder if anyone can help, as the BT helpdesk have refused to acknowledge that I have a problem. My BT Infinity Download speed os very good, around 30 mbits/sec. My Upload speed is very very poor, if fluctuates between 0.3 and 0.5 mbits/sec. If I u
-
Application running in Solaris 9 container generating core files. what to do?
My solaris 9 zone configuration in solaris 10 looks like: zonecfg:sms> info zonename: sms zonepath: /zone/sms brand: solaris9 autoboot: true bootargs: pool: limitpriv: default,proc_priocntl,proc_clock_highres,proc_lock_memory,sys_time,priv_proc_prioc
-
Is there any advantage in performing a clean install?
I'm curious... My 80GB internal hard drive is nearly full so I will be upgrading to a 250GB. Is there any advantage in performing a clean install of Tiger on the new HDD and then copying across files etc from the old one using migration tool? (the id