10-08-2014 9:33 AM
Hello Everyone,
Thank you for giving your time. I have an internal table having thousands of records. How can I replace the value of a variable in one go without using loops.
Ex. -
LOOP AT gt_bseg_02 INTO gs_bseg_02.
IF gs_bseg_02-koart = ''.
gs_bseg_02-koart = 'XYZ'.
ENDIF. " IF gs_bseg_02-koart = ''
modify gt_bseg_02 from gs_bseg_02.
ENDLOOP. " LOOP AT gt_bseg_02 INTO gs_bseg_02
Is there any single statement to do this? like we can simple delete the records without using loops with the delete statement.
Regards
Mani
10-08-2014 10:00 AM
Hi Mani,
You can use the below code,
Assign the value to the field like below, and then modify from the work area as written below.
WA_BSEG-KOART = 'XYZ'.
MODIFY gt_bseg_02 FROM wa_bseg TRANSPORTING koart WHERE koart EQ ''.
Please let us know on the progress :).
regards,
Satish
10-08-2014 10:15 AM
Also Please check the below documentation for further clarifications.
http://help.sap.com/erp2005_ehp_04/helpdata/EN/fc/eb35eb358411d1829f0000e829fbfe/frameset.htm
Regards,
Satish
10-08-2014 11:23 AM
Although some people don't like it:
LOOP AT itab ASSIGNING <field-symbol> is NEVER slower but suaually much faster than LOOP AT itab INTO headerline.
FIELD-SYMBOLS:
<bseg> TYPE bseg.
LOOP AT it_bseg ASSIGNING <bseg>
WHERE koart IS INITIAL.
<bseg>-koart = 'your value'.
ENDLOOP.
No modify needed because you are working directly with the table.
It won't be much slower than MODIFY itab TRANSPORTING ... WHERE
Regards
Clemens
10-08-2014 10:07 AM
Use modify transporting...
From the ABAP Keyword Documentation:
"The addition TRANSPORTING has the same effect as changing individual rows. The addition WHERE can only be specified together with the addition TRANSPORTING".
gs_bseg_02-koart = 'XYZ'.
modify gt_bseg_02 from gs_bseg_02 transporting koart where koart = ''.
10-08-2014 11:11 AM
Instead of loop you can use modify statement.
MODIFY itab FROM wa TRANSPORTING field WHERE <your condition>.
wa = work area containing your required value.
condition = optional