Skip to Content

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

How to do validation in Dynamic table update program?

Hi Experts,

I have a requirement to update any table by giving the table name, and an input file with table primary key and the field value need to update.

I am updating the table using the below code. Here I am getting the Primary keys and fields of the table using FM CACS_GET_TABLE_FIELDS.

But how can I check the full primary key of the table is available in the input file and corresponding entry is present in the table?

*--- Selection Screen
PARAMETERS: p_table
TYPE dd02l-tabname OBLIGATORY.
PARAMETERS: p_file
LIKE rlgrap-filename OBLIGATORY MEMORY ID ysm.


*--- Declarations for dynamic data
DATA gt_data TYPE REF TO data.
DATA GS_DATA TYPE REF TO data.

FIELD-SYMBOLS: <ft_data>
TYPE STANDARD TABLE,
<FS_DATA>
TYPE ANY.

START-OF-SELECTION.
*--- Create dynamic internal table
CREATE DATA gt_data TYPE TABLE OF (p_table).
ASSIGN gt_data->* TO <ft_data>.
*--- Create dynamic work area
CREATE DATA gs_data TYPE (p_table).
ASSIGN gs_data->* TO <fs_data>.
*--- Get Excel data in internal table
PERFORM f_convert_excel.
*--- Upload data to database table
PERFORM f_upload_table.
END-OF-SELECTION.


*&---------------------------------------------------------------------*
*& Form F_CONVERT_EXCEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_convert_excel .


DATA lt_raw_data TYPE truxs_t_text_data.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header =
'X'
i_tab_raw_data = lt_raw_data
i_filename = P_file
TABLES
i_tab_converted_data = <FT_DATA>
EXCEPTIONS
conversion_failed =
1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
" F_CONVERT_EXCEL


*&---------------------------------------------------------------------*
*& Form upload_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_upload_table.
SET UPDATE TASK LOCAL. " Switch to local update
LOOP AT <ft_data> ASSIGNING <fs_data>.
MODIFY (P_TABLE) FROM <FS_DATA>.
IF SY-SUBRC = 0.
GV_SUCCESS = GV_SUCCESS +
1.
ELSE.
delete <ft_data> index sy-tabix.
GV_ERROR = GV_ERROR +
1.
ENDIF.
ENDLOOP.
ENDFORM.
"upload_data

Regards,

Dipin

Former Member
replied

Hi Dipin,

F4_CONV_SELOPT_TO_WHERECLAUSE FM which help you to convert the value to dynamically.

Populate I_SELOPT as follows


I_SELOPT-SHLPNAME = You need to fill table name

I_SELOPT-SHLPFIELD      = you need to fill field name

I_SELOPT-SIGN           = I
I_SELOPT-OPTION         = EQ
I_SELOPT-LOW            = your internal table value for key field

APPEND  I_SELOPT.

Use FM 'F4_CONV_SELOPT_TO_WHERECLAUSE', pass I_selopt and get v_where.
 
Here V_WHERE will have the dynamic where clause.

   SELECT * FROM (fill table name dynamically)
             INTO table itab WHERE (V_WHERE).

Bu this way, you can check the entries in table with excel.

0 View this answer in context

Helpful Answer

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