Quantcast
Channel: SCN : Blog List - ABAP Development
Viewing all articles
Browse latest Browse all 943

Modelling Legacy Data Upload

$
0
0

Do Not reinvent the wheel how many times have we heard this.... But do we really tend to use the term re-usability.

 

Well being into multiple implementation projects one thing that always exists is Legacy System and so is Data Transfer or Data upload.....

 

As we all know LSMW is one of the best tool provided by SAP for data migration but at times it becomes a compulsion to write a conversion program

 

Thanks to Thomas For the input had forgot to mention LSMW

 

Here is a snapshot what I did to have a generic template for upload programs.

 

First I jotted what is common.

 

File Upload either from presentation server or application server

 

Second F4 help for file selection.

 

Third was type of process determination whether it is a BDC or BAPI.....

 

Fourth was the output of processed records with appropriate messages.

 

With All this in Place I created a template program.... Well I could have created a Class but.... You can innovate

 

Selection Screen Select File name.

 

Radio Button 2 Fore Ground and Application Server.

 

For F4 on File selection

 

This for presentation server

 

CALL METHOD cl_gui_frontend_services=>file_open_dialog

      EXPORTING

        window_title            = window_title

      CHANGING

        file_table              = i_file

        rc                      = lc_return

      EXCEPTIONS

        file_open_dialog_failed = 1

        cntl_error              = 2

        error_no_gui            = 3

        OTHERS                  = 5.

 

 

This is for application server.

 

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'

         IMPORTING

              serverfile       = file_path

         EXCEPTIONS

              canceled_by_user = 1

              OTHERS           = 2.

 

Declared a Type and Table for Error Output

 

TYPES: BEGIN OF gs_output,

         KEY1   TYPE c LENGTH 25,

         KEY2   TYPE c LENGTH 25,

          RECNO  TYPE i,

         msg    TYPE c LENGTH 125,

       END OF gs_output.

 

Created a BLANK Perform for processing the uploaded file.

 

Created a Date Conversion perform just in case.

 

FORM update_date  USING    p_date TYPE char10

              CHANGING c_date TYPE sy-datum.

 

  CLEAR c_date.

 

  CONCATENATE p_date+6(4)

              p_date+3(2)

              p_date(2)

         INTO c_date.

 

ENDFORM.                    " UPDATE_DATE

 

Perform for BDC Append.

 

*&---------------------------------------------------------------------*
*&      Form  build_bdc_table
*&---------------------------------------------------------------------*

FORM BUILD_BDC_TABLE USING P_SCREEN TYPE C P_FIELD TYPE C P_VALUE TYPE C.

 

  CLEAR BDCDATA.

 

  IF P_SCREEN = 'X'.
    BDCDATA-DYNBEGIN = 'X'.
    BDCDATA-PROGRAM  = P_FIELD.
    BDCDATA-DYNPRO   = P_VALUE.
  ELSE.
    BDCDATA-FNAM = P_FIELD.
    BDCDATA-FVAL = P_VALUE.
  ENDIF.

 

  APPEND BDCDATA.

 

ENDFORM.                    " build_bdc_table

 

Created Perform's for error handling.

 

BAPI Error Handling

 

READ TABLE git_return INTO lwa_ret WHERE type = 'E'.

 

IF sy-subrc IS INITIAL


          MESSAGE ID lwa_ret-id

        TYPE lwa_ret-type

      NUMBER lwa_ret-number

        WITH lwa_ret-message_v1 lwa_ret-message_v2 lwa_ret-message_v3 lwa_ret-message_v4

        INTO lwa_out-message.

 

  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

 

ELSE.

 

  MOVE : gwa_table-po_number TO lwa_out-key2,

         'Success'           TO lwa_out-message.

 

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            wait = 'X'.

 

        WAIT UP TO 1 SECONDS.

 

ENDIF.

 

APPEND lwa_out TO git_out.

 

BDC Error Handling.

 

Here I_MSG table is the BDCMSGCOLL which we pass in CALL Transaction.

 

DATA V_MSG(255) TYPE C.

 

READ TABLE I_MSG WITH KEY MSGTYP = 'E'.

 

IF SY-SUBRC = 0.

 

  CALL FUNCTION 'FORMAT_MESSAGE'

    EXPORTING

      ID = I_MSG-MSGID

      LANG = 'E'

      NO = I_MSG-MSGNR

      V1 = I_MSG-MSGV1

      V2 = I_MSG-MSGV2

      V3 = I_MSG-MSGV3

      V4 = I_MSG-MSGV4

    IMPORTING

      MSG = V_MSG

 

ENDIF.

 

 

 

Finally you can output the ERROR table with the processed status.

 

And use this template in all projects irrespective of the call.

 

I hope it helps to streamline things.

 

Any inputs are WELCOME ! ! ! !


Viewing all articles
Browse latest Browse all 943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>