Skip to Content
author's profile photo Former Member
Former Member

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

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

    Add a comment
    10|10000 characters needed characters exceeded

    Assigned Tags

    Related questions

    1 Answer

    • author's profile photo Former Member
      Former Member
      Posted on Jun 19, 2006 at 02:44 PM

      Hi BWer,

      Can you post the structure of ZBUDGET_FILES. Also, when you mean to check for double year in the 3'rd column, can you let us know how can it be as an example (is it something like 20052006 or 0506 )...

      This is just a clue as how to do.

      data: year like sy-datum.

      loop at GOOD_FILE_LIST.

      year = GOOD_FILE_LIST-year. (assuming "year" is the name of 3'rd column)

      (check for two years at this place).

      message E398(00) with "inconsistent Year". (00 is message class ID)

      endloop.

      If you can provide more information, it would be helpful.

      Regards,

      Vicky

      Add a comment
      10|10000 characters needed characters exceeded

    Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.