Skip to Content

1 Create open hub as like below.

/wp-content/uploads/2012/12/1_170000.jpg

2 HEADER column is holding headers data and length is 200, you can change according to your requirement.

/wp-content/uploads/2012/12/2_170002.jpg

3 Do not map in transformation for Header column.

4 And write below ABAP code in End Routine

data: t_rs type standard table of _ty_s_TG_1.

data: wa_rs type _ty_s_TG_1.

clear: t_rs.

wa_rs-header = ‘HED;MATERIAL;MATERIAL_GROUP;MATERIAL_TYPE’.

append wa_rs to t_rs.

clear: wa_rs.

loop at RESULT_PACKAGE into wa_rs.

wa_rs-header = ‘Header’.

append wa_rs to t_rs.

endloop.

clear: RESULT_PACKAGE.

RESULT_PACKAGE[] = t_rs[].

5 we will get Flat file output as like below

HED, MATERIAL, MATERIAL_GROUP, MATERIAL_TYPE–> Header information

Header;LUX,ZBC,HC–> Actual data





To report this post you need to login first.

18 Comments

You must be Logged on to comment or reply to a post.

  1. Angélica Jiménez

    Hello Nanda!  Thanks  a lot, this worked perfectly for me but I didn´t add an xtra column (HEADER). I used the code on another field I already had.

    Regards! Angie

    (0) 
  2. Els Schepers

    Hi,

    At the end of my header line a lot of seperator signs (;) appear. How do you avoid this ?

    I checked the content of t_rs in the debugger, but it does not contain these signs. So, this happens when writing to the flatfile.

    2016-01-25 10_49_39-ZOH_TEST.CSV - Notepad.png

    Kind Regards,

    Els

    (0) 
      1. Els Schepers

        Hello,

        Here’s the code :

            DATA: t_rs TYPE STANDARD TABLE OF _ty_s_tg_1.

            DATA: wa_rs TYPE _ty_s_tg_1.

            TYPES : BEGIN OF ty_s_material,

                      material TYPE /bi0/oimaterial,

                      txtmd    TYPE rstxtmd,

                    END OF ty_s_material.

            DATA :

              lt_material TYPE TABLE OF ty_s_material,

              lr_material LIKE LINE OF lt_material.

            SELECT material txtmd FROM /bi0/tmaterial INTO TABLE lt_material

              FOR ALL ENTRIES IN RESULT_PACKAGE WHERE material =

              RESULT_PACKAGE-material

              AND langu = ‘F’.

            SORT lt_material BY material.

            CLEAR: t_rs.

            wa_rs-header =

        ‘HEAD;BP_ACTIVIT;SOLDFR;SOLDTO;MATERIAL;ARTDESC;CREATEDON;QUOTFROM’ &

        ‘;QUOTTO;DISTCHAN;SALESORG;DIVISION;DOC_CATEG;NETVAL;DOCCUR;’ &

        ‘AMTTTC;REASONREJ;GLOBSTAT’ .

            APPEND wa_rs TO t_rs.

            CLEAR: wa_rs.

            LOOP AT RESULT_PACKAGE INTO wa_rs.

              CLEAR lr_material.

              READ TABLE lt_material INTO lr_material

              WITH KEY material = wa_rs-material BINARY SEARCH.

              IF sy-subrc = 0.

                wa_rs-artdesc = lr_material-txtmd.

              ENDIF.

              CONDENSE wa_rs-net_value NO-GAPS.

              CONDENSE wa_rs-/bic/zamtttc NO-GAPS.

              DATA: var1 TYPE c LENGTH 25.

              var1 = wa_rs-material.

              SHIFT var1 LEFT DELETING LEADING ‘0’.

              wa_rs-material = var1.

              APPEND wa_rs TO t_rs.

            ENDLOOP.

            CLEAR: RESULT_PACKAGE.

            RESULT_PACKAGE[] = t_rs[].

        Kind Regards,

        Els

        (0) 
        1. Nanda Anantha Post author

          Hi Els,

          Code looks good no issues, my suggestion is keep debug the code after updating result_package to till it writes to flat file some where this values may generate and update

          Regards

          Nanda

          (0) 
          1. Els Schepers

            Hi Nanda,

            I think I know why this happens, but I can’t solve this..

            open hub issue.png

            If you look at the content through the debugger, you see that “Header” is as seperate column besides the other columns of which the values are seperated by “;”.

            So, if he writes the first line of the flatfile he only finds the content of column “Header” and adds blanks for each of the other colums. These values are seperated by “;”. This explains why you have ;;;;;;;… at the end of the first line.  Do you know how this can be avoided ?

            Kind Regards,

            Els

            (0) 
            1. Nanda Anantha Post author

              Hi Els,

              I’m sorry, if the values exist in RESULT_PACKAGE we can do something, since the values are not in RESULT_PACKAGE so we cannot do anything  however I will try to do same in my system when I get some free time.

              Regards

              Nanda

              (0) 
  3. José Luis López

    Hello.

    First I would like to thanks of this how to. It is very usefull and I am using it.

    But I have the same problem that Els. At the end of the header I have as “;” as fields I have in the file. The header is written in the first field because it is a char of 254 but in the file I have “header;;;;0;0;00;”

    Could you help me how to solve it. If I can solve it the procedure is nor valid for me.

    Thanks.

    (0) 
  4. Donnie Burhan

    Hi,

     

    In case that the result package is greater than one, then we need to make sure that the header line will only showing on the first data package, not the subsequent ones:

    If datapackid = '000001'
    
    //Insert your code here.
    
    Endif.

     

    (0) 

Leave a Reply