*&———————————————————————*
*& Report ZPR_READ_DATA_FROM_AS_FILES
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT ZPR_READ_DATA_FROM_AS_FILES.
PARAMETERS: P_FILE LIKE RLGRAP–FILENAME OBLIGATORY DEFAULT ‘/usr/sap/PRD/DVEBMGS00/work/SO_CITRUSTEST.txt’.
TYPES:
BEGIN OF TY_DATA,
COL TYPE STRING,
END OF TY_DATA.
DATA IT_DATA TYPE STANDARD TABLE OF TY_DATA.
DATA WA_DATA LIKE LINE OF IT_DATA.
TYPES:
BEGIN OF TY_STRING,
STRING TYPE STRING,
END OF TY_STRING.
DATA IT_STRING TYPE STANDARD TABLE OF TY_STRING.
DATA WA_STRING LIKE LINE OF IT_STRING.
TYPES:
BEGIN OF TY_INDEX,
INDEX TYPE I,
END OF TY_INDEX.
DATA IT_HINDEX TYPE STANDARD TABLE OF TY_INDEX.
DATA IT_DINDEX TYPE STANDARD TABLE OF TY_INDEX.
DATA WA_INDEX LIKE LINE OF IT_HINDEX.
DATA WA_INDEX_NEXT LIKE LINE OF IT_HINDEX.
CONSTANTS LV_SEPARATOR TYPE C VALUE ‘|’.
DATA LV_1LINE(65535) TYPE C.
DATA LV_1LINE_TMP(65535) TYPE C.
DATA LV_LENGTH TYPE I.
DATA LV_POSITION TYPE I.
DATA LV_LENGTH_GET TYPE I.
DATA LV_CURRENT TYPE I.
DATA LV_PRE TYPE I.
DATA LV_INDEX TYPE I.
CLEAR LV_1LINE.
OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY–SUBRC = 0.
READ DATASET P_FILE INTO LV_1LINE.
CLOSE DATASET P_FILE.
ENDIF.
LV_1LINE_TMP = LV_1LINE.
REPLACE ALL OCCURRENCES OF ‘#’ IN LV_1LINE_TMP WITH ”.
TRANSLATE LV_1LINE_TMP USING ‘#’.
REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB IN LV_1LINE_TMP WITH ”.
REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE IN LV_1LINE_TMP WITH ”.
LV_CURRENT = 0.
DO.
SEARCH LV_1LINE_TMP FOR ‘H|’.
IF SY–SUBRC = 0.
LV_LENGTH = STRLEN( LV_1LINE_TMP ).
LV_POSITION = SY–FDPOS + 2.
LV_CURRENT = LV_CURRENT + LV_POSITION.
LV_LENGTH_GET = LV_LENGTH – LV_POSITION.
LV_1LINE_TMP = LV_1LINE_TMP+LV_POSITION(LV_LENGTH_GET).
CLEAR WA_INDEX.
WA_INDEX–INDEX = LV_CURRENT – 2.
APPEND WA_INDEX TO IT_HINDEX.
ELSE.
EXIT.
ENDIF.
ENDDO.
LV_1LINE_TMP = LV_1LINE.
REPLACE ALL OCCURRENCES OF ‘#’ IN LV_1LINE_TMP WITH ”.
TRANSLATE LV_1LINE_TMP USING ‘#’.
REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB IN LV_1LINE_TMP WITH ”.
REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE IN LV_1LINE_TMP WITH ”.
LV_CURRENT = 0.
DO.
SEARCH LV_1LINE_TMP FOR ‘D|’.
IF SY–SUBRC = 0.
LV_LENGTH = STRLEN( LV_1LINE_TMP ).
LV_POSITION = SY–FDPOS + 2.
LV_CURRENT = LV_CURRENT + LV_POSITION.
LV_LENGTH_GET = LV_LENGTH – LV_POSITION.
LV_PRE = SY–FDPOS – 1.
IF LV_1LINE_TMP+LV_PRE(1) <> ‘I’.
CLEAR WA_INDEX.
WA_INDEX–INDEX = LV_CURRENT – 2.
APPEND WA_INDEX TO IT_DINDEX.
ENDIF.
LV_1LINE_TMP = LV_1LINE_TMP+LV_POSITION(LV_LENGTH_GET).
ELSE.
EXIT.
ENDIF.
ENDDO.
APPEND LINES OF IT_DINDEX TO IT_HINDEX.
LOOP AT IT_HINDEX INTO WA_INDEX.
CLEAR WA_STRING.
CLEAR WA_INDEX_NEXT.
LV_INDEX = SY–TABIX + 1.
READ TABLE IT_HINDEX INTO WA_INDEX_NEXT INDEX LV_INDEX.
IF SY–SUBRC = 0.
LV_LENGTH_GET = WA_INDEX_NEXT–INDEX – WA_INDEX–INDEX.
WA_STRING–STRING = LV_1LINE+WA_INDEX–INDEX(LV_LENGTH_GET).
APPEND WA_STRING TO IT_STRING.
ELSE.
LV_LENGTH = STRLEN( LV_1LINE ).
LV_LENGTH_GET = LV_LENGTH – WA_INDEX–INDEX.
WA_STRING–STRING = LV_1LINE+WA_INDEX–INDEX(LV_LENGTH_GET).
APPEND WA_STRING TO IT_STRING.
ENDIF.
ENDLOOP.
LOOP AT IT_STRING INTO WA_STRING.
WRITE: / WA_STRING–STRING.
ENDLOOP.
Add Comment