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

help for "insert data to variable tables"

Former Member
0 Likes
841

hi, guys.

I want to make a tool to upload mass-data then insert the data to tables of SAP for integrative test.

for example, to input the object tablename "AAAA" from screen, the program willl find the information of this table then input the data to the "AAAA" tables.

But i have no idea how to define the internal table to suit various tables ( by define dynamic table? or any other ways) ,could you kindly give me some advice?

thanks a lot in advance.

Message was edited by:

huijuan zhao

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
786

Hi,

Check this link for a sample code to create dynamic internal table for the given table name in the selection screen..

Thanks

Naren

Hi,

Check this link for a sample code to create dynamic internal table for the given table name in the selection screen..

Thanks

Naren

4 REPLIES 4
Read only

Former Member
0 Likes
786

hi zhao,

welcome to sdn,

for your requirement u can use bdc to upload file to internal table then u can update these internal table fileds to sap tables.

or

use <b>gui_upload</b> function module to upload data to internal table then u can use just <b>insert</b> keyword to update sap tables.

see this sample code to update the database table <b>edpar</b>,

report zsd_edpar_update no standard page heading.

&----


*&Purpose:

*& program will be used to update EDAPR table on a daily basis.

*& This update will be based on Customer Sold To / Ship To partner

*& functions assignment. Ship To customer(s) will be linked to

*& the appropriate Sold To customer using the ?Acct at Cust?

*& number as a reference. Then, Ship To customer(s) will be

*& set up withthe appropriate partner function with the Sold

*& To customer.it updated the DB tabel and gives the information

*& of customer level visibility t account receivable.

&----


*define database tables...

tables: edpar,

knvv,

knvp.

*define types...

types: begin of t_tab_edpar,

mandt type mandt,

kunnr type kunnr,

parvw type parvw,

expnr type edi_expnr,

inpnr type edi_inpnr.

types: end of t_tab_edpar.

types: begin of t_tab_knvv,

kunnr type kunnr,

vkorg type vkorg,

vtweg type vtweg,

spart type spart,

eikto type eikto.

types: end of t_tab_knvv.

types: begin of t_tab_knvp,

kunnr type kunnr,

vkorg type vkorg,

vtweg type vtweg,

spart type spart,

parvw type parvw,

kunn2 type kunn2.

types: end of t_tab_knvp.

type-pools: slis.

*define data statments...

data: g_tab_edpar type standard table of t_tab_edpar,

g_wa_edpar like line of g_tab_edpar.

data: g_tab_edpar1 type standard table of t_tab_edpar,

g_wa_edpar1 like line of g_tab_edpar1.

data: g_tab_edpar2 type standard table of t_tab_edpar,

g_wa_edpar2 like line of g_tab_edpar2.

data: g_tab_knvv type standard table of t_tab_knvv,

g_wa_knvv like line of g_tab_knvv.

data: g_tab_knvp type standard table of t_tab_knvp,

g_wa_knvp like line of g_tab_knvp.

data: repid like sy-repid,

l_tab_fieldcat type slis_t_fieldcat_alv,

l_tab_fieldcat1 type slis_t_fieldcat_alv,

l_tab_fieldcat2 type slis_t_fieldcat_alv,

layout type slis_layout_alv,

events type slis_t_event,

events1 type slis_t_event,

wa_events like line of events,

l_pos type i.

*selection screen...

selection-screen begin of block b1 with frame title text-001.

select-options: s_cust for knvv-kunnr obligatory,

s_sorg for knvv-vkorg,

s_dcha for knvv-vtweg,

s_divi for knvv-spart,

s_parf for knvp-parvw.

selection-screen end of block b1.

*start-of-selection...

perform get_data.

*to update the db table edpar...

perform update_edpar.

*display alv block...

perform alv_block.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_data .

select kunnr

vkorg

vtweg

spart

parvw

kunn2

from knvp

into table g_tab_knvp

where

kunnr in s_cust

and

vkorg in s_sorg

and

vtweg in s_dcha

and

spart in s_divi

and

parvw in s_parf.

loop at g_tab_knvp into g_wa_knvp.

move: g_wa_knvp-kunnr to g_wa_edpar-kunnr,

g_wa_knvp-kunn2 to g_wa_edpar-inpnr,

g_wa_knvp-parvw to g_wa_edpar-parvw.

append g_wa_edpar to g_tab_edpar.

endloop.

if not g_tab_knvp[] is initial.

select kunnr

vkorg

vtweg

spart

eikto

from knvv

into table g_tab_knvv

for all entries in g_tab_knvp

where

kunnr eq g_tab_knvp-kunnr

and

vkorg eq g_tab_knvp-vkorg

and

vtweg eq g_tab_knvp-vtweg

and

spart eq g_tab_knvp-spart.

loop at g_tab_knvp into g_wa_knvp .

sort g_tab_knvv by kunnr.

clear g_wa_knvv-eikto.

read table g_tab_knvv into g_wa_knvv with key kunnr = g_wa_knvp-kunnr.

if sy-subrc eq 0.

move: g_wa_knvv-eikto to g_wa_edpar-expnr.

modify g_tab_edpar from g_wa_edpar transporting expnr where kunnr eq g_wa_knvp-kunnr.

endif.

endloop.

endif.

sort g_tab_edpar by kunnr.

delete adjacent duplicates from g_tab_edpar comparing kunnr parvw.

endform. " get_data

&----


*& Form update_edpar

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form update_edpar .

delete from edpar." FROM TABLE g_tab_delete.

call function 'DB_COMMIT'.

loop at g_tab_edpar into g_wa_edpar.

insert into edpar values g_wa_edpar.

if sy-subrc eq 0.

move-corresponding g_wa_edpar to g_wa_edpar1.

append g_wa_edpar1 to g_tab_edpar1.

else.

move-corresponding g_wa_edpar to g_wa_edpar2.

append g_wa_edpar2 to g_tab_edpar2.

endif.

endloop.

reward points if helpful,

regards,

seshu.

Read only

0 Likes
786

dear sesu.

Thanks a lot for yr kind reply!!!!

Sorry, I re-edit my post.....if you have idea,plese kindly notice me..

Read only

Former Member
0 Likes
787

Hi,

Check this link for a sample code to create dynamic internal table for the given table name in the selection screen..

Thanks

Naren

Read only

0 Likes
786

Thanks a lot very much!!!!!

U all r so KIND o