Application Development and Automation 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: 
Read only

Dynamic internal table or structure field type change dynamically

venkat_o
Active Contributor
0 Likes
1,183

Hi friends,

<li>I am creating dynamic internal table based on the table given on the Selection-screen input parameter.

PARAMETERS:P_TABLE TYPE RSRD1-TBMA_VAL.

<li>Creating dynamic internal table and dynamic structure like below

CREATE DATA GV_DREF TYPE TABLE OF (P_TABLE).
   ASSIGN GV_DREF->* TO <IT_DATA>.

   CREATE DATA GW_DREF LIKE LINE OF <IT_DATA>.
   ASSIGN GW_DREF->* TO <WA_DATA>.

Question:

Can I change dynamically created internal table field type to C(char) type ?

or

Actually I am developing generic program to download Infotype table table data. After creating dynamic table, is there any way to keep preceding Zeros to Employee number when you download to XLS file.

Regards,

Venkat.O

7 REPLIES 7
Read only

guillaume-hrc
Active Contributor
0 Likes
722

Hi,

Try adding simple quoite (') in front of numeric fields.

Haven't tried it yet but did you try ABAP2XLSX ?

/people/community.user/blog/2010/07/12/abap2xlsx--generate-your-professional-excel-spreadsheet-from-abap

Best regards,

Guillaume

Read only

0 Likes
722

Guillaume,

<li>The below code works fine. What I want is that after downloading, I must see preceding zeros for the PERNR field.

REPORT ZTEST_PROGRAM.
 DATA: GV_DREF TYPE REF TO DATA,
       GW_DREF TYPE REF TO DATA.
*FIELD-SYMBOLS
 FIELD-SYMBOLS: <IT_DATA> TYPE STANDARD TABLE,
                <WA_DATA> TYPE ANY.
 PARAMETERS:P_TABLE TYPE RSRD1-TBMA_VAL default 'PA0001'.
*" START-OF-SELECTION
 START-OF-SELECTION.

   CREATE DATA GV_DREF TYPE TABLE OF (P_TABLE).
   ASSIGN GV_DREF->* TO <IT_DATA>.

   CREATE DATA GW_DREF LIKE LINE OF <IT_DATA>.
   ASSIGN GW_DREF->* TO <WA_DATA>.

   SELECT * FROM (P_TABLE) INTO TABLE <IT_DATA>  UP TO 10 ROWS.

   CALL FUNCTION 'GUI_DOWNLOAD'
     EXPORTING
       FILENAME = 'C:\temp\test.txt'
       FILETYPE = 'ASC'
     TABLES
       DATA_TAB = <IT_DATA>.
   IF SY-SUBRC = 0.
     WRITE 'successfully downloaded'.
   ENDIF

.

Regards,

Venkat.O

Read only

0 Likes
722

I don't do HR so I can't see the field definition you refer to, but the format you're asking for should be automatic if it's stored that way in the DB.

After creating dynamic table, is there any way to keep preceding Zeros to Employee number when you download to XLS file.

But, you are not creating an XLS file, given the code that you showed; you are creating a fixed-width text file and the field formatiing should not change from the selected record to the downloaded record. How are you viewing the file after download? Are you forcing a field conversion during opening? What does Notepad show?

Read only

0 Likes
722

Hi,

I think you can create a fieldcatalog first using the table name

then change the datatype to 'C' from 'N' for the required fields.

You can then create your internal table using same fieldcatalog.

Check the below code for the reference,


CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_STRUCTURE_NAME       = TABLENM
      I_CLIENT_NEVER_DISPLAY = 'X'
    CHANGING
      CT_FIELDCAT            = T_FCAT_LVC.
*changes to fcat as required

 CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
      EXPORTING

         IT_FIELDCATALOG           = T_FCAT
       IMPORTING
         EP_TABLE                  = DY_TABLE
             .
     IF SY-SUBRC <> 0.
*      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.

Thanks,

Anmol Bhat.

Read only

0 Likes
722

Hi,

<li>Small correction

Changing file path

'C:\temp\test.txt'

to

'C:\temp\test.xls'

Regards,

Venkat.O

Read only

0 Likes
722

Hi Anmol,

<li> CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE has length restiction I believe.

Any how it does not serve my problem.

Regards,

Venkat.O

Edited by: Venkat.O on Nov 23, 2010 10:56 AM

Read only

0 Likes
722

u2022Small correction

That 'small correction' makes a huge difference in the question...since you have specified 'XLS' then Excel has assumed the field is numeric and dropped the leading zeros. Use RTTI to read the field definitions and format the cells accordingly before a binary download.