2007 Feb 15 1:23 PM
please explain dynamic memory allocation with respect to "SPECIFYING THE SOURCE FIELD DYNAMICALLY" using WRITE TO in simple terms
2007 Feb 15 2:13 PM
Hi ,
Follwing Function module is an example for creating a table dynamically. Use this and try to create a filed dynamically. Based on a field i am retrieving the data and filling the created table.
unction yrel_copy_data_req.
*"----
""Local interface:
*" IMPORTING
*" VALUE(REQ_NO) TYPE YREL_REQNO
*" VALUE(DEST) TYPE ADRTP
*" EXPORTING
*" VALUE(RET_CODE) TYPE CHAR1
*" EXCEPTIONS
*" INVALID_REQ_NO
*" INVALID_TABLE_NAME
*" FIELD_NOT_FOUND_IN_TABLE
*"----
************************************************************************
Function Module Name : YREL_COPY_DATA_REQ *
Start Date : *
Developer : *
CR# : *
Description : To create a table dynacally and fill the data *
************************************************************************
Modification Log *
----
ChangeReq Date DevID * Description *
----
*-- Tables
tables : dd03l,
*-Adding table in place of Tab_name parameter.
yrel_tables. " YREL Table
*--Field symbols
field-symbols: <f_fs> type table.
*--Global variables
data: g_repid like sy-repid,
g_tabname like dcobjdef-name,
g_ucomm like sy-ucomm,
g_destin(10) type c,
g_alvtab type slis_tabname,
g_batch(10) type c,
g_ret_code type char1.
*-- Internal tables
data: d_ref type ref to data,
d_ref2 type ref to data,
d_ref1 type ref to data,
new_table type ref to data,
new_line type ref to data,
tb_alv_cat type table of lvc_s_fcat,
tb_alv_cat1 type table of lvc_s_fcat,
ls_alv_cat like line of tb_alv_cat.
data: tb_data like zuptab occurs 0 with header line.
data: begin of tb_dd03l occurs 0,
tabname type tabname,
fieldname type fieldname,
end of tb_dd03l.
data: begin of tb_header occurs 0.
include structure dntab.
data: end of tb_header.
data: begin of tb_request occurs 0,
whereclause(72),
end of tb_request.
*-Table to hold YREL_TABLE data.
data: begin of i_yrel_tables occurs 0,
tabname like yrel_tables-tabname,
end of i_yrel_tables.
*- Fetching Table contents .
select tabname into table i_yrel_tables
from yrel_tables.
Check for the table name
loop at i_yrel_tables.
select tabname fieldname into table tb_dd03l
from dd03l
where tabname = i_yrel_tables-tabname.
if sy-subrc <> 0.
raise invalid_table_name.
endif.
Check for the reqno field
read table tb_dd03l with key fieldname = 'REQNO'.
if sy-subrc <> 0.
raise field_not_found_in_table.
endif.
Get the table name
g_tabname = i_yrel_tables-tabname.
Get the fields of the table
refresh tb_header.
call function 'NAMETAB_GET'
exporting
langu = sy-langu
tabname = g_tabname
tables
nametab = tb_header
exceptions
no_texts_found = 1.
loop at tb_header .
ls_alv_cat-fieldname = tb_header-fieldname.
ls_alv_cat-ref_table = i_yrel_tables-tabname.
ls_alv_cat-ref_field = tb_header-fieldname.
append ls_alv_cat to tb_alv_cat.
endloop.
Build the internal table
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = tb_alv_cat
importing ep_table = d_ref .
assign d_ref->* to <f_fs>.
concatenate 'REQNO' 'EQ' req_no into tb_request-whereclause
separated by space.
append tb_request.
select * from (i_yrel_tables-tabname)
into corresponding fields of table <f_fs>
where (tb_request).
Get the destination
case dest.
when 'D48'.
g_destin = c_dest_d48.
when 'M08'.
g_destin = c_dest_m08.
when 'P08'.
g_destin = c_dest_p08.
when 'T48'.
g_destin = c_dest_t48.
endcase.
Assign the data to the internal table
tb_data[] = <f_fs>.
Update the data in the given destination
call function 'YREL_COPY_DATA_REQ_DEST' destination g_destin
exporting
tabname = i_yrel_tables-tabname
importing
ret_code = g_ret_code
tables
data = <f_fs>.
Pass the return code
if g_ret_code = 0.
ret_code = 'S'.
else.
ret_code = 'F'.
endif.
*-Depending upon RET_CODE we need to raise an event.
endloop.
endfunction.
Regards,
Jayaram...
please explain dynamic memory allocation with respect to "SPECIFYING THE SOURCE FIELD DYNAMICALLY" using WRITE TO in simple terms
2007 Feb 15 2:13 PM
Hi ,
Follwing Function module is an example for creating a table dynamically. Use this and try to create a filed dynamically. Based on a field i am retrieving the data and filling the created table.
unction yrel_copy_data_req.
*"----
""Local interface:
*" IMPORTING
*" VALUE(REQ_NO) TYPE YREL_REQNO
*" VALUE(DEST) TYPE ADRTP
*" EXPORTING
*" VALUE(RET_CODE) TYPE CHAR1
*" EXCEPTIONS
*" INVALID_REQ_NO
*" INVALID_TABLE_NAME
*" FIELD_NOT_FOUND_IN_TABLE
*"----
************************************************************************
Function Module Name : YREL_COPY_DATA_REQ *
Start Date : *
Developer : *
CR# : *
Description : To create a table dynacally and fill the data *
************************************************************************
Modification Log *
----
ChangeReq Date DevID * Description *
----
*-- Tables
tables : dd03l,
*-Adding table in place of Tab_name parameter.
yrel_tables. " YREL Table
*--Field symbols
field-symbols: <f_fs> type table.
*--Global variables
data: g_repid like sy-repid,
g_tabname like dcobjdef-name,
g_ucomm like sy-ucomm,
g_destin(10) type c,
g_alvtab type slis_tabname,
g_batch(10) type c,
g_ret_code type char1.
*-- Internal tables
data: d_ref type ref to data,
d_ref2 type ref to data,
d_ref1 type ref to data,
new_table type ref to data,
new_line type ref to data,
tb_alv_cat type table of lvc_s_fcat,
tb_alv_cat1 type table of lvc_s_fcat,
ls_alv_cat like line of tb_alv_cat.
data: tb_data like zuptab occurs 0 with header line.
data: begin of tb_dd03l occurs 0,
tabname type tabname,
fieldname type fieldname,
end of tb_dd03l.
data: begin of tb_header occurs 0.
include structure dntab.
data: end of tb_header.
data: begin of tb_request occurs 0,
whereclause(72),
end of tb_request.
*-Table to hold YREL_TABLE data.
data: begin of i_yrel_tables occurs 0,
tabname like yrel_tables-tabname,
end of i_yrel_tables.
*- Fetching Table contents .
select tabname into table i_yrel_tables
from yrel_tables.
Check for the table name
loop at i_yrel_tables.
select tabname fieldname into table tb_dd03l
from dd03l
where tabname = i_yrel_tables-tabname.
if sy-subrc <> 0.
raise invalid_table_name.
endif.
Check for the reqno field
read table tb_dd03l with key fieldname = 'REQNO'.
if sy-subrc <> 0.
raise field_not_found_in_table.
endif.
Get the table name
g_tabname = i_yrel_tables-tabname.
Get the fields of the table
refresh tb_header.
call function 'NAMETAB_GET'
exporting
langu = sy-langu
tabname = g_tabname
tables
nametab = tb_header
exceptions
no_texts_found = 1.
loop at tb_header .
ls_alv_cat-fieldname = tb_header-fieldname.
ls_alv_cat-ref_table = i_yrel_tables-tabname.
ls_alv_cat-ref_field = tb_header-fieldname.
append ls_alv_cat to tb_alv_cat.
endloop.
Build the internal table
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = tb_alv_cat
importing ep_table = d_ref .
assign d_ref->* to <f_fs>.
concatenate 'REQNO' 'EQ' req_no into tb_request-whereclause
separated by space.
append tb_request.
select * from (i_yrel_tables-tabname)
into corresponding fields of table <f_fs>
where (tb_request).
Get the destination
case dest.
when 'D48'.
g_destin = c_dest_d48.
when 'M08'.
g_destin = c_dest_m08.
when 'P08'.
g_destin = c_dest_p08.
when 'T48'.
g_destin = c_dest_t48.
endcase.
Assign the data to the internal table
tb_data[] = <f_fs>.
Update the data in the given destination
call function 'YREL_COPY_DATA_REQ_DEST' destination g_destin
exporting
tabname = i_yrel_tables-tabname
importing
ret_code = g_ret_code
tables
data = <f_fs>.
Pass the return code
if g_ret_code = 0.
ret_code = 'S'.
else.
ret_code = 'F'.
endif.
*-Depending upon RET_CODE we need to raise an event.
endloop.
endfunction.
Regards,
Jayaram...
2007 Feb 15 3:29 PM
could you pls amplify:-
"Use this and try to create a filed dynamically. Based on a field i am retrieving the data and filling the created "
regards
Sujoy
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |