Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

loading data

Former Member
0 Likes
1,138

Hello ABAPers,

I have a requirement like:

In R/3 there are 3 t.codes ie., MCBZ ,MC.9 & ZM0019- running these 3 tcodes results in 3 result sets, by selecting few fields from all the 3 an excel sheet is made.

Now the requirement is i have to create a ZTABLE with all the fields in the EXCEL sheet and upload data into it.

I created the ZTABLE by identifying the fields and SAP tables behind the Tcodes, i want help in writing the upload program.

Can i use the program behind the tcodes (MCBZ,MC.9 & ZM0019), modify and write my upload program?

And if i want to run it automatically what to do?

Please help me regarding this which is an urgent requirement.

Thank YOu,

Vaishu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
993

Hi Vaishu,

I believe that you seem to be doing correct.

Instead of using the insert in a LOOP. Try using ARRAY INSERT. Which will do insert of all the records in one shot instead of in a loop.

If you only want to insert records then use the INSERT command. If you also want to update if the records already eixts or insert if it does not exists then use MODIFY that will help to achieve both.

Cheers

VJ

Message was edited by: Vijayendra Rao

6 REPLIES 6
Read only

hymavathi_oruganti
Active Contributor
0 Likes
993

u created the ztable with the fields right?

now u need an upload program ,

for that u can write a z program and use gui_upload fn module in that and upload into an internal table

and then

UPDATE ZTABLE FROM ITAB.

y u need the upload program behind the tcodes?? i didnt understand?

now clearly data is in xcel right? then write another zprogram upload.

Read only

0 Likes
993

Thank you for your response.

I don't want the data from EXCEL, but the data in the SAP tables.

TO be clear, my ztable contains fields which are in sap tables s032,s031 & s094, so the data in s032,s031 & s094 i want.

can this be done with some select & insert statements.

I am also attaching the code i tried, please suggest me whether this code works or not.

-


REPORT ZRS032V .

TABLES : ztabzinvent,s032,S031,S094.

DATA tmp TYPE i VALUE 0.

DATA: BEGIN OF itab22 OCCURS 0,

matnr like s032-matnr,

werks like s032-werks,

mbwbest like s032-mbwbest,

wbwbest like s032-wbwbest,

mkobest like s032-mkobest,

LETZTZUG like s032-LETZTZUG,

LETZTVER like s032-LETZTVER,

LETZTABG like s032-LETZTABG,

LETZTBEW like s032-LETZTBEW,

MGVBR like s031-MGVBR,

WGVBR like s031-WGVBR,

GABGA like s094-GABGA,

WGABGA like s094-WGABGA,

END OF itab22.

*SELECT * FROM s032 INTO corresponding fields of TABLE itab22.

*SELECT * FROM s031 INTO corresponding fields of TABLE itab22.

*SELECT * FROM s094 INTO corresponding fields of TABLE itab22.

SELECT pmatnr pmbwbest pwbwbest pmkobest

pletztver pletztabg pletztbew pletztzug

qmgvbr qwgvbr rwgabga rspmon

INTO CORRESPONDING FIELDS OF TABLE itab22

FROM ( ( s032 AS p INNER JOIN s031 AS q ON pmatnr = qmatnr )

INNER JOIN s094 AS r ON pmatnr = rmatnr ).

  • WHERE s032-matnr = itab22-matnr.

SORT itab22 BY matnr.

LOOP AT itab22.

ztabzinvent-zmatnr = itab22-matnr.

ztabzinvent-zwerks = itab22-werks.

ztabzinvent-zmbwbest = itab22-mbwbest.

ztabzinvent-Zwbwbest = itab22-wbwbest.

ztabzinvent-Zmkobest = itab22-mkobest.

ztabzinvent-ZLETZTZUG = itab22-LETZTZUG.

ztabzinvent-ZLETZTVER = itab22-LETZTVER.

ztabzinvent-ZLETZTABG = itab22-LETZTABG.

ztabzinvent-ZLETZTBEW = itab22-LETZTBEW.

ztabzinvent-ZMGVBR = itab22-MGVBR.

ztabzinvent-ZWGVBR = itab22-WGVBR.

ztabzinvent-ZGABGA = itab22-GABGA.

ztabzinvent-ZWGABGA = itab22-WGABGA.

ztabzinvent-ZLDATE = SY-DATUM.

INSERT ztabzinvent.

IF sy-subrc <> 0.

tmp = tmp + 1.

ENDIF.

ENDLOOP.

WRITE tmp.

Thak you.

Vaishu

Read only

0 Likes
993

Thank you for your response.

I don't want the data from EXCEL, but the data in the SAP tables.

TO be clear, my ztable contains fields which are in sap tables s032,s031 & s094, so the data in s032,s031 & s094 i want.

can this be done with some select & insert statements.

I am also attaching the code i tried, please suggest me whether this code works or not.

-


REPORT ZRS032V .

TABLES : ztabzinvent,s032,S031,S094.

DATA tmp TYPE i VALUE 0.

DATA: BEGIN OF itab22 OCCURS 0,

matnr like s032-matnr,

werks like s032-werks,

mbwbest like s032-mbwbest,

wbwbest like s032-wbwbest,

mkobest like s032-mkobest,

LETZTZUG like s032-LETZTZUG,

LETZTVER like s032-LETZTVER,

LETZTABG like s032-LETZTABG,

LETZTBEW like s032-LETZTBEW,

MGVBR like s031-MGVBR,

WGVBR like s031-WGVBR,

GABGA like s094-GABGA,

WGABGA like s094-WGABGA,

END OF itab22.

*SELECT * FROM s032 INTO corresponding fields of TABLE itab22.

*SELECT * FROM s031 INTO corresponding fields of TABLE itab22.

*SELECT * FROM s094 INTO corresponding fields of TABLE itab22.

SELECT pmatnr pmbwbest pwbwbest pmkobest

pletztver pletztabg pletztbew pletztzug

qmgvbr qwgvbr rwgabga rspmon

INTO CORRESPONDING FIELDS OF TABLE itab22

FROM ( ( s032 AS p INNER JOIN s031 AS q ON pmatnr = qmatnr )

INNER JOIN s094 AS r ON pmatnr = rmatnr ).

  • WHERE s032-matnr = itab22-matnr.

SORT itab22 BY matnr.

LOOP AT itab22.

ztabzinvent-zmatnr = itab22-matnr.

ztabzinvent-zwerks = itab22-werks.

ztabzinvent-zmbwbest = itab22-mbwbest.

ztabzinvent-Zwbwbest = itab22-wbwbest.

ztabzinvent-Zmkobest = itab22-mkobest.

ztabzinvent-ZLETZTZUG = itab22-LETZTZUG.

ztabzinvent-ZLETZTVER = itab22-LETZTVER.

ztabzinvent-ZLETZTABG = itab22-LETZTABG.

ztabzinvent-ZLETZTBEW = itab22-LETZTBEW.

ztabzinvent-ZMGVBR = itab22-MGVBR.

ztabzinvent-ZWGVBR = itab22-WGVBR.

ztabzinvent-ZGABGA = itab22-GABGA.

ztabzinvent-ZWGABGA = itab22-WGABGA.

ztabzinvent-ZLDATE = SY-DATUM.

INSERT ztabzinvent.

IF sy-subrc <> 0.

tmp = tmp + 1.

ENDIF.

ENDLOOP.

WRITE tmp.

Thak you.

Vaishu

Read only

0 Likes
993

1. USING SELECT statements first retrive the required fields into an internal table.

2. from the internal table u can update the ztabl using

UPDATE statemnt.

3. y u need to down load to xcel in the middle.

any way, using gui_download u can download the data from internal table to xcel sheet.

select a~matnr

a~werks

a~mbwbest

a~wbwbest

a~mkobest

a~LETZTZUG

a~LETZTVER

a~LETZTABG

a~LETZTBEW

b~MGVBR

b~WGVBR

from s032 as a inner join s031 as b

on amatnr = bmatnr and algort = blgort

and awerks = bwerks into corresponding fields of table itab.

if itab[] is not initial.

select GABGA,WGABGA from s094 into table itab1

for all entries in itab where matnr = itab-matnr

and werks = itab-werks.

endif.

now take a third internal table with the required fields

and now move the corresponding fields from both itab and itab1 to itab2 and append itab2.

now update ztable from itab2.

Read only

sbhutani1
Contributor
0 Likes
993

Hi vaishu,

You can fill the internal table with data in your z program and use gui_upload function for uploading the data from excel to itab.

regarding run it automatically you can schedule this program using sm36 define background job in this transaction you give the zprogram name and date and time to execute it will run it in background

Hope this will help you

Regards

Sumit Bhutani

<b>Ps reward points if helpful</b>

Read only

Former Member
0 Likes
994

Hi Vaishu,

I believe that you seem to be doing correct.

Instead of using the insert in a LOOP. Try using ARRAY INSERT. Which will do insert of all the records in one shot instead of in a loop.

If you only want to insert records then use the INSERT command. If you also want to update if the records already eixts or insert if it does not exists then use MODIFY that will help to achieve both.

Cheers

VJ

Message was edited by: Vijayendra Rao