abap move-corresponding
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了abap move-corresponding相关的知识,希望对你有一定的参考价值。
请教下abap中 move-corresponding.to.
比如 内表A中有 1 2 3 4 这四个字段,内表B中有 1 5 6 7 8 这5个字段,我用move-corresponding A to B ,为什么内表B得到结果只是一个 1字段的值,其他字段都为空值,有什么办法把内表A中字段1的值复制到内表B中字段1的值,同时保留 5 6 7 8的字段值.
* BEGIN OF LW_COM,
* NAME2 TYPE C LENGTH 10 VALUE 'ACCENTURE',
* ADD TYPE C LENGTH 30 VALUE 'DALIAN SOFTWARE PARK',
* END OF LW_COM,
* BEGIN OF LW_PER,
* ID TYPE N LENGTH 4 VALUE '0001',
* NAME TYPE C LENGTH 6 VALUE 'MARK',
* NAME2 TYPE C LENGTH 10,
* ADD TYPE C LENGTH 30,
* END OF LW_PER.
*
* PERFORM F_ADD_DATE2.
*
*
**-------------------------------------------------------
**&---------------------------------------------------------------------*
**& Form F_ADD_DATE
**&---------------------------------------------------------------------*
**& text
**&---------------------------------------------------------------------*
**& --> p1 text
**& <-- p2 text
**&---------------------------------------------------------------------*
*FORM F_ADD_DATE2.
*
* MOVE-CORRESPONDING LW_COM TO LW_PER.
* WRITE: LW_PER-ID,
* LW_PER-NAME,
* LW_PER-NAME2,
* LW_PER-ADD.
*ENDFORM.
用工作区就可以。我用表to表也是只有相同的字段会覆盖过去,不相同的字段为空。
*尝试用表
TYPES:
BEGIN OF TYP_W_COM,
NAME2 TYPE C LENGTH 10 ,
ADD TYPE C LENGTH 30,
END OF TYP_W_COM,
TYP_T_COM TYPE STANDARD TABLE OF TYP_W_COM,
BEGIN OF TYP_W_PER,
ID TYPE N LENGTH 4,
NAME TYPE C LENGTH 6,
NAME2 TYPE C LENGTH 10,
ADD TYPE C LENGTH 30,
END OF TYP_W_PER,
TYP_T_PER TYPE STANDARD TABLE OF TYP_W_PER.
DATA:
LW_01 TYPE TYP_W_COM,
LW_02 TYPE TYP_W_PER,
LT_01 TYPE TYP_T_COM,
LT_02 TYPE TYP_T_PER.
LW_01-NAME2 = 'ACCENTURE'.
LW_01-ADD = 'DALIAN SOFTWARE PARK'.
INSERT LW_01 INTO TABLE LT_01.
LW_02-ID = '0001'.
LW_02-NAME = 'MARK'.
INSERT LW_02 INTO TABLE LT_02.
PERFORM F_ADD_DATE2.
*-------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form F_ADD_DATE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM F_ADD_DATE2.
MOVE-CORRESPONDING LT_01 TO LT_02.
LOOP AT LT_02 INTO LW_02.
WRITE: LW_02-ID,
LW_02-NAME,
LW_02-NAME2,
LW_02-ADD.
ENDLOOP.
ENDFORM. 参考技术B 不要用move-corresponding ,对b做循环,根据合适的条件直接把a-1赋值给b-1,然后modify b
ABAP ??????????????????
?????????
???.????????????abap??????????????????????????????????????????????????????????????????????????????????????????
1.??????????????????????????????
(1).????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
(2).??????????????????????????????????????????????????????,??????????????????????????????excel????????????????????????????????????????????????????????????????????????????????????
"??????????????????
PARAMETERS :
P_FILE LIKE RLGRAP-FILENAME MODIF ID M1. "????????????
*&--------------------------------------------------------*
*& ????????????????????????????????????
*&--------------------------------------------------------*
AT SELECTION-SCREEN.
*&---????????????????????????
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION ???F4_FILENAME???
EXPORTING
PROGRAM_NAME = ?????? " ???????????????
IMPORTING
FILE_NAME = P_FILE. " ????????????
(3).???????????????????????????????????????????????????????????????????????????
"???????????????
*&--------------------------------------------------------*
*& ??????????????????
*&--------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SAKNR.
CALL FUNCTION ???F4IF_INT_TABLE_VALUE_REQUEST???
EXPORTING
RETFIELD = ???SAKNR??? "?????????????????????????????????????????????
DYNPPROG = SY-REPID
DYNPNR = SY-DYNNR
DYNPROFIELD = ???P_SAKNR???
VALUE_ORG = ???S???
TABLES
VALUE_TAB = IT_SKAT. "?????????????????????????????????
IF SY-SUBRC <> 0.
MESSAGE ?????????????????????????????? TYPE ???I???.
ENDIF.
2.ALV?????????????????????????????????OOALV???
(1).??????ALV??????????????????????????????????????????????????????????????????????????????MKAL-MATNR?????????????????????????????????MARA??????MATNR,???????????????????????????????????????????????????????????????????????????????????????fieldecat??????????????????????????????
WA_FIELDCAT-REF_FIELD = ???MKAL???.
WA_FIELDCAT-REF_TABLE = ???MATNR???.
?????????????????????????????????????????????
(2).??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
1).SE11-??????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????function?????????????????????????????????????????????F4IF_SHLP_EXIT_EXAMPLEH????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????alv?????????fieldcat?????????????????????????????????
WA_FIELDCAT-REF_FIELD = ??????????????????.
WA_FIELDCAT-REF_TABLE = ??????????????????.
(3).???????????????SE11?????????????????????????????????????????????????????????????????????????????????CRHD?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????alv????????????????????????????????????????????????????????????????????????????????????
"1.?????????????????????????????????
TYPES : BEGIN OF T_CRHD,
WERKS LIKE CRHD-WERKS,
VERWE LIKE CRHD-VERWE,
ARBPL LIKE CRHD-ARBPL,
KTEXT LIKE CRTX-KTEXT,
END OF T_CRHD.
DATA : IT_CRHD TYPE TABLE OF T_CRHD,
WA_CRHD LIKE LINE OF IT_CRHD.
"2.??????????????????????????????
"??????????????????????????????????????????
SELECT
A~WERKS
A~VERWE
A~ARBPL
B~KTEXT
INTO CORRESPONDING FIELDS OF TABLE IT_CRHD
FROM CRHD AS A
JOIN CRTX AS B ON B~OBJTY = A~OBJTY AND B~OBJID = A~OBJID
WHERE A~ARBPL LIKE ???ZRP%??? AND B~SPRAS = SY-LANGU.
"3.??????????????????
*&--------------------------------------------------------*
*& CLASS LCL_EVENT_HANDLER DEFINITION
*&--------------------------------------------------------*
* TEXT alv????????????
*---------------------------------------------------------*
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS:
*--????????????????????????
HANDLE_ON_F4_HELP_9000
FOR EVENT ONF4 OF CL_GUI_ALV_GRID
IMPORTING E_FIELDNAME ES_ROW_NO ER_EVENT_DATA.
ENDCLASS.
*&--------------------------------------------------------*
*& CLASS LCL_EVENT_HANDLER IMPLEMENTATION
*&--------------------------------------------------------*
* TEXT ALV????????????
*---------------------------------------------------------*
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*--????????????????????????
METHOD HANDLE_ON_F4_HELP_9000.
PERFORM HANDLE_ON_F4_HELP_9000 USING E_FIELDNAME ES_ROW_NO
ER_EVENT_DATA .
ENDMETHOD.
ENDCLASS.
"4.????????????form
*&--------------------------------------------------------*
*& Form HANDLE_ON_F4_HELP
*&--------------------------------------------------------*
* text ????????????????????????
*---------------------------------------------------------*
FORM HANDLE_ON_F4_HELP_9000 USING E_FIELDNAME
ES_ROW_NO TYPE LVC_S_ROID
ER_EVENT_DATA.
DATA : E_INDEX TYPE I,
E_MDV01 LIKE ZTPP_CONF_ITEM07-MDV01,
LT_RET_TAB TYPE TABLE OF DDSHRETVAL WITH HEADER LINE.
IF E_FIELDNAME = ???MDV01???. "?????????????????????????????????
E_INDEX = ES_ROW_NO-ROW_ID.
READ TABLE IT_SHOW INTO WA_SHOW INDEX E_INDEX.
CHECK SY-SUBRC = 0.
"??????function
CALL FUNCTION ???F4IF_INT_TABLE_VALUE_REQUEST???
EXPORTING
RETFIELD = ???ARBPL??? "????????????
VALUE_ORG = ???S???
TABLES
VALUE_TAB = IT_CRHD
RETURN_TAB = LT_RET_TAB
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3.
IF SY-SUBRC = 0.
"????????????
READ TABLE LT_RET_TAB INDEX 1.
IF LT_RET_TAB-FIELDVAL <> ??????.
"???????????????
CALL FUNCTION ???CONVERSION_EXIT_ALPHA_INPUT???
EXPORTING
INPUT = LT_RET_TAB-FIELDVAL
IMPORTING
OUTPUT = E_MDV01 .
WA_SHOW-MDV01 = E_MDV01.
ENDIF.
MODIFY IT_SHOW FROM WA_SHOW INDEX E_INDEX.
ENDIF.
"??????ALV
PERFORM REFRESH_TABLE_DISPLAY USING PP_ALV_GRID.
ENDIF.
ENDFORM. " HANDLE_ON_F4_HELP
"5.??????fieldcat
WA_FIELDCAT-F4AVAILABL = ???X???.
"6.????????????
"????????????F4??????
DATA: LT_F4 TYPE LVC_T_F4 WITH HEADER LINE.
CLEAR LT_F4.
LT_F4-FIELDNAME = ???MDV01???.
LT_F4-REGISTER = ???X???.
LT_F4-CHNGEAFTER = ???X???.
* LT_F4-GETBEFORE = ???X???.
* LT_F4-INTERNAL = ???X???.
APPEND LT_F4.
CALL METHOD PP_ALV_GRID->REGISTER_F4_FOR_FIELDS
EXPORTING
IT_F4 = LT_F4[].
SET HANDLER GR_EVENT_HANDLER->HANDLE_ON_F4_HELP_9000
FOR PP_ALV_GRID.
以上是关于abap move-corresponding的主要内容,如果未能解决你的问题,请参考以下文章