Google Search - Blog...........

ABAP - Interface Program To Create Required Number Of Jobs For A Given Path In The Application Server.

*-----------------------------------------------------------------------
* Here is an interface program to create the required no of jobs
* automatically with the given path in the application server by
* specifying filename no of files to be created and sites and
* article range
*-----------------------------------------------------------------------
REPORT zmio_manu_onhand_extr LINE-SIZE 180
LINE-COUNT 65
NO STANDARD PAGE HEADING
MESSAGE-ID zr.
*-----------------------------------------------------------------------
* database tables
*-----------------------------------------------------------------------

TABLES: t001w ,
mard .
*-----------------------------------------------------------------------
* variables
*-----------------------------------------------------------------------
DATA: g_lines LIKE sy-tabix,
g_read LIKE sy-tabix,
g_filename LIKE edi_path-pthnam,
g_records TYPE sy-tabix,
g_total_rec TYPE i,
g_fileno TYPE i,
v_records TYPE i,
v_fileno(3) TYPE c .
*-----------------------------------------------------------------------
* internal tables
*-----------------------------------------------------------------------
*---table for sites
TYPES: BEGIN OF ty_t001w ,
werks TYPE werks_d,
END OF ty_t001w.
*--types for plant store
TYPES:BEGIN OF ty_mard ,
matnr LIKE mard-matnr,
werks LIKE mard-werks,
lgort LIKE mard-lgort,
END OF ty_mard.
*---database tables
DATA: it_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,
it_exp_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,
it_mard TYPE STANDARD TABLE OF ty_mard WITH HEADER LINE .
*-----------------------------------------------------------------------
* selection screen
*-----------------------------------------------------------------------
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME .
SELECT-OPTIONS:s_matnr FOR mard-matnr, "articles
s_werks FOR t001w-werks. "plant
PARAMETERS: p_file1(45) TYPE c , "filename
p_numjob(3) TYPE n . "no of jobs to be created
SELECTION-SCREEN: END OF BLOCK b1.
*-----------------------------------------------------------------------
* ranges
*-----------------------------------------------------------------------
*--ranges for plant
RANGES: r_werks FOR t001w-werks.

*----------------------------------------------------------------------*
* AT SELECTION SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN .
*---if there is no message raise a message to enter file name
IF p_file1 IS INITIAL.
MESSAGE i001 WITH 'Enter File Name'.
ENDIF.
*---if the no of jobs to be create field is initial raise a message to enter a value
IF p_numjob EQ space.
MESSAGE i001 WITH 'Enter a valid no of files to be created'.
ENDIF.
*-----------------------------------------------------------------------
* start of selection
*-----------------------------------------------------------------------

START-OF-SELECTION.
*---write the header of the output with filename and no of records downloaded
PERFORM header_name.
*--get the data for the plants
PERFORM get_data.
*--process the data for creating the file in application server
PERFORM process_data .

*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data .

REFRESH:it_t001w.
*---get data for plants
SELECT werks
FROM t001w
INTO TABLE it_t001w
WHERE werks IN s_werks.
IF NOT it_t001w[] IS INITIAL.
SORT it_t001w BY werks.
*---count the no of records from plant table
DESCRIBE TABLE it_t001w LINES g_lines.
ENDIF.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
FORM process_data .

*---get the no of plant records per job
g_read = g_lines / p_numjob.
*---this is to avoid the short dump
IF g_read = 0.
g_read = 1.
ENDIF.

CLEAR g_lines.
g_lines = p_numjob.

*--processing of the job
DO.
*---if the number of jobs to be create is greate than one
IF g_lines > 1.
*---send some of the records to the first job to process
APPEND LINES OF it_t001w FROM 1 TO g_read TO it_exp_t001w.

REFRESH r_werks.
*---fill the records into the ranges to be processed for first job
PERFORM fill_range.
*---get the the file no
ADD 1 TO g_fileno.

v_fileno = g_fileno.

CONCATENATE p_file1 '\test' v_fileno INTO g_filename.
*---get the filename with path
CONDENSE g_filename NO-GAPS.
*---get the no articles from the plants selected in the ranes
PERFORM get_mard_data.

CLEAR: it_exp_t001w, it_exp_t001w[].
*---decrease the no of jobs by one
g_lines = g_lines - 1.
*---check for further processing
IF it_t001w[] IS INITIAL.
g_lines = 0.
ENDIF.
*---if the no of jobs to be created is one
ELSEIF g_lines = 1.
*---send all the records to one internal table
APPEND LINES OF it_t001w TO it_exp_t001w.

REFRESH r_werks.
*---get the records in ranges
PERFORM fill_range.
REFRESH IT_MARD.
PERFORM get_mard_data.
CLEAR: it_exp_t001w, it_exp_t001w[], it_t001w[].
*--check for further processing
CHECK it_t001w[] IS INITIAL.
EXIT.
ELSE.
CHECK it_t001w[] IS INITIAL.
EXIT.
ENDIF.
ENDDO.

ENDFORM. " process_data
*&---------------------------------------------------------------------*
*& Form get_mard_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM get_mard_data . REFRESH: it_mard. SELECT matnr werks lgort FROM mard INTO TABLE it_mard FOR ALL ENTRIES IN it_t001w WHERE werks = it_t001w-werks. IF NOT it_mard[] IS INITIAL. SORT it_mard BY werks. *----write the file into application server PERFORM write_file. ENDIF. ENDFORM. " get_mard_data *&---------------------------------------------------------------------* *& Form write_file *&---------------------------------------------------------------------* FORM write_file . DATA: outrec(100) TYPE c. *---get the no of records from the mard table DESCRIBE TABLE it_mard LINES v_records. *---open file in appilication server to write these records OPEN DATASET g_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0. EXIT. ENDIF. LOOP AT it_mard. outrec+0(18) = it_mard-matnr. outrec+25(4) = it_mard-werks. outrec+40(16) = it_mard-lgort. TRANSFER outrec TO g_filename . ENDLOOP. *---write the file name and no of records downloaded PERFORM file_name. *---close the file in application server CLOSE DATASET g_filename. ENDFORM. " write_file *&---------------------------------------------------------------------* *& Form fill_range *&---------------------------------------------------------------------* FORM fill_range . LOOP AT it_exp_t001w. r_werks-low = it_exp_t001w-werks. r_werks-sign = 'I'. r_werks-option = 'EQ'. APPEND r_werks. ENDLOOP. DELETE it_t001w FROM 1 TO g_read. ENDFORM. " fill_range *&---------------------------------------------------------------------* *& Form header_name *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM header_name .
WRITE:/1(130) sy-uline .
WRITE:/1 sy-vline,
2 'CREATED FILENAME' COLOR 7,
62 sy-vline,
64 'NO OF SUCCESSFUL RECORDS IN THIS FILE ' COLOR 7 ,
130 sy-vline.
WRITE:/1(130) sy-uline .
ENDFORM. " header_name
*&---------------------------------------------------------------------*
*& Form FILE_NAME
*&---------------------------------------------------------------------*
FORM file_name .

WRITE:/1(130) sy-uline .

WRITE:/1 sy-vline,
2 g_filename,
62 sy-vline,
64 v_records,
130 sy-vline.

WRITE:/1(130) sy-uline .

ENDFORM. " FILE_NAME

No comments:

Post a Comment