Form itabtodataset (from White)

Source: Internet
Author: User
Tags dname
Form itabtodataset
From http://blog.chinaunix.net/u1/40527/showart.php? Id = 370362

Form itabtodataset tables intab
Using dname type C.
Data: TAB type X value '09 ',
Enter (2) Type X value '0d0a ',
Count (8) type N.
Data: Begin of headtab occurs 0,
Length type I,
Decimals type I,
Type_kind type C,
Name (30) type C,
End of headtab.
Data N type I.
Data descr_ref type ref to cl_abap_structdescr.
Field-Symbols: <comp_wa> type abap_compdescr,
<F_field>,
<F_intab> type any.
Data: Str type string,
Text1 type C.
Data: runtime type int4,
Repid like sy-repid.
Data: FLEN type I.
Field-Symbols: <dyn_table> type standard table,
<Dyn_wa>,
<Dyn_field>.
Data: dy_table type ref to data,
Dy_line type ref to data,
Xfc type lvc_s_fcat,
IFC type lvc_t_fcat.

Descr_ref? = Cl_abap_typedescr => describe_by_data (intab ).
Loop at descr_ref-> components assigning <comp_wa>.
Move-corresponding <comp_wa> to headtab.
Append headtab.
Endloop.
Loop at headtab.
FLEN = FLEN + headtab-Length + headtab-Decimals + 1.
Endloop.
Clear xfc.
Xfc-fieldname = 'line '.
Xfc-datatype = 'Char '. "Or xfc-inttype = 'C '.
Xfc-intlen = FLEN.
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 <dyn_table>.
Create data dy_line like line of <dyn_table>.
Assign dy_line-> * to <dyn_wa>.
Assign component 'line' of structure <dyn_wa> to <dyn_field>.

Describe table headtab lines n.

Loop at intab assigning <f_intab>.
Do n times.
Assign component sy-index of structure <f_intab> to <f_field>.
STR = <f_field>.
Read Table headtab index sy-index.
If headtab-type_kind = 'I' or headtab-type_kind = 'P'
Or headtab-type_kind = 'F '.
Search STR '-'.
If sy-subrc = 0 and sy-fdpos <> 0.
Split STR at '-' into STR text1.
Condense Str.
Concatenate '-'str into Str.
Else.
Condense Str.
Endif.
Else.
* Shift STR Left deleting leading '0 '.
Endif.
Concatenate <dyn_field> tab STR into <dyn_field>.
Enddo.
Shift <dyn_wa>.
Append <dyn_wa> to <dyn_table>.
Clear <dyn_wa>.
Count = count + 1.
Endloop.

Open dataset dname for output in binary mode.
If sy-subrc Ne 0.
Endif.

Loop at <dyn_table> into <dyn_wa>.
STR = <dyn_wa>.
Transfer STR to dname.
Transfer enter to dname.
Endloop.
Close dataset dname.
Endform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.