‎2014 Mar 13 6:42 AM
Hi Friend,
i have written program with table s026 and coep with internal table gt_s026 is my final internal table i used collect statement to store data in that above
now i want to fetch data from coep based on werks ,(objnr with prefix (OR) )using for all entry of gt_s026.
i want to take value of wkgbtr and megbtr for only those kstar which i mention below code .
in my gt_s026 internal table i have 2 line item based on aufnr which is (000060010137 ,000060010144)
and in my gt_coep internal table i have 20 line item based on objnr whcih is 10 line for (000060010137 ) and 10 line for (000060010144)
now i want to move data from gs_coep to gs_s026_n and modify gt_s026_n but it overwrigt gt_s026 i want to collect value wkgbtr and megbtr based on kstar which shown below code
loop at gt_s026_n into gs_s026_n .
clear gs_coep.
sort gt_coep1 by objnr kstar ascending .
loop at gt_coep1 into gs_coep .
if sy-subrc = 0.
case gs_coep-kstar.
when '0080000010'.
gs_s026_n-wkgbtr1 = gs_coep-wkgbtr .
gs_s026_n-megbtr1 = gs_coep-megbtr.
when '0080000020'.
gs_s026_n-wkgbtr2 = gs_coep-wkgbtr .
gs_s026_n-megbtr2 = gs_coep-megbtr.
when '0080000030'.
gs_s026_n-wkgbtr3 = gs_coep-wkgbtr .
gs_s026_n-megbtr3 = gs_coep-megbtr.
when '0080000040'.
gs_s026_n-wkgbtr4 = gs_coep-wkgbtr .
gs_s026_n-megbtr4 = gs_coep-megbtr.
when '0080000070'.
gs_s026_n-wkgbtr5 = gs_coep-wkgbtr .
gs_s026_n-megbtr5 = gs_coep-megbtr.
when '0080000080'.
gs_s026_n-wkgbtr6 = gs_coep-wkgbtr .
gs_s026_n-megbtr6 = gs_coep-megbtr.
when '00l80000090'.
gs_s026_n-wkgbtr7 = gs_coep-wkgbtr .
gs_s026_n-megbtr7 = gs_coep-megbtr.
when others.
endcase.
endif.
shift gs_coep-objnr left deleting leading 'OR'.
if gs_s026_n-aufnr = gs_coep-objnr.
modify gt_s026_n from gs_s026_n transporting wkgbtr1 megbtr1 wkgbtr2 megbtr2 wkgbtr3 megbtr3 wkgbtr4 megbtr4
wkgbtr5 megbtr5 wkgbtr6 megbtr6 wkgbtr7 megbtr7 aufnr
where aufnr = gs_coep-objnr.
endif.
endloop.
endloop.
Regard's,
shaikh khalid
‎2014 Mar 13 7:22 AM
‎2014 Mar 13 7:26 AM
is not modifying my final table gt_s026_n i wan to collect all wkgbtr1 megbtr1 field value but it overwritting filed value
‎2014 Mar 13 7:32 AM
Hi Ali,
if you use modify mean the internal table will hold last transporting value only... you have to use collect statements instead of modify.
Regards,
Thangam.P
‎2014 Mar 13 8:24 AM
but i already used collect statment above for this table for some calculation again if i used it going workout ?
‎2014 Mar 13 8:34 AM
‎2014 Mar 13 9:12 AM
see this is my above code i collect in gt_s026_n .
loop at gt_s026 into gs_s026.
clear: gs_s026_n.
* flg_mcomp = gs_s026-mcomp+1(1).
gs_s026_n-aufnr = gs_s026-aufnr.
if gs_s026-mcomp+12(1) = '1' or gs_s026-mcomp+12(1) = 3.
gs_s026_n-enmng = gs_s026-enmng.
gs_s026_n-enwrt = gs_s026-enwrt.
elseif gs_s026-mcomp+12(1) = 2.
gs_s026_n-enmng1 = gs_s026-enmng.
gs_s026_n-enwrt1 = gs_s026-enwrt.
endif.
gs_s026_n-werks = gs_s026-werks.
gs_s026_n-matnr = gs_s026-matnr.
collect gs_s026_n into gt_s026_n.
endloop
again if i am using collect statment for gt_s026_n it modify value for gs_s026_n-enwrt and enmng th isnsted of my modifyng value of internal table for field gt_coep-wkgbtr and gt_coep-megbtr
shift gs_coep-objnr left deleting leading 'OR'.
if gs_s026_n-aufnr = gs_coep-objnr.
modify gt_s026_n from gs_s026_n transporting wkgbtr1 megbtr1 wkgbtr2 megbtr2 wkgbtr3 megbtr3 wkgbtr4 megbtr4 wkgbtr5 megbtr5 wkgbtr6 megbtr6 wkgbtr7 megbtr7 aufnr
where aufnr = gs_coep-objnr.
endif.
‎2014 Mar 13 9:04 AM
Hi Ali,
Try with below code.
sort gt_coep1 by objnr kstar ascending .
loop at gt_s026_n ASSIGNING <fs_s026_n> .
clear gs_coep.
loop at gt_coep1 into gs_coep .
if <fs_s026_n>-aufnr = gs_coep-objnr.
case gs_coep-kstar.
when '0080000010'.
<fs_s026_n>-wkgbtr1 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr1 = gs_coep-megbtr.
when '0080000020'.
<fs_s026_n>-wkgbtr2 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr2 = gs_coep-megbtr.
when '0080000030'.
<fs_s026_n>-wkgbtr3 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr3 = gs_coep-megbtr.
when '0080000040'.
<fs_s026_n>-wkgbtr4 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr4 = gs_coep-megbtr.
when '0080000070'.
<fs_s026_n>-wkgbtr5 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr5 = gs_coep-megbtr.
when '0080000080'.
<fs_s026_n>-wkgbtr6 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr6 = gs_coep-megbtr.
when '00l80000090'.
<fs_s026_n>-wkgbtr7 = gs_coep-wkgbtr .
<fs_s026_n>-megbtr7 = gs_coep-megbtr.
when others.
endcase.
shift gs_coep-objnr left deleting leading 'OR'.
endif.
clear gs_coep.
endloop.
endloop.
If you use field symbols no need to use Modify statement for updating internal table.
Regards,
Manasa Veena P.
‎2014 Mar 13 9:21 AM
hi mansa,
as you send me code actualy i didnt use field symbol
in my gt_s026_n internal table i have aufnr field value (000060010137 and 000060010144)
and in my gt_coep1 internal table i have objnr field value (OR000060010137 and OR000060010144)
so how i can compare this
if <fs_s026_n>-aufnr = gs_coep-objnr.
loop at gt_s026_n ASSIGNING <fs_s026_n> .
clear gs_coep.
loop at gt_coep1 into gs_coep .
if <fs_s026_n>-aufnr = gs_coep-objnr.
‎2014 Mar 13 10:12 AM
Hi Ali,
Yes , your are not using the field symbols.
Instead of using Work area use field symbols. Performance wise also it is good to use field symbols.
As field symbols act as a place holder if you modify the data in field symbol automatically it gets reflected in internal table.
if your declaration of work area is
data gs_s026_n type XXXXX(Structure you are refering).
replace it with
FIELD-SYMBOLS : <fs_s026_n> TYPE XXXX.
and in your first post you are using
if gs_s026_n-aufnr = gs_coep-objnr.
Condition and modifying the data so replace it with
if <fs_s026_n>-aufnr = gs_coep-objnr. at the stating of loop so that you can avoid un-necessary execution of the code .If condition satisfies then only data get changed.
Regards,
Manasa Veena P.
‎2014 Mar 13 10:12 AM
Before the IF statement use your existing SHIFT statement to remove 'OR'
loop at gt_s026_n ASSIGNING <fs_s026_n> .
clear gs_coep.
loop at gt_coep1 into gs_coep .
shift gs_coep-objnr left deleting leading 'OR'.-> Insert this SHIFT statement
if <fs_s026_n>-aufnr = gs_coep-objnr.
‎2014 Mar 13 10:19 AM
Hi Ali,
You can modify the internal table using index. Like you keep the index in a variable and then use it for modifying the table.
Data l_index type i. " Added
loop at gt_s026_n into gs_s026_n .
l_index = sy-tabix. " Added
clear gs_coep.
And then use this index to modify.
modify gt_s026_n from gs_s026_n
index l_index " Added
transporting wkgbtr1 megbtr1 wkgbtr2 megbtr2 wkgbtr3 megbtr3 wkgbtr4 megbtr4 wkgbtr5 megbtr5 wkgbtr6 megbtr6 wkgbtr7 megbtr7 aufnr.
I think this will be helpful.
With Regards,
Nabarun
‎2014 Mar 17 9:07 AM
Hi all,
thank's to all,
my issue was resolved,
regard's,
shaikh.khalid
‎2014 Mar 19 8:18 AM