2009 Feb 02 4:18 PM
Hi,
I like to read dynamically from a table via field symbols. The reading part is working.
But now I like to do some changes on the entry and then write it to another table with a similar structure.
I use SAP 4.6c
There I have two problems:
1. At the statement I get a dump:
<l_sysid> = sy-sysid.--> Field symbol has not yet been assigned.
I think that the problem is somewhere around
assign <table_to> to <wa_to>.2. the data change inside the loop. There I like to add the sysid to the target-wa and then copy the source-wa it to the new target-wa to append it to the target table.
But this does not work. What kind of code do I need? The "move-correspondig" is not correct.
--> see code around
loop at <table_from> assigning <wa_from>.Below you can find my code. The problem is within the last loop-statement.
FUNCTION Z_MIG_COPY_TABLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(I_TABNAME_FROM) TYPE TABNAME
*" REFERENCE(I_TABNAME_TO) TYPE TABNAME
*" REFERENCE(I_KOMP_TRANS) LIKE ZS_KOMP_TRANS STRUCTURE
*" ZS_KOMP_TRANS OPTIONAL
*" TABLES
*" I_SELCON STRUCTURE ZS_SELCON
*" EXCEPTIONS
*" NOT_FOUND
*" OTHERS
*"----------------------------------------------------------------------
*
* zeilenweiser Aufbau Tabelle I_SELCON z.B.:
* bukrs = 3011
* AND
* bstyp = 'F'
*
* I_KOMP_TRANS
* dient zur Uebersetzung von alt/neu, z.B. bei LIFNR
* der angegebene Funktionsbaustein wird genutzt,
* um den neuen Wert der übergebenen Komponente zu ermitteln
* Angabe z.B.:
* LIFNR
DATA: dref TYPE REF TO data,
dref_to TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat,
i_alv_cat_to TYPE TABLE OF lvc_s_fcat,
ls_alv_cat_to LIKE LINE OF i_alv_cat.
DATA: BEGIN OF itab OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab.
DATA: BEGIN OF itab_to OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab_to.
FIELD-SYMBOLS: <table_from> TYPE ANY TABLE.
FIELD-SYMBOLS: <table_to> TYPE Standard TABLE.
FIELD-SYMBOLS: <wa_from> TYPE ANY.
FIELD-SYMBOLS: <wa_to> TYPE ANY.
FIELD-SYMBOLS: <l_komp> TYPE ANY.
FIELD-SYMBOLS: <l_sysid> TYPE ANY.
Data: l_alt type ELIFN.
Data: l_neu type ELIFN.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_from
TABLES
DFIES_TAB = itab
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = i_tabname_from.
ls_alv_cat-ref_field = itab-fieldname.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = dref.
ASSIGN dref->* TO <table_from>.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_to
TABLES
DFIES_TAB = itab_to
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab_to.
ls_alv_cat_to-fieldname = itab_to-fieldname.
ls_alv_cat_to-ref_table = i_tabname_to.
ls_alv_cat_to-ref_field = itab_to-fieldname.
APPEND ls_alv_cat_to TO i_alv_cat_to.
ENDLOOP.
* break-point.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat_to
IMPORTING
ep_table = dref_to.
ASSIGN dref_to->* TO <table_to>.
*Select Ursprungstabelle mit Selektionsbedingungen
SELECT * FROM (i_tabname_from) up to 5 rows
INTO CORRESPONDING FIELDS OF TABLE <table_from>
where (i_selcon).
* break-point.
*Aufbau interne Tabelle mit eventuell geänderten Feldern
assign <table_to> to <wa_to>.
if not I_KOMP_TRANS is initial.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
* move-corresponding <wa_from> to <wa_to>.
append <wa_to> to <table_to>.
endloop.
* break-point.
*Speichern der ausgelesenen Daten in Zieltabelle
MODIFY (i_tabname_to) FROM TABLE <table_to>.
if sy-subrc <> 0.
MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Modify von Tabelle '&'.
endif.
else.
*Speichern der ausgelesenen Daten in Zieltabelle
MODIFY (i_tabname_to) FROM TABLE <table_from>.
if sy-subrc <> 0.
MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Modify von Tabelle '&'.
endif.
endif.
commit work.
if sy-subrc <> 0.
MESSAGE E002(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Commit von Tabelle '&'.
endif.
* break-point.
ENDFUNCTION.
Thanks a lot for any hints.
Regards
Tom
2009 Feb 02 4:52 PM
Hi,
Answers below.
1) For this...you assigning an internal table to a work area...
assign <table_to> to <wa_to>.
This should solve the problem..
* Create the target work area..
DATA: new_line TYPE REF TO data.
CREATE DATA new_line LIKE LINE OF <table_to>.
ASSIGN new_line->* TO <wa_to>.
Now the target work area is created..
2) For the second one...
************New code
FIELD-SYMBOLS: <FS>,<FS1>.
************New code End.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
************New code
LOOP AT itab .
ASSIGN COMPONENT itab-fieldname of structure <WA_FROM> TO <FS>.
CHECK SY-SUBRC = 0.
ASSIGN COMPONENT itab-fieldname of structure <WA_TO> TO <FS1>.
CHECK SY-SUBRC = 0.
* Move from source to target.
<FS1> = <FS>.
ENDLOOP.
************New code End
append <wa_to> to <table_to>.
endloop.Thanks
Naren
Hi,
I like to read dynamically from a table via field symbols. The reading part is working.
But now I like to do some changes on the entry and then write it to another table with a similar structure.
I use SAP 4.6c
There I have two problems:
1. At the statement I get a dump:
<l_sysid> = sy-sysid.--> Field symbol has not yet been assigned.
I think that the problem is somewhere around
assign <table_to> to <wa_to>.2. the data change inside the loop. There I like to add the sysid to the target-wa and then copy the source-wa it to the new target-wa to append it to the target table.
But this does not work. What kind of code do I need? The "move-correspondig" is not correct.
--> see code around
loop at <table_from> assigning <wa_from>.Below you can find my code. The problem is within the last loop-statement.
FUNCTION Z_MIG_COPY_TABLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(I_TABNAME_FROM) TYPE TABNAME
*" REFERENCE(I_TABNAME_TO) TYPE TABNAME
*" REFERENCE(I_KOMP_TRANS) LIKE ZS_KOMP_TRANS STRUCTURE
*" ZS_KOMP_TRANS OPTIONAL
*" TABLES
*" I_SELCON STRUCTURE ZS_SELCON
*" EXCEPTIONS
*" NOT_FOUND
*" OTHERS
*"----------------------------------------------------------------------
*
* zeilenweiser Aufbau Tabelle I_SELCON z.B.:
* bukrs = 3011
* AND
* bstyp = 'F'
*
* I_KOMP_TRANS
* dient zur Uebersetzung von alt/neu, z.B. bei LIFNR
* der angegebene Funktionsbaustein wird genutzt,
* um den neuen Wert der übergebenen Komponente zu ermitteln
* Angabe z.B.:
* LIFNR
DATA: dref TYPE REF TO data,
dref_to TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat,
i_alv_cat_to TYPE TABLE OF lvc_s_fcat,
ls_alv_cat_to LIKE LINE OF i_alv_cat.
DATA: BEGIN OF itab OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab.
DATA: BEGIN OF itab_to OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab_to.
FIELD-SYMBOLS: <table_from> TYPE ANY TABLE.
FIELD-SYMBOLS: <table_to> TYPE Standard TABLE.
FIELD-SYMBOLS: <wa_from> TYPE ANY.
FIELD-SYMBOLS: <wa_to> TYPE ANY.
FIELD-SYMBOLS: <l_komp> TYPE ANY.
FIELD-SYMBOLS: <l_sysid> TYPE ANY.
Data: l_alt type ELIFN.
Data: l_neu type ELIFN.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_from
TABLES
DFIES_TAB = itab
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = i_tabname_from.
ls_alv_cat-ref_field = itab-fieldname.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = dref.
ASSIGN dref->* TO <table_from>.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_to
TABLES
DFIES_TAB = itab_to
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab_to.
ls_alv_cat_to-fieldname = itab_to-fieldname.
ls_alv_cat_to-ref_table = i_tabname_to.
ls_alv_cat_to-ref_field = itab_to-fieldname.
APPEND ls_alv_cat_to TO i_alv_cat_to.
ENDLOOP.
* break-point.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat_to
IMPORTING
ep_table = dref_to.
ASSIGN dref_to->* TO <table_to>.
*Select Ursprungstabelle mit Selektionsbedingungen
SELECT * FROM (i_tabname_from) up to 5 rows
INTO CORRESPONDING FIELDS OF TABLE <table_from>
where (i_selcon).
* break-point.
*Aufbau interne Tabelle mit eventuell geänderten Feldern
assign <table_to> to <wa_to>.
if not I_KOMP_TRANS is initial.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
* move-corresponding <wa_from> to <wa_to>.
append <wa_to> to <table_to>.
endloop.
* break-point.
*Speichern der ausgelesenen Daten in Zieltabelle
MODIFY (i_tabname_to) FROM TABLE <table_to>.
if sy-subrc <> 0.
MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Modify von Tabelle '&'.
endif.
else.
*Speichern der ausgelesenen Daten in Zieltabelle
MODIFY (i_tabname_to) FROM TABLE <table_from>.
if sy-subrc <> 0.
MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Modify von Tabelle '&'.
endif.
endif.
commit work.
if sy-subrc <> 0.
MESSAGE E002(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Commit von Tabelle '&'.
endif.
* break-point.
ENDFUNCTION.
Thanks a lot for any hints.
Regards
Tom
2009 Feb 02 4:52 PM
Hi,
Answers below.
1) For this...you assigning an internal table to a work area...
assign <table_to> to <wa_to>.
This should solve the problem..
* Create the target work area..
DATA: new_line TYPE REF TO data.
CREATE DATA new_line LIKE LINE OF <table_to>.
ASSIGN new_line->* TO <wa_to>.
Now the target work area is created..
2) For the second one...
************New code
FIELD-SYMBOLS: <FS>,<FS1>.
************New code End.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
************New code
LOOP AT itab .
ASSIGN COMPONENT itab-fieldname of structure <WA_FROM> TO <FS>.
CHECK SY-SUBRC = 0.
ASSIGN COMPONENT itab-fieldname of structure <WA_TO> TO <FS1>.
CHECK SY-SUBRC = 0.
* Move from source to target.
<FS1> = <FS>.
ENDLOOP.
************New code End
append <wa_to> to <table_to>.
endloop.Thanks
Naren
2009 Feb 02 5:45 PM
Hi Naren
thanks a lot for your help. It working correct now.
Thanks and regards
Tom
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |