Source Code of ABAP Program to Browse a file on the application server

Source Code of ABAP Program to Browse a file on the application server

REPORT ZBROWSE MESSAGE-ID Z1
NO STANDARD PAGE HEADING
* LINE-COUNT 65
LINE-SIZE 255.

*———————————————————————*
* Topic: Browse a file on the appication server
* *
* Author: Sheila Titchener
* *
*———————————————————————*
DATA: BEGIN OF TAB1 OCCURS 0,
LINE(5000),
END OF TAB1.

 

DATA: BEGIN OF TAB2 OCCURS 0,
LINE(5000),
END OF TAB2.
DATA: PARCOM_LOC(100) TYPE C.
DATA: COLOR TYPE I.
DATA: COUNT(16) TYPE C.
DATA: MESS(50).
*——————————————————————-*
* Parameters. *
*——————————————————————-*
SELECTION-SCREEN SKIP 2.
PARAMETERS: PARCOM1(55) TYPE C LOWER CASE.
* parcom2(55) type c lower case,
* parcom3 like rlgrap-filename,
* parcom4 like rlgrap-filename ,
* p_pc radiobutton group one,
*8 p_unix radiobutton group one.
*——————————————————————-*
* Parameter validation *
*——————————————————————-*

*——————————————————————-*
* TOP-OF-PAGE. *
*——————————————————————-*
TOP-OF-PAGE.
PERFORM WRITE_PAGE_HEADING.

*——————————————————————-*
* INITIALIZATION. *
*——————————————————————-*
INITIALIZATION.
PARCOM1 = ‘\\sapdev1\export\’.

*——————————————————————-*
* START-OF-SELECTION. *
*——————————————————————-*
START-OF-SELECTION.
PERFORM COLLECT_DATA.
PERFORM WRITE_FILE_CONTENT.
*———————————————————————*
* FORM COLLECT_DATA. *
*———————————————————————*
FORM COLLECT_DATA.
OPEN DATASET PARCOM1 FOR INPUT IN TEXT MODE MESSAGE MESS.
IF SY-SUBRC NE 0.
WRITE: ‘Unable to open’, PARCOM1.
WRITE: / MESS.
ELSE.
DO.
READ DATASET PARCOM1 INTO TAB1.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
APPEND TAB1.
ENDDO.
CLOSE DATASET PARCOM1.
ENDIF.

ENDFORM.

*——————————————————————-*
* FORM WRITE_FILE_CONTENT. *
*——————————————————————-*
FORM WRITE_FILE_CONTENT.
DATA: E LIKE SY-FDPOS.
LOOP AT TAB1.
E = STRLEN( TAB1-LINE ).
IF E GE 0.
PERFORM COLORLINE USING ‘ 0’ TAB1-LINE+0(99).
PERFORM STREGER_3.
ENDIF.

IF E GE 100.
PERFORM COLORLINE USING ‘100’ TAB1-LINE+99(100).
PERFORM STREGER_3.
ENDIF.
* write: /10 tab1.
*
ENDLOOP.
ENDFORM.

*——————————————————————-*
* FORM WRITE_PAGE_HEADING. *
*——————————————————————-*
FORM WRITE_PAGE_HEADING.

WRITE:/1(110) SY-ULINE.
PERFORM STREGER_2.
FORMAT INTENSIFIED.
WRITE: / PARCOM1 COLOR 1.
PERFORM STREGER_2.
WRITE:/1(110) SY-ULINE.
PERFORM STREGER_2.
FORMAT INTENSIFIED.
WRITE: /2(109) SPACE COLOR 3.
WRITE: 2 ‘Offset’ COLOR 3,
10 ‘0….+….1….+….2….+….3….+….’ COLOR 3,
50 ‘4….+….5….+….6….+….7….+….’ COLOR 3,
90 ‘8….+….9….+….’ COLOR 3.
PERFORM STREGER_3.
FORMAT RESET.
WRITE:/1(110) SY-ULINE.
ENDFORM.

*——————————————————————-*
* FORM STREGER_2. *
*——————————————————————-*
FORM STREGER_2.
PERFORM WRITE_VLINE USING ‘ ‘ 1.
PERFORM WRITE_VLINE USING ‘ ‘ 80.
ENDFORM.

*——————————————————————-*
* FORM STREGER_3. *
*——————————————————————-*
FORM STREGER_3.
PERFORM WRITE_VLINE USING ‘ ‘ 1.
PERFORM WRITE_VLINE USING ‘ ‘ 9.
PERFORM WRITE_VLINE USING ‘ ‘ 110.
ENDFORM.

*——————————————————————-*
* WRITE_VLINE. *
*——————————————————————-*
FORM WRITE_VLINE USING MODE POS.
IF MODE NE ‘T’.
FORMAT INTENSIFIED.
ENDIF.
POSITION POS.
WRITE: SY-VLINE.
IF MODE NE ‘T’.
FORMAT RESET.
ENDIF.
ENDFORM.

*——————————————————————-*
* FORM COLORLINE. *
*——————————————————————-*
FORM COLORLINE USING TEXT1 TEXT2.
ON CHANGE OF SY-TABIX.
COLOR = COLOR + 1.
COLOR = COLOR MOD 2.
ENDON.
FORMAT RESET.
IF COLOR = 1.
WRITE: /2(79) SPACE COLOR 2.
IF TEXT1 = ‘ 0’.
WRITE: 3 TEXT1 COLOR 2, 11 TEXT2 COLOR 2.
ELSE.
WRITE: 3 TEXT1 COLOR 2, 10 TEXT2 COLOR 2.
ENDIF.
ELSE.
WRITE: /2(79) SPACE COLOR 4.
IF TEXT1 = ‘ 0’.
WRITE: 3 TEXT1 COLOR 4, 11 TEXT2 COLOR 4.
ELSE.
WRITE: 3 TEXT1 COLOR 4, 10 TEXT2 COLOR 4.
ENDIF.
ENDIF.
ENDFORM.

*——————————————————————-*
* FORM WRITE_NUMBER_OF_CONTENT. *
*——————————————————————-*
FORM WRITE_NUMBER_OF_CONTENT.
DESCRIBE TABLE TAB1 LINES COUNT.

FORMAT RESET. CONDENSE COUNT.
RESERVE 3 LINES.
WRITE:/1(80) SY-ULINE.
WRITE: /2(79) SPACE COLOR 2.
WRITE: 2 ‘Number of records in file:’ COLOR 2,
29 COUNT COLOR 2.
PERFORM STREGER_2.
WRITE:/1(80) SY-ULINE.
ENDFORM.