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: 

Error in uploaded excel file into internal table through FM 'ALSM_EXCEL_TO_INTERNAL_TABLE'

Rangan
Explorer
0 Kudos
558

Hi, I have this ABAP code with me:

Please help to resolve this issue, required images are provided at the end.

REPORT ztest_009.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
  PARAMETERSp_radio1 RADIOBUTTON GROUP rad1 DEFAULT 'X' USER-COMMAND rad,
              p_radio2 RADIOBUTTON GROUP rad1.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
  PARAMETERSp_file TYPE localfile.
  PARAMETERSp_run AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b2.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name p_file.

AT SELECTION-SCREEN.

  IF p_radio1 'X' AND  p_file IS INITIAL.
    MESSAGE 'Please upload Excel File for excecution' TYPE 'E'.
  ENDIF.

START-OF-SELECTION.

  DATAvend_data_t        TYPE TABLE OF ztmd_lve_ven_vsr,
        vend_data_s        TYPE ztmd_lve_ven_vsr,
        filename           TYPE rlgrap-filename,
        display_errors_t   TYPE TABLE OF string,
        display_errors_s   TYPE string,
        excel_t            TYPE TABLE OF alsmex_tabline,
        excel_s            TYPE alsmex_tabline,
        lt_output          TYPE TABLE OF ztmd_lve_ven_vsr,
        lt_duplicate_check TYPE TABLE OF ztmd_lve_ven_vsr.
*        split_lifnr        TYPE char10.


  filename p_file.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename    filename
      i_begin_col 1
      i_begin_row 2
      i_end_col   5
      i_end_row   1000
    TABLES
      intern      excel_t
*  EXCEPTIONS
*     INCONSISTENT_PARAMETERS       = 1
*     UPLOAD_OLE  = 2
*     OTHERS      = 3
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here

    MESSAGE'upload excel' TYPE 'E'.

  ENDIF.

  CLEARexcel_s.
  LOOP AT excel_t INTO excel_s.
    CASE excel_s-col.
      WHEN 1.
        vend_data_s-lifnr excel_s-value.
      WHEN 2.
        vend_data_s-ltsnr excel_s-value.
      WHEN 3.
        vend_data_s-zind excel_s-value.
      WHEN 4.
        IF excel_s-value IS NOT INITIAL.
          SPLIT excel_s-value AT '.' INTO DATA(dayDATA(monthDATA(year).
          vend_data_s-zvalfrom year && month && day" Convert to YYYYMMDD
        ENDIF.
      WHEN 5.
        IF excel_s-value 'X'.
          DELETE FROM ztmd_lve_ven_vsr WHERE lifnr vend_data_s-lifnr AND ltsnr vend_data_s-ltsnr.
        ENDIF.

    ENDCASE.
    APPEND vend_data_s TO vend_data_t.

    CLEARvend_data_s.

  ENDLOOP.

 

Facing issues as data is mismatched in uploaded excel file and my internal table vend_data_t.

Uploaded excel file:

image (1).jpg

Internal table: vend_data_t:

image (2).jpg

Data in table excel_t:

image (8).png

12 REPLIES 12

rr_dev
Discoverer
0 Kudos
515

Ok.
Inside your LOOP AT excel_t INTO excel_s, is missing both AT NEW ROW (start from zero your structure) and AT END OF row (append the completed structure to your table).

Rangan
Explorer
0 Kudos
469

Hi rr_dev,

Can you pleaser provide the full code to me.

0 Kudos
434

Hii, 

code changes required on a urgent basis, Can anyone please help with the logic.

raymond_giuseppi
Active Contributor
0 Kudos
429

Use some AT NEW-ENDAT and AT-END OF block to

  • initialize record for a new one, in AT NEW block 
  • Only append the final record to final itab, in AT END OF block

This is basic Abap for itab, just look at the sample provided in SAP online documentation (or your Abap course)

0 Kudos
427

Hi raymond_giuseppi,

where should i put AT NEW-INDAT and AT-ENDOF statements, inside CASE - ENDCASE or after ENDCASE

0 Kudos
423

Usually those are the first and last blocks inside the LOOP-ENDLOOP

  • Except when AT FIRST/LAST-ENDAT block are used
  • Check the sample of online documentation)

Rangan
Explorer
0 Kudos
419

Hi raymond_giuseppi,

do u have any source for the documentation.

If u would help me edit the code, i would be grateful.

0 Kudos
192

Do not use Answer to respond to a command or answer. Answer is intended to be used to propose a solution to the initial question. Use Comment instead.

Rangan
Explorer
0 Kudos
411

Hii,

This is an urgent requirement. Can anyone please help?

rr_dev
Discoverer
0 Kudos
345

Please remind this: you must check SO posts or ABAP tutorials (without mentionining GPT) for this kind of exercises. SAP Community is always ready to help anyone, but 1) your must have done all your effort in order to check solutions before... this must be your last resource (you may find another posts for advanced questions more involved with ABAP).

sort excel_t by row col.
LOOP AT excel_t INTO excel_s.

AT NEW row.
IF vend_data_s-lifnr is not initial."
APPEND vend_data_s TO vend_data_t.
ENDIF.
CLEAR vend_data_s.
ENDAT.

CASE excel_s-col.
WHEN 1.
WHEN 2.
WHEN 3.
vend_data_s-zind = excel_s-value. " Indicator field
WHEN 4.
IF excel_s-value IS NOT INITIAL.
" Split and convert date from DD.MM.YYYY to YYYYMMDD
SPLIT excel_s-value AT '.' INTO DATA(day) DATA(month) DATA(year).
vend_data_s-zvalfrom = year && month && day. " Convert to YYYYMMDD
ENDIF.
WHEN 5.
IF excel_s-value = 'X'.
" Perform deletion logic based on the key fields
DELETE FROM ztmd_lve_ven_vsr
WHERE lifnr = vend_data_s-lifnr
AND ltsnr = vend_data_s-ltsnr.
ENDIF.
ENDCASE.
ENDLOOP

.Greetings

rr_dev
Discoverer
0 Kudos
205

Please in case any of the answers of this post was helpful, you can close this post or maybe give us any comments about.
Greetings.

 

Rangan
Explorer
168

Hi @rr_dev / @raymond_giuseppi ,

I used this code and my problem was resolved:

CLEARexcel_s,vend_data_s.

  LOOP AT excel_t INTO excel_s .

    CASE excel_s-col.
      WHEN 1.
        vend_data_s-lifnr excel_s-value.
      WHEN 2.
        vend_data_s-ltsnr excel_s-value.
      WHEN 3.
        vend_data_s-zind excel_s-value.
      WHEN 4.
        SPLIT excel_s-value AT '.' INTO DATA(dayDATA(monthDATA(year).
        vend_data_s-zvalfrom year && month && day.
      WHEN 5.
        vend_data_s-deletion_ind excel_s-value.

    ENDCASE.
    AT END OF row.
      APPEND vend_data_s TO vend_data_t.
      CLEARvend_data_s.
    ENDAT.

  ENDLOOP.

Thank you for your solutions.