Application Development and Automation 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: 
Read only

Problem while comparing two internal tables

Former Member
0 Likes
581

I have to modify work start date which are initial in the data base table for the records in the flat file.

my code is:

REPORT ZAUFK_WORKSTARTDATE_UPDATE .

  • Tables Declaration

TABLES: AUFK.

  • Type pools Declaration

TYPE-POOLS : SLIS.

  • Internal Table Declaration

DATA: I_AUFK LIKE AUFK OCCURS 0 WITH HEADER LINE,

IT_AUFK LIKE AUFK OCCURS 0 WITH HEADER LINE,

ITAB1 LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF I_AUFK1 OCCURS 0,

AUFNR(12),

AUART(4),

END OF I_AUFK1.

  • Data Declaration

DATA I_FIELDCAT TYPE SLIS_FIELDCAT_ALV OCCURS 0.

DATA WA_FCAT LIKE LINE OF I_FIELDCAT.

DATA: B1 TYPE I VALUE 1,

C1 TYPE I VALUE 1,

B2 TYPE I VALUE 256,

C2 TYPE I VALUE 65536.

  • Selection Screen Declaration

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.

SELECT-OPTIONS: S_AUFNR FOR AUFK-AUFNR,

S_AUART FOR AUFK-AUART.

PARAMETERS: P_USER7 LIKE AUFK-USER7 DEFAULT '20070101' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

PARAMETERS: R1 RADIOBUTTON GROUP G1 DEFAULT 'X' USER-COMMAND UCOMM1, " Upload using File Path

R2 RADIOBUTTON GROUP G1. " Uplaod using particular IO's

SELECTION-SCREEN END OF BLOCK B2.

  • To get F4 Help for File path on selection screen.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

IMPORTING

FILE_NAME = P_FILE.

  • To disbale the filepath when r2 radiobutton is selected

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

  • Check if R1 is checked

IF R1 = 'X'.

IF SCREEN-NAME = 'S_AUFNR-LOW' OR

SCREEN-NAME = 'S_AUFNR-HIGH' OR

SCREEN-NAME = 'S_AUART-LOW' OR

SCREEN-NAME = 'S_AUART-HIGH'.

  • Make the Internal order number and order type field disable from the selection screen

SCREEN-INPUT = '0'.

MODIFY SCREEN.

ENDIF.

ELSEIF R2 = 'X' AND SCREEN-NAME = 'P_FILE'.

  • Make the file path field disappear from the selection screen

SCREEN-INPUT = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

  • Start of executable code

START-OF-SELECTION.

  • To get the relavent IO data from the order master data table

SELECT *

FROM AUFK

INTO TABLE I_AUFK

WHERE AUFNR IN S_AUFNR

AND AUART IN S_AUART

AND ( AUART = '5200' OR AUART = '5500'

OR AUART = '5700' OR AUART = '8500'

OR AUART = '8700' ).

  • Table must be updated using flat file

IF R1 = 'X'.

  • To Upload Excel sheet data into an internal table

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FILE

I_BEGIN_COL = B1

I_BEGIN_ROW = C1

I_END_COL = B2

I_END_ROW = C2

TABLES

INTERN = ITAB1

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • To organize the data in the internal table(excel data) as per our requirement

PERFORM ORGANIZE_UPLOADED_DATA.

<b> LOOP AT I_AUFK1.

  • Comparing the excel data and the database table data

READ TABLE I_AUFK WITH KEY AUFNR = I_AUFK1-AUFNR.

IF SY-SUBRC EQ 0.

  • Check if the the work start date is initial(blank)

IF I_AUFK-USER7 IS INITIAL.

  • If work start is initial move the value in p_user7 to the work start date field in i_aufk

MOVE P_USER7 TO I_AUFK-USER7.

MODIFY I_AUFK.

  • Moving the data which is changed into it_aufk internal table(this table is for displaying the updated records)

MOVE-CORRESPONDING I_AUFK TO IT_AUFK.

APPEND IT_AUFK.

ENDIF.

ENDIF.

ENDLOOP.

endif.</b>

WA_FCAT-FIELDNAME = 'AUFNR'.

WA_FCAT-TABNAME = 'I_AUFK'.

WA_FCAT-SELTEXT_M = 'Internal Order Number'.

WA_FCAT-OUTPUTLEN = 12.

APPEND WA_FCAT TO i_fieldcat.

WA_FCAT-FIELDNAME = 'AUART'.

WA_FCAT-TABNAME = 'I_AUFK'.

WA_FCAT-SELTEXT_M = 'Order Type'.

WA_FCAT-OUTPUTLEN = 4.

APPEND WA_FCAT TO I_FIELDCAT.

WA_FCAT-FIELDNAME = 'KTEXT'.

WA_FCAT-TABNAME = 'I_AUFK'.

WA_FCAT-SELTEXT_M = 'Description'.

WA_FCAT-OUTPUTLEN = 40.

APPEND WA_FCAT TO I_FIELDCAT.

WA_FCAT-FIELDNAME = 'USER7'.

WA_FCAT-TABNAME = 'I_AUFK'.

WA_FCAT-SELTEXT_M = 'Work Start Date'.

WA_FCAT-OUTPUTLEN = 10.

APPEND WA_FCAT TO I_FIELDCAT.

  • Updating the AUFK(Internal Order Data Table) using i_aufk

*MODIFY AUFK FROM TABLE I_AUFK.

  • Check if the database table is modified

*IF SY-SUBRC = 0.

  • Display the modified data

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

I_GRID_TITLE = 'List of updated Records'

IT_FIELDCAT = I_FIELDCAT[]

TABLES

T_OUTTAB = IT_AUFK[]

EXCEPTIONS

PROGRAM_ERROR = 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.

ENDIF.

&----


*& Form ORGANIZE_UPLOADED_DATA

&----


  • text

----


FORM ORGANIZE_UPLOADED_DATA .

SORT ITAB1 BY ROW COL.

LOOP AT ITAB1.

CASE ITAB1-COL.

WHEN 1.

I_AUFK1-AUFNR = ITAB1-VALUE.

WHEN 2.

I_AUFK1-AUART = ITAB1-VALUE.

ENDCASE.

AT END OF ROW.

APPEND I_AUFK1.

ENDAT.

ENDLOOP.

LOOP AT I_AUFK1.

CONCATENATE '000000' I_AUFK1-AUFNR INTO I_AUFK1-AUFNR.

MODIFY I_AUFK1.

ENDLOOP.

ENDFORM. " ORGANIZE_UPLOADED_DATA

The bold are is were i'm facing problem. Please help me .its urgent.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
551

Hi try using the below code...

LOOP AT I_AUFK1.

  • Comparing the excel data and the database table data

READ TABLE I_AUFK WITH KEY AUFNR = I_AUFK1-AUFNR.

IF SY-SUBRC EQ 0.

  • Check if the the work start date is initial(blank)

IF I_AUFK-USER7 IS INITIAL.

  • If work start is initial move the value in p_user7 to the work start date field in i_aufk

MOVE P_USER7 TO I_AUFK-USER7.

[<u>b]MODIFY I_AUFK from i_aufk transporting user7.</b></u>

  • Moving the data which is changed into it_aufk internal table(this table is for displaying the updated records)

MOVE-CORRESPONDING I_AUFK TO IT_AUFK.

APPEND IT_AUFK.

ENDIF.

ENDIF.

ENDLOOP.

endif.

if you can't still solve some more questions

what is teh sy-subrc of teh read ..

what does the header line contain after teh read

and what happens after modify.. does the contents change?

6 REPLIES 6
Read only

Former Member
0 Likes
551

Hi,

Use MODIFY I_AUFK from I_AUFK transporting USER7.

after this no need of append or omve corresponding.

Thanks

Sandeep

Reward if helpful:)

Read only

Former Member
0 Likes
551

Hi

What is the problem you are facing?

Regards

Raj

Read only

0 Likes
551

my problem is for 1 table i get data from flat file only 2 fields.

2nd table gets data from database table

we need to compare the 2 tables and check if the work start date is initial.

if it is initial modify according to the selection screen parameter.

but i'm unable to do that.

Read only

former_member196280
Active Contributor
0 Likes
551

LOOP AT I_AUFK1.

  • Comparing the excel data and the database table data

READ TABLE I_AUFK WITH KEY AUFNR = I_AUFK1-AUFNR.

IF SY-SUBRC EQ 0.

  • Check if the the work start date is initial(blank)

IF I_AUFK-USER7 IS INITIAL.

  • If work start is initial move the value in p_user7 to the work start date field in i_aufk

MOVE P_USER7 TO I_AUFK-USER7.

MODIFY I_AUFK. <b>"This cannot be used</b>

  • Moving the data which is changed into it_aufk internal table(this table is for displaying the updated records)

MOVE-CORRESPONDING I_AUFK TO IT_AUFK.

APPEND IT_AUFK.

ENDIF.

ENDIF.

ENDLOOP.

endif.

Read only

Former Member
0 Likes
551

Could you be more specific what problem you are facing ..

my guess is may be the modify is not working.

try using modify with transporting field option and also you can give the index.

MODIFY i_aufk TRANSPORTING user7

Read only

Former Member
0 Likes
552

Hi try using the below code...

LOOP AT I_AUFK1.

  • Comparing the excel data and the database table data

READ TABLE I_AUFK WITH KEY AUFNR = I_AUFK1-AUFNR.

IF SY-SUBRC EQ 0.

  • Check if the the work start date is initial(blank)

IF I_AUFK-USER7 IS INITIAL.

  • If work start is initial move the value in p_user7 to the work start date field in i_aufk

MOVE P_USER7 TO I_AUFK-USER7.

[<u>b]MODIFY I_AUFK from i_aufk transporting user7.</b></u>

  • Moving the data which is changed into it_aufk internal table(this table is for displaying the updated records)

MOVE-CORRESPONDING I_AUFK TO IT_AUFK.

APPEND IT_AUFK.

ENDIF.

ENDIF.

ENDLOOP.

endif.

if you can't still solve some more questions

what is teh sy-subrc of teh read ..

what does the header line contain after teh read

and what happens after modify.. does the contents change?