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 columns in file

Former Member
0 Likes
510

My requirement is po upload using bapi.in that we hav to provide both presentation server and application server option in the selection screen.

If the presentation server option is selected then user can select the file type like Text or Excel.

File will contain field names in the first line of the fileu2026u2026for this we hav to declare one work area w1(each field 40 char) and we hav to move the header which hav field names to this work area.

The actual data starts from second line of the file.so for this we hav to declare another work area w2 with actual length and we hav to move the data from second line to this work area(w2).

Moving the data is based on the header i.e

If w1-header = indicator .

W2-poind = file-poind.

If w1-header = company code

W2-bukrs = file-bukrs.

So that the columns can be interchanged in the file and program can be executedu2026u2026

My requirement is po upload using bapi.in that we hav to provide both presentation server and application server option in the selection screen.

If the presentation server option is selected then user can select the file type like Text or Excel.

File will contain field names in the first line of the fileu2026u2026for this we hav to declare one work area w1(each field 40 char) and we hav to move the header which hav field names to this work area.

The actual data starts from second line of the file.so for this we hav to declare another work area w2 with actual length and we hav to move the data from second line to this work area(w2).

Moving the data is based on the header i.e

If w1-header = indicator .

W2-poind = file-poind.

If w1-header = company code

W2-bukrs = file-bukrs.

So that the columns can be interchanged in the file and program can be executedu2026u2026

2 REPLIES 2
Read only

Former Member
0 Likes
476

hi,

Use this code to upload data from Excel to internal table...

DATA l_count TYPE sy-tabix.

   CONSTANTS: lc_begin_col TYPE i VALUE '1',

              lc_begin_row TYPE i VALUE '2',

              lc_end_col   TYPE i VALUE '2',

              lc_end_row   TYPE i VALUE '3000'.

* Begin of CALK912848 - Carlos Werberich - 16Sep08

  CLEAR p_i_excel_data. REFRESH p_i_excel_data.

* End   of CALK912848 - Carlos Werberich - 16Sep08

* Function module to read excel file and convert it into internal table

   CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'

     EXPORTING

       filename                = p_p_file

       i_begin_col             = lc_begin_col

       i_begin_row             = lc_begin_row

       i_end_col               = lc_end_col

       i_end_row               = lc_end_row

     TABLES

       intern                  = i_data

     EXCEPTIONS

       inconsistent_parameters = 1

       upload_ole              = 2

       OTHERS                  = 3.

* Error in file upload

   IF sy-subrc NE 0 .

     MESSAGE text-006 TYPE 'E'.

     EXIT.

   ENDIF.

   IF i_data[] IS INITIAL .

     MESSAGE text-007 TYPE 'E'.

     EXIT.

   ELSE.

     SORT i_data BY row col .

* Loop to fill data in Internal Table

     LOOP AT i_data .

       MOVE i_data-col TO l_count .

       ASSIGN COMPONENT l_count OF STRUCTURE p_i_excel_data TO  .

       AT END OF row .

* Append data into internal table

         APPEND p_i_excel_data.

         CLEAR p_i_excel_data.

       ENDAT .

     ENDLOOP .

   ENDIF 

Read only

0 Likes
476

hi avinash,

for excel upload i shuld use only TEXT_CONVERT_XLS_TO_SAP function module.