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

Itab creation on runtime

Former Member
0 Likes
1,498

Hi friends,

Have run into to trouble trying to create a dynamic structure as follows

"Material Land Nov.09 Dez.09 Jan.10 Feb.10 Mar.10 TotalCount"

The dates are created dynamically with regard to the time period entered in the select options.

The first 2 fields("Material","Land" and the last field "TotalCount") will always be there.The date fields have to change according to the dates entered.

Runtime error - "Load_PROGRAM_NOT_FOUND"

Exception - CX_SY_PROGRAM_NOT_FOUND

on calling

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog = ifc
  IMPORTING
    ep_table        = dy_table.

Have filled by field catalog as follows:

xfc-fieldname = 'Material'.
xfc-datatype = 'CHAR'.
xfc-intlen = '15'.
APPEND xfc TO ifc.
CLEAR xfc.

xfc-fieldname = 'Opco'.
xfc-datatype = 'CHAR'.
xfc-intlen = '15'.
APPEND xfc TO ifc.
CLEAR xfc.

LOOP AT gt_monthcalc INTO gs_monthcalc.

  xfc-fieldname = gs_monthcalc-month.
  xfc-datatype = 'CHAR'.
  xfc-intlen = '10'.
  APPEND xfc TO ifc.
  CLEAR xfc.
ENDLOOP.

xfc-fieldname = 'Totalcount'.
xfc-datatype = 'CHAR'.
xfc-intlen = '15'.
APPEND xfc TO ifc.
CLEAR xfc.

Please advice what iam doing wrong.

->If the dynamic itab is created ,how to fill it with values.

For example.- I want to access specifically the field names like itab-dez.09 or itab-Feb.10 to put values in it.Is it possible?

->If I write this itab using "Write" statement - Will the field names be written

For example - the following field names.

"Material Land Nov.09 Dez.09 Jan.10 Feb.10 Mar.10 TotalCount"

Thanks

P

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,463

Hi

The field name should be Upper Case, try to indicate:

- the internal type: xfc-inttype = 'C

- the table name: xfc-tabname = 'ITAB'

U need to use the field-symbol in order' to fill it:

LOOP AT XFC.
   ASSIGN COMPONENT XFC-FIELDNAME OF STRCUTURE <WA> TO <VALUE>.
   
   CASE XFC-FIELDNAME.
     WHEN '........'.  <VALUE> = ...... 
     WHEN '........'.  <VALUE> = ...... 
     WHEN '........'.  <VALUE> = ...... 

<WA> has to be a field-symbol structured like your dynamic table:

ASSIGN dy_table->* to <itab>.

CREATE DATA DY_WA LIKE LINE OF <ITAB>.

ASSIGN DY_WA->* TO <WA>.

All caharacteristics of your table are in XFC, u can use it to write the header line.

Max

13 REPLIES 13
Read only

Former Member
0 Likes
1,464

Hi

The field name should be Upper Case, try to indicate:

- the internal type: xfc-inttype = 'C

- the table name: xfc-tabname = 'ITAB'

U need to use the field-symbol in order' to fill it:

LOOP AT XFC.
   ASSIGN COMPONENT XFC-FIELDNAME OF STRCUTURE <WA> TO <VALUE>.
   
   CASE XFC-FIELDNAME.
     WHEN '........'.  <VALUE> = ...... 
     WHEN '........'.  <VALUE> = ...... 
     WHEN '........'.  <VALUE> = ...... 

<WA> has to be a field-symbol structured like your dynamic table:

ASSIGN dy_table->* to <itab>.

CREATE DATA DY_WA LIKE LINE OF <ITAB>.

ASSIGN DY_WA->* TO <WA>.

All caharacteristics of your table are in XFC, u can use it to write the header line.

Max

Read only

0 Likes
1,463

The code creates still the dump on calling

"cl_alv_table_create=>create_dynamic_table".

What should I give here

xfc-tabname = 'ITAB'. Have commented it out in the code.Without comment also it gives the same dump.

what should be given in the field xfc-tabname.

Have changed the code as follows according to the suggestion

xfc-fieldname = 'MAT'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = '15'.
"xfc-tabname = 'ITAB'.
APPEND xfc TO ifc.
CLEAR xfc.

xfc-fieldname = 'OPCO'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = '15'.
"xfc-tabname = 'ITAB'.
APPEND xfc TO ifc.
CLEAR xfc.

LOOP AT gt_monthcalc INTO gs_monthcalc.
  
  TRANSLATE gs_monthcalc-month to UPPER CASE.
  xfc-fieldname = gs_monthcalc-month.
  xfc-datatype = 'CHAR'.
  xfc-inttype = 'C'.
  xfc-intlen = '10'.
  "xfc-tabname = 'ITAB'.
  APPEND xfc TO ifc.
  CLEAR xfc.
ENDLOOP.

xfc-fieldname = 'TOTALCOUNT'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = '15'.
"xfc-tabname = 'ITAB'.
APPEND xfc TO ifc.
CLEAR xfc.



CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog = ifc
  IMPORTING
    ep_table        = dy_table.

Read only

0 Likes
1,463

Have found that the field catalog field inside my loop is causing the dump.

LOOP AT gt_monthcalc INTO gs_monthcalc.
  
  TRANSLATE gs_monthcalc-month to UPPER CASE.
  xfc-fieldname = gs_monthcalc-month.
  xfc-datatype = 'CHAR'.
  xfc-inttype = 'C'.
  xfc-intlen = '10'.
  "xfc-tabname = 'ITAB'.
  APPEND xfc TO ifc.
  CLEAR xfc.
ENDLOOP.

TYPES : BEGIN OF gty_monthcalc,

month TYPE c length 10,

END OF gty_monthcalc.

DATA gt_monthcalc TYPE TABLE OF gty_monthcalc.

DATA gs_monthcalc LIKE LINE OF gt_monthcalc.

No idea until now..still working...

Edited by: pazzuzu on Mar 16, 2010 4:15 PM

Edited by: pazzuzu on Mar 16, 2010 4:22 PM

Edited by: pazzuzu on Mar 16, 2010 4:22 PM

Read only

0 Likes
1,463

What are u meaning?

Max

Read only

0 Likes
1,463

Max,

If I comment out the field catalog in the loop

the call to CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = ifc

IMPORTING

ep_table = dy_table.

doesnt cause any dump.

I think it has to do with this

  • xfc-fieldname = gs_monthcalc-month.

statement inside the loop

gs_monthcalc-month is declared as follows:

TYPES : BEGIN OF gty_monthcalc,
          month TYPE  c length 30,
        END OF gty_monthcalc.

DATA gt_monthcalc TYPE TABLE OF gty_monthcalc.
DATA gs_monthcalc LIKE LINE OF gt_monthcalc.


xfc-fieldname = 'MAT'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = 10.
xfc-decimals = 0.
"xfc-tabname = 'ITAB'.
APPEND xfc TO ifc.
CLEAR xfc.

xfc-fieldname = 'OPCO'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = 10.
xfc-decimals = 0.
"xfc-tabname = 'ITAB'.
APPEND xfc TO ifc.
CLEAR xfc.

"LOOP AT gt_monthcalc INTO gs_monthcalc.
"
"  xfc-fieldname = gs_monthcalc-month.
"  xfc-datatype = 'CHAR'.
"  xfc-inttype = 'C'.
"  xfc-intlen = 10.
"  xfc-decimals = 0.
"  "xfc-tabname = 'ITAB'.
"  APPEND xfc TO ifc.
"  CLEAR xfc.
"
"ENDLOOP.

xfc-fieldname = 'TOTALCOUNT'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = 10.
xfc-decimals = 0.
"xfc-tabname = 'ITAB'.
APPEND xfc TO ifc.
CLEAR xfc.



CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog = ifc
  IMPORTING
    ep_table        = dy_table.

Edited by: pazzuzu on Mar 16, 2010 4:47 PM

Read only

0 Likes
1,463

I think the problem can be on how u call the field for the month: don't use the dot (so NOV.09, but NOV09), this sample works fine:

TYPES : BEGIN OF GTY_MONTHCALC,
          MONTH TYPE  C LENGTH 30,
        END OF GTY_MONTHCALC.

DATA GT_MONTHCALC TYPE TABLE OF GTY_MONTHCALC.
DATA GS_MONTHCALC LIKE LINE OF GT_MONTHCALC.


DATA IFC TYPE LVC_T_FCAT.
DATA XFC TYPE LVC_S_FCAT.

DATA DY_TABLE TYPE REF TO DATA.
DATA DY_WA    TYPE REF TO DATA.

FIELD-SYMBOLS: <FS_ITAB> TYPE TABLE,
               <FS_WA>   TYPE ANY,
               <FS_VAL>  TYPE ANY.

GS_MONTHCALC-MONTH = 'NOV09'. APPEND GS_MONTHCALC TO GT_MONTHCALC.
GS_MONTHCALC-MONTH = 'DIC09'. APPEND GS_MONTHCALC TO GT_MONTHCALC.
GS_MONTHCALC-MONTH = 'GEN10'. APPEND GS_MONTHCALC TO GT_MONTHCALC.
GS_MONTHCALC-MONTH = 'FEB10'. APPEND GS_MONTHCALC TO GT_MONTHCALC.
GS_MONTHCALC-MONTH = 'MAR10'. APPEND GS_MONTHCALC TO GT_MONTHCALC.
GS_MONTHCALC-MONTH = 'APR10'. APPEND GS_MONTHCALC TO GT_MONTHCALC.
GS_MONTHCALC-MONTH = 'MAY10'.  APPEND GS_MONTHCALC TO GT_MONTHCALC.

XFC-FIELDNAME = 'MAT'.
XFC-INTTYPE   = 'C'.
XFC-INTLEN    = '15'.
APPEND XFC TO IFC.

CLEAR XFC.
XFC-FIELDNAME = 'OPCO'.
XFC-DATATYPE  = 'CHAR'.
XFC-INTTYPE   = 'C'.
XFC-INTLEN    = '15'.
APPEND XFC TO IFC.

LOOP AT GT_MONTHCALC INTO GS_MONTHCALC.
  CLEAR XFC.
  XFC-FIELDNAME = GS_MONTHCALC-MONTH.
  XFC-INTTYPE = 'C'.
  XFC-INTLEN = '10'.
  APPEND XFC TO IFC.
ENDLOOP.


XFC-FIELDNAME = 'TOTALCOUNT'.
XFC-INTTYPE   = 'C'.
XFC-INTLEN    = '15'.
APPEND XFC TO IFC.



CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
  EXPORTING
    IT_FIELDCATALOG = IFC
  IMPORTING
    EP_TABLE        = DY_TABLE.

ASSIGN DY_TABLE->* TO <FS_ITAB>.

CREATE DATA DY_WA LIKE LINE OF <FS_ITAB>.
ASSIGN DY_WA->*    TO <FS_WA>.

LOOP AT IFC INTO XFC.
  ASSIGN COMPONENT XFC-FIELDNAME OF STRUCTURE <FS_WA> TO <FS_VAL>.
  READ TABLE GT_MONTHCALC TRANSPORTING NO FIELDS
    WITH KEY MONTH = XFC-FIELDNAME.
  IF SY-SUBRC = 0.
    <FS_VAL> = 'Month'.
  ELSE.
    <FS_VAL> = 'No Month'.
  ENDIF.
ENDLOOP.
APPEND <FS_WA> TO <FS_ITAB>.

LOOP AT <FS_ITAB> ASSIGNING <FS_WA>.
  WRITE: <FS_WA>.
ENDLOOP.

Max

Read only

0 Likes
1,463

max, Thank you very mucht....You almost made my day:).

I have 1 more question.Iam not going home until it is done....Will post in a few minutes

Read only

0 Likes
1,463

mAX thank you very much.......

Still I have 1 question in my mind....

Now I have the dynamic itab .is it posible to fill it like normal static itabs.

For example like a static one as follows.

DATA: gt_tab TYPE TABLE OF gty_cum_opco,
      gs_tab LIKE LINE OF gt_itab.

CLEAR gs_tab.
gs_tab-matnummer = '2001898892'.
gs_tab-soldto = 'A'.
gs_tab-month = 'Nov'.
gs_tab-dqty =  4.
gs_tab-kunnr =  '123'.
gs_tab-liefers =  '345'.
APPEND gs_tab TO gt_tab.

I have some quantities stored in the above itab for the month of "Nov".

When Iam Looping through this itab I have to write the Quantity into the corresponding month field of the dynamic tab.In this case the "Nov" Field.

So I have to do some thing like this:

loop gt_tab into gs_tab.

if gs_tab-month = 'Nov'.

dynITAB-nOV = 4.

endif.

endloop.

In your previous code you said something as follows, but as the months are dynamic(It could be in different years as well) so when calling

"when" statement in the following code what is the field name.Its dynamic I dont know.

LOOP AT XFC.
   ASSIGN COMPONENT XFC-FIELDNAME OF STRCUTURE <WA> TO <VALUE>.
   
   CASE XFC-FIELDNAME.
     WHEN '........'.  <VALUE> = ...... 
     WHEN '........'.  <VALUE> = ...... 
     WHEN '........'.  <VALUE> = ......

Read only

0 Likes
1,463

Hi

The way to fill your dynamic table it depends on howo you've defined it, so a possible solution can be:

loop gt_tab into gs_tab.
    CLEAR <FS_WA>.
* Move material code
    PERFORM MOVE_VALUE USING 'MAT' GS_TAB-MATNR.
* Get month field
    TRANSLATE GS_TAB-MONTH TO UPPER CASE.
* I suppose the 3 first character are the month name, the other 2 char are the year
    LOOP AT GT_MONTHCALC INTO GS_MONTHCALC    
         WHERE MONTH(3) = GS_TAB-MONTH.
    ENDLOOP.
    PERFORM MOVE_VALUE USING GS_MONTHCALC-MONTH gs_tab-dqty. 
    APPEND <FS_WA> TO <FS_ITAB>.
endloop.

FORM MOVE_VALUE  USING    P_FIELD
                          P_VALUE.
  ASSIGN COMPONENT P_FIELD OF STRUCTURE <FS_WA> TO <FS_VAL>.
  MOVE P_VALUE TO <FS_VAL>.
ENDFORM. 

Max

Read only

0 Likes
1,463

Max,

Iam confused now.....

Iam referring to the dynamic table you defined in your sample code

In your code for me the FS_iTAB is the itab and FS_WA is the work area.

The "GT_MONTHCALC" itab we dont need anymore,as It was used only to fill in the fieldcatalog with months.

loop gt_tab into gs_tab.
 
if gs_tab-month = 'Nov'.
 
FS_WA-nOV = 4. //I want to do this!! 

MODIFY FS_WA TO fS_itab. //This as well.
 
endif.
 
endloop.

Edited by: pazzuzu on Mar 16, 2010 6:50 PM

Read only

0 Likes
1,463

Now my head is getting clear.

I have an itab structure as follows filled with values.

Only 1 row is filled in this case as an example.

DATA: gt_tab TYPE TABLE OF gty_cum_opco,
      gs_tab LIKE LINE OF gt_itab.
 
CLEAR gs_tab.
gs_tab-matnummer = '2001898892'.
gs_tab-soldto = 'A'.
gs_tab-month = 'Nov'.
gs_tab-dqty =  4.
gs_tab-kunnr =  '123'.
gs_tab-liefers =  '345'.

APPEND gs_tab TO gt_tab.

Now I want to

copy the contents of the field "matnummer" to "mat" in fS_itab

copy the contents of the field "soldto" to "OPCO" in fS_itab

copy the contents of the field "dqty" to "NOV" in fS_itab

Thats what I need....:=)

Read only

0 Likes
1,463

Hi

I thought my sample was clear:

The "GT_MONTHCALC" itab we dont need anymore,as It was used only to fill in the fieldcatalog with months.

If I rember a your requisition is to create the name of the month concatening the short name and the year, something like this:

NOV09 DEC09 GEN10 FEB10 MAR10 APR10 ..........

In this case the fieldname of month of your dynamic table doesn't corrispond to value in gs_tab-month as here you have stored the short name of the month only.

I suppose if gs_tab-month is nov, the quantity has to move in the field called NOV09, if it's so it needs to get a link in order to know the real name of the moth field of dynamic table.

This link can be in GT_MONTHCALC only, because you've used it to create dynamic table.

Now I've create a routine to transfer the value from GS_TAN to <FS_WA>:

FORM MOVE_VALUE  USING    P_FIELD
                          P_VALUE.
  ASSIGN COMPONENT P_FIELD OF STRUCTURE <FS_WA> TO <FS_VAL>.
  MOVE P_VALUE TO <FS_VAL>.
ENDFORM.

P_FIELD is the name of dynamic table field

P_VALUE is the value to be transfered

Now I want to 
copy the contents of the field "matnummer" to "mat" in fS_itab
copy the contents of the field "soldto" to "OPCO" in fS_itab
................................................................................................

This requirement is easy because the name of the dynamic table are constant:

loop gt_tab into gs_tab.
    CLEAR <FS_WA>.
* Move material code
    PERFORM MOVE_VALUE USING 'MAT' GS_TAB-MATNUMMER.
*  Move soldto
   PERFORM MOVE_VALUE USING 'OPCO' GS_TAB-SOLDTO.
....................................

....................
copy the contents of the field "dqty" to "NOV" in fS_itab

In this case you need to move the value to FS_ITAB-NOV09, so:

......................
Found the name of dynamic table:
TRANSLATE FS_ITAB-MONTH TO UPPER CASE.

LOOP AT GT_MONTHCALC INTO GS_MONTHCALC.
   IF GS_MONTHCALC-MONTH(3) = FS_ITAB-MONTH.
* I found the right name
     EXIT.
  ENDIF.
ENDLOOP.
* Move qty 
PERFORM MOVE_VALUE USING GS_MONTHCALC-MONTH GS_TAB-DQTY.

I hope it's clear now

Max

Read only

0 Likes
1,463

Max... Thanks a lot for all the effort...Iam closing this thread . These things look a bit complicated as a beginner for me.Dont feel taken aback when I say something like that. Yesterday I was working late and today morning I thought abt a much simpler idea.

But sill I need help on that one.

I will be making a post on it soon.If time please have a look....