0% found this document useful (0 votes)
71 views6 pages

BDC Standard Program

This document describes a program that imports data from an Excel file into an SAP system using internal tables and BDC calls. Key details: - The program imports data from an Excel file specified by the user into internal tables. - It then loops through the internal tables to populate BDC tables for calls to transaction Z--- to input the data into SAP. - Various validation and error handling is performed within the BDC calls.

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)
71 views6 pages

BDC Standard Program

This document describes a program that imports data from an Excel file into an SAP system using internal tables and BDC calls. Key details: - The program imports data from an Excel file specified by the user into internal tables. - It then loops through the internal tables to populate BDC tables for calls to transaction Z--- to input the data into SAP. - Various validation and error handling is performed within the BDC calls.

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/ 6

*&---------------------------------------------------------------------*

*& Report (Z------------)


*&
*&---------------------------------------------------------------------*
*&
*& PROGRAM
: (Z------------).
*& DESCRIPTION
: (------------)
*& AUTHOR
: DILIP VARMA .K
*& TRANSPORT REQUEST : (Z------------).
*& CREATED ON
: --/--/20--.
*&---------------------------------------------------------------------*
report (Z------------)
no standard page heading line-size 255.
*include bdcrecx1.
*
*parameters: dataset(132) lower case.
***
DO NOT CHANGE - the generated data section - DO NOT CHANGE
*
*
If it is nessesary to change the data section use the rules:
*
1.) Each definition of a field exists of two lines
*
2.) The first line shows exactly the comment
*
'* data element: ' followed with the data element
*
which describes the field.
*
If you don't have a data element use the
*
comment without a data element name
*
3.) The second line shows the fieldname of the
*
structure, the fieldname must consist of
*
a fieldname and optional the character '_' and
*
three numbers and the field length in brackets
*
4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE
TYPES:begin of record,
ACTION_001(003),
REFDOC_002(003),
PO_NUMBER_004(010),
MAKTX_008(003),
ERFMG_009(017),
LSMNG_015(017),
NAME1_011(030),

***

***

LGOBE_012(016),
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 3
,
"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 = '(Z------------)'
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.
FORM PERFORM_BDC .

LOOP AT IT_FINAL INTO record.

CLEAR:

BDCDATA[] .

IF record-ACTION_001 <> ''.


*****************************************************************

*perform open_group.
IF record-REFDOC_002 = 'R10'.
perform bdc_dynpro
using 'SAPLMIGO' '0001'.
perform bdc_field
using 'BDC_OKCODE'
'=OK_GO'.
perform bdc_field
using 'GODYNPRO-ACTION'
record-ACTION_001.
perform bdc_field
using 'GODYNPRO-REFDOC'
record-REFDOC_002.
perform bdc_field
using 'GODEFAULT_TV-BWART'
'561'.
*perform bdc_field
using 'GOHEAD-BLDAT'
*
'17.06.2011'.
*perform bdc_field
using 'GOHEAD-BUDAT'
*
'17.06.2011'.
perform bdc_field
using 'GOHEAD-WEVER'
'1'.
perform bdc_field
using 'GODYNPRO-DETAIL_ZEILE'
'
1'.
perform bdc_field
using 'GOITEM-MAKTX'
record-MAKTX_008.
perform bdc_field
using 'GOITEM-ERFMG'
record-ERFMG_009.
perform bdc_field
using 'BDC_CURSOR'
'GOITEM-LGOBE'.
perform bdc_field
using 'GOITEM-BWART'
'561'.
perform bdc_field
using 'GOITEM-NAME1'
record-NAME1_011.
perform bdc_field
using 'GOITEM-LGOBE'
record-LGOBE_012.
perform bdc_dynpro
using 'SAPLMIGO' '0001'.
perform bdc_field
using 'BDC_OKCODE'
'=OK_CHECK'.
perform bdc_field
using 'GODEFAULT_TV-BWART'

ENDIF.
**************************>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>
CALL TRANSACTION '(Z---)' USING BDCDATA
MODE CTUMODE
UPDATE 'A'.
CLEAR record.

*perform close_group.

**********************************************************************
ENDIF.
*at LAST.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy