REPLACE...IN.....WITH.... 的使用,例子用于改变alv的gt_fieldcat_alv
LOOP AT gt_fieldcat_alv ASSIGNING <fs_fieldcat> . IF <fs_fieldcat>-fieldname = 'DYLLKC'. REPLACE '所在月' IN <fs_fieldcat>-seltext_l WITH lilun. ELSE. SEARCH <fs_fieldcat>-seltext_l FOR '当月'. "如果<fs_fieldcat>-seltext_l中包含‘当月’返回sy-subrc = 0 IF sy-subrc = 0. REPLACE '当' IN <fs_fieldcat>-seltext_l WITH l_month_curr. "在‘当’后面插入变量l_month_curr ENDIF. SEARCH <fs_fieldcat>-seltext_l FOR '次月'. IF sy-subrc = 0. REPLACE '次' IN <fs_fieldcat>-seltext_l WITH l_month_last. ENDIF. ENDIF. ENDLOOP.