ABAP顾问
分类:
2007-12-12 10:15:50
FORM write_wa USING wa field newline.
DATA: str TYPE string ,
str_idx TYPE string .
FIELD-SYMBOLS:
IF newline = 'X'. WRITE / ''.ENDIF.
POSITION 1 .
DO .
ASSIGN COMPONENT sy-index OF STRUCTURE wa TO
IF sy-subrc <> 0.
EXIT.
ELSE.
str_idx = sy-index .
CONDENSE str_idx.
IF field CS str_idx OR field = ''.
str =
WRITE str.
ENDIF.
ENDIF.
ENDDO.
ENDFORM. "write_wa
PERFORM write_wa USING itab_out '1 2 3 4 5' 'X'.
2008年3月25日改良后的程序:
把决定是否输出的文本改为Mask方式。
REPORT z_barry_write_wa.
DATA: BEGIN OF itab_out OCCURS 0 ,
f1 TYPE c,
f2 TYPE c,
END OF itab_out.
itab_out-f1 = 'a'.
itab_out-f2 = 'b'.
APPEND itab_out.
itab_out-f1 = 'a'.
itab_out-f2 = 'e'.
APPEND itab_out.
LOOP AT itab_out.
PERFORM write_wa USING itab_out 'XX' 'X' 'X'.
ENDLOOP.
*---------------------------------------------------------------------*
* FORM write_wa *
*---------------------------------------------------------------------*
FORM write_wa USING wa fieldmask newline alllen.
DATA: str TYPE string ,
str_idx TYPE string ,
f_index TYPE i ,
f_len TYPE i .
FIELD-SYMBOLS:
f_len = strlen( fieldmask ).
IF newline = 'X'. WRITE / ''.ENDIF.
POSITION 1 .
DO .
ASSIGN COMPONENT sy-index OF STRUCTURE wa TO
IF sy-subrc <> 0 OR sy-index > f_len.
EXIT.
ELSE.
str_idx = sy-index .
CONDENSE str_idx.
f_index = sy-index - 1.
IF fieldmask+f_index(1) = 'X'.
IF alllen = ''.
str =
WRITE str.
ELSE.
WRITE
ENDIF.
ENDIF.
ENDIF.
ENDDO.
ENDFORM. "write_wa