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: 

flat file with header and item data to the internal tables

Former Member
0 Kudos

experts help needed

i am having a flat file like this in application server.

if the first field is hd then it represents header and items is represented by it.

Now i want to download this into internal table.

hd ponumber11 customernumber podate deliverydate

it material1 materialtext quantity price plant

it material2 materialtext quantity price plant

it material3 materialtext quantity price plant

hd ponumber21 customernumber podate deliverydate

it material1 materialtext quantity price plant

it material2 materialtext quantity price plant

it material3 materialtext quantity price plant

hd ponumber31 customernumber podate deliverydate

it material1 materialtext quantity price plant

it material2 materialtext quantity price plant

it material3 materialtext quantity price plant

1)Do i need to declare 2 internal tables or one ie one for header and another for item or single internal table with all the fields?

2)if i declare 2 interanl tables how to check ie which is header and which is item and how to populate into interanl table from the application server file?

READ DATASET file INTO itab_header . " if i say like this it will be problem because we are having two differnet structures in flat file ie header and item, so please help

3)after downlaoding to 2 internal tables how can i know which items belong to which header?

but by seeing the flat file we can say below hd all the items belong to that header etc.

so please me , how many tables i want and how to populate into itabs using read data set and how to know which items belongs to which header , because with this data i need to crea te the sales orders..

1 ACCEPTED SOLUTION

former_member559067
Participant
0 Kudos

Govaabaper,

You need to declare 3 different internal tables, One for Header Details, One for Item Details, and One for the final data which will be passed for further process (Consisting of Header and Line Item Details accordingly).

Do one think when ever the file is downloaded, you should check for the Initial Text of the row/record. You should Check for Indicator "HD" - Header "IL"- Line Item. Use Indicator or a flag to check whether it is a header or line item and move the data into the respective internal tabels of header and line items.

File Format should be

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

While downloading the file check for the data in the row, based on the indicator extract the data into HEADER intrenal table Or Line Item Internal table.

Anmol Saxena.

Edited by: Anmol Saxena on Oct 7, 2009 9:00 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:02 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:03 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:04 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:05 AM

10 REPLIES 10

Former Member
0 Kudos

depends upon what you need, you need them in two tables or one?

just to pass to internal tables, only one table is enough. you can declared the fields for internal table as string.

data : begin of itab,
             hdit       type string, " this can take hd or it
             pomat      type string,  " this can take ponum or mat number
             custdesc   type string,   "this can tke customer or mat desc
             pdtqty     type string,   "this can take podate or qty
             ddtprice   type string,  "delivery date/ price
             plant      type string,    "plant(only for items) else blank
         end of itab.

while reading the table you can check the first field and work as you need.

0 Kudos

thank you sowmya for the reply.

if i declare two internal tables then how to use the read data set to populate header into one table and item into another table.

if i have populated the data from file into 2 tables , how can i identify which items belongs to which header.

please help

0 Kudos

the HD and IT is your identifier for header and item.. right?

fetch every thing to one table and then split them into two tables using a loop in the fetched table.

0 Kudos

yes HD and IT is my identifer.

how to put into two tables at this statement readdatastatement?

first declaring a table and then looping it to fill another 2 tables or directly fill the 2 tables at the read dataset statement, whcih is the best , because after reading that once again anyway I need to again prepare a final internal table with header and item data with common indicator in them here i will place my po number in items also here i will remove hd and it, for example like below.

ponumebra kunnr podate deliverydate

ponumber item1 material1 materialtext qty

ponumbera item2 material2 materialtext qty

ponumberb kunnr podate deliverydate

ponumberb item1 material1 materialtext qty

ponumberb item2 material2 materialtext qty

so now it will be easy for me to identify with items belongs to which orders,

the similar code i have shown below , so please help me how to handle this issue

1)first getting the file

2)populating into final table

3)and passing the header and item info in the loop so that my fun module will take the header and multiple items data and create an order.

loop at itab into workarea.

MOVE-CORRESPONDING itab to itab1.

APPEND itab1.

CLEAR itab1.

at END OF po.

***now i will be having header and item for one sales order

edi_dd40-segnum = 1.

edi_dd40-segnam = 'E2EDK14 '.

edi_dd40-mandt = sy-mandt.

edi_dd40-psgnum = psgnum.

e2edk14-qualf = '008' .

e2edk14-orgid = 'NN21.

MOVE e2edk14 TO edi_dd40-sdata.

append edi_dd40 to itab_output.

edi_dd40-segnum = 1.

edi_dd40-segnam = 'E2EDK14 '.

edi_dd40-mandt = sy-mandt.

edi_dd40-psgnum = psgnum.

e2edk14-qualf = '006' .

e2edk14-orgid = 'ni.

MOVE e2edk14 TO edi_dd40-sdata.

append edi_dd40 to itab_output.

"Call your function module MAST_IDOC_DISTRIBUTE and pass the above data

"and itab1 data which has only one perticular PO data.

CLEAR itab1[].

endat.

ENDLOOP.

0 Kudos

use a single do endo. and two internal tables.

do

read the dataset into a string,

if first two chars are 'HD'

pass the string to HEADER internal table

elseif first two chars are 'IT'

pass the string to ITEM internal table

endif.

enddo.

former_member559067
Participant
0 Kudos

Govaabaper,

You need to declare 3 different internal tables, One for Header Details, One for Item Details, and One for the final data which will be passed for further process (Consisting of Header and Line Item Details accordingly).

Do one think when ever the file is downloaded, you should check for the Initial Text of the row/record. You should Check for Indicator "HD" - Header "IL"- Line Item. Use Indicator or a flag to check whether it is a header or line item and move the data into the respective internal tabels of header and line items.

File Format should be

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

|HD| Header Details1|Header Details2|Header Details3|Header Details4|Header Details5|Header Details6|Header Details7|

|IL| Item Details1|Item Details2|Item Details3|Item Details4|Item Details5|Item Details6|Item Details7|

While downloading the file check for the data in the row, based on the indicator extract the data into HEADER intrenal table Or Line Item Internal table.

Anmol Saxena.

Edited by: Anmol Saxena on Oct 7, 2009 9:00 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:02 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:03 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:04 AM

Edited by: Anmol Saxena on Oct 7, 2009 9:05 AM

Clemenss
Active Contributor
0 Kudos

Hi Gova,

I would go for one internal table with one component that is another internal table, i.e. like this:

TYPES:
  begin of ty_header,
    header_component_1 type whatever,
    header_component_2 type whatever,
    header_component_3 type whatever,
    header_component_n type whatever,
  end of  ty_header,
  begin of ty_item,
    item_component_1 type whatever,
    item_component_2 type whatever,
    item_component_3 type whatever,
    item_component_n type whatever,
  end of  ty_item,
  ty_t_item type table of ty_item,
  begin of ty_whole object,
    header type ty_header,
    t_item type ty_t_item,
  end of ty_whole object,
  ty_t_whole object type table of ty_whole object.

data:
  ls_item         type ty_item,
  ls_whole_object type ty_whole_object,
  lt_whole_object type ty_t_whole_object,
  lv_datrec       type string.
field-symbols:
  <whole_object>  type ty_whole_object, 
  <header>        type ty_header, 
  <item>          type ty_item, 
do.
  read dataset file into lv_datrec.
  if sy-subrc NE 0.
    exit.
  endif.
  case lv_datrec(2).
    when 'HD'.
* put data into ls_whole_object-header, your job    
      append ls_whole_object to lt_whole_object.   
    when 'IT'.
* put data into ls_item, your job 
      append ls_item TO ls_whole_object-t_item.   
  endcase.
enddo.

loop at lt_whole_object assigning <whole_object>.
* process header, your job
  loop at <whole_object>-t_item assigning <item>. 
* process item, your job
  endloop.
endloop

Now you have a nice, transparent and clean solution without trouble to get headers and items mixed, always having the right items under the right header.

Precondition: Your input file is not mixed up.

Regards,

Clemens

Former Member
0 Kudos

Hi,

1) U can use read dataset and check the first few (2) characters of row.

If it is header, populate into 1 internal table.

If it is item, populate/ append into another itab.

2) For creating bdc etc, u can use nested loop uisng loop at where and use the primary key. before loop, pls sort the tables.

Thanks,

Rupalee

Former Member
0 Kudos

You are talking about changing a hierarchical structured data into a relational structured data. The only way you can do that is to add the PO number to the item table also. So any of the solutions provided by others will work but not without adding the PO number to the item table.

loop at file.

append header data to header_tab.

move po number to item table and move the rest of the item data.

append item data to item tab.

endloop.

0 Kudos

Hi Srinivas,

thank you for the abstract explanation.

I hope you do not feel insulted if I add a correction to your statement.

You may have noticed, that

my solution

does not change the hierarchical structured data into a relational structured data but stores the hierarchical structured file data into a hierarchical structured internal table data.

This is the reason I do not need any corresponding number.

If you do not have numbers in your file data, any of your preferred solutions must create an artificial sequence number.

My solution does not require this and can make use of the internal numbering provided by SAP when creating documents.

Kind regards,

Clemens