0% found this document useful (0 votes)
244 views7 pages

BDC For Class

This document defines a report and internal table for class data in ABAP. It includes: 1) Declarations for internal tables to store interim and final class records from an uploaded Excel file. 2) Methods to upload the Excel file into internal tables, populate BDC data to insert the class records into transaction CL01, and call the transaction. 3) Forms to populate BDC data for screen navigation and field values using the class records from the internal tables. The report loads class data from an Excel file into internal tables, then uses BDC to navigate screens and insert the records into transaction CL01.

Uploaded by

Sreedhar Konduru
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
244 views7 pages

BDC For Class

This document defines a report and internal table for class data in ABAP. It includes: 1) Declarations for internal tables to store interim and final class records from an uploaded Excel file. 2) Methods to upload the Excel file into internal tables, populate BDC data to insert the class records into transaction CL01, and call the transaction. 3) Forms to populate BDC data for screen navigation and field values using the class records from the internal tables. The report loads class data from an Excel file into internal tables, then uses BDC to navigate screens and insert the records into transaction CL01.

Uploaded by

Sreedhar Konduru
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

BDC for CLASS

*&---------------------------------------------------------------------*
*& Report ZCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT

ZCLASS.

*&---------------------------------------------------------------------*
*& Report ZNEWCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
*REPORT ZNEWCLASS.
TYPES: begin of record,
* data element: KLASSE_D
CLASS_001(018),
* data element: KLASSENART
KLART_002(003),
* data element: KLSBEZ
KLBEZ_003(040),
* data element: KLSTATUS
STATU_004(001),
* data element: VONDAT
VONDT_005(010),
* data element: BISDAT
BISDT_006(010),
* data element: PRAUSP
PRAUS_007(001),
* data element: SMERKMAL
MERKMA_01_008(030),
* data element: PAGAC
EINTRAG_009(003),
end of record.
*** End generated data section ***

*&----------------------------------------------------------------------*
*&
I N T E R N A L T A B L E
D E C L A R A T I O N S
*&----------------------------------------------------------------------*
DATA : IT_FINAL
TYPE STANDARD TABLE OF record.
DATA : IT_INTRN
TYPE STANDARD TABLE OF ALSMEX_TABLINE.
*&----------------------------------------------------------------------*
*&
W O R K A R E A
D E C L A R A T I O N S
*&----------------------------------------------------------------------*
DATA: IS_INTRN
TYPE ALSMEX_TABLINE,
IS_FINAL
TYPE record,
record
TYPE record.
*&----------------------------------------------------------------------*
*&
V A R I A B L E
D E C L A R A T I O N S
*&----------------------------------------------------------------------*
DATA : W_FNAME TYPE RLGRAP-FILENAME
.
DATA : W_COUNT
TYPE I.

*&----------------------------------------------------------------------*
*&
C O N S T A N T S
D E C L A R A T I O N S
*&----------------------------------------------------------------------*
DATA: C_WAIT
LIKE BAPITAWAIT VALUE 'X'
,
" Using the command `COMMIT AND WAIT`
C_BCOL
TYPE I
VALUE 1
,
"START COLUM
N
C_BROW
TYPE I
VALUE 2
,
"START ROW
C_ECOL
TYPE I
VALUE 200
,
"Ending colu
mn
C_EROW
TYPE I
VALUE 40000
.
"ENDING ROW
*Used to stores error information from CALL TRANSACTION Function Module
DATA: BEGIN OF MESSTAB OCCURS 0.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF MESSTAB.
*Used to store BDC data
DATA: BDCDATA
TYPE STANDARD TABLE OF BDCDATA INITIAL SIZE 1 WITH HEADER LIN
E.
DATA: W_TEXTOUT
LIKE T100-TEXT.
* This method of file download with check uses the latest techniques
* and achieves a very neat solution
DATA: LD_FILENAME TYPE STRING,
LD_PATH TYPE STRING,
LD_FULLPATH TYPE STRING,
LD_RESULT TYPE I.

*&----------------------------------------------------------------------*
*&
S E L E C T I O N
S C R E E N D E S I G N I N S
*&----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_FNAME TYPE RLGRAP-FILENAME OBLIGATORY
.
*PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'E'.
DATA CTUMODE LIKE CTU_PARAMS-DISMODE VALUE 'A'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
SELECTION-SCREEN END OF BLOCK B1

*&----------------------------------------------------------------------*
*&
AT - S E L E C T I O N
S C R E E N
*&----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = 'ZCHAR'
DYNPRO_NUMBER = '1000'
FIELD_NAME
= 'P_FNAME'
CHANGING
FILE_NAME
= P_FNAME.
IF NOT P_FNAME IS INITIAL.
W_FNAME = P_FNAME.
ENDIF.
PERFORM SUB_UPLOADEXCEL.
PERFORM PERFORM_BDC.

start-of-selection.
*perform open_dataset using dataset.
*perform open_group.
*do.
*
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
FORM PERFORM_BDC .
data storeClass TYPE record-CLASS_001.
data calc TYPE n VALUE 1 .
data string TYPE string.

LOOP AT IT_FINAL INTO record.


IF storeClass is INITIAL.
storeClass = record-CLASS_001.
ELSEIF storeClass <> record-CLASS_001 AND record-CLASS_001 <> ''.
perform bdc_field
using 'BDC_CURSOR'
'RMCLM-MERKMA(01)'.
perform bdc_dynpro
using 'ZCCC' '1000'.
perform bdc_field
using 'BDC_OKCODE'
'=INSERT'.
CALL TRANSACTION 'CL01' USING BDCDATA
MODE CTUMODE
UPDATE 'A'.
CLEAR: BDCDATA[] .
storeClass = record-CLASS_001.
calc = 1.
ENDIF.

IF record-CLASS_001 <> ''.

perform bdc_dynpro
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_dynpro
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_field

using 'SAPLCLMO' '0100'.


using 'BDC_CURSOR'
'RMCLM-CLASS'.
using 'BDC_OKCODE'
'/00'.
using 'RMCLM-CLASS'
record-CLASS_001.
using 'RMCLM-KLART'
record-KLART_002.
using 'SAPLCLMO' '7777'.
using 'BDC_OKCODE'
'=MERK'.
using 'BDC_CURSOR'
'RMCLM-KLBEZ'.
using 'RMCLM-KLBEZ'
record-KLBEZ_003.
using 'RMCLM-STATU'
record-STATU_004.
using 'RMCLM-VONDT'
record-VONDT_005.
using 'RMCLM-BISDT'

perform bdc_field

perform bdc_dynpro
perform bdc_field
perform bdc_field
perform bdc_field
*perform bdc_field
*

record-BISDT_006.
using 'RMCLM-PRAUS'
record-PRAUS_007.
using 'SAPLCLMO' '7777'.
using 'BDC_OKCODE'
'/00'.
using 'BDC_CURSOR'
'RMCLM-MERKMA(01)'.
using 'RMCLM-MERKMA(01)'
record-MERKMA_01_008.
using 'RMCLM-EINTRAG'
record-EINTRAG_009.

ELSE.
string = ''.
calc = calc + 1.
CONCATENATE 'RMCLM-MERKMA(' calc ')' INTO
perform bdc_dynpro
perform bdc_field
perform bdc_field
perform bdc_field
*
*

perform bdc_field

*perform bdc_field
*
*perform bdc_field
*

string.

using 'SAPLCLMO' '7777'.


using 'BDC_OKCODE'
'/00'.
using 'BDC_CURSOR'
string.
using string
record-MERKMA_01_008.
using 'RMCLM-EINTRAG'
record-EINTRAG_009.
using 'BDC_CURSOR'
'RMCLM-MERKMA(01)'.
using 'RMCLM-EINTRAG'
record-EINTRAG_009.

ENDIF.

at LAST.
perform bdc_field
perform bdc_dynpro
perform bdc_field

using 'BDC_CURSOR'
'RMCLM-MERKMA(01)'.
using 'SAPLCLMO' '7777'.
using 'BDC_OKCODE'
'=SAVE'.

CALL TRANSACTION 'CL01' USING BDCDATA


MODE CTUMODE
UPDATE 'A'.
*

CLEAR:

record ,BDCDATA[] .

ENDAT.
endloop.
ENDFORM.

FORM SUB_UPLOADEXCEL .
IF NOT W_FNAME IS INITIAL.
DATA : WL_INDEX TYPE I.
FIELD-SYMBOLS <FS>.
REFRESH: IT_INTRN,IT_FINAL.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME
= W_FNAME
I_BEGIN_COL = C_BCOL
I_BEGIN_ROW = C_BROW
I_END_COL
= C_ECOL
I_END_ROW
= C_EROW
TABLES
INTERN
= IT_INTRN.
*--- Sorting the internal table
SORT IT_INTRN BY ROW COL.
* CLEAR IT_INTERN.
LOOP AT IT_INTRN INTO IS_INTRN.
MOVE IS_INTRN-COL TO WL_INDEX.
*--- Assigning the each record to an internal table row
ASSIGN COMPONENT WL_INDEX OF STRUCTURE IS_FINAL TO <FS>.
IF SY-SUBRC = 0.
*--- Asigning the field value to a field symbol
CONDENSE IS_INTRN-VALUE.
MOVE IS_INTRN-VALUE TO <FS>.
ENDIF.
AT END OF ROW.
APPEND IS_FINAL TO IT_FINAL.
CLEAR IS_FINAL.
ENDAT.
ENDLOOP.
CLEAR : P_FNAME, W_FNAME.
ELSE.
MESSAGE I002(SY) WITH 'Select valid file'.

ENDIF.
ENDFORM.

" SUB_UPLOADEXCEL

*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO
= DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
"BDC_DYNPRO
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
"NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
"BDC_FIELD

You might also like