0% found this document useful (0 votes)
304 views4 pages

Call Transaction Using BDC (Fk01)

This document contains code for extracting data from an Excel file, mapping it to internal tables, and using SAP BDC functionality to populate master data in SAP transaction codes MF02K and FK01. Key aspects include: 1) Using function TEXT_CONVERT_XLS_TO_SAP to extract data from a specified Excel file and load it into internal tables. 2) Looping through the internal tables to populate fields in various SAP transactions using BDC functionality. 3) Calling transaction FK01 at the end to commit the changes, and handling any error messages. 4) Helper forms are defined to start new dynpro screens and insert field values for the BDC calls.

Uploaded by

anon_758290984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
304 views4 pages

Call Transaction Using BDC (Fk01)

This document contains code for extracting data from an Excel file, mapping it to internal tables, and using SAP BDC functionality to populate master data in SAP transaction codes MF02K and FK01. Key aspects include: 1) Using function TEXT_CONVERT_XLS_TO_SAP to extract data from a specified Excel file and load it into internal tables. 2) Looping through the internal tables to populate fields in various SAP transactions using BDC functionality. 3) Calling transaction FK01 at the end to commit the changes, and handling any error messages. 4) Helper forms are defined to start new dynpro screens and insert field values for the BDC calls.

Uploaded by

anon_758290984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

report ZRAJ_ARMY

no standard page heading line-size 255.


TABLES : RF02K, LFA1,LFB1.
TYPE-POOLS : TRUXS.
TYPES : BEGIN OF TY_TAB,
BUKRS TYPE RF02K-BUKRS,
KTOKK TYPE RF02K-KTOKK,
ANRED TYPE LFA1-ANRED,
NAME1 TYPE LFA1-NAME1,
LAND1 TYPE LFA1-LAND1,
REGIO TYPE LFA1-REGIO,
AKONT TYPE LFB1-AKONT,
ZTERM TYPE LFB1-ZTERM,
END OF TY_TAB.
DATA : IT_DATA TYPE TRUXS_T_TEXT_DATA,
IT_TAB TYPE TABLE OF TY_TAB,
WA_TAB TYPE TY_TAB,
BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE.
DATA: IT_ERROR TYPE TABLE OF BDCMSGCOLL,
WA_ERROR LIKE LINE OF IT_ERROR.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE T.
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
SELECTION-SCREEN : END OF BLOCK B1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME
= SYST-CPROG
DYNPRO_NUMBER
= SYST-DYNNR
FIELD_NAME
= 'P_FILE'
IMPORTING
FILE_NAME
= P_FILE
.
IF P_FILE IS NOT INITIAL.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING
I_FIELD_SEPERATOR
= 'X'
I_LINE_HEADER
= 'X'
I_TAB_RAW_DATA
= IT_DATA
I_FILENAME
= P_FILE
TABLES
I_TAB_CONVERTED_DATA
= IT_TAB
EXCEPTIONS
CONVERSION_FAILED
= 1
OTHERS
= 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
*include bdcrecx1.
start-of-selection.
LOOP AT it_tab INTO wa_tab.
REFRESH BDCDATA.
*perform open_group.
perform bdc_dynpro
using 'SAPMF02K' '0105'.
perform bdc_field
using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'RF02K-BUKRS'
WA_TAB-BUKRS."'2'.
perform bdc_field
using 'RF02K-KTOKK'
WA_TAB-KTOKK."'2'.
perform bdc_dynpro
using 'SAPMF02K' '0110'.
perform bdc_field
using 'BDC_CURSOR'
'LFA1-REGIO'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'LFA1-ANRED'
WA_TAB-ANRED."'company'.
perform bdc_field
using 'LFA1-NAME1'
WA_TAB-NAME1."'APPLE INDIA'.
perform bdc_field
using 'LFA1-LAND1'

WA_TAB-LAND1."'in'.
perform bdc_field
using 'LFA1-REGIO'
WA_TAB-REGIO."'13'.
perform bdc_dynpro
using 'SAPMF02K' '0120'.
perform bdc_field
using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'LFA1-KUNNR'
''.
perform bdc_dynpro
using 'SAPMF02K' '0130'.
perform bdc_field
using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field
using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro
using 'SAPMF02K' '0210'.
perform bdc_field
using 'BDC_CURSOR'
'LFB1-AKONT'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'LFB1-AKONT'
WA_TAB-AKONT."'1002'.
perform bdc_dynpro
using 'SAPMF02K' '0215'.
perform bdc_field
using 'BDC_CURSOR'
'LFB1-ZTERM'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'LFB1-ZTERM'
WA_TAB-ZTERM."'0001'.
perform bdc_dynpro
using 'SAPMF02K' '0220'.
perform bdc_field
using 'BDC_CURSOR'
'LFB5-MAHNA'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
*perform bdc_transaction using 'FK01'.
CALL TRANSACTION 'FK01' USING BDCDATA MODE 'A' UPDATE 'S' MESSAGES I
NTO IT_ERROR.
*perform close_group.
ENDLOOP.
LOOP AT IT_ERROR INTO WA_ERROR WHERE MSGTYP EQ 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID
= WA_ERROR-MSGID
MSGNR
= WA_ERROR-MSGNR
MSGV1
= WA_ERROR-MSGV1

MSGV2
= WA_ERROR-MSGV2
MSGV3
= WA_ERROR-MSGV3
MSGV4
= WA_ERROR-MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT
= WA_ERROR
.
ENDLOOP.
*---------------------------------------------------------------------*
*
Start new screen
*
*---------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO
= DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*---------------------------------------------------------------------*
*
Insert field
*
*---------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.

You might also like