Sie sind auf Seite 1von 9

ABAP Code Sample to Upload Data

Using BDC Recording


Code samples are intended for educational use only, not deployment. They are untested and
unsupported by SAP. SAP disclaims all liability to any person in respect to any damage that is
incurred, whether wholly or partially, from use of the code.
Applies To:
ABAP
Summary
This step-by-step code sample helps you upload data using BDC.
By !a"itha Bhu"aneswaran, #ipro Technologies
Date $% &an '(()
Procedure
*i"e the t-code shdb in the command field.
Clic+ the new recording button.
*i"e a name to the recording and the t-code you want to record.
,.g.
-ecording ./AT01P23AD
Transaction code //($
#hen you clic+ sa"e, it ta+es you to t-code 4//($5 you would li+e to do recording for
upload.
-ecord carefully. 6ill in the details you want to upload. 7n this case 7 ha"e entered the
material no, industry sector, material type, material description and basic unit of measure.
Then the Transaction recorder 8 edit recording ./AT01P23AD screen is displayed. 9ou
can edit your recording or :ust sa"e it and clic+ bac+ button.
Select your recording and clic+ create program button.
,nter the program name say ./AT01P23AD.Select the transfer from recording option.
Sa"e it.*i"e the program title, type as e;ecutable program and clic+ source code button
at the bottom.
The following piece of code is generated automatically.
report ZMAT_UPLOAD
no standard page heading line-size 255.
include dcrec!".
start-o#-selection.
per#or$ open_group.
per#or$ dc_d%npro using &'APLM(MM& &))*)&.
per#or$ dc_#ield using &+D,_,U-'O-&
&-MM("-MAT.-&.
per#or$ dc_#ield using &+D,_O/,OD0&
&1AU'2&.
per#or$ dc_#ield using &-MM("-MAT.-&
&M3MAT0-4AL")&.
per#or$ dc_#ield using &-MM("-M+-'5&
&P&.
per#or$ dc_#ield using &-MM("-MTA-T&
&ZO5&.
per#or$ dc_d%npro using &'APLM(MM& &))6)&.
per#or$ dc_#ield using &+D,_,U-'O-&
&M'4,5TAU'2-D3T7T8)"9&.
per#or$ dc_#ield using &+D,_O/,OD0&
&10.T-&.
per#or$ dc_#ield using &M'4,5TAU'2-/Z'0L8)"9&
&7&.
per#or$ dc_d%npro using &'APLM(MM& &:)):&.
per#or$ dc_#ield using &+D,_O/,OD0&
&1+U&.
per#or$ dc_#ield using &MA/T-MA/T7&
&M3 MAT0-4AL")&.
per#or$ dc_#ield using &+D,_,U-'O-&
&MA-A-M04.'&.
per#or$ dc_#ield using &MA-A-M04.'&
&(&.
per#or$ dc_#ield using &MA-A-MTPO'_MA-A&
&.O-M&.
per#or$ dc_transaction using &MM)"&.
Per#or$ close_group.
6rom the abo"e code it is clear that recording has been created using matnr < my
material $( , industry sector < p , material type < =oh , description < my material$( ,
basic unit of measure < g. 6or our case 7 ha"e assumed industry sector and material type
to be constant and ha"e not included in flat file.
The colored lines in the below code are the changes made to the sap generated program
, to upload our data.
;Progra$$ed % < /a=itha
+hu=anes>aran..................................;
;Description < progra$ to upload ne>
$aterials...........................;
;Techni?ue used < +D,
recording.................................................;
report ZMAT_UPLOAD
no standard page heading line-size 255.
;t%pes
declaration.........................................................
.................;
t%pes < egin o# t_$at@
$atnr82)9@
desc85)9@
uo$859@
end o# t_$at.
;internal tale and >orAarea
declaration.......................................;
data < i_$at t%pe tale o# t_$at.
data < >a_$at t%pe t_$at.
include dcrec!".
start-o#-selection.
;$o=ing the #lat #ile content to internal
tale................................;
,ALL BU.,T4O. &UPLOAD&
07PO-T4.(
B4L0T3P0 1 &DAT&
TA+L0'
data_ta 1 i_$at
.
4B s%-surc CD ).
; M0''A(0 4D '3-M'(4D T3P0 '3-M'(T3 .UM+0- '3-M'(.O
; 24T5 '3-M'(E" '3-M'(E2 '3-M'(EF '3-M'(E:.
0.D4B.
per#or$ open_group.
loop at i_$at into >a_$at.
per#or$ dc_d%npro using &'APLM(MM& &))*)&.
per#or$ dc_#ield using &+D,_,U-'O-&
&-MM("-MAT.-&.
per#or$ dc_#ield using &+D,_O/,OD0&
&1AU'2&.
per#or$ dc_#ield using &-MM("-MAT.-&
>a_$at-$atnr.
per#or$ dc_#ield using &-MM("-M+-'5&
&P&.
per#or$ dc_#ield using &-MM("-MTA-T&
&ZO5&.
per#or$ dc_d%npro using &'APLM(MM& &))6)&.
per#or$ dc_#ield using &+D,_,U-'O-&
&M'4,5TAU'2-D3T7T8)"9&.
per#or$ dc_#ield using &+D,_O/,OD0&
&10.T-&.
per#or$ dc_#ield using &M'4,5TAU'2-/Z'0L8)"9&
&7&.
per#or$ dc_d%npro using &'APLM(MM& &:)):&.
per#or$ dc_#ield using &+D,_O/,OD0&
&1+U&.
per#or$ dc_#ield using &MA/T-MA/T7&
>a_$at-desc.
per#or$ dc_#ield using &+D,_,U-'O-&
&MA-A-M04.'&.
per#or$ dc_#ield using &MA-A-M04.'&
>a_$at-uo$.
per#or$ dc_#ield using &MA-A-MTPO'_MA-A&
&.O-M&.
per#or$ dc_transaction using &MM)"&.
endloop.
Per#or$ close_group.
Test the abo"e modified program. #e get a selection screen as below.
#e can choose either the session or call transaction method. 7n our case we continue
with session method. *i"e a name to session say ./AT01P23AD and e;ecute. Then
we get the prompt as below.
,nter your flat file name and clic+ transfer.

C> Document s and
Sett ings> !A?7 T@A> Des+top>material.t;t
#e get the below list.
Then go to S/A) and select your session and clic+ process.
9ou can process it in any of the A modes as shown below.
7f you are using the call transaction method you can select the run mode in the initial
screen itself. 4see page )5.Then we must browse for the flat file.4see page B5.
Data gets uploaded.
Disclaimer & Liability Notice
This document may discuss sample coding, which does not include official interfaces and
therefore is not supported. Changes made based on this information are not supported and can
be o"erwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing of the code and
methods suggested here, and anyone using these methods, is doing it under hisCher own
responsibility.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the
content of the technical article, including any liability resulting from incompatibility between the
content of the technical article and the materials and ser"ices offered by SAP. 9ou agree that you
will not hold SAP responsible or liable with respect to the content of the Technical Article or see+
to do so.
Copyright D '((E SAP A*, 7nc. All -ights -eser"ed. SAP, mySAP, mySAP.com,
;Apps, ;App, and other SAP products and ser"ices mentioned herein as well as
their respecti"e logos are trademar+s or registered trademar+s of SAP A* in
*ermany and in se"eral other countries all o"er the world. All other product,
ser"ice names, trademar+s and registered trademar+s mentioned are the
trademar+s of their respecti"e owners.

Das könnte Ihnen auch gefallen