REPORT z_jason_test999 .
DATA: BEGIN OF intab OCCURS 0 ,
f1 LIKE mseg-menge,
f2(10) TYPE c,
f3(10) TYPE c,
f4 TYPE c,
END OF intab.
DATA: dname(40) TYPE c VALUE '/usr/sap/BQD/DVEBMGS00/work/0002.txt'.
START-OF-SELECTION.
intab-f1 = '-123.456'.
intab-f2 = ''.
intab-f3 = 'A3'.
APPEND intab.
intab-f1 = '3'.
intab-f2 = 'B2'.
intab-f3 = 'B3'.
intab-f4 = 'A'.
APPEND intab.
PERFORM ftoline TABLES intab[]
USING dname.
*&---------------------------------------------------------------------*
*& Form ftoline
*&---------------------------------------------------------------------*
FORM ftoline TABLES p_intab
USING p_dname.
DATA: BEGIN OF outtab OCCURS 0,
line(1000) TYPE c,
END OF outtab.
DATA: tab TYPE x VALUE '09',
enter(2) TYPE x VALUE '0D0A'.
DATA: BEGIN OF headtab OCCURS 0,
length TYPE i,
decimals TYPE i,
type_kind TYPE c,
name(30) TYPE c,
END OF headtab.
DATA: n TYPE i.
DATA: descr_ref TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS: TYPE abap_compdescr,
TYPE ANY,
TYPE ANY.
DATA: str TYPE string,
text1 TYPE c.
descr_ref ?= cl_abap_typedescr=>describe_by_data( intab ).
LOOP AT descr_ref->components ASSIGNING .
MOVE-CORRESPONDING TO headtab.
APPEND headtab.
ENDLOOP.
DESCRIBE TABLE headtab LINES n.
LOOP AT p_intab ASSIGNING .
DO n TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE TO .
str = .
READ TABLE headtab INDEX sy-index.
IF headtab-type_kind = 'I' OR headtab-type_kind = 'P'.
SEARCH str FOR '-'.
IF sy-subrc = 0 AND sy-fdpos <> 0.
SPLIT str AT '-' INTO str text1.
CONDENSE str.
CONCATENATE '-' str INTO str.
ELSE.
CONDENSE str.
ENDIF.
ENDIF.
CONCATENATE outtab tab str INTO outtab.
ENDDO.
SHIFT outtab.
APPEND outtab.
CLEAR outtab.
ENDLOOP.
OPEN DATASET p_dname FOR OUTPUT IN BINARY MODE.
IF sy-subrc NE 0.
EXIT.
ENDIF.
LOOP AT outtab.
str = outtab.
TRANSFER str TO p_dname.
TRANSFER enter TO p_dname.
ENDLOOP.
CLOSE DATASET p_dname.
ENDFORM. " ftoline
阅读(510) | 评论(0) | 转发(0) |