BDC sample
*&---------------------------------------------------------------------*
*& Report ZHCM_BDC_PA30_NEW
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZHCM_BDC_PA30_NEW.
TYPE-POOLS: TRUXS,SLIS.
TYPES TRUXS_T_TEXT_DATA(4096) TYPE C OCCURS 0.
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: L_MSTRING(480).
TYPES: BEGIN OF TY_TAB,
PERNR(08),
BEGDA(10),
MASSN(02),
MASSG(02),
PLANS(08),
WERKS(04),
PERSG(01),
PERSK(02),
BEGDA1(10),
ANREX(05),
VORNA(40),
NACHN(40),
GESCH(01),
GBDAT(10),
GBORT(40),
GBLND(03),
SPRSL(01),
FATXT(01),
ANZKD(03),
NATIO(03),
GBDEP(04),
BEGDA2(10),
BTRTL(04),
END OF TY_TAB,
*include bdcrecx1.
BEGIN OF TY_MESSAGE,
MESSAGE TYPE STRING,
END OF TY_MESSAGE.
DATA : IT_TAB TYPE STANDARD TABLE OF TY_TAB ,
IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
IT_MSG TYPE STANDARD TABLE OF BDCMSGCOLL,
WA_MSG LIKE LINE OF IT_MSG,
S_MSG TYPE BDCMSGCOLL ,
WA_TAB TYPE TY_TAB.
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID LIKE SY-REPID.
DATA : IT_SORTCAT TYPE SLIS_T_SORTINFO_ALV.
DATA: LV_REC_COUNT(3) VALUE 0.
DATA : IT_MESSAGE TYPE TABLE OF TY_MESSAGE,
WA_MESSAGE TYPE TY_MESSAGE.
*&--------------------- SELECTION SCREEN ------------------------------------&*
SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.
PARAMETERS: FILENAM1 TYPE RLGRAP-FILENAME OBLIGATORY,
P_MODE TYPE CTU_MODE DEFAULT 'A'.
SELECTION-SCREEN END OF BLOCK BLK.
SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME .
PARAMETERS P_FRMLIN TYPE I DEFAULT 2. " FROM LINE NO
PARAMETERS P_TOLINE TYPE I DEFAULT 65000. " TO LINE NO
PARAMETERS P_FRMCOL TYPE I DEFAULT 1. " FROM COL NO
PARAMETERS P_TOCOL TYPE I DEFAULT 57. " TO COL NO
SELECTION-SCREEN END OF BLOCK B.
*&-------------------------------------------------------------------------&*
DATA: BEGIN OF IT_FILE_UPLOAD1 OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE. " ROWS FOR TABLE WITH EXCEL DATA
DATA: END OF IT_FILE_UPLOAD1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAM1.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'FILENAME'
IMPORTING
FILE_NAME = FILENAM1.
*&----------------------------------------------------------------------------&*
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = FILENAM1
I_BEGIN_COL = P_FRMCOL
I_BEGIN_ROW = P_FRMLIN
I_END_COL = P_TOCOL
I_END_ROW = P_TOLINE
TABLES
INTERN = IT_FILE_UPLOAD1
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&----------------------------------------------------------------------------&*
SORT IT_FILE_UPLOAD1 BY ROW COL.
LOOP AT IT_FILE_UPLOAD1.
CASE IT_FILE_UPLOAD1-COL.
WHEN 1.
WA_TAB-PERNR = IT_FILE_UPLOAD1-VALUE.
WHEN 2.
WA_TAB-BEGDA = IT_FILE_UPLOAD1-VALUE .
WHEN 3.
WA_TAB-MASSN = IT_FILE_UPLOAD1-VALUE.
WHEN 4.
WA_TAB-MASSG = IT_FILE_UPLOAD1-VALUE.
WHEN 5.
WA_TAB-PLANS = IT_FILE_UPLOAD1-VALUE.
WHEN 6.
WA_TAB-WERKS = IT_FILE_UPLOAD1-VALUE.
WHEN 7.
WA_TAB-PERSG = IT_FILE_UPLOAD1-VALUE.
WHEN 8.
WA_TAB-PERSK = IT_FILE_UPLOAD1-VALUE.
WHEN 9.
WA_TAB-BEGDA1 = IT_FILE_UPLOAD1-VALUE.
WHEN 10.
WA_TAB-ANREX = IT_FILE_UPLOAD1-VALUE.
WHEN 11.
WA_TAB-VORNA = IT_FILE_UPLOAD1-VALUE.
WHEN 12.
WA_TAB-NACHN = IT_FILE_UPLOAD1-VALUE .
WHEN 13.
WA_TAB-GESCH = IT_FILE_UPLOAD1-VALUE.
WHEN 14.
WA_TAB-GBDAT = IT_FILE_UPLOAD1-VALUE.
WHEN 15.
WA_TAB-GBORT = IT_FILE_UPLOAD1-VALUE.
WHEN 16.
WA_TAB-GBLND = IT_FILE_UPLOAD1-VALUE.
WHEN 17.
WA_TAB-SPRSL = IT_FILE_UPLOAD1-VALUE.
WHEN 18.
WA_TAB-FATXT = IT_FILE_UPLOAD1-VALUE.
WHEN 19.
WA_TAB-ANZKD = IT_FILE_UPLOAD1-VALUE.
WHEN 20.
WA_TAB-NATIO = IT_FILE_UPLOAD1-VALUE.
WHEN 21.
WA_TAB-GBDEP = IT_FILE_UPLOAD1-VALUE.
WHEN 22.
WA_TAB-BEGDA2 = IT_FILE_UPLOAD1-VALUE.
WHEN 23.
WA_TAB-BTRTL = IT_FILE_UPLOAD1-VALUE.
ENDCASE.
AT END OF ROW.
APPEND WA_TAB TO IT_TAB.
CLEAR: WA_TAB.
ENDAT.
ENDLOOP.
* perform open_group.
LOOP AT IT_TAB INTO WA_TAB..
REFRESH: IT_BDCDATA.
perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RP50G-PERNR'
WA_TAB-PERNR."'1'.
perform bdc_field using 'BDC_CURSOR'
'T582S-ITEXT(01)'.
perform bdc_field using 'RP50G-SELEC(01)'
'X'.
perform bdc_field using 'RP50G-TIMR6'
'X'.
perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
perform bdc_field using 'RP50G-PERNR'
WA_TAB-PERNR."'1'.
perform bdc_field using 'BDC_CURSOR'
'T582S-ITEXT(01)'.
perform bdc_field using 'RP50G-TIMR6'
'X'.
perform bdc_field using 'RP50G-CHOIC'
'Actions'.
perform bdc_dynpro using 'MP000000' '2000'.
perform bdc_field using 'BDC_CURSOR'
'P0000-BEGDA'.
perform bdc_field using 'BDC_OKCODE'
'=UPD'.
perform bdc_field using 'P0000-BEGDA'
WA_TAB-BEGDA."'28.10.2013'.
perform bdc_field using 'P0000-MASSN'
WA_TAB-BEGDA."'ZA'.
perform bdc_field using 'P0000-MASSG'
WA_TAB-MASSG."'02'.
perform bdc_field using 'PSPAR-PLANS'
WA_TAB-PLANS."'99999999'.
perform bdc_field using 'PSPAR-WERKS'
WA_TAB-WERKS."'A001'.
perform bdc_field using 'PSPAR-PERSG'
WA_TAB-PERSG."'A'.
perform bdc_field using 'PSPAR-PERSK'
WA_TAB-PERSK."'E1'.
perform bdc_dynpro using 'MP000100' '2000'.
perform bdc_field using 'BDC_CURSOR'
'P0001-BTRTL'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'P0001-BEGDA'
WA_TAB-BEGDA2."'28.10.2013'.
perform bdc_field using 'P0001-ENDDA'
'31.12.9999'.
perform bdc_field using 'P0001-BTRTL'
WA_TAB-BTRTL."'CX02'.
***perform bdc_field using 'P0001-ABKRS'
*** 'P1'.
***perform bdc_field using 'PPRHPR-PROZT'
*** '100,00'.
***perform bdc_field using 'P0001-PLANS'
*** '99999999'.
***perform bdc_field using 'P0001-VDSK1'
*** 'A001'.
***perform bdc_dynpro using 'MP000100' '2000'.
***perform bdc_field using 'BDC_CURSOR'
*** 'P0001-BEGDA'.
***perform bdc_field using 'BDC_OKCODE'
*** '=UPD'.
***perform bdc_field using 'P0001-BEGDA'
*** '28.10.2013'.
***perform bdc_field using 'P0001-ENDDA'
*** '31.12.9999'.
***perform bdc_field using 'P0001-BTRTL'
*** 'CX02'.
***perform bdc_field using 'P0001-ABKRS'
*** 'P1'.
***perform bdc_field using 'PPRHPR-PROZT'
*** '100,00'.
***perform bdc_field using 'P0001-PLANS'
*** '99999999'.
***perform bdc_field using 'P0001-VDSK1'
*** 'A001'.
perform bdc_dynpro using 'MP000200' '2040'.
perform bdc_field using 'BDC_CURSOR'
'P0002-GBORT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'P0002-BEGDA'
WA_TAB-BEGDA1."'01.01.1979'.
perform bdc_field using 'P0002-ENDDA'
'31.12.9999'.
perform bdc_field using 'Q0002-ANREX'
WA_TAB-ANREX."'Mr.'.
perform bdc_field using 'P0002-NACHN'
WA_TAB-NACHN."'FilLING'.
perform bdc_field using 'P0002-VORNA'
WA_TAB-VORNA."'Manager'.
*perform bdc_field using 'P0002-INITS'
* 'a'.
perform bdc_field using 'P0002-GESCH'
WA_TAB-GESCH."'1'.
perform bdc_field using 'P0002-SPRSL'
WA_TAB-SPRSL."'EN'.
perform bdc_field using 'P0002-GBDAT'
WA_TAB-GBDAT."'01.01.1970'.
perform bdc_field using 'Q0002-FATXT'
WA_TAB-FATXT."'Single'.
perform bdc_field using 'P0002-GBORT'
WA_TAB-GBORT."'DEHRADUN'.
perform bdc_field using 'P0002-GBLND'
WA_TAB-GBLND."'IN'.
perform bdc_field using 'P0002-ANZKD'
WA_TAB-ANZKD."'40'.
perform bdc_field using 'P0002-GBDEP'
WA_TAB-GBDEP."'24'.
*perform bdc_field using 'Q0002-KITXT'
* 'HND'.
perform bdc_field using 'P0002-NATIO'
WA_TAB-NATIO."'IN'.
***perform bdc_dynpro using 'MP000200' '2040'.
***perform bdc_field using 'BDC_CURSOR'
*** 'P0002-BEGDA'.
***perform bdc_field using 'BDC_OKCODE'
*** '=UPD'.
***perform bdc_field using 'P0002-BEGDA'
*** '01.01.1979'.
***perform bdc_field using 'P0002-ENDDA'
*** '31.12.9999'.
***perform bdc_field using 'Q0002-ANREX'
*** 'Mr.'.
***perform bdc_field using 'P0002-NACHN'
*** 'FilLING'.
***perform bdc_field using 'P0002-VORNA'
*** 'Manager'.
***perform bdc_field using 'P0002-INITS'
*** 'a'.
***perform bdc_field using 'P0002-GESCH'
*** '1'.
***perform bdc_field using 'P0002-SPRSL'
*** 'EN'.
***perform bdc_field using 'P0002-GBDAT'
*** '01.01.1970'.
***perform bdc_field using 'Q0002-FATXT'
*** 'Single'.
***perform bdc_field using 'P0002-GBORT'
*** 'DEHRADUN'.
***perform bdc_field using 'P0002-GBLND'
*** 'IN'.
***perform bdc_field using 'P0002-ANZKD'
*** '40'.
***perform bdc_field using 'P0002-GBDEP'
*** '24'.
***perform bdc_field using 'Q0002-KITXT'
*** 'HND'.
***perform bdc_field using 'P0002-NATIO'
*** 'IN'.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_CURSOR'
'04/03'.
perform bdc_field using 'BDC_OKCODE'
'=CANC'.
perform bdc_dynpro using 'MP000700' '2000'.
perform bdc_field using 'BDC_OKCODE'
'/EBCK'.
perform bdc_field using 'BDC_CURSOR'
'P0007-BEGDA'.
perform bdc_dynpro using 'SAPMP50A' '1100'.
perform bdc_field using 'BDC_OKCODE'
'/EBCK'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-PERNR'.
CALL TRANSACTION 'PA30' USING IT_BDCDATA
MODE P_MODE
UPDATE 'S'
MESSAGES INTO IT_MSG.
REFRESH: IT_BDCDATA.
ENDLOOP.
DATA: V_MSG(255).
LOOP AT IT_MSG INTO S_MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = S_MSG-MSGID
LANG = S_MSG-MSGSPRA
NO = S_MSG-MSGNR
V1 = S_MSG-MSGV1
V2 = S_MSG-MSGV2
V3 = S_MSG-MSGV3
V4 = S_MSG-MSGV4
IMPORTING
MSG = WA_MESSAGE-MESSAGE
EXCEPTIONS
NOT_FOUND = 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.
APPEND WA_MESSAGE TO IT_MESSAGE.
CLEAR : WA_MESSAGE.
ENDLOOP.
IF NOT IT_MESSAGE IS INITIAL.
PERFORM BUILD_CATALOG.
PERFORM ALV_DISPLAY.
PERFORM LAYOUT.
ENDIF.
***&---------------------------------------------------------------------*
*& FORM BDC_DYNPRO
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->PROGRAM TEXT
* -->DYNPRO TEXT
*----------------------------------------------------------------------*
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.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*& FORM BUILD_CATALOG
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM BUILD_CATALOG .
WA_FIELDCATALOG-FIELDNAME = 'MESSAGE'.
WA_FIELDCATALOG-SELTEXT_M = 'MESSAGE.'.
APPEND WA_FIELDCATALOG TO I_FIELDCAT.
CLEAR WA_FIELDCATALOG.
ENDFORM. " BUILD_CATALOG
*&---------------------------------------------------------------------*
*& FORM ALV_DISPLAY
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM ALV_DISPLAY .
GD_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GD_REPID
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = I_FIELDCAT[]
TABLES
T_OUTTAB = IT_MESSAGE
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
ENDFORM. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& FORM LAYOUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM LAYOUT .
CLEAR GD_LAYOUT.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'." OPTIMIZATION OF COL WIDTH
ENDFORM. " LAYOUT