Skip to Content
0
Former Member
Jun 13, 2006 at 03:44 PM

Read the file and find the year in the 3rd column

41 Views

Hello ABAP Experts,

I have below a abap code which

1) gets a list of lies from teh directory

2) lookup on a good files names from the table

3) compares both and prepares a good file list and a bad file list

to this i need to add func:

1) to read the good file 3rd column. which contains the year. and if there are two years. in there is then add a message that year is inconsistent.

Any suggestions appreciated.

&----


*& REPORT ZBUDGET_LS

*&

&----


*&

*&

&----


REPORT Zfile_LS.

DATA: BEGIN OF TABL OCCURS 0,

LINE(132),

END OF TABL.

DATA: GOOD_FILE LIKE ZBUDGET_FILES.

DATA: GOOD_FILE_LIST TYPE ZBUDGET_FILES OCCURS 0.

DATA: WA_GOOD_FILE_LIST LIKE LINE OF GOOD_FILE_LIST.

DATA: BAD_FILES LIKE TABL OCCURS 0.

DATA: WA_BAD_FILES LIKE TABL.

DATA: FILE_COUNT(4) TYPE N.

DATA: GOOD_FILE_COUNT(4) TYPE N.

DATA: BAD_FILE_COUNT(4) TYPE N.

DATA: PARCOM_LOC(100) TYPE C.

DATA: L_LIST_DIR(100) TYPE C.

DATA: SIZE(10) TYPE C,

LINE LIKE TABL-LINE,

SUM(16) TYPE C.

----


  • PARAMETERS. *

----


SELECTION-SCREEN SKIP 2.

PARAMETERS: LIST_DIR TYPE ZBUDGET_DIR-LOGICAL_DRCTORY OBLIGATORY.

----


  • VALIDATE PARAMETER. *

----


AT SELECTION-SCREEN.

CONDENSE: LIST_DIR NO-GAPS.

----


  • START-OF-SELECTION. *

----


START-OF-SELECTION.

PERFORM MAKE_LOC.

PERFORM COLLECT_DATA.

PERFORM FILE_LIST.

----


  • FORM MAKE_LOC. *

----


FORM MAKE_LOC.

CLEAR: PARCOM_LOC.

*--- FROM DIRECTORY

SELECT PHYSICAL_DRCTRY INTO L_LIST_DIR FROM ZBUDGET_DIR WHERE LOGICAL_DRCTORY = LIST_DIR.

ENDSELECT.

PARCOM_LOC(2) = 'ls'.

PARCOM_LOC+4(45) = L_LIST_DIR.

ENDFORM. "MAKE_LOC

----


  • FORM COLLECT_DATA. *

----


FORM COLLECT_DATA.

REFRESH TABL.

CALL 'SYSTEM' ID 'COMMAND' FIELD PARCOM_LOC

ID 'TAB' FIELD TABL-SYS.

ENDFORM. "COLLECT_DATA

----


  • FORM FILE_LIST. *

----


FORM FILE_LIST.

FORMAT RESET.

  • CLEAR SUM.

LOOP AT TABL.

CLEAR LINE.

CLEAR GOOD_FILE_LIST.

LINE = TABL-LINE.

  • CASE LIST_DIR.

  • WHEN 'DIR_BUDGET_ARCHIVE'.

  • SELECT *

  • INTO GOOD_FILE

  • FROM ZBUDGET_ARCHIVE

  • WHERE BUDGET_FILE_ARC = LINE.

  • WRITE 'ARCHIVE'.

  • WHEN OTHERS.

  • SELECT *

    INTO GOOD_FILE

    FROM ZBUDGET_FILES

    WHERE BUDGET_FILE = LINE.

    ENDSELECT.

    • ENDCASE.

    IF SY-SUBRC = 0.

    APPEND GOOD_FILE TO GOOD_FILE_LIST.

    ELSE.

    APPEND TABL TO BAD_FILES.

    ENDIF.

    • WRITE /2 LINE.

    ENDLOOP.

    CLEAR: FILE_COUNT, GOOD_FILE_COUNT, BAD_FILE_COUNT.

    WRITE:/1(132) SY-ULINE.

    CASE LIST_DIR.

    WHEN 'DIR_BUDGET_ARCHIVE'.

    WHEN OTHERS.

    WRITE:/'GOOD FILES'.

    ENDCASE.

    WRITE:/1(132) SY-ULINE.

    LOOP AT GOOD_FILE_LIST INTO WA_GOOD_FILE_LIST.

    WRITE /2 WA_GOOD_FILE_LIST-BUDGET_FILE.

    FILE_COUNT = FILE_COUNT + 1.

    GOOD_FILE_COUNT = GOOD_FILE_COUNT + 1.

    ENDLOOP.

    WRITE:/1(132) SY-ULINE.

    CASE LIST_DIR.

    WHEN 'DIR_BUDGET_ARCHIVE'.

    WRITE:/'ARCHIVED FILES'.

    WHEN OTHERS.

    WRITE:/'BAD FILES'.

    ENDCASE.

    WRITE:/1(132) SY-ULINE.

    LOOP AT BAD_FILES INTO WA_BAD_FILES.

    WRITE /2 WA_BAD_FILES-LINE.

    FILE_COUNT = FILE_COUNT + 1.

    BAD_FILE_COUNT = BAD_FILE_COUNT + 1.

    ENDLOOP.

    WRITE:/1(132) SY-ULINE.

    CONDENSE FILE_COUNT.

    CONDENSE GOOD_FILE_COUNT.

    CONDENSE BAD_FILE_COUNT.

    CASE LIST_DIR.

    WHEN 'DIR_BUDGET_ARCHIVE'.

    WRITE:/'Count of Archived Files', BAD_FILE_COUNT.

    WHEN OTHERS.

    WRITE:/'Total Number of Files', FILE_COUNT.

    WRITE:/'Count of Good Files', GOOD_FILE_COUNT.

    WRITE:/'Count of Bad Files', BAD_FILE_COUNT.

    ENDCASE.

    ENDFORM. "FILE_LIST