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

Dynamic internal table problem

Former Member
0 Likes
507

&----


*& Form build_dynamic_itab

&----


  • build dynamic internal table

----


form build_dynamic_itab.

data : lv_fname(30),

lv_coltext(40),

lv_index type i,

lv_date like sy-datum,

lv_perid like pc260-fpper,

lv_son(1).

define bfcat.

gs_fcat-fieldname = &1.

gs_fcat-ref_table = &2.

gs_fcat-col_pos = &3.

gs_fcat-coltext = &4.

gs_fcat-emphasize = &5.

append gs_fcat to gt_fcat.

end-of-definition.

move p_perid-low to lv_date.

bfcat 'LIFNR' 'LFA1' 0 'Satıcı Kodu' '' .

bfcat 'NAME1' 'LFA1' 1 'Satıcı Adı' '' .

lv_index = 2.

clear lv_son.

do.

concatenate 'PY' lv_date(6) into lv_fname.

bfcat lv_fname '' lv_index 'Son Bir Yıl' ''.

lv_index = lv_index + 1.

perform find_month_name using lv_date+4(2) changing lv_coltext.

concatenate 'PA' lv_date(6) into lv_fname.

bfcat lv_fname '' lv_index lv_coltext ''.

lv_index = lv_index + 1.

if lv_son eq 'X'.

exit.

endif.

move lv_date(6) to lv_perid.

call function 'HR_CALC_MONTH'

exporting

delta = 1

changing

periode = lv_perid.

move lv_perid to lv_date(6).

if lv_date(6) eq p_perid-high(6).

lv_son = 'X'.

endif.

enddo.

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = gt_fcat

importing

ep_table = gv_data .

assign gv_data->* to <itab> .

endform. " build_dynamic_itab

&----


*& Form get_data

&----


  • get data

----


form get_data.

field-symbols : <field>, <line>.

data : gv_line type ref to data ,

lv_fname type string.

create data gv_line like line of <itab>.

assign gv_line->* to <line>.

select * into corresponding fields of table gt_sat from zppsat.

loop at gt_sat.

select single name1 into gt_sat-name1 from lfa1 where

lifnr = gt_sat-lifnr.

modify gt_sat.

clear <line>.

lv_fname = '<line>-LIFNR'.

assign (lv_fname) to <field>.

<b> <field> = gt_sat-lifnr.</b>

lv_fname = '<line>-NAME1'.

assign (lv_fname) to <field>.

<field> = gt_sat-name1.

append <line> to <itab>.

endloop.

endform. " get_data

<b>this code gives runtime error here

<field> = gt_sat-lifnr

like this</b>

The program tried to assign a new value to a field even though

it is protected against changes.

The following objects are protected:

- Character or numeric literals,

- Constants (CONSTANTS),

- Function module and method parameters with the type IMPORTING

REFERENCE,

- Untyped field symbols to which a field has not yet been assigned

using ASSIGN,

- TABLES parameters, if the corresponding actual parameter is protected

against changes,

- USING reference parameters and CHANGING parameters in FORMS, if the

actual parameter is protected against changes,

- Field symbols, if the field assigned using ASSIGN is protected against

changes,

- External write access to attributes with the READ-ONLY property.

WHY???

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
472

lv_fname = '<line>-LIFNR'.

assign (lv_fname) to <field>.

<field> = gt_sat-lifnr.

Instead of above coding, try this

assign component 'LIFNR' of <LINE> to <field>.

IF sy-subrc = 0.

<field> = gt_sat-lifnr.

endif.

Do the same thing for others as well.

Regards,

Ravi

Note - Please mark all the helpful answers

3 REPLIES 3
Read only

Former Member
0 Likes
473

lv_fname = '<line>-LIFNR'.

assign (lv_fname) to <field>.

<field> = gt_sat-lifnr.

Instead of above coding, try this

assign component 'LIFNR' of <LINE> to <field>.

IF sy-subrc = 0.

<field> = gt_sat-lifnr.

endif.

Do the same thing for others as well.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
472

thanks Ravikumar

your solution solved my problem

i reward points

Read only

Former Member
0 Likes
472

Hi,

use below logic and change your code accordingly

DATA V_FORM TYPE P.

DATA: SYNTAX_CHECK_MSG(240),

SYNTAX_CHECK_LINE TYPE I,

SYNTAX_CHECK_WORD(72).

DATA SOURCE_TAB(72) OCCURS 0 WITH HEADER LINE.

DATA V_SPACE TYPE C VALUE ''''.

APPEND 'Program zformula.' TO SOURCE_TAB..

APPEND 'form calculate_formula changing form_value.' TO SOURCE_TAB.

APPEND 'compute form_value = ' TO SOURCE_TAB.

CONCATENATE V_SPACE '67.341667' V_SPACE INTO SOURCE_TAB.

APPEND SOURCE_TAB.

SOURCE_TAB = '+'.

APPEND SOURCE_TAB.

CONCATENATE V_SPACE '1.240000 ' V_SPACE INTO SOURCE_TAB.

APPEND SOURCE_TAB.

APPEND '.' TO SOURCE_TAB.

CONCATENATE 'write' '/' 'form_value' INTO SOURCE_TAB SEPARATED

BY SPACE.

APPEND SOURCE_TAB.

APPEND '.' TO SOURCE_TAB.

APPEND 'ENDFORM.' TO SOURCE_TAB.

SYNTAX-CHECK FOR SOURCE_TAB MESSAGE SYNTAX_CHECK_MSG

LINE SYNTAX_CHECK_LINE

WORD SYNTAX_CHECK_WORD.

DATA Z_SEQ_NO(4) TYPE N.

DO 20001 TIMES.

DATA Z_REPID LIKE SY-REPID.

Z_REPID = 'ZTEST_DEM'.

INSERT REPORT Z_REPID FROM SOURCE_TAB.

GENERATE REPORT Z_REPID.

IF SY-SUBRC NE 0.

DO 1000 TIMES.

GENERATE REPORT Z_REPID.

IF SY-SUBRC = 0.

EXIT.

ENDIF.

ENDDO.

ENDIF.

PERFORM CALCULATE_FORMULA IN PROGRAM (Z_REPID)

CHANGING V_FORM.

DELETE REPORT Z_REPID.

reward if usefull..