Skip to Content
author's profile photo Former Member
Former Member

Filling fields in work area and counting fields

Hi,

1. I would like to know how to get the number of fields in an internal table by passing the table as input.

2. Then,

do 4 times.

move table-record index <..> to work_area-field1.

enddo.

the four records in table are four fields in the work area. Using the do loop i must fill the work area with data from the table. The workarea field names are generated dynamically by the program. Can any one help me with some suggestions and sample codes.

Thanks in advance.

Regards,

Kathir

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 25, 2004 at 07:34 AM

    Hi,

    I got the first problem solved. Just tell me how to append the data in <FS> (type any) to a work area <FS_1>

    that has 4 fields. Using a loop i am supposed to append data into the work area <FS_1> first and finally update it to the table <FS_data>. And i am using field symbols for all these operations.Hope i am clear. Please help me in this regard.

    Thanks in advance.

    Kathir.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      I shall take an example and let you know how to do this. I am guessing two things , let me know if I am correct.

      a) You are developing a report

      b) This report is about months which are stored as records and now to be displayed as columns.

      Consider an internal table like this:

      <b>LT_INTERNALTABLE</b>
       -------------------------------
      | <b>Type</b>   | <b>Month</b>  |  <b>Quantity</b> |
       -------------------------------
      | Sales  | Jan    |  20       |
      | Sales  | Feb    |  30       |
      | Sales  | Mar    |  10       |
       -----------------------------
      | Inven  | Jan    |  45       |
      | Inven  | Feb    |  60       |
      | Inven  | Mar    |  75       |
       -----------------------------
      | Distr  | Jan    |  35       |
      | Distr  | Feb    |  45       |
      | Distr  | Mar    |  60       |
       -----------------------------
      

      There are nine records in the internal table which you have fetched from the database. However, you do not want to show this in the given format, but you want to show it something similar to this:

      <b>Sales</b>
      ------
      Jan     Feb       Mar
      20      30        10
      
      <b>Inventory</b>
      ---------
      Jan     Feb       Mar
      45      60        75
      
      <b>Distribution</b>
      ------------
      Jan     Feb       Mar
      35      45        60
      

      Let me know if I have got this part correct.(I would also wish if you could state your problem as clearly as possible, as I have stated my assumption ). This could have additional fields like MATNR(Material number) etc.. so that the number of entries in the above table will be more than 1.

      Coming back to your query, if this is what you intend to do, then it is a slightly tricky approach.

      You mentioned that you have created the internal table in runtime. If you are having any problems with that refer to this :

      /people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

      Let us say the original internal table with data is

      a) <b>LT_INTERNALTABLE</b> - Original Internal Table

      b) <b><FS_INTERNALTABLE></b> - Dynamic Internal Table that you have created

      c) <b><FS_WORKAREA></b> - Work area of type <FS_INTERNALTABLE>

      d) <b><FS_FIELD></b> - Field symbol which accesses each field of <FS_INTERNALTABLE>

      e) <b><FS_WORKAREA></b> has first field as TYPE

      count = 2.  "Since FS_WORKAREA has first field as type,
                  "need to start putting values from 2 onwards
      
      SORT LT_INTERNALTABLE BY TYPE.
      LOOP AT LT_INTERNALTABLE INTO WA_INTERNALTABLE.
      
         AT NEW TYPE.
         <FS_WORKAREA>-TYPE = WA_INTERNALTABLE-TYPE.
         ENDAT.
      
         ASSIGN COMPONENT count of STRUCTURE <FS_WORKAREA> TO <FS_FIELD>.
         if sy-subrc = 0.
            <FS_FIELD> = WA_INTERNALTABLE-QUANTITY.
            count = count + 1
         else.
            clear count.
            APPEND <FS_WORKAREA> TO <FS_INTERNALTABLE>.
         endif.
      
      ENDLOOP.
      

      Let us know if this works, or have I gone tangent.

      Regards,

      Subramanian V.

  • Posted on Dec 23, 2004 at 12:35 PM

    Hi Kathir,

    DO.

    ASSIGN COMPONENT SY-INDEX OF STRUCTURE tab TO <F>.

    IF SY-SUBRC <> 0.

    EXIT.

    ELSE.

    add 1 to count. "1)

    *2)

    if count = x.

    assign COMPONENT count OF STRUCTURE wa TO <W>.

    *move table-record index <..> to work_area-field1.

    <w> = <f>.

    endif.

    enndo.

    grx Andreas

    P.S.

    merry christmas and a happy new year to all SDN's

    SAP's and ABAP's

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2004 at 12:56 PM

    Hi Andreas,

    My first problem is solved. Lte me put things clear for the second case,

    I created a table (<FS_DATA>) dynamically and assigned it to a new symbol <FS_1>.

    Now,

    do count times.

    move table-record1 index <..> to <FS_1>-field1.

    enddo.

    now table-record1 should go to <FS_1>-Field1,

    table-record2 should go to <FS_1>-Field2,

    The Problem is that the number of fields in the work area is not fixed. So i need a generalized code such that if there 4 fields in <FS_1> then those four fields should be filled automatically using a loop. ie <FS_1>-Field1, <FS_1>-Field2...are to be referred in a dynamic manner.

    Thanks in advance.

    Kathir.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Kathirvel,

      Andreas has given the code for changing work area, as you desire. If you see the

      DO.
      ASSIGN COMPONENT SY-INDEX OF STRUCTURE <structure_name> to <FS>
      if sy-subrc <> 0.
         exit.
      endif.
      ENDDO.
      

      What the above code does is, SY-INDEX starts with 1, and assigns the first field of <structure_name> to the field-symbol and this continues as long as that assign does not fail. So if your structure keeps on varying, it does not matter. At the point where it fails, it will exit.

      In case your question is answered, make sure you give Andreas his deserved points. It is Christmas after all.

      Regards,

      Subramanian V.

      P.S. - Merry Christmas to everyone here and a HAPPY NEW YEAR too.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2004 at 03:11 AM

    Yes.. I got the problem fixed. Thanks a lot Andreas and Subramanian.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.