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: 

How to upload a Excel document in background mode

Former Member
0 Kudos

Hello there, how are you?

I am doing an interface program that needs to upload an excel document into an internal table, to do this I used the FM ALSM_EXCEL_TO_INTERNAL_TABLE. The problem with this FM is that only works in foregroung mode, If I run the programin bcakground the FM does not work.

I would like to know if exist a way to upload an excel document into an internal table, for a program that have to be execute in background mode.

Thanks in advance

Best Regards

Alexis Ramirez

9 REPLIES 9

former_member156446
Active Contributor
0 Kudos

if you are having any GUI interface, program will not execute successfully in background

you need to place the file in app server and find an option to pull data from xcel file on application server.

0 Kudos

The file is in the application server, but still the FM does not work.

0 Kudos
&---------------------------------------------------------------------*

*& Form application_server

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*FORM APPLICATION_SERVER .

TYPE-POOLS: KCDE.

DATA : lt_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.*DATA : INTERN1 TYPE KCDE_INTERN.FILE = PATH.

OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.**--- Display error messages if any.IF SY-SUBRC NE 0.

MESSAGE E001(ZSD_MES).

EXIT.* ENDIF.ELSE.

DO.

READ DATASET FILE INTO Wa_TAB.

append wa_tab to IT_TAB.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

clear wa_TAB.

LOOP AT IT_TAB into wa_tab.

CASE wa_tab-COL.

WHEN '0001'.

WA_TAB2-PLANT = wa_tab-VALUE.

WHEN '0002'.

WA_TAB2-STGE_LOC = wa_tab-VALUE.

WHEN '0003'.

WA_TAB2-MATERIAL = wa_tab-VALUE.

WHEN '0004'.

WA_TAB2-QUANTITY = wa_tab-VALUE.

WHEN '0005'.

WA_TAB2-BASE_UOM = wa_tab-VALUE.

WHEN '0006'.

WA_TAB2-COSTCENTER = wa_tab-VALUE.

ENDCASE.

AT END OF ROW.

APPEND WA_TAB2 TO IT_TAB2.

CLEAR WA_TAB2.

ENDAT.

clear wa_tab.

ENDLOOP.

ENDIF.

CLOSE DATASET FILE.

ENDFORM. " application_server

Refer here:[How to Read Excel file from Application or Presentation Server and Download into Internal Table. |https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/how%252bto%252bread%252bexcel%252bfile%252bfrom%252bapplication%252bor%252bpresentation%252bserver%252band%252bdownload%252binto%252binternal%252btable.]

Former Member

Former Member
0 Kudos

You can't upload a file from presentation server in background mode.

but if you know the specific path and system where the file is store. I think we can configure that in AL11, create a file in the application directory specifying the path of that folder. The basis people will be able to do that.

and you can use open dataset / read dataset command afterwards to read the file.

0 Kudos

HI Navneet, the excel docuemt is already in the application server. How can I read and excel document using Dataset commands.

Thnaks

Alexis

0 Kudos

DATA : ITAB TYPE standard TABLE OF ALSMEX_TABLINE,

ITAB_LINE LIKE LINE OF ITAB.

OPEN DATASET <File name> FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc EQ 0.

DO.

READ DATASET FILE INTO ITAB_LINE.

IF SY-SUBRC <> 0.

EXIT.

ELSE.

APPEND ITAB_LINE TO ITAB.

ENDIF.

ENDDO.

CLOSE DATASET FILE.

After this you need to loop on ITAB and append this data to original table based on the col number, there is a field COL into the ITAB.

0 Kudos

Hi Navneet, I implemnet your code but I get an error when the program execute READ DATASET p_file0 INTO itab_line.

Runtime Errors CONVT_CODEPAGE

Except. CX_SY_CONVERSION_CODEPAGE

Short text

A character set conversion is not possible.

What happened?

At the conversion of a text from codepage '4110' to codepage '4103':

- a character was found that cannot be displayed in one of the two

codepages;

- or it was detected that this conversion is not supported

The number of characters that could not be displayed (and therefore not

be converted), is 1150. If this number is 0, the second error case, as

mentioned above, has occurred.

former_member376453
Contributor
0 Kudos

Suppose you want to upadte the data into an internal table itab_record.


" Open the Application server file p_apath is your application server path
  OPEN DATASET p_apath FOR INPUT IN TEXT MODE ENCODING DEFAULT.
"-- File can not be opened successfully
  IF sy-subrc NE 0.                                         " I(1)
    MESSAGE i099.            " File could not be opened
    LEAVE LIST-PROCESSING.
  ENDIF.                                                    " I(1)

  DO.                                                       " L(1)
    TRY.
" Read the Application server file
        READ DATASET p_apath INTO wa_record-rec_line .
          IF sy-subrc EQ 0.                                
"-- Populating Internal table 'itab_record'
          APPEND wa_record TO itab_record.
          CLEAR wa_record.
        ELSE.                                               " I(2)
          EXIT.                      " Otherwise Exit from block
        ENDIF.                                              " I(2)
      CATCH cx_root.                                     "#EC CATCH_ALL
        MESSAGE i100.                " Data could not be read
        LEAVE LIST-PROCESSING.
    ENDTRY.
  ENDDO.                                                    " L(1)

" Close the Application server file
  CLOSE DATASET p_apath.