SAP ABAP - Report Program For BDC To Create Condition Types & Amount For Tcode MEK1.


REPORT zptp_bdc_mek1
NO STANDARD PAGE HEADING LINE-SIZE 255.


**********DATA DECLARATION***********
TYPE-POOLS : truxs.
DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA : v_path TYPE string.
DATA : r_data TYPE truxs_t_text_data.
DATA: BEGIN OF it_upload OCCURS 0,
kschl LIKE rv13a-kschl,
matnr LIKE komg-matnr,
KBETR(13),
lifnr LIKE konp-lifnr,
END OF it_upload.

DATA: BEGIN OF it_upload_err OCCURS 0,
kschl LIKE rv13a-kschl,
matnr LIKE komg-matnr,
KBETR(13),
lifnr LIKE konp-lifnr,
END OF it_upload_err.

DATA : it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
it_bdcdata_view LIKE bdcdata OCCURS 0 WITH HEADER LINE,
it_data(3200) OCCURS 0 WITH HEADER LINE,
it_field(3200) OCCURS 0 WITH HEADER LINE,
it_bdcmsg LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS : TYPE ANY.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP 1.
PARAMETERS : p_path LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_path.

START-OF-SELECTION.
PERFORM upload_internal_table.
DATA: v_date(10) TYPE c.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = sy-datum
IMPORTING
date_external = v_date
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
PERFORM fill_bdcdata.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

DATA: BEGIN OF record,
kschl_001(004),
matnr_01_004(018),
datab_006(010),
KBETR_01_005(018),
lifnr_008(010),
END OF record.



*&---------------------------------------------------------------------*
*& Form upload_internal_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM upload_internal_table .
v_path = p_path.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = 'X'
i_tab_raw_data = r_data
i_filename = p_path
TABLES
i_tab_converted_data = it_upload[] .

ENDFORM. " upload_internal_table

*&---------------------------------------------------------------------*
*& Form FILL_BDCDATA
 *&---------------------------------------------------------------------*
 * text *----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM fill_bdcdata .
LOOP AT it_upload.
REFRESH it_bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_upload-kschl.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ' '.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'SAPMV13A' '1445'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMG-MATNR(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_upload-matnr.

PERFORM bdc_dynpro USING 'SAPMV13A' '1445'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KOMG-MATNR(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=PDAT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'KONP-KBETR(01)' it_upload-kbetr.

PERFORM bdc_dynpro USING 'SAPMV13A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR' 'KONP-LIFNR'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'RV13A-DATBI' '31.12.9999'.

PERFORM bdc_field USING 'KONP-STFKZ' 'A'.

PERFORM bdc_field USING 'KONP-LIFNR' it_upload-lifnr.

**CALL TRANSACTION MEK1

CALL TRANSACTION 'MEK1' USING it_bdcdata
MODE 'N' MESSAGES INTO it_bdcmsg.

IF sy-subrc <> 0.
MOVE-CORRESPONDING it_upload TO it_upload_err.
APPEND it_upload_err.
WRITE :/ 'Data is not uploaded for the material :'.
ENDIF.

ENDLOOP.

* ERROR MESSAGE

IF it_upload_err[] IS NOT INITIAL.

CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = ' '
filetype = 'DAT'
TABLES
data_tab = it_upload_err.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ELSE.
WRITE :/ 'Data is uploaded sucessfully for all materials.'.
ENDIF.

ENDFORM. " FILL_BDCDATA

**----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. "BDC_DYNPRO

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
IF fval <> space.
CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD


MORE PROGRAMS ON REPORT PROGRAMMING:


- Edit / Create Customer Specific Message / Text On Login Screen Via SE61.

- MM - Determine Shelf Life Of Materials.

- Fetch Company Code Of All The Vendors.

- Send an excel sheet to the concerned person in an email format via SAP System.

- Upload the financial documents from a legacy system (excel file) into SAP using transaction code FB01.

- ...Back To Index On Report Programming.



Your suggestions and comments are welcome in this section.


Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.