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

Internal table

Hi friends,

I have a doubt in building an internal table.

The scenario, is am getting an excel sheet with records.

I have to convert this excel format into one of sap format where the internal table should have two different structures.

Say for example, i read the 1st record from the excel, but i need to build an internal table with 2 structures i.e 2 line items now.

Convert single record from excel to 2 records in itab and each of these lines have differnent structures.

Hope am clear!!

Please help me in this

Thanks

Ramya

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Dec 04, 2007 at 11:53 PM

    You cannot create different different structures for the rows in the internal table. You can create 2 nested internal tables in the one main table. But it will not solve your problem.

    Instead of using same Internal table, Create two different table.

    Upload your file into first internal table which has the same structure as the EXCEL file.

    APPEND another table, which has a different structure, from the first table.

    Like:

    UPLOAD FILE TO ITAB1.

    LOOP AT ITAB1.

    MOVE ITAB1 TO ITAB2.

    APPEND ITAB2.

    ENDLOOP.

    YOu can use one of the field as the unique key which can relate both tables.

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

    • Try something like this...

      data: begin of itab2 occurs 0,
            ind,
      *     header field
            fld1(10),
      *     rec field
            fld2(10),
            end   of itab2.
            
      loop at itab.
        if header = 'X'.
          itab2-ind = 'H'.
          itab2-head = itab-head
          append itb2.
        else.
          itba2-ind = 'R'.
          itab2-head = itab-head
          append itb2.
        endif.
      endloop. 

      Regards,

      Naimesh Patel

  • Posted on Dec 05, 2007 at 01:55 AM

    Hi,

    Declare an internal table like this.

    data: begin of itab occurs0,

    data(500),

    end of itab.

    upload the data of the excel into this flat type internal table using GUI_UPLOAD etc.

    then do something like this.

    loop at itab-data.

    if <cond1>.

    split itab-data at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into itab1-field1

    itab1-field2 itab1-field3 itab1-field4....

    append itab1.

    clear itab1.

    endif.

    if <cond2>.

    split itab-data at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into itab2-field1

    itab2-field2 itab2-field3 itab2-field4....

    append itab2.

    clear itab2.

    endif.

    endloop.

    Regards,

    Ravi Kanth Talagana

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi I resolved by ownself.

      Declared an Internla table with a variable type string and using offset concept we can manage any kind of structure.

      here is the ex:

      DATA: BEGIN OF IT_CHECK_HEAD OCCURS 0,

      VALUE(255) TYPE C,

      END OF IT_CHECK_HEAD.

      LOOP AT IT_TAB.

      CALL FUNCTION 'CONVERSION_EXIT_PDATE_INPUT'

      EXPORTING

      INPUT = IT_TAB-DATE

      IMPORTING

      OUTPUT = DATE.

      IT_CHECK_HEAD-VALUE+0(1) = '1'.

      IT_CHECK_HEAD-VALUE+19(15) = IT_TAB-BANKID.

      IT_CHECK_HEAD-VALUE+34(18) = IT_TAB-ACCNO.

      IT_CHECK_HEAD-VALUE+55(8) = DATE.

      IT_CHECK_HEAD-VALUE+63(3) = IT_TAB-CURR.

      Comments: upload the data into an itab from tabdelimited file and push into it_check_head internal table using offset concept. so it_check_head has no of line items with each one of them having our own desined structures.

      LOOP AT IT_TAB.

      CALL FUNCTION 'CONVERSION_EXIT_PDATE_INPUT'

      EXPORTING

      INPUT = IT_TAB-DATE

      IMPORTING

      OUTPUT = DATE.

      IT_CHECK_HEAD-VALUE+0(1) = '1'.

      IT_CHECK_HEAD-VALUE+19(15) = IT_TAB-BANKID.

      IT_CHECK_HEAD-VALUE+34(18) = IT_TAB-ACCNO.

      IT_CHECK_HEAD-VALUE+55(8) = DATE.

      IT_CHECK_HEAD-VALUE+63(3) = IT_TAB-CURR.

      AT NEW BANKID.

      IF NOT IT_CHECK_HEAD-VALUE IS INITIAL.

      APPEND IT_CHECK_HEAD.

      ENDIF.

      ENDAT.

      CLEAR IT_CHECK_HEAD.

      IT_CHECK_HEAD-VALUE+0(1) = '5'.

      IT_CHECK_HEAD-VALUE+1(8) = DATE.

      IT_CHECK_HEAD-VALUE+9(13) = IT_TAB-CKNUM.

      REPLACE ALL OCCURRENCES OF ',' IN IT_TAB-AMT WITH ''.

      IT_TAB-AMT = IT_TAB-AMT * 100.

      CONDENSE IT_TAB-AMT.

      IT_CHECK_HEAD-VALUE+22(11) = IT_TAB-AMT.

      IT_CHECK_HEAD-VALUE+58(8) = DATE.

      APPEND IT_CHECK_HEAD.

      CLEAR IT_CHECK_HEAD.

      ENDLOOP.

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.