05-25-2016 7:07 AM
Hello Friends,
I have a work area e.x (wa_tab1) and in this i have 100 fields and most of these fields are filled with values 'X'.
Now if i want to change all the work area (wa_tab1) fields which are filled with value 'X' how can i make it simple.
e.x if wa_tab1-field1 = 'X'.
wa_tab1-field1 = 'Y'.
endif.
The above statement shows the method of changing the single field value , if i want to repeat this for 100 fields how can i make it simple.
Regards,
Vinodkumar.
05-25-2016 7:42 AM
Hi Vinod,
I hope you can try the following code.
field-symbols: <field> type any.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_tab1 TO <field>.
IF sy-subrc IS INITIAL.
"Check value contains 'X'
if <field> EQ 'x'.
<field> = 'Y'.
endif.
ELSE.
EXIT. "Exit from the Do loop
ENDIF.
ENDDO.
Regards
Rajkumar Narasimman
05-25-2016 7:42 AM
Hi Vinod,
I hope you can try the following code.
field-symbols: <field> type any.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_tab1 TO <field>.
IF sy-subrc IS INITIAL.
"Check value contains 'X'
if <field> EQ 'x'.
<field> = 'Y'.
endif.
ELSE.
EXIT. "Exit from the Do loop
ENDIF.
ENDDO.
Regards
Rajkumar Narasimman
05-25-2016 8:44 AM
Hi Raj,
Thanks for your reply , this solved my issue.
Hope you are doing well, Still remember the KT given for ESPAC .
Regards,
Vinodkumar.
05-25-2016 7:51 AM
You can get number of fields in structure or table from table DD03L.
Then you can access fields dynamically.
For Ex.
LOOP ANT IT_MAKT ASSIGN <FS_MAKT>.
LOOP AT LT_DD03L INTO LS_DD03L.
ASSIGN COMPONENT LS_DD03L-FIELDNAME OF STRUCTURE <FS_MAKT> TO <F_FIELD>.
IF <F_FIELD> = 'X'.
<F_FIELD> = 'Y'.
ENDIF.
ENDLOOP.
ENDLOOP.
I din't try this but I hope this will work.
05-25-2016 8:00 AM
Like the one before but without db-access.
field-symbols <ls_data> type any. |
data(lv_structure) = 'MAKT'. | |
select * up to 1 rows | |
into table @data(lt_makt) | |
from makt. |
try. | |
data(lo_structdescr) = cast cl_abap_structdescr( cl_abap_typedescr=>describe_by_name( lv_structure ) ). |
loop at lt_makt assigning field-symbol(<ls_eanl>). | |
loop at lo_structdescr->components assigning field-symbol(<ls_field>). | |
assign component <ls_field>-name of structure <ls_eanl> to <ls_data>. | |
if sy-subrc = 0. | |
if <ls_data> = abap_true. | |
<ls_data> = abap_false. | |
endif. | |
endif. | |
endloop. | |
endloop. | |
catch cx_sy_move_cast_error. |
endtry. |
05-25-2016 8:05 AM
Hi Vinod ,
Work area is a field string , so you can change values as pertaining to string.
Sample Code :
TYPES : BEGIN OF ty_tab,
field1,
field2,
field3,
field4,
field5,
field6,
field7,
END OF ty_tab.
DATA : it_tab TYPE TABLE OF ty_tab,
wa_tab TYPE ty_tab.
wa_tab-field2 = 'X' .
wa_tab-field4 = 'X'.
wa_tab-field6 = 'X'.
wa_tab-field7 = 'X'.
data: len1 type i.
data: ofst1 type i.
len1 = strlen( wa_tab ).
do.
if ofst1 = len1.
exit.
endif.
if wa_tab+ofst1(1) eq 'X' .
wa_tab+ofst1(1) = 'Y'.
ENDIF.
ofst1 = ofst1 + 1.
enddo.
Regards
Yogendra Bhaskar