参考上面代码:
* 0021 55555555555555555555555555555BEGIN XIAOYONG 20200429 双信息类型 0021 0528 测试通过
IF is_input-it_p0021[] IS NOT INITIAL.
CLEAR:lt_p0021[],lt_newp0021[], lt_fields[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_p0021 FROM pa0021
FOR ALL ENTRIES IN is_input-it_p0021
WHERE pernr = is_input-it_p0021-pernr
AND subty = is_input-it_p0021-subty
AND begda <= sy-datum
AND endda >= sy-datum.
SORT lt_p0021 BY pernr subty.
CLEAR:lt_p0528[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_p0528 FROM pa0528
FOR ALL ENTRIES IN is_input-it_p0021
WHERE pernr = is_input-it_p0021-pernr
AND subty = is_input-it_p0021-subty
AND begda <= sy-datum
AND endda >= sy-datum.
SORT lt_p0528 BY pernr subty.
LOOP AT is_input-it_p0021 ASSIGNING FIELD-SYMBOL(<fs_0021>).
IF <fs_0021>-begda IS INITIAL.
<fs_0021>-begda = sy-datum.
ENDIF.
IF <fs_0021>-endda IS INITIAL.
<fs_0021>-endda = '99991231'.
ENDIF.
CLEAR:lt_newp0021[].
lo_descr ?= cl_abap_typedescr=>describe_by_data(ls_p0021).
lt_fields = lo_descr->get_ddic_field_list( p_langu = '1'
p_including_substructres = abap_true ).
READ TABLE lt_p0021 ASSIGNING FIELD-SYMBOL(<wa_0021>) WITH KEY pernr = <fs_0021>-pernr
subty = <fs_0021>-subty BINARY SEARCH.
IF sy-subrc = 0.
LOOP AT lt_fields ASSIGNING <fs_fields>.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <fs_0021> TO <fs>.
IF sy-subrc = 0 AND <fs> IS NOT INITIAL.
IF <fs1> IS ASSIGNED .
UNASSIGN <fs1>.
ENDIF.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <wa_0021> TO <fs1>.
IF sy-subrc = 0.
<fs1> = <fs>.
ENDIF.
ENDIF.
ENDLOOP.
APPEND <wa_0021> TO lt_newp0021.
ELSE.
APPEND INITIAL LINE TO lt_newp0021 ASSIGNING <wa_0021>.
LOOP AT lt_fields ASSIGNING <fs_fields>.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <fs_0021> TO <fs>.
IF sy-subrc = 0 AND <fs> IS NOT INITIAL.
IF <fs1> IS ASSIGNED .
UNASSIGN <fs1>.
ENDIF.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <wa_0021> TO <fs1>.
IF sy-subrc = 0.
<fs1> = <fs>.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR:lt_fields[].
lo_descr ?= cl_abap_typedescr=>describe_by_data(ls_p0528).
lt_fields = lo_descr->get_ddic_field_list( p_langu = '1'
p_including_substructres = abap_true ).
CLEAR:lt_newp0528[].
READ TABLE lt_p0528 ASSIGNING FIELD-SYMBOL(<wa_0528>) WITH KEY pernr = <fs_0021>-pernr
subty = <fs_0021>-subty BINARY SEARCH.
IF sy-subrc = 0.
LOOP AT lt_fields ASSIGNING <fs_fields>.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <fs_0021> TO <fs>.
IF sy-subrc = 0 AND <fs> IS NOT INITIAL.
IF <fs1> IS ASSIGNED .
UNASSIGN <fs1>.
ENDIF.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <wa_0528> TO <fs1>.
IF sy-subrc = 0.
<fs1> = <fs>.
ENDIF.
ENDIF.
ENDLOOP.
ASSIGN COMPONENT 'INFTY' OF STRUCTURE <wa_0528> TO <fs>.
IF sy-subrc = 0.
<fs> = '0528'.
ENDIF.
ASSIGN COMPONENT 'LAND1' OF STRUCTURE <wa_0528> TO <fs>.
IF sy-subrc = 0.
<fs> = 'CN'.
ENDIF.
APPEND <wa_0528> TO lt_newp0528.
ELSE.
APPEND INITIAL LINE TO lt_newp0528 ASSIGNING <wa_0528>.
LOOP AT lt_fields ASSIGNING <fs_fields>.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <fs_0021> TO <fs>.
IF sy-subrc = 0 AND <fs> IS NOT INITIAL.
IF <fs1> IS ASSIGNED .
UNASSIGN <fs1>.
ENDIF.
ASSIGN COMPONENT <fs_fields>-fieldname OF STRUCTURE <wa_0528> TO <fs1>.
IF sy-subrc = 0.
<fs1> = <fs>.
ENDIF.
ENDIF.
ENDLOOP.
ASSIGN COMPONENT 'INFTY' OF STRUCTURE <wa_0528> TO <fs>.
IF sy-subrc = 0.
<fs> = '0528'.
ENDIF.
ASSIGN COMPONENT 'LAND1' OF STRUCTURE <wa_0528> TO <fs>.
IF sy-subrc = 0.
<fs> = 'CN'.
ENDIF.
ENDIF.
CLEAR:ls_pskey.
MOVE-CORRESPONDING <wa_0021> TO ls_pskey.
PERFORM frm_lock_per_data USING ls_pskey-pernr 'X' CHANGING es_output-message.
IF es_output-message-msgtx = 'E'.
EXIT.
ENDIF.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
infty = '0021'
number = ls_pskey-pernr
subtype = ls_pskey-subty
objectid = ls_pskey-objps
lockindicator = ls_pskey-sprps
validityend = ls_pskey-endda
validitybegin = ls_pskey-begda
recordnumber = ls_pskey-seqnr
record = <wa_0021>
secondary_record = <wa_0528>
operation = 'INS'
tclas = 'A'
nocommit = 'X'
view_identifier = '28'
dialog_mode = '0'
IMPORTING
return = ls_return.
IF ls_return-type = 'E' OR ls_return-type = 'A' .
es_output-message-msgtx = 'E'.
MESSAGE ID ls_return-id TYPE ls_return-type NUMBER ls_return-number INTO es_output-message-msgty
WITH ls_return-message_v1
ls_return-message_v2
ls_return-message_v3
ls_return-message_v4.
PERFORM frm_lock_per_data USING ls_pskey-pernr '' CHANGING es_output-message.
EXIT.
ENDIF.
PERFORM frm_lock_per_data USING ls_pskey-pernr '' CHANGING es_output-message.
* CLEAR:<WA_0528>,<WA_0021>.
ENDLOOP.
IF es_output-message-msgtx = 'E'.
ROLLBACK WORK.
CALL FUNCTION 'RHOM_ALL_BUFFER_INIT'.
CALL FUNCTION 'HR_PSBUFFER_INITIALIZE'.
EXIT.
ENDIF.
ENDIF.
*0021 55555555555555555555end xiaoyong 20200429
依照下面代码能写入双信息类型