2024 Oct 23 9:37 PM
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.
PARAMETERS: p_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.
PARAMETERS: p_file TYPE localfile.
PARAMETERS: p_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.
DATA: vend_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.
CLEAR: excel_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(day) DATA(month) DATA(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.
CLEAR: vend_data_s.
ENDLOOP.
Facing issues as data is mismatched in uploaded excel file and my internal table vend_data_t.
Uploaded excel file:
Internal table: vend_data_t:
Data in table excel_t:
2024 Oct 24 12:30 AM
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).
2024 Oct 24 4:22 AM
Hi rr_dev,
Can you pleaser provide the full code to me.
2024 Oct 24 9:03 AM
Hii,
code changes required on a urgent basis, Can anyone please help with the logic.
2024 Oct 24 9:34 AM
Use some AT NEW-ENDAT and AT-END OF block to
This is basic Abap for itab, just look at the sample provided in SAP online documentation (or your Abap course)
2024 Oct 24 9:39 AM
Hi raymond_giuseppi,
where should i put AT NEW-INDAT and AT-ENDOF statements, inside CASE - ENDCASE or after ENDCASE
2024 Oct 24 9:45 AM
Usually those are the first and last blocks inside the LOOP-ENDLOOP
2024 Oct 24 9:49 AM
Hi raymond_giuseppi,
do u have any source for the documentation.
If u would help me edit the code, i would be grateful.
a month ago
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.
2024 Oct 24 10:06 AM
Hii,
This is an urgent requirement. Can anyone please help?
2024 Oct 24 3:01 PM
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
a month ago
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.
a month ago
Hi @rr_dev / @raymond_giuseppi ,
I used this code and my problem was resolved:
CLEAR: excel_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(day) DATA(month) DATA(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.
CLEAR: vend_data_s.
ENDAT.
ENDLOOP.
Thank you for your solutions.