FUNCTION ZFM_MOVE_CORRESPONDING
.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IS_INPUT) OPTIONAL
*" REFERENCE(IV_STRUCTURE) OPTIONAL
*" CHANGING
*" REFERENCE(CS_INPUT) OPTIONAL
*"----------------------------------------------------------------------
FIELD-SYMBOLS :
《 L_FIELD》 TYPE ANY , "从工作区结构
《 L_FIELD_C 》 TYPE ANY . "到工作区结构
*
DATA : LT_IDETAILS TYPE ABAP_COMPDESCR_TAB WITH HEADER LINE .
DATA : LR_REF_TABLE_DES TYPE REF TO CL_ABAP_STRUCTDESCR .
LR_REF_TABLE_DES ?=
CL_ABAP_TYPEDESCR =>DESCRIBE_BY_NAME ( IV_STRUCTURE ) .
CLEAR LT_IDETAILS[] .
LT_IDETAILS[] = LR_REF_TABLE_DES ->COMPONENTS[] .
"循环判断结构每个字段
LOOP AT LT_IDETAILS .
ASSIGN COMPONENT LT_IDETAILS -NAME OF STRUCTURE IS_INPUT TO 《 L_FIELD 》 .
IF SY-SUBRC = 0 AND IS NOT INITIAL.
ASSIGN COMPONENT LT_IDETAILS -NAME OF STRUCTURE CS_INPUT TO 《 L_FIELD_C 》 .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IS_INPUT) OPTIONAL
*" REFERENCE(IV_STRUCTURE) OPTIONAL
*" CHANGING
*" REFERENCE(CS_INPUT) OPTIONAL
*"----------------------------------------------------------------------
FIELD-SYMBOLS :
《 L_FIELD》 TYPE ANY , "从工作区结构
《 L_FIELD_C 》 TYPE ANY . "到工作区结构
*
DATA : LT_IDETAILS TYPE ABAP_COMPDESCR_TAB WITH HEADER LINE .
DATA : LR_REF_TABLE_DES TYPE REF TO CL_ABAP_STRUCTDESCR .
LR_REF_TABLE_DES ?=
CL_ABAP_TYPEDESCR =>DESCRIBE_BY_NAME ( IV_STRUCTURE ) .
CLEAR LT_IDETAILS[] .
LT_IDETAILS[] = LR_REF_TABLE_DES ->COMPONENTS[] .
"循环判断结构每个字段
LOOP AT LT_IDETAILS .
ASSIGN COMPONENT LT_IDETAILS -NAME OF STRUCTURE IS_INPUT TO 《 L_FIELD 》 .
IF SY-SUBRC = 0 AND IS NOT INITIAL.
ASSIGN COMPONENT LT_IDETAILS -NAME OF STRUCTURE CS_INPUT TO 《 L_FIELD_C 》 .
IF SY-SUBRC = 0
《 L_FIELD_C 》 = 《 L_FIELD 》 .
《 L_FIELD_C 》 = 《 L_FIELD 》 .
endif.
ENDIF .
ENDLOOP .
ENDFUNCTION .
ENDIF .
ENDLOOP .
ENDFUNCTION .
测试程序:
REPORT YLM_TEST026.
DATA: LW_SPFLI LIKE SPFLI.
DATA: LW_SPFLI2 LIKE SPFLI.
SELECT SINGLE * FROM SPFLI INTO LW_SPFLI.
CALL FUNCTION 'ZFM_MOVE_CORRESPONDING'
EXPORTING
IS_INPUT = LW_SPFLI
IV_STRUCTURE = 'SPFLI'
CHANGING
CS_INPUT = LW_SPFLI2.
IF 1 = 2.
ENDIF.
DATA: LW_SPFLI LIKE SPFLI.
DATA: LW_SPFLI2 LIKE SPFLI.
SELECT SINGLE * FROM SPFLI INTO LW_SPFLI.
CALL FUNCTION 'ZFM_MOVE_CORRESPONDING'
EXPORTING
IS_INPUT = LW_SPFLI
IV_STRUCTURE = 'SPFLI'
CHANGING
CS_INPUT = LW_SPFLI2.
IF 1 = 2.
ENDIF.
注释:因为字段负号中尖括号会被web解码时误读,故外面加了书名号:
《
L_FIELD_C
》
字段符合赋值后,必须判断subr再操作,不然可能会dump