2006 Feb 16 8:12 AM
HI SDN COMMUNITY..!!
I HAVE TO USE THE WA_SEKPO-FIELDNAME DYNAMICALLY..
-
DATA: BEGIN OF WA_SEKPO,
EBELN TYPE EBELN,
BRTWR TYPE BRTWR,
EFFWR TYPE EFFWR,
MENGE TYPE MENGE,
END OF WA_SEKPO.
DATA: SEKPO LIKE TABLE OF WA_SEKPO.
DATA: VAR_FNAME TYPE STRING.
FIELD-SYMBOLS: <FS> TYPE ANY.
STRUCTURE OF <b>EDITPOS</b>(INTERNAL TABLE)
****************************************
-
|OBJECTID |TABNAME|FNAME | F_NEW | F_OLD
-
|4500016340 |EKPO |BRTWR | 26 | 11
|4500016340 |EKPO |EFFWR | 25 | 12
|4500016340 |EKPO |MENGE | 22 | 13
.
.
.
.
.
.
.
.
-
INTERNAL TABLE :
<b>EDITPOS</b> CONTAINS VALUES FOR : BRTWR
EFFWR
MENGE
IT MAY CONTAIN VALUES FOR MORE FIELDS.
NOW PROBLEM IS
I HAVE TO UPDATE MY INTERNAL TABLE : SEKPO
FOR FIELDNAMES : BRTWR
EFFWR
MENGE
BUT I DONT HAVE TO HARD CODE IT FOR EACH FIELD.
PLEASE CHECK, HOW THIS CAN BE ACHIVED?
WA_SEKPO-BRTWR = WA_EDITPOS-F_NEW.
PLEASE UPDATE THE CODE:
LOOP AT EDITPOS INTO WA_EDITPOS.
ASSIGN WA_EDITPOS-FNAME TO <FS>.
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
WA_SEKPO-(<FS>) = WA_EDITPOS-F_NEW.
* MODIFY TABLE SEKPO FROM WA_SEKPO
* TRANSPORTING <FS>.
ENDLOOP.
HELP WILL BE APPRICIATED
THANKS IN ADVANCE
VIJAY RAHEJA
2006 Feb 16 8:24 AM
LOOP AT EDITPOS INTO WA_EDITPOS.
ASSIGN WA_EDITPOS-FNAME TO <FS>.
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
to be added
assign (VAR_FNAME) to <FS2>
<FS2> = WA_EDITPOS-F_NEW.
end of code to be added
MODIFY TABLE SEKPO FROM WA_SEKPO
TRANSPORTING <FS>.
ENDLOOP.
Create another field symbol <FS2> for this.
2006 Feb 16 8:24 AM
LOOP AT EDITPOS INTO WA_EDITPOS.
ASSIGN WA_EDITPOS-FNAME TO <FS>.
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
to be added
assign (VAR_FNAME) to <FS2>
<FS2> = WA_EDITPOS-F_NEW.
end of code to be added
MODIFY TABLE SEKPO FROM WA_SEKPO
TRANSPORTING <FS>.
ENDLOOP.
Create another field symbol <FS2> for this.
2006 Feb 16 8:38 AM
PLEASE BE CLEAR WHAT IS UR EXCAT REQUIREMNET.
to create table dynamically, there are many posts in form, pls earch.
also to create structure also dynamically there r many posts.
just place the topic and click on search
2006 Feb 16 9:28 AM
HI
STRUCTURE OF EDITPOS(INTERNAL TABLE)
****************************************
-
|OBJECTID |TABNAME|FNAME | F_NEW | F_OLD
-
|4500016340 |EKPO |BRTWR | 26 | 11
|4500016340 |EKPO |EFFWR | 25 | 12
|4500016340 |EKPO |MENGE | 22 | 13
LOOP AT EDITPOS INTO WA_EDITPOS.
IF WA_EDITPOS = 'BRTWR'.
WA_SEKPO-BRTWR = WA_EDITPOS-F_NEW.
MODIFY TABLE SEKPO FROM WA_SEKPO
TRANSPORTING BRTWR.
ELSEIF WA_EDITPOS = 'EFFWR'.
WA_SEKPO-EFFWR = WA_EDITPOS-F_NEW.
MODIFY TABLE SEKPO FROM WA_SEKPO
TRANSPORTING EFFWR.
ELSEIF WA_EDITPOS = 'MENGE'.
WA_SEKPO-EFFWR = WA_EDITPOS-F_NEW.
MODIFY TABLE SEKPO FROM WA_SEKPO
TRANSPORTING MENGE.
ENDIF.
ENDLOOP.
*******************************************
I AM TRYING TO ACHIEVE THE ABOVE FUNCTIONALITY DYNAMICALLY,
AS I AM UNAWARE OF ENTRIES IN Internal Table: EDITPOS.
It contains values: BRTWR/EFFWR/MENGE
But it may contain more,SO i cannot straight away HARD code it for modifying entries in SEKPO.
for which i have written the code:
-
LOOP AT EDITPOS INTO WA_EDITPOS.
ASSIGN WA_EDITPOS-FNAME TO <FS>.
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
WA_SEKPO-<FS> = WA_EDITPOS-F_NEW.
MODIFY TABLE SEKPO FROM WA_SEKPO
TRANSPORTING <FS>.
ENDLOOP.
-
But there it shown Error before Activating the code: that <fs> is not a component of work area wa_sekpo
WA_SEKPO-<FS>
that is the problem,How to assign fieldname to a work area Dynamically.
Regards,
Vijay Raheja
2006 Feb 16 9:33 AM
replace the folloeing
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
WA_SEKPO-<FS> = WA_EDITPOS-F_NEW.
with
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
VAR_FNAME = WA_EDITPOS-F_NEW.
2006 Feb 16 10:09 AM
Hello Vijay and Anand,
Assigning the variable name (a string!) to the field symbol is not the right thing to do, and will result in a short dump. You would have to assign the variable itself to the field symbol. I cannot see a way to do this dynamically. However here is a simple solution for your program, using a form:
LOOP AT editpos INTO wa_editpos.
CONCATENATE 'wa_sekpo' wa_editpos-fname INTO var_fname.
PERFORM assign_fs.
<fs> = wa_editpos-f_new.
...
ENDLOOP.
FORM assign_fs.
CASE var_fname.
WHEN 'EBELN'. ASSIGN wa_sekpo-ebeln TO <fs>.
WHEN 'BRTWR'. ASSIGN wa_sekpo-brtwr TO <fs>.
WHEN 'EFFWR'. ASSIGN wa_sekpo-effwr TO <fs>.
WHEN 'MENGE'. ASSIGN wa_sekpo-menge TO <fs>.
WHEN OTHERS. WRITE 'Illegal fieldname'.
ENDCASE.
ENDFORM.
Kind regards,
Michael
2006 Feb 16 10:27 AM
HI Michael Kraemer
Thanks for replying...But Problem is still there.
USING YOUR CODE.
WHEN 'EBELN'.
ASSIGN wa_sekpo-ebeln TO <fs>.
<FS> WILL CONTAIN wa_sekpo-ebeln
and then
<fs> = wa_editpos-f_new.
<fs> will contain the value for EBELN in EDITPOS-F_NEW
BUT I NEED THE VALUE IN
<b>WA_SEKPO-EBELN = wa_editpos-f_new.</b>
***************************
problem is still there...
MODIFY TABLE SEKPO FROM <b>WA_SEKPO-EBELN</b>
TRANSPORTING EBELN.
Regards,
Vijay Raheja
2006 Feb 16 11:16 AM
Hello Vijay,
You wrote:
"<fs> will contain the value for EBELN in EDITPOS-F_NEW
BUT I NEED THE VALUE IN
WA_SEKPO-EBELN = wa_editpos-f_new."
But the value is there in wa_sekpo-ebeln already!! By assigning the value to the field symbol you are assigning it to the variable to which it points. The reason is that a field symbol is a placeholder for a variable, similar to a pointer.
Please pay attention to this difference:
1. ASSIGN wa_sekpo-ebeln TO <fs>.
This lets the field symbol <fs> be a placeholder for the variable wa_sekpo-ebeln. From now on everything that you do to <fs> happens to wa_sekpo-ebeln.
2. <fs> = wa_editpos-f_new.
This assigns the value in wa_editpos-f_new to the variable wa_sekpo-ebeln, because <fs> at present points to this variable.
Here is a simple example:
DATA city(10) TYPE c.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN city TO <fs>.
<fs> = 'HYDERABAD'.
WRITE city.
The output of this program is: HYDERABAD
Kind regards,
Michael
2006 Feb 16 1:14 PM
Thanks Folks.!!
Anand's reply is perfect.
LOOP AT EDITPOS INTO WA_EDITPOS.
ASSIGN WA_EDITPOS-FNAME TO <FS>.
CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
<b> ASSIGN (VAR_FNAME) TO <VALUE>.
<VALUE> = WA_EDITPOS-F_NEW .</b>
ENDLOOP.
ASSIGN (VAR_FNAME)TO <FS>
THIS PERFORMS THE SAME TASK AS :
ASSIGN WA_SEKPO-BRTWR TO <FS>
Regards,
Vijay Raheja