Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Need help with the coding logic...?

Gurus,

I had written a program that uploads data from an excel file into the SAP custom tables..This FM works but we have to manually remove the headers out of the excel table..and insert a column for client within the excel file...so overall before loading the table i have to delete the heading s row and insert a extra column for client and fill it...

Now how shud i change my code that it automatically does this....is it possible...is there any FM that i have to use....Please give some inputs....

Right now the main FM's that i am using are: LVC_FIELDCATALOG_MERGE,METHOD cl_alv_table_create=>create_dynamic_table,TEXT_CONVERT_XLS_TO_SAP....

Please suggest...

Thnaks

Sam

Tags:
Former Member
Former Member replied

There is a simple fix for this.

The syntax checker cannot determine the structure statically, since the table is dynamic.

So we have to do it indirecty.

define a local structure with a single field MANDT, and move sy-mandt to that.

Next, do a move-corresponding from that structure. See below:

FORM get_data_from_excel  USING    rp_filenm TYPE dxlpath.
 
  DATA: v_filenm TYPE localfile.
  v_filenm = rp_filenm.

* define MANDT structure
  TYPES:  BEGIN OF ty_mandt_struct,
            mandt       TYPE mandt,
          END OF ty_mandt_struct.
  DATA: s_mandt TYPE ty_mandt_struct.

* Upload the excel document into internal table
 
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = t_raw_data
      i_filename           = v_filenm
      I_LINE_HEADER        = 'X'
    TABLES
      i_tab_converted_data = <f_dyn_table2>
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
 
  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN 1.
        MESSAGE i003 WITH 'Close the file if it is open'(029).
        LEAVE LIST-PROCESSING.
      WHEN OTHERS.
        MESSAGE i003 WITH 'Error in Reading File'(030).
        LEAVE LIST-PROCESSING.
    ENDCASE.
  ENDIF.
 
* loop at table 2 and move to original table, adding MANDT

*load MANDT into structure, this can be done one-time outside of loop
  s_mandt-mandt = sy-mandt.
  MOVE-CORRESPONDING s_mandt TO <f_dyn_wa>.

  LOOP AT <f_dyn_table2> ASSIGNING <f_dyn_wa2>.
    MOVE-CORRESPONDING <f_dyn_wa2> to <f_dyn_wa>.
    APPEND <f_dyn_wa> TO <f_dyn_table>.
  ENDLOOP.
 
ENDFORM.                    " get_data_from_excel

This fixes the problem.

Good luck

Brian

Add introductory comments, put code tags in, move MANDT logic

Message was edited by:

Brian Sammond

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question