Skip to Content

We got a situation, were to load multiple files on a single go from legacy systems, below are the steps that are followed and with mandatory updates:

Mandatory updates:

1. The multiple files structure should be same.

2. The files should be derived from one common application server path.

3. time interval between files to be taken care.

Step 1:

Check the files structure, we received following input in our application server,

Untitled1.png

Step 2 :

we will be receiving 40+ files at same time,which should be automated in an single go.

Untitled2.png

Step 3:

We deployed a Change routine in info pack, which collates all the files into a single file and processed into BI server.

Untitled3.png

Step 4:

Use the below routine,

Local TYpes Declaration

TYPES: BEGIN OF ty_final,

         vendor   TYPE char10,

         loctype  TYPE char2,

         upc      TYPE char18,

         qty      TYPE char17,

         buom     TYPE char3,

*         fsv_site TYPE char4,                                  “Mod-001

       END OF ty_final.

*BEGIN OF DELETION- Mod-001

*       BEGIN OF ty_file2,

*         vendor   TYPE char10,

*         loctype  TYPE char2,

*         fsv_site TYPE char4,

*       END OF ty_file2.

*END OF DELETION- Mod-001

* Local Constants declaration

  CONSTANTS: c_filepath1 TYPE rsfilenm VALUE ‘/interfaces/’,

             c_filepath2 TYPE rsfilenm VALUE ‘/inbound/GMII036’,

             c_file      TYPE char30    VALUE

             ‘I1306_GENTRAN_SAPBI_FSV_AVAIL_’,

             c_slash      TYPE char1    VALUE ‘/’,

             c_file_extn  TYPE char4    VALUE ‘.txt’,

             c_file_ext   TYPE char4    VALUE ‘.DAT’,

             c_file_ext1  TYPE char4    VALUE ‘.DAT’,

             c_prefix     TYPE char16   VALUE ‘FSV_FINAL_’,

             c_x          TYPE char1    VALUE ‘X’,

*BEGIN OF DELETION- Mod-001

*             c_comma      TYPE char1    VALUE ‘,’,

*             c_file2      TYPE char20   VALUE ‘FSV_SITE_EXTRACT.txt’,

*             c_tab        TYPE char1    VALUE

*              cl_abap_char_utilities=>horizontal_tab,

*END OF DELETION- Mod-001

             c_cntl       TYPE char4    VALUE ‘CNTL’.

* Local Internal tables declaration

  DATA: li_final      TYPE STANDARD TABLE OF string,

        li_target     TYPE STANDARD TABLE OF ty_final.

*        li_file2      TYPE STANDARD TABLE OF ty_file2.         “Mod-001

* Local Work Area declaration

  DATA: rec_filedat        TYPE string,

        rec_filechar(4096) TYPE c,

        rec_final          TYPE ty_final,

*        rec_file2          TYPE ty_file2,                      “Mod-001

        rec_target         TYPE ty_final.

* Local Variables declaration

  DATA: l_v_dir       TYPE dirname_al11,

        l_v_file      TYPE string,

        l_v_finalpath TYPE rsfilenm,

        l_v_name      TYPE string,

        l_v_rectype   TYPE char4,

        l_v_flag      TYPE char1,

        l_v_cntrl     TYPE char4,

        l_v_date      TYPE char6,

        l_v_time      TYPE char6,

        l_v_dd        TYPE char2,

        l_v_mm        TYPE char2,

        l_v_yy        TYPE char2,

        l_v_datum     TYPE char6,

        l_v_input     TYPE string,

        l_v_tabix     TYPE sy-tabix.

* Get the File Directory

  CONCATENATE c_filepath1 sy-sysid c_filepath2 INTO l_v_dir.

* Append timestamp to file name

  CONCATENATE c_file sy-datum c_file_extINTO l_v_input.

    CLEAR: l_v_file.

    CONCATENATE l_v_dir l_v_input INTO l_v_file

                SEPARATED BY c_slash.

* Reading the Application File

    OPEN DATASET l_v_file FOR INPUT

                IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc NE 0.

      CLEAR: l_v_file, l_v_input.

* Append timestamp to file name

       CONCATENATE c_file ‘20130729’ c_file_ext1 INTO l_v_input.

       CONCATENATE l_v_dir l_v_input INTO l_v_file

                SEPARATED BY c_slash.

* Reading the Application File

    OPEN DATASET l_v_file FOR INPUT

                IN TEXT MODE ENCODING DEFAULT.

    ENDIF.

    IF sy-subrc EQ 0.

      DO .

        READ DATASET l_v_file INTO rec_filedat.

        IF sy-subrc <> 0.

          EXIT.

        ELSE.

* Moving string variable values to char variable

          MOVE rec_filedat TO rec_filechar.

*Validating date in the control record

          l_v_cntrl = rec_filechar+0(4).

          IF l_v_cntrl = c_cntl .

            CLEAR l_v_flag.

            l_v_date = rec_filechar+4(6).

            l_v_time = rec_filechar+10(6).

*Splitting SY-DATUM into YYMMDD format

            l_v_dd = sy-datum+6(2).

            l_v_mm = sy-datum+4(2).

            l_v_yy = sy-datum+2(2).

            CONCATENATE l_v_yy

                        l_v_mm

                        l_v_dd

                        INTO l_v_datum.

            IF l_v_date NE l_v_datum.

             l_v_flag = c_x.

            ELSE.

              clear l_v_flag.

            ENDIF.

          ELSEIF l_v_flag IS INITIAL.

* Consolidating the file(s) contents

            APPEND rec_filedat TO li_final.

            CLEAR rec_filedat.

          ENDIF.

        ENDIF.

      ENDDO.

      CLOSE DATASET l_v_file.

    ENDIF.

  CLEAR l_v_file.

  DELETE li_final INDEX 1.

  IF li_final IS NOT INITIAL.

    LOOP AT li_final INTO rec_filedat.

* Moving string variable values to char variable

      CLEAR rec_filechar.

      MOVE rec_filedat TO rec_filechar.

      l_v_rectype = rec_filechar+0(4).

*processing input file to form the target file in required format

      CASE l_v_rectype.

        WHEN ‘AV01’.

          rec_final-vendor = rec_filechar+9(5).

          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

            EXPORTING

              input  = rec_final-vendor

            IMPORTING

              output = rec_final-vendor.

        WHEN ‘AV05’.

          rec_final-loctype  = rec_filechar+5(2).

          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

            EXPORTING

              input  = rec_final-loctype

            IMPORTING

              output = rec_final-loctype.

        WHEN ‘AV10’.

          rec_final-upc  = rec_filechar+4(8).

          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

            EXPORTING

              input  = rec_final-upc

            IMPORTING

              output = rec_final-upc.

          rec_final-qty  = rec_filechar+12(16).

          APPEND rec_final TO li_target.

*       WHEN OTHERS.

      ENDCASE.

    ENDLOOP.

  ENDIF.

  CLEAR rec_final.

  IF li_target IS NOT INITIAL.

*BEGIN OF DELETION – Mod-001

*reading second input file ‘FSV_SITE_EXTRACT.TXT’

*    CONCATENATE l_v_dir c_file2 INTO l_v_file

*                                  SEPARATED BY c_slash.

** Reading the Application File

*    OPEN DATASET l_v_file FOR INPUT

*                IN TEXT MODE ENCODING DEFAULT.

*    IF sy-subrc EQ 0.

*      DO .

*        READ DATASET l_v_file INTO rec_filedat.

*        IF sy-subrc <> 0.

*

*          EXIT.

*        ELSE.

** Moving string variable values to char variable

*          CLEAR rec_filechar.

*          MOVE rec_filedat TO rec_filechar.

*          SPLIT rec_filechar AT c_tab

*           INTO rec_file2-vendor

*                rec_file2-loctype

*                rec_file2-fsv_site.

*

*          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

*            EXPORTING

*              input  = rec_file2-vendor

*            IMPORTING

*              output = rec_file2-vendor.

*

*          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

*            EXPORTING

*              input  = rec_file2-loctype

*            IMPORTING

*              output = rec_file2-loctype.

*

*          APPEND rec_file2 TO li_file2.

*          CLEAR rec_file2.

*        ENDIF.

*      ENDDO.

*    ENDIF.

*END OF DELETION – Mod-001

    CLOSE DATASET l_v_file.

    CLEAR l_v_file.

*Look up for FSV_SITE in LI_FILE2 and adding to LI_TARGET

*    SORT li_file2 BY vendor loctype.                           “Mod-001

    CLEAR l_v_name.

    CONCATENATE c_prefix sy-datum c_file_extn INTO l_v_name.

    CONCATENATE l_v_dir c_slash l_v_name  INTO l_v_finalpath .

** Write the Application server file with the consolidated Content(s)

    OPEN DATASET l_v_finalpath FOR OUTPUT

                IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc EQ 0.

      CLEAR rec_filedat.

      LOOP AT li_target INTO rec_final.

        CLEAR : rec_filedat.

*                rec_file2.                                     “Mod-001

*BEGIN OF DELETION – Mod-001

*      READ TABLE li_file2 INTO rec_file2

*        WITH KEY vendor  = rec_final-vendor

*                 loctype = rec_final-loctype BINARY SEARCH.

*      IF sy-subrc = 0.

*        rec_final-fsv_site = rec_file2-fsv_site.

*        endif.

*END OF DELETION – Mod-001

        CONCATENATE rec_final-vendor

                    rec_final-loctype

                    rec_final-upc

*                    rec_final-fsv_site                         “Mod-001

                    rec_final-qty

                    rec_final-buom

                    INTO rec_filedat.

        TRANSFER rec_filedat TO l_v_finalpath.

        CLEAR rec_filedat.

      ENDLOOP.

      CLOSE DATASET l_v_finalpath.

    ENDIF.

    p_filename = l_v_finalpath.

    CLEAR: l_v_finalpath.

    REFRESH: li_target,li_final.

  ENDIF.

** Clearing used internal tables, work areas and variables

*….

  p_subrc = 0.

*$*$ end of routine – insert your code only before this line         *-*

endform.

This is Just an example, you can modify your code,based upon your requirements and inputs.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply