Application Development 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: 

Internal table

Former Member
0 Kudos
95

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

5 REPLIES 5

naimesh_patel
Active Contributor
0 Kudos
49

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

0 Kudos
49

hey thanks patel,

I am doing the same. But the scenario is as follwos:

I have itab1 same as excel format and uploading into it. This works perfect.

Now i want to move these contents to another internal table itab2.

Itab2 should have 2 strcutures Check_head and check_rec.

So i have to split the header record and check record from itab1 and put as two line items in the same table itab2.

how do i do this?

0 Kudos
49

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

former_member181962
Active Contributor
0 Kudos
49

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

0 Kudos
49

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.