on 01-12-2011 3:35 AM
Hi All ,
I am facing a problem while modifying an internal table.I want to modify only one field LIFNR (rest of the fields remain unchanged) of the internal table .Can anybody please let me know how I can do this . For your refrence I have explained the scenario below :
I have an internal table gt_pos_data defined as follows:
Field-symbols : <gt_pos_data> type table,
<gs_pos_data>.
Say suppose I have 5 records in internal table <gt_pos_data>. In all 5 records the field LIFNR is blank. Now I want to change the value of field LIFNR base on some logic. I need to loop at the internal table and modify the field LIFNR inside the loop.Say for example, if I want to set the field LIFNR to '11000021' . Please let me know how can I do this .
Regards
Manish
Hello,
In case of dynamic internal tables the fields can be assigned via the ASSIGN COMPONENT statement.
E.g.,
FIELD-SYMBOLS: <lv_fieldval> TYPE ANY.
LOOP AT <gt_pos_data> ASSIGNING <gs_pos_data>.
ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <gs_pos_data> TO <lv_fieldval>.
<lv_fieldval> = '11000021'.
ENDLOOP.
BR,
Suhas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Manish,
Look at the below code.
You have to use dynamic assignment by storing the table-fieldname into a string.
DATA: it_mara TYPE TABLE OF mara,
wa_mara TYPE mara,
name(20).
FIELD-SYMBOLS: <gt_pos_data> TYPE table,
<gt_temp> TYPE ANY, "Any type to change the value
<gt_line> TYPE ANY. "ANY type to loop through table
SELECT * FROM mara INTO TABLE it_mara UP TO 10 ROWS.
LOOP AT it_mara INTO wa_mara. "Display data before changing
WRITE : /0 wa_mara-aenam.
ENDLOOP.
ULINE.
ASSIGN it_mara TO <gt_pos_data>. "Assign to type TABLE
LOOP AT <gt_pos_data> ASSIGNING <gt_line>. "Loop through the FS Table into FS Any
CONCATENATE '<gt_line>' 'aenam' INTO name SEPARATED BY '-'. "Store the dynamic name as string
ASSIGN (name) TO <gt_temp>. "Assign the dynamic name
<gt_temp> = 'Jovito'. "Change the value
ENDLOOP.
LOOP AT it_mara INTO wa_mara. "Display data after changing
WRITE : /0 wa_mara-aenam.
ENDLOOP.
Regards,
Jovito
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.